No, like this:
Ship ship = new Ship(); Shot shot = new Shot(ship);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class RedBlip here. * * @author (Caleb Painter) * @version (6/22/2012 VERSION 1.0) */ public class Blip extends Actor { private int shotTimer = 0; /** * Act - do whatever the Blip wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (shotTimer > 0) { shotTimer = shotTimer - 1; } else if (Greenfoot.isKeyDown("space")) { getWorld().addObject(new Shot(this), getX(), getY()); shotTimer = 100; // delay next shot } if (Greenfoot.isKeyDown("w")) { move(4); } if (Greenfoot.isKeyDown("a")) { turn (-3); } if (Greenfoot.isKeyDown("d")) { turn(3); } if (Greenfoot.isKeyDown("s")) { move(-4); } { Ship ship = new Ship(); Shot shot = new Shot(ship); // set the rotation // add it to the world } eat(); } public Blip() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 10, image.getHeight() - 10); setImage(image); } public void eat() { Actor goldenball; goldenball= getOneObjectAtOffset(0, 0, GoldenBall.class); if (goldenball != null) { World world; world = getWorld(); world.removeObject(goldenball); } } }
Shot shot = new Shot(ship);
getWorld().addObject(new Shot(this), getX(), getY());
Shot shot = new Shot(this); shot.setRotation(getRotation()); getWorld().addObject(shot, getX(), getY());
{ Blip blip = new Blip(); Shot shot = new Shot(blip); shot.setRotation(getRotation()); getWorld().addObject(shot, getX(), getY()); // set the rotation // add it to the world }
{ Blip blip = new Blip(); Shot shot = new Shot(blip); shot.setRotation(getRotation()); getWorld().addObject(shot, getX(), getY()); // set the rotation // add it to the world }