This site requires JavaScript, please enable it in your browser!
Greenfoot back
JayHawk
JayHawk wrote ...

2016/5/25

Pacman Game

JayHawk JayHawk

2016/5/25

#
//I am creating a pacman game.(Sorta). I want the pixel to disappear after it touched the pacman. I wrote some code to do this bu tit is not working. Can someone please help me? public void act() { checkKeys(); if(getOneIntersectingObject(Pacman.class)!=null) { Actor Pixel=getOneIntersectingObject(Pacman.class); getWorld().removeObject(Pixel); getWorld().removeObject(this); } }
danpost danpost

2016/5/25

#
I will presume the code given is in the class of the pixel. You are assigning a Pacman object to the variable 'Pixel' and removing it. Why? I would think the only thing you would want to remove is the pixel itself, or 'this' (which you are doing on the last line -- remove the two lines before that).
JayHawk JayHawk

2016/5/25

#
It is in the pacman class
JayHawk JayHawk

2016/5/25

#
it worked. Thx
JayHawk JayHawk

2016/5/25

#
now how do i get a actor to randomly move?
danpost danpost

2016/5/26

#
JayHawk wrote...
now how do i get a actor to randomly move?
For a pacman ghost, you would do something like this: (1) turn to face current direction moving (2) move (3) determine and list possible directions to proceed from new location (4) randomly choose a direction from the list (5) set possibly new current direction to move as determined by random choice in (4) (6) reset rotation back to zero
You need to login to post a reply.