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

2015/11/10

i have a problem in my gaming project that after i launch a ball and it disappears and i cannot launch another ball

fbl fbl

2015/11/10

#
i have to launch a ball by pressing space and i have 10 balls in hand with reset the game in between . after i launch my first ball, if it hits the truck or the edge it should disappear.. and it does that too but after disappearing if i try to launch another ball, i am not able to do that even i press space. can anyone help me out with it please
danpost danpost

2015/11/10

#
fbl wrote...
i have to launch a ball by pressing space and i have 10 balls in hand with reset the game in between . after i launch my first ball, if it hits the truck or the edge it should disappear.. and it does that too but after disappearing if i try to launch another ball, i am not able to do that even i press space. can anyone help me out with it please
Show your code!
fbl fbl

2015/11/10

#
public void shoot() { //if(!shooting) { double power = rectanglemeter.getFilledRatio(); speed = 3 * power; double angle = circle.getAngle(); double xVelocity = speed * Math.cos(circle.getAngle()); double yVelocity = -speed * Math.sin(circle.getAngle()); int shoot = board.getLeft(); if(shoot>0) { board.decrementLeft(); Projectile ball = new Projectile (xVelocity, yVelocity); //this.addObject(ball, getArcX(), getArcY()); this.addObject(ball, circle.getArcX(), circle.getArcY()); shooting = true; } else { shooting = false; } }
fbl fbl

2015/11/10

#
this shoots a ball when i hit space bar .. but i want ball should not launch even if i hit space when the ball is in the world. i just need a general idea how to do that
fbl fbl

2015/11/10

#
.
danpost danpost

2015/11/10

#
fbl wrote...
this shoots a ball when i hit space bar .. but i want ball should not launch even if i hit space when the ball is in the world. i just need a general idea how to do that
You do not need the 'shooting' field. You can check for Ball in world with this:
boolean noShotsInWorld = getWorld().getObjects(Projectile.class).isEmpty();
The right part can be used as a condition in an 'if' statement for shooting.
fbl fbl

2015/11/11

#
it works now ... thank you :)
You need to login to post a reply.