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

2021/11/24

Help with x and y coordinates

TimFNA TimFNA

2021/11/24

#
I have an actor, who can jump and i have another actor, who can shoot. The problem is that if i shoot in the air i want the bullet to hit the player1(P1) only on certain x and y coordinates. I tried to put the getX into the code and that worked. So now i can only hit him on these certain x coordinate but i want him to get hit on a certain x and y coordinate. How can i make him get hit also on a y coordinate? public class BulletP12 extends Mover { public void act() { move(13.5); lookForP2(); if(atWorldEdge()) { getWorld().removeObject(this); getImage().setTransparency(255); } } public void lookForP2() { if (isTouching(P2.class)&& getX()>=1050 ) { removeTouching(P2.class); getImage().setTransparency(0); } } }
danpost danpost

2021/11/24

#
You mention bullet hitting a P1 object, but I only see code for hitting a P2 object.
You need to login to post a reply.