Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PacMan

Status
Not open for further replies.

Oak

Programmer
Aug 6, 2000
77
CA
Hi!
I'm bulding a PacMan game(it works good at this point). I went into a dilem. What kind of processing should I use about PacMan eating stuff? There's 2 hypothesis that begs me for attention.
Pixel Detection:
detect% = POINT(pac.x, pac.y)
IF detect% = 0 THEN ...
and so on...
Coordination:
IF pac.x = 12 AND pac.y = 20 THEN ...
and so on...


What should I do for my craving PacMan?
 
Set up some collision detection to see if any of PacMan's borders are touching any dots. Like this:

' Ok, lets assume you have a type array that contains
' the dots coordinates. Dot(60).X, and Dot(60).Y. We
' also have the variables PacMan.X and PacMan.Y

' Loop through all the dots and see if any borders of
' PacMan are touching them. PacMan's width is 20 pixels
' and his height is 18 pixels.

For Looper = 0 to 60 step 1
DidCollide = 1
If PacMan.X > Dot(Looper).X then
DidCollide = 0
Elseif PacMan.Y > Dot(Looper).Y then
DidCollide = 0
Elseif PacMan.X + 20 < Dot(Looper).X then
DidCollide = 0
Elseif PacMan.Y + 18 < Dot(Looper).Y then
DidCollide = 0
Endif
If DidCollide = 1 then
' Take care of anything that happens when
' PacMan hits a dot.
Endif
Next
 
I've been gone for the week end. I'll try it!
I presume that phantom collision detection should be implemented the same way. Is it correct?
Thanks
 
Please define what you mean by 'Phantom'... There is a million ways to say the same thing when it comes to programming!
 
If by phantom you are reffering to the fact that you are checking allready-dissapeared dots, you could make another object in the Dot array: Dot.Active(0-60), then alter the above code so you're never checking the same dot twice:

For Looper = 0 to 60 step 1
If Dot.Active(Looper) = 1 then
DidCollide = 1
If PacMan.X > Dot(Looper).X then
DidCollide = 0
Elseif PacMan.Y > Dot(Looper).Y then
DidCollide = 0
Elseif PacMan.X + 20 < Dot(Looper).X then
DidCollide = 0
Elseif PacMan.Y + 18 < Dot(Looper).Y then
DidCollide = 0
Endif
If DidCollide = 1 then
Dot.Active(Looper) = 0
' Take care of anything that happens when
' PacMan hits a dot.
Endif
Endif
Next
 
Lol... It took me this long to figure out that when you said &quot;Phantom&quot; collision detection, you ment collision detection width those Blue, Red, and White &quot;Ghosts&quot; that run around the screen in the hopes of killing Pac-Man...

Code:
   .-------.
   |  .-.  |
   | | OO| |
   | |   | |
   | '^^^'.--------.
   '------|  .--.  |
          | / _.-' |
          | \  '-. |
          |  '--'  |
          '--------'

You should be able to use that collision detection code, except insted of just using the X and Y values of the dot, we must compare the Width and Height of the 'Phantom'. The width and height of the Phantom is 20, 18.

For Looper = 0 to 4 step 1
If Phantom(Looper).Alive = 1 then
DidCollide = 1
If PacMan.X > Phantom(Looper).X + 20 then
DidCollide = 0
Elseif PacMan.Y > Phantom(Looper).Y + 18 then
DidCollide = 0
Elseif PacMan.X + 20 < Phantom(Looper).X then
DidCollide = 0
Elseif PacMan.Y + 18 < Phantom(Looper).Y then
DidCollide = 0
Endif
If DidCollide = 1 then
' Take care of anything that happens when
' PacMan hits a Phantom.
Endif
Endif
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top