Hi hi need help wih firing the cannon using algorithm.
here is my code.
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 = 0; int angle = 0; private StatusBoard statusboard; /** * Act - do whatever the Cannon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Cannon( StatusBoard status) { statusboard = status; } public void act() { if( Greenfoot.isKeyDown("up")) { power = power + 1; } if( Greenfoot.isKeyDown("down ")) { power = power - 1; } if( Greenfoot.isKeyDown("right") && angle > 0) { angle = angle - 1; } if( Greenfoot.isKeyDown("left") && angle < 90) { angle = angle + 1; } if("space".equals(Greenfoot.getKey())) { fire(); } setRotation(-angle); statusboard.setValues(angle,power); } public void fire() { World myWorld = getWorld(); Chicken chicken = new Chicken(angle,power); myWorld.addObject(chicken, getX(),getY()); } } cannon class