It is currently Thu Jun 20, 2013 4:12 am

 All times are UTC

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Collisoin detectionPosted: Fri Jan 11, 2013 5:54 pm
 Rookie

Joined: Fri Jan 11, 2013 5:47 pm
Posts: 3
Hi
I need some help with my program, i am using a 2d array to make pacman for the gameboy advanced.

i have made the array to look like the map with 1's being the walls and 0's being empty spaces (no enemies or that yet just trying to get this right first).

im not sure how to do the collision detection, i can make pacman move but dont know how to stop him going through the walls

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 6:11 pm
 Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
Just keep track of pacmans direction (x = {-1,0,1} and y = {-1,0,1}).
Then you can check if pacman can move using his position, than adding his direction and see if this piece in your array is a NULL value.
If not there is a wall.

Hope this helps.

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 6:14 pm
 Rookie

Joined: Fri Jan 11, 2013 5:47 pm
Posts: 3
sorry but whats the {-1,0,1}

sorry im still learning to code,

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 6:17 pm
 Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
It just means that the value x (say for example an enum) can be 0 or 1 or -1.
For x: 1 would mean going to the right, -1 to the left.

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 6:19 pm
 Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
I used an int enum direction{LEFT RIGHT UP DOWN} for my game. Pacman's direction gets updated with keypress. You could also only update the direction if it's possible for pacman to go there(as pacman has a constant speed in a particular direction).
ie: if pacman has a wall to his left and you press the left key, his direction doesn't get updated

But to the point, you would check pacman's direction to see if his next position in the collision array is 1, if so update direction. (pacman's x + 1 for right, etc...)

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 8:00 pm
 Rookie

Joined: Fri Jan 11, 2013 5:47 pm
Posts: 3
okay so ive got if ((REG_KEYINPUT & KEY_UP) == 0)
{
if (level[PosX, PosY - 1] == 0)
{
PosY--;
}
else
{

do i need the else and if i dont what do i put to not move?

Top

 Post subject: Re: Collisoin detectionPosted: Fri Jan 11, 2013 9:57 pm
 Gamer Geek

Joined: Fri Dec 07, 2012 2:54 pm
Posts: 35
TurtleBubble wrote:
okay so ive got if ((REG_KEYINPUT & KEY_UP) == 0)
{
if (level[PosX, PosY - 1] == 0)
{
PosY--;
}
else
{

do i need the else and if i dont what do i put to not move?

The idea is you only update the direction of you pacman when they key pressed is in the direction of a walkable tile, you'd update the position if the pacman's next tile is walkable.
It look very hacky, but the idea behind it looks ok. Although I don't know I'm not familiar with development for GBA.

Top

 Post subject: Re: Collisoin detectionPosted: Sat Jan 12, 2013 9:31 am
 Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 283
Location: Here (where else?)
TurtleBubble wrote:
okay so ive got ...
For the next, time, please add a 'code' block around any code that you post, that preserves the indentation, making it much more readable.

TurtleBubble wrote:
do i need the else and if i dont what do i put to not move?
Is there anything you want to do when "(REG_KEYINPUT & KEY_UP) != 0"? If so, code it in the 'else' part. If not, drop the else.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News