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

2014/5/19

SmootheMover

Master79 Master79

2014/5/19

#
I am trying to make this smooth mover class for my pepperjackcheese class. here is the smooth mover and pepperjackcheese. i dont know what is wrong it says that the vector is wrong.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
[code]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;
    }
}
/** * 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; CheeseWorld cw = (CheeseWorld) getWorld(); public void act() { fly();//this is the moving method breakUp(); if (getY() <= 0 && getWorld()!= null)//disappear at top of world { getWorld().removeObject(this); 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; } }
danpost danpost

2014/5/19

#
Looks like you cut part of the PepperJackCheese class code from the post. Also, the Cheese class might be important. It would be best to copy/paste the entire code of each class into individual 'code' embedding windows.
You need to login to post a reply.