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

2012/4/19

HELP PLZZZ. senior project dueFRIDAY

OGava OGava

2012/4/19

#

i can link anyone a file if your interested in helping. I should be the majority of the way finished just need cutting up on a few things not too shabby with greenfoot thanks for taking a look a guess.

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.Class;

public class recyclingBin extends Actor
{
private boolean touched = false;
    /**
     * Act - do whatever the RecyclingBin wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       moveAndTurn();
       eat(paperball);
       Actor body = getOneIntersectingObject(Body.class);
       if (touched && paperball == null)
       {
          eat(paperball);
       }
       else if (!touched && body != null)   // just being touched now
        {
            touched = true;
            Greenfoot.playSound(sound);
        }
       
    }
    public void getObjectsAtCollision()
   
       eat(paperball)
       {
           when touchpaperball - paperball;
           value--;
       }
}

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;

public class paperball extends Actor
{
private static final double GRAVITY = 7.8;
private double mass;
    /**
     * Act - do whatever the paperball wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public paperball()
    {
        this (20, 300, new Vector());
        
    }
    public paperball(int size, double mass, Vector movement) 
     {  move(-37);
        this.mass = mass;
        addForce(movement);
        if(Greenfoot.getRandomNumber(-27) < -7)
        {
            turn(Greenfoot.getRandomNumber(0) + 4);
        }
        if(getX() <- 5 || getX() >= getWorld().getWidth())
        {
            turn(1380);
        }
        if(getY() <= 5 || getY() >= getWorld().getWidth())
        {
            turn(180);
        }
    }   
    public void act() 
    {
        applyForces();
        move();
        bounceAtEdge();
    }
    private void bounceAtEdge()
    {
        if (getX() == 0 || getX() == getWorld().getWidth()-1) {
            setLocation((double)getX(), (double)getY());
            getMovement().revertHorizontal();
            accelerate(0.7);
        }
        else if (getY() == 0 || getY() == getWorld().getHeight()-1) {
            setLocation((double)getX(), (double)getY());
            getMovement().revertVertical();
            accelerate(0.7);
        }
    }
    private void applyForces()
    {
        List<Body> bodies = (List<Body>) getWorld().getObjects(Body.class);
        
        for (Body body : bodies) 
        {
            if (body != this) 
            {
                applyGravity (body);
            }
        }
        
        // ensure that we don't get too fast: If the current speed is very fast, decelerate a bit.
        if (getSpeed() > 7) 
        {
            accelerate (0.9);  // acceleration with factor < 1 is actually slowing down.
        }
    }
    
    private void applyGravity(paperball other)
    {
        double dx = other.getExactX() - this.getExactX();
        double dy = other.getExactY() - this.getExactY();
        Vector force = new Vector (dx, dy);
        double distance = Math.sqrt (dx*dx + dy*dy);
        double strength = GRAVITY * this.mass * other.mass / (distance * distance);
        double acceleration = strength / this.mass;
        force.setLength (acceleration);
        addForce (force);
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class user extends Actor
{
    
    public void act() 
    {
        checkKeys();
        
        
        usermoveObject(userForce + paperball = paperball);
        
        
        if(Greenfoot.isKeyDown("left"))
        {
            turn(10);
        }
        if (Greenfoot.isKeyDown("right"))
        {
            turn(15);
        }
    }
    
    
    public void checkKeys()
    {
        if (Greenfoot.isKeyDown("left") )
        {
            moveLeft();
        }
        if (Greenfoot.isKeyDown("right") )
        {
            moveRight();
        }
        if (Greenfoot.isKeyDown("down") )
        {
            moveDown();
        }
        if (Greenfoot.isKeyDown("up") )
        {
            moveUp();
        }
    }
    
    
}

public class Space extends World
{

private Counter scoreCounter;
private int startpaperballs = 12;

    /**
     * Constructor for objects of class Space.
     * 
     */
    public Space()
    {    
        
        super(600, 400, 1);
        createrecyclingBin;
        addObject(user 300,100);
    }
    public void createpaperball()
    {
        int i = 0;
        while (paperball == !touched)
        {
            paperball value == 12;
            if(recyclingBin touches paperball)
            value--;
        }
    }
}
OGava OGava

2012/4/19

#
sry for such the long post tho guys...
danpost danpost

2012/4/19

#
Your applyForce() method at line 88 has a Body class in it, yet your are calling applyGravity(body) to a method that needs a paperball object. I see paperball extends Actor, so a paperball object cannot be a Body object. I have never seen any syntax as in line 128 (not sure what that does). I do not see any call to createpaperball(), though the code in that method looks like pseudo-code (not real code); and, besides, does not create paperball objects. You seem to be all over the place. In line 56, I am not sure why you would use negative numbers there. Line 60 has a '<-' where you probably want a '<='. Line 62 should probabaly be 'turn(180);'. Line 29 is out of place. Line 31 looks like more pseudo-code. In the user class, it looks like you are using the same key for two different things (that is, 'left' and 'right' for moving and turning) You should build your scenario one part at a time, compiling and testing each part as you create it (even with parts that came from other scenarios, to make sure they run properly in yours). Clean up what you have here, and re-post for specifics.
IsVarious IsVarious

2012/4/19

#
OGava wrote...
sry for such the long post tho guys...
I think the best thing you can do, is work with one piece of code at a time. What are you trying to have your project do, or what is the current issue you're trying to work out? It doesn't really help to just send lines and lines of code, because it requires us to work through all your code. So start with one small piece, and we can work from there. If you're clear on the "problem" you're having, it will help us better be able to help you :) Hope this helps.
IsVarious IsVarious

2012/4/19

#
The reason why his code is mixed, is because he pasted every line of code he has from all the classes.
OGava OGava

2012/4/19

#
thanks you guys, I did have it look wayy too mixed up and scattered but I'm mainly working on getting my user to only push the paperballs away from him so that he can score by getting them in the Bin. But as of now half of my code works im getting their. thanks alot dan
You need to login to post a reply.