Hi I need help. When i shoot out a cannonball it doesnt change direction after the cannon
here is my cannon class
and here os my cannon ball class
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Cannon here. * * @author (your name) * @version (a version number or a date) */ public class Cannon extends Actor { int power = 100; int angle = 0; private StatusBoard statusboard = null; /** * Act - do whatever the Cannon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.isKeyDown("up")) { power = +1; } if(Greenfoot.isKeyDown("down")) { power = -1; } if(Greenfoot.isKeyDown("right") && angle > 0 ) { angle = angle - 1; } if(Greenfoot.isKeyDown("left") && angle < 90) { angle = angle + 1; } setRotation(-angle); if("space".equals(Greenfoot.getKey())) { fire(); } } public void fire() { World myWorld = getWorld(); Chicken chicken = new Chicken(angle,power); myWorld.addObject(chicken, getX(),getY()); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Chicken here. * * @author (your name) * @version (a version number or a date) */ public class Chicken extends Actor { int GRAVITY = 2; int xSpeed = 0; int ySpeed = 0; /** * Act - do whatever the Chicken wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Chicken( int angle, int power) { power = (power * 10/ 25); xSpeed = (int)(power*Math.cos(Math.toRadians(angle))); ySpeed = (int)(power*Math.sin(Math.toRadians(angle))); } public void act() { setLocation(getX()+ xSpeed, getY() -ySpeed); ySpeed = ySpeed = GRAVITY; World myWorld = getWorld(); if(getY() > myWorld.getHeight()) { myWorld.removeObject(this); } } }