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

2014/6/2

CheeseArcher

Master79 Master79

2014/6/2

#
Cheese Code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Cheese here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Cheese extends Animal
{
    /**
     * Act - do whatever the Cheese wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public int speed; 
    public void fly()
    {
        speed = 25;
        setLocation(getX(), getY() - speed);
    }
}
PepperJack Cheese Code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class PepperJackCheese here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PepperJackCheese extends Cheese
{
    /**
     * Act - do whatever the PepperJackCheese wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public int x;
    private int size;
    private int stability;
    public void act() 
    {
        fly();//this is the moving method
        //breakUp();
        if (getY() <= 0 && getWorld()!= null)//disappear at top of world
        {
            getWorld().removeObject(this);
            return;
        }
    }
    public PepperJackCheese()
    {
        this(50);
    }
    public PepperJackCheese(int size)
    {
        super(new Vector(Greenfoot.getRandomNumber(360), 2));
        setSize(size);
    }
    public PepperJackCheese(int size, Vector speed)
    {
        super(speed);
        setSize(size);
    }
    public void setSize(int size) 
    {
        stability = size;
        this.size = size;
        GreenfootImage image = getImage();
        image.scale(size, size);
    }
    public int getStability() 
    {
        return stability;//<LEFT OFF HERE
    }

    private void breakUp() 
    {
        CheeseWorld space = (CheeseWorld) getWorld();
        Greenfoot.playSound("Explosion.wav");
        space.countScore();
        if(size <= 16) 
        {
            getWorld().removeObject(this);
            space.addAsteroids(1);
            space.countScore();
            space.countAsteroids();
        }
        else 
        {
            int r = getMovement().getDirection() + Greenfoot.getRandomNumber(45);
            double l = getMovement().getLength();
            Vector speed1 = new Vector(r + 60, l * 1.2);
            Vector speed2 = new Vector(r - 60, l * 1.2);        
            Asteroid a1 = new Asteroid(size/2, speed1);
            Asteroid a2 = new Asteroid(size/2, speed2);
            getWorld().addObject(a1, getX(), getY());
            getWorld().addObject(a2, getX(), getY());        
            a1.move();
            a2.move();
            getWorld().removeObject(this);
        }
    }
    
}
SmoothMover
import greenfoot.*;  
public abstract class SmoothMover extends Actor
{

    private Vector movement;
    private double exactX;
    private double exactY;
    
    public SmoothMover()
    {
        this(new Vector());
    }

    public SmoothMover(Vector movement)
    {
        this.movement = movement;
    }

    public void move() 
    {
        exactX = exactX + movement.getX();
        exactY = exactY + movement.getY();
        if(exactX >= getWorld().getWidth()) {
            exactX = 0;
        }
        if(exactX < 0) {
            exactX = getWorld().getWidth() - 1;
        }
        if(exactY >= getWorld().getHeight()) {
            exactY = 0;
        }
        if(exactY < 0) {
            exactY = getWorld().getHeight() - 1;
        }
        super.setLocation((int) exactX, (int) exactY);
    }

    public void setLocation(double x, double y) 
    {
        exactX = x;
        exactY = y;
        super.setLocation((int) x, (int) y);
    }

    public void setLocation(int x, int y) 
    {
        exactX = x;
        exactY = y;
        super.setLocation(x, y);
    }

    public double getExactX() 
    {
        return exactX;
    }

    public double getExactY() 
    {
        return exactY;
    }

    public void addForce(Vector force) 
    {
        movement.add(force);
    }

    public void accelerate(double factor)
    {
        movement.scale(factor);
        if (movement.getLength() < 0.15) {
            movement.setNeutral();
        }
    }

    public double getSpeed()
    {
        return movement.getLength();
    }

    public void stop()
    {
        movement.setNeutral();
    }

    public Vector getMovement() 
    {
        return movement;
    }

}
I can't get the Vector to work.
Master79 Master79

2014/6/3

#
I can post source code on my game.
lordhershey lordhershey

2014/6/3

#
You can include the source when you publish the scenario. Question, when the pepper jack explodes , did you want a bunch of pellets to fly out and kill the invaders?
You need to login to post a reply.