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

2013/10/22

shooting things

smilyface999 smilyface999

2013/10/22

#
hello, does anyone know how to make something shoots a bullet? eg a rocket thanks
bloter6 bloter6

2013/10/22

#
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);
        }
    }
}
You need to make a bullet class. When you make it, give it a parameter that is equal to the direction the shooter is facing. Enjoy, and plagerize the shit out of this.
smilyface999 smilyface999

2013/10/24

#
i have put the code in but it says that i need to put in a string direction and i dont know what that is
You need to login to post a reply.