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

2012/11/12

Shooting

macforce macforce

2012/11/12

#
Hey Ive got some problems with a shooting game I want to be able to shoot multible shoots from my canon, As it is now I can just fire once and then I have to reset the whole project. I think Im doing something wrong in my fire method in the while loop. Appreciating any tips! public class Ball extends Actor { private double X; private double Y; private double length; private double theta; private double startVelX; private double startVelY; private double curVelY; private double g; private double ballAngle; private double dt; public Ball CanonBall; private Target target; public Ball() { GreenfootImage canonball = new GreenfootImage(10,10); canonball.setColor(Color.BLACK); canonball.fillOval(0, 0, 15, 15); setImage(canonball); } public void act() { Angel(); setBallAngle(); fire(); } public void Angel() { CanonWorld world = (CanonWorld) getWorld(); Canon canon = world.getCanon(); theta = canon.getAngle(); if( Greenfoot.isKeyDown("1")) { length = 10.0; } if( Greenfoot.isKeyDown("2")) { length = 22.0; } if( Greenfoot.isKeyDown("3")) { length = 32.0; } startVelX = length*Math.cos(theta); startVelY = length*Math.sin(theta); curVelY = startVelY; g = 0.5; X = getX(); Y = getY(); } public void setBallAngle() { ballAngle = Math.toDegrees(Math.atan2(-1*curVelY,startVelX)); } public void fire() { if (Greenfoot.mouseClicked(null)) while (dt < 8) { setBallAngle(); X = X + startVelX; Y = Y - curVelY; setLocation((int) X, (int) Y); Greenfoot.delay(2); curVelY = curVelY - g; dt += .01; checkCollision(); } }
macforce macforce

2012/11/12

#
I know that I need to call the method for adding balls but as I have tried a couple of different ways of doing it with no succes, Im turning to you guys.
macforce macforce

2012/11/12

#
Solved
You need to login to post a reply.