Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Wed Oct 01, 2014 8:17 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Collisoin detection
PostPosted: 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

please help, i'm so stuck, thanks


Top
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: 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
 Profile  
 
 Post subject: Re: Collisoin detection
PostPosted: Sat Jan 12, 2013 9:31 am 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 365
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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group