Archived

This topic is now archived and is closed to further replies.

korbitz

how to stop my pacman eating the walls??

Recommended Posts

here goes---> i''m designing a pacman clone(for personnal pleasure) and while all seams to be running smoothly upto now, when ever i try to go east or south pac eats all the bleedin walls up heres the movement code switch (sprite_currDir) { case N: sprite_yPos--; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18; while (map[sprite_myPos][sprite_mxPos] == 2) { sprite_yPos++; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18; } break; case S: sprite_yPos++; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/2))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/2))/18; while (map[sprite_myPos][sprite_mxPos] == 2) { sprite_yPos--; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/2))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/2))/18; } break; case W: sprite_xPos--; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18; while (map[sprite_myPos][sprite_mxPos] == 2) { sprite_xPos++; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18 ; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18; } break; case E: sprite_xPos++; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/2))/18; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/2))/18; while (map[sprite_myPos][sprite_mxPos] == 2) { sprite_xPos--; sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/2))/18 ; sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/2))/18; } break; } i am using a char array of 22x19 map[x][y]== 2 is the walls ne help will be appreciated if further info is required please reply or contact me on icq 120471999, will send entire source code if needed thnx in advance

Share this post


Link to post
Share on other sites
im not to sure but Y do u have for S,E

sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/2))/18;

and

sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18;

ule notice that u devide by 2 on SE and 36 in toher directions, this will mac mr pac man much bigger i think and destoy walls??


~prevail by daring to fail~

Share this post


Link to post
Share on other sites
My PacMan used to always take a dump on his sleeping pillow. What I did is every time I''d rub his nose in it and eventually he stopped!

Share this post


Link to post
Share on other sites
i''m kinda new to all this but here goes, changed a few parameters

now s & e work, n & w dont work properly now

is it me or is there an easier way to keep pac dead center within the map

and does anyone understand this code (i copied this portion of code from somewere else, problem is i cant remember were)

slightly amended code--->

switch (sprite_currDir)
{
case N:
sprite_yPos--;
sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18;
sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18;

while (map[sprite_myPos][sprite_mxPos] == 2)
{
sprite_yPos++;
sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18;
sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18;
}
break;

case S:
sprite_yPos++;
sprite_mxPos = (sprite_xPos-1 + (SPRITE_WIDTH))/18;
sprite_myPos = (sprite_yPos-1 + (SPRITE_HEIGHT))/18;

while (map[sprite_myPos][sprite_mxPos] == 2)
{
sprite_yPos--;
sprite_mxPos = (sprite_xPos-1 + (SPRITE_WIDTH))/18;
sprite_myPos = (sprite_yPos-1 + (SPRITE_HEIGHT))/18;
}
break;

case W:
sprite_xPos--;
sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18;
sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18;

while (map[sprite_myPos][sprite_mxPos] == 2)
{
sprite_xPos++;
sprite_mxPos = (sprite_xPos + (SPRITE_WIDTH/36))/18 ;
sprite_myPos = (sprite_yPos + (SPRITE_HEIGHT/36))/18;
}
break;

case E:
sprite_xPos++;
sprite_mxPos = (sprite_xPos-1 + (SPRITE_WIDTH))/18;
sprite_myPos = (sprite_yPos-1 + (SPRITE_HEIGHT))/18;

while (map[sprite_myPos][sprite_mxPos] == 2)
{
sprite_xPos--;
sprite_mxPos = (sprite_xPos-1 + (SPRITE_WIDTH))/18 ;
sprite_myPos = (sprite_yPos-1 + (SPRITE_HEIGHT))/18;
}
break;
}

Share this post


Link to post
Share on other sites
For the actual problem, what Zerosignull said seems right (from a very casual glance at the code posted).


If you ever decide to re-do any of this, using collisions to see when he hits a wall isn''t necessarily the best way. Pac-Man keeps running until he hits a wall so you only really care which "tile" he happens to be on, and whether it has a pellet, fruit etc on it... the following hypothetical data structure might give you an idea


typedef struct
{
MAPTILE* pWhatsNorthOfThisTile;
MAPTILE* pWhatsEastOfThisTile;
MAPTILE* pWhatsSouthOfThisTile;
MAPTILE* pWhatsWestOfThisTile;
bool bDoesThisTileHaveAPelletOnIt;
..etc..
}
MAPTILE;


Thinking in terms of tiles lets you free your imagination a tad when doing maps:

http://www.creative-asylum.com/image/pacgallery04.jpg
http://www.creative-asylum.com/image/pacgallery05.jpg
http://www.creative-asylum.com/pac.html


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
quote:
i''m designing a pacman clone(for personnal pleasure)


Sounds naughty.

//John
-----------------------------------------
Swedish saying:
"The one who joins the game must face the consequences of the game."

Share this post


Link to post
Share on other sites