Pacman-Clone Help
Blitz3D Forums/Blitz3D Beginners Area/Pacman-Clone Help
| ||
Hi, I'm trying to code a pacman clone in Blitz3d but I can't figure out how to move pacman properly through the maze (which is made out of simple 2*2*2 cubes, arranged according to a data list). The problem is: Pacman should only try to move in a certain direction if there is no wall. ###################### P ###################### That is, in the above picture Pacman(P) should only be able to go left or right as there are walls(#) above and below him. If the player hits up or down, Pacman should ignore the command in order to avoid getting stuck. Anyone have an idea how to do that? Thanks in advance, Kunfista |
| ||
I know that somewhere on the web there are the exact "logic" behind the original PacMan I want to do a perfect clone myself someday, and looking forward to seeing yours |
| ||
Well, check the collisions between the wall and the pacmans next position.x=100 y=100 ;;pacman is safe at this location ;; there is a wall above him and below him if keyhit(200) then ; key pressed to go down if imagescollided(pacman,x,y-16,0,level,0,0,0)=false then; assume each grid position is 16x16 y=y-16; move player up as the result of the if statement is false. end if; if player does collide, nothing will happen and the y co-ords stays the same Something like that. Check with the imagecollide() command, the pacman and the wall. BUT subtract a grid square from the y co-ord (y-16) to check the images location up a square. The image doesn't need to be drawn at this location :) And your not changing y till the grid square above the pacman is empty :) That should do it i think :D |
| ||
Failing that. If you store each image, for a block of wall in an array. 1= wall, 0= empty, 2=player pos. Then just check the grid above the player to see if it's empty. This way assumes your using some sort of tile map :) |
| ||
@Ross C Nice idea, but how would you do that in Blitz3d? You can't collide Pacman's next position with the level, as B3D's collision command is totally different: EntityCollided(Pacman,Level). @Hansie thx, will look for that |
| ||
Aha, didn't see your last post. But I would have to make Pacman always go by steps of 16 (for example)!? |
| ||
Got it! I used the method with the array and it works great in 2d and 3d. Thanks for your advice! |
| ||
Maybe try makeing it with the Blitz3D good old 2D graphics routines first before even thinking about attempting it in 3D. But if you just gotta do it in 3D right this minute...then the other possability is to make the pills into nodes...something like: Type Pill Field location% ;points to a pivot Field eaten ; 0=flase, 1=true Field up.pill ; pointer to the next closest pill above Field left.pill ; pointer to the next closest pill to the left Field right.pill ; pointer to right pill field down.pill ; pointer to pill below End Type for each pill (both the small and large ones) you create an instance of this type...create a pivot at the 3D location of this pill..and child the pill model to this pivot...if pacman touches this pill make it's alpha = 0 and set the pill\eaten flag to 1 (then loop through all of these pills and if all have the eaten flag then the level is completed)...not every pill node needs to have a model child either (only the ones that pac-man is required to eat) the pointers to the other pills within this type are the key...basicly at the game start place pacman to the same location as one of these pills...if the player presses left and the pill\left pointer isn't null...then calculate the vector to that pill (vector = pill\left\pivot - pill\pivot)...align the pac-man to this vector and move him in that direction...if pac-man tries to move in a direction (up,down,left,right) that the pill indicates is null then the pac-man stops on the pill node and waits for a valid direction input... aditionaly the ghosts can use these pill nodes too...you could even include a "pac-man was here" field in the pill type so the ghosts can more easily track the player (when pac-man reaches the node set the counter to some value and decrease it back to zero every game update...then the ghosts can scan the connected nodes once they reach them to see where pac-man has been recently) |
| ||
Easiest way i've found is using an underlying array for collisions, cellsare either walkable or blocked. |
| ||
Erm...I should add that the way I described with the nodes can work with other types of games too...or even pac-man maps with different "layers" or some other simular effect |
| ||
That sounds like a good idea MSW. One pitfall is that there would have to be a node at every intersection even if you don't want a pill there. Also, how would you check for a collision with the node? Since 3D isn't exact, and spherical collisions have to have SOME size (even if it's very small), how would you make sure that Pacman actually turns at the exact moment (or position, whatever)? |
| ||
a linear interpolation from one node 3D location to the other, no Blitz3D collisions required... once you have a destination node....find the distance between the two nodes and divide by the pac-man speed...this will tell you how many game loop updates will be needed to reach the destination node...then use this value to calculate the X,Y,Z stepper values that are used to posistion the pac-man each game update...then you just set up a counter...start it at zero with the max being the number of game updates required...then for everyup date increase this counter if the player is moveing to the target node and once the counter matches the number of game updates then pac-man has reached the node...if the player decides to turn around midway to the destination node then start subtracting from the counter until it reaches zero at which point pac-man is back at the original node and a new one can be selected and the whole process starts over... |
| ||
@MSW *snip*...if pac-man tries to move in a direction (up,down,left,right) that the pill indicates is null then the pac-man stops on the pill node and waits for a valid direction input...*snip* ->But that's exactly what he shouldn't do! Pacman must always be moving and only stop at a corner where the player doesn't press the proper key of if the player doesn't press a key at all. @John That's how I did it in the end. But Pacman has to move always in cells, so that he can only try to take another direction when he's exactly in the middle of a cell - otherwise he would get stuck at corners. |
| ||
@msw I just realised your idea with the game loop updates and combined it with John's method and taadaaa! PERFECT Pacman movement! You guys rock ;) When I've finished the movement I'll post the code in the database. Many thx, Kungfista |