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

2014/9/16

Anyone tell me how to make my actor shoot

coder04 coder04

2014/9/16

#
this is my code so far what do i need to add onto it
coder04 coder04

2014/9/16

#
import greenfoot.*;

/**
 *  A user-controlled spaceship that can be teleported from one portal to another
 *  This class uses a somewhat make-shift move algorithm with drift slowing to stop
 *  (although, in space, this kind of slowing is not present)
 */
public class Ship extends Actor
{
    int speed = 5;
    /**
     * Method act: move spaceship and check teleporting status
     */
    public void act() 
    {
        move();
    }

    /**
     * Method move: checks for keystrokes and applies the changes, then moves the ship.
     * I applied a bit of slowing to the ship's speed (so it would be drifting to a stop)
     */
    private void move()
    {
        int dz = 0;
        if (Greenfoot.isKeyDown("d")) dz++;
        if (Greenfoot.isKeyDown("a")) dz--;
        setRotation(getRotation() + dz * 5);
        int ds = -1;
        if (Greenfoot.isKeyDown("w")) ds += 2;
        speed += ds;
        if (speed < 0) speed = 0;
        if (speed > 90) speed = 90;
        if (speed >= 200) move(speed / 100);
        if (Greenfoot.isKeyDown("s")) ds += 5;
        speed += ds;
        if (speed < 5) speed = 5;
        if (speed > 200) speed = 200;
        if (speed >= 20) move(speed / 10);
    }
}
danpost danpost

2014/9/16

#
If "s" is for decelerating, you should be subtracting on line 35. Lines 31, 32, 33, 34 and 38 should be removed. You need an Actor subclass for the object the Ship is to shoot. Then, you need to add a method to the ship class for shooting that is called from the act method.
coder04 coder04

2014/9/17

#
can u write the code for me with my code
davmac davmac

2014/9/17

#
You should watch the tutorial videos on shooting: http://www.youtube.com/playlist?list=PL73D989ED1678D0EC Then, have a go at coding it yourself, and ask for help if you run into any problems.
coder04 coder04

2014/9/17

#
THANX
You need to login to post a reply.