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

2013/7/26

Impassible objects...

Sparky Sparky

2013/7/26

#
I'm trying to make Pacman Multiplayer,how would you an object that You cant pass...a barricade or block,thanks in advance
Gevater_Tod4711 Gevater_Tod4711

2013/7/26

#
You can use every object. This objects don't even have to do anything. You packman just has to recognice that there is such an object on the field and so don't move there. I think there are many packman examples to be found on this webside and also some with a easy code for beginners. Just search for some of them, download them and have a look on how others solved this problems.
Sparky Sparky

2013/7/26

#
no if you use an inadament object,pacman moves right trough it,how to make him stop and be unable to move through it.
danpost danpost

2013/7/26

#
@Sparky, the Actor class API contains several methods that can be used for collision detection. Normally, the event chain will be 'move, check for intersection, and move back if intersecting an object. This chain of events will normally be performed once each act cycle. In this way, the pacman will maintain his status of not intersecting any object it is not supposed to be.
Sparky Sparky

2013/7/26

#
@danpost Omg...you are like an expert,thanks,could i have the code i need to copy for doing this,you can just write anything,like dont collide randomobject() ??? void collide { dont touch } just random example thank you btw,ill follow/like you
danpost danpost

2013/7/26

#
Let us say your barrier is created in the 'Barrier' class; then:
1
2
move(4);
if (!getIntersectingObjects(Barrier.class).isEmpty()) move(-4);
would be an example of moving, and if intersecting a barrier object, moving back. Of course, you will not be changing the rotation of your pacman object as you change its direction; so, this will probably have to be modified using 'setLocation'. BTW, I do have a Pakman scenario with open source you can look at to see how I did it. (It did take me a little while to come up with workable code for collision checking -- I had to make the size of the actor 'fit' snuggly between the walls and increase the move distance to 2 instead of 1.) I am not saying you will have to do this -- it depends on how you program the movements, among other things.
Sparky Sparky

2013/7/27

#
Thanks,
Sparky Sparky

2013/7/30

#
danpost wrote...
Let us say your barrier is created in the 'Barrier' class; then:
1
2
move(4);
if (!getIntersectingObjects(Barrier.class).isEmpty()) move(-4);
would be an example of moving, and if intersecting a barrier object, moving back. Of course, you will not be changing the rotation of your pacman object as you change its direction; so, this will probably have to be modified using 'setLocation'. BTW, I do have a Pakman scenario with open source you can look at to see how I did it. (It did take me a little while to come up with workable code for collision checking -- I had to make the size of the actor 'fit' snuggly between the walls and increase the move distance to 2 instead of 1.) I am not saying you will have to do this -- it depends on how you program the movements, among other things.
heres my code,ill just give it to you for Pacman_P1... public void act() { eat(); move(); // Add your action code here. } public void move() { if (Greenfoot.isKeyDown("left")) { move(-1); } if (Greenfoot.isKeyDown("right")) { move(1); } if (Greenfoot.isKeyDown("up")) { setLocation(getX(), getY() - 1); } if (Greenfoot.isKeyDown("down")) { setLocation(getX(), getY() +1); } if (!getIntersectingObjects(VerticleBar.class).isEmpty()) move(-1); if (!getIntersectingObjects(VerticleBar.class).isEmpty()) move(+1); if (!getIntersectingObjects(VerticleBar.class).isEmpty()) setLocation(getX(), getY() -1); if (!getIntersectingObjects(VerticleBar.class).isEmpty()) setLocation(getX(), getY() +1); if (!getIntersectingObjects(HorizontalBar.class).isEmpty()) move(-1); if (!getIntersectingObjects(HorizontalBar.class).isEmpty()) move(+1); if (!getIntersectingObjects(HorizontalBar.class).isEmpty()) setLocation(getX(), getY() -1); if (!getIntersectingObjects(HorizontalBar.class).isEmpty()) setLocation(getX(), getY() +1); } it wont work,if Pacman comes into a place where to objects meet it will allow Pacman to pass right through
Sparky Sparky

2013/7/30

#
i need him to not pass trough three objects,they are 1. HorizontalBar 2. VerticleBar 3. GhostGate
danpost danpost

2013/7/30

#
I would suggest taking all keystrokes into consideration when determining which direction to move. Then, you only have to attempt to move once and if intersecting any one of the three types of objects, move back. Of course, pacman is supposed to continue to move in the current direction until a barrier in front or a valid change in direction is detected. With this in mind, you should also attempt to move forward when all else fails.
AngelusNeko13 AngelusNeko13

2015/10/21

#
guys can u help me with making two cars collide and end the game when you crash into the other cars? this is my code i used:
1
2
3
4
5
6
7
8
9
10
11
12
13
public void checkCollision()
   {
        
      Actor Car = getOneIntersectingObject(Vehicle.class);
        
       if(Car != null)
        
       {
           Greenfoot.playSound("crash.wav");
           Greenfoot.stop();
            
       }
   }
AngelusNeko13 AngelusNeko13

2015/10/21

#
guys can u help me with making two cars collide and end the game when you crash into the other cars? this is my code i used:
1
2
3
4
5
6
7
8
9
10
11
12
13
public void checkCollision()
   {
        
      Actor Car = getOneIntersectingObject(Vehicle.class);
        
       if(Car != null)
        
       {
           Greenfoot.playSound("crash.wav");
           Greenfoot.stop();
            
       }
   }
You need to login to post a reply.