Hi again!
I have continued on my physics engine and it is working ok. You press up, and they person jumps. well, flies. you let go and the person goes back down. What I am trying to do is to make it so you can only jump whilst touching the ground. However, it seems to be completely ignoring the ground boolean. Here is my code:
import greenfoot.*;
/**
* Write a description of class Person here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Person extends Actor
{
int MotionY = 0;
int MotionX = 0;
boolean Ground = false;
/**
* Act - do whatever the Person wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation( getX() + MotionX , getY() );
setLocation( getX(), getY() - MotionY);
Actor grass;
grass = getOneObjectAtOffset(0, 0, Grass.class);
if (grass != null)
{
MotionY = 0;
Ground = true;
}
else
{
MotionY-=2;
Ground = false;
}
if (Greenfoot.isKeyDown("left"))
{
MotionX-=1;
}
if (Greenfoot.isKeyDown("right"))
{
MotionX+=1;
}
if (Greenfoot.isKeyDown("up"))
{
if (Ground = true)
{
MotionY = 10;
Ground = false;
}
}
}
}