hello,
does anyone know how to make something shoots a bullet? eg a rocket
thanks
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Projectile
{
public String pointed;
private int speed;
private int delay = 7;
private boolean hit = false;
public Bullet(String direction){
pointed = direction;
if(pointed=="left"){
speed= -8;
}else{
speed= 8;
}
}
/**
* Act - do whatever the Rocket wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
movement();
contact();
outField();
}
public void movement(){
move(speed);
}
public void contact(){
if(isTouching(Penguin.class)){
if(delay<1){
getWorld().removeObject(this);
}else{
delay--;
}
hit=true;
}
}
public void outField(){
if(!hit&&(getX()<5||getX()>895)){
getWorld().removeObject(this);
}
}
}