Computer Science Canada Pacman game problems |
Author: | Partizan [ Wed May 14, 2008 8:30 am ] | ||||
Post subject: | Pacman game problems | ||||
Hello. I'm making a pacman game for a school assignment but having problems with collision and movement. The pacman is drawn using the following code:
and the movement is as follows:
I would like to make it so that once a key is pressed, pacman moves non stop in one direction until the other key is pressed. As for collision, I tried different ways and found the most efficient one to be using the View.WhatDotColor command, but I can't get it to work properly, pacman still moves through the borders. Help is greatly appreciated. |
Author: | Insectoid [ Wed May 14, 2008 10:12 am ] | ||||
Post subject: | RE:Pacman game problems | ||||
perhaps something like
you could also use the getch command, for pacman it makes no difference. For collision detection, whatdotcolor is the best option in this scenario. going diagonally is automatic with Input.KeyDown, so you don't need. And you don't really need to go diagonally in pacman, do you?
using a sprite as pacman is probably a better idea, so you don't need to redraw everything. Check out my PacMan blog, Here |
Author: | Partizan [ Wed May 14, 2008 10:33 am ] | ||
Post subject: | RE:Pacman game problems | ||
Thanks for the help. How would I go about using whatdotcolor for my type of pacman though? Say I have the following border:
|
Author: | isaiahk9 [ Wed May 14, 2008 3:09 pm ] |
Post subject: | RE:Pacman game problems |
For the boundaries, it would be something similar to this : If the user clicks move if Veiw.Whatdotcolor (pacmanx, pacmany) not=9 then code for moving end if end if do that for all the arrow keys. This makes it so that if the character is not on grey then he can move. |
Author: | Insectoid [ Wed May 14, 2008 4:35 pm ] |
Post subject: | RE:Pacman game problems |
I drew my maps in paint. This is a sample of my code (sort of...) [code] if key (KEY_UP_ARROW) and whatdotcolor (y + 10) then y += 1 [/code |
Author: | StealthArcher [ Wed May 14, 2008 4:38 pm ] |
Post subject: | RE:Pacman game problems |
An interesting idea I heard was to have two pictures for each map: -One your 'visual' map, the one everyone sees. -Another with just pure black, and pure white, check for whatdotcolor on this one. Then draw the visual map. EDIT: I think you can still use sprites this way too. |
Author: | Insectoid [ Wed May 14, 2008 4:57 pm ] |
Post subject: | RE:Pacman game problems |
I guess that would work, if the top picture is a sprite (whatdotcolor ignores sprites, I believe...) |
Author: | Partizan [ Thu May 15, 2008 12:03 pm ] | ||||||
Post subject: | Re: Pacman game problems | ||||||
Thank you all for the help, I got collision and movement working One last problem I'm having is calculating a proper score with the pills. Our teacher doesn't want us to use sprites so all the images have to be drawn using Turing, including the pacman. Here is an example for my pills code:
And I have used the following to calculate the score:
Problem is, because the way my pacman is drawn*, it sometimes glitches and adds more than one point per pill, or sometimes doesn't even calculate the pills at all. *
Thank you all for the help. Once I get this right I can pretty much polish my program and finish it. |
Author: | Insectoid [ Thu May 15, 2008 5:54 pm ] | ||
Post subject: | RE:Pacman game problems | ||
What I did was draw the pictures in turing, then save them using Pic.ScreenSave I think..Then you could print that code and hand it in to the teacher while using the pictures it saved as your sprite. My coins were drawn automaticaly using an if statement and a for loop ('if this space is big enouph and nothing else is there, draw a circle') I used a procedure for collecting coins, sort of like
|
Author: | Partizan [ Sun May 18, 2008 2:53 pm ] |
Post subject: | Re: Pacman game problems |
Having a problem with my primitive ghost AI. It works fine at first, but as soon as you complete the level (eat the red dot in the middle) the ghost refuses to go down. |
Author: | Insectoid [ Tue May 20, 2008 3:44 pm ] | ||
Post subject: | RE:Pacman game problems | ||
It seems that you aren't using sprites after all? did your teacher have a problem with you changing pictures drawn in turing into sprites? Hmm, I just thought of a way to maybe have a self-contained program (draw & save pictures, then load the pictures in the same program) For the AI, use something like:
Wait, you are doing that! Your code is a bit weird to me, You seem to be making things a bit to complicated. |
Author: | isaiahk9 [ Tue May 20, 2008 4:05 pm ] |
Post subject: | RE:Pacman game problems |
That would start out simple with insectoid's programming, to avoid the ghosts (they would usually walk into walls). However, multiple ghosts in different areas of the map with the same programming would be very difficult or impossible. |
Author: | Insectoid [ Tue May 20, 2008 4:19 pm ] |
Post subject: | RE:Pacman game problems |
Nah, You just have the same thing for every ghost! And as there only are 4 ghost (inky, blinky, pinky & clyde) it wouldn't be that hard. I have mine starting in each corner. They act completely independantly. You should google pacman to find out some of the special things that were in the original game ('scramble mode, speedy's special, etc.) |
Author: | isaiahk9 [ Tue May 20, 2008 4:25 pm ] |
Post subject: | RE:Pacman game problems |
I meant if there was, about 20 ghosts then the levels would be impossible with each ghost having the type of AI you posted at 4:44 pm. But, using that AI, the ghosts would just run into the walls. It needs an if loop somewhere. |
Author: | Insectoid [ Tue May 20, 2008 4:42 pm ] |
Post subject: | RE:Pacman game problems |
*sigh* If you want real pathfinding AI, that's a few hundred extra lines of code. Otherwise, this simple AI is fine. Since when does PacMan have 20 ghosts? If partizan wants to stay true to the original game, then he'll never have more than 4 ghosts. Oh, how could I have posted at 4:44 if your post that mentioned that time was written before then? (I wrote that at 3:44) |
Author: | isaiahk9 [ Tue May 20, 2008 6:25 pm ] |
Post subject: | RE:Pacman game problems |
I didn't mean pathfinding. I was just saying that partizan could use View.WhatDotColor or some other method to glitch less. I meant if he didn't care - most knock offs just increase difficulty by increasing the number of ghosts. My time for compsci is messed up - I definitely gave myself the wrong time zone. |
Author: | Insectoid [ Tue May 20, 2008 7:32 pm ] |
Post subject: | RE:Pacman game problems |
Well of course he's going to do wall collision (with whichever method he chooses to use) In my example I was just doing the bare ass of the work. Frankly, I thought it was very obvious. I don't do knockoffs, they are a mystery to me. I clone as best I can. |
Author: | isaiahk9 [ Wed May 21, 2008 5:51 am ] |
Post subject: | RE:Pacman game problems |
Yes, I wield to your logic. Just pointing out the obvious in case anybody didn't see it. |
Author: | Insectoid [ Wed May 21, 2008 7:53 am ] |
Post subject: | RE:Pacman game problems |
you wield my logic? Can't be too effective...(exploiting typoes...) I suppose the solution to the whole problem could be that a variable needs to be reset... What do you think, partizan? What do you think of this conversation? Do you feel excluded? Have we helped...at all? Seems all we've done is argue...lol |
Author: | Partizan [ Sat May 24, 2008 1:03 pm ] |
Post subject: | RE:Pacman game problems |
Haha, well, I didn't get an answer for several days so I went and found out on my own, it's ok though, you guys helped a lot before . Everything works pretty well, except I had to implement my own Pacman style of gameplay. Right now I am trying to figure out how to have the highscores write the variables onto a file and them load them when called upon. Shouldn't be too hard though. |
Author: | Sean [ Sat May 24, 2008 1:17 pm ] |
Post subject: | Re: Pacman game problems |
Read up on: Read and Write functions. Edit: Open and Close will be needed aswell |
Author: | Partizan [ Sat May 24, 2008 1:44 pm ] |
Post subject: | RE:Pacman game problems |
Thanks, got it working. Except I used the put and get functions to write into the file and to output from the file instead of read and write. Sweet, I'm all set for my computer science class. I guess it's Counter Strike until the end of the year, lol. |