i am trying to learn to use greenfoot an wanted to make a platformer but the tutorial(s) is out of date so some of the old rules/code dont work anymore anyone know the new ways?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The person who will move about platforms.
* @author - Michael "webmessia"
*/
public class Person extends Actor
{
//Basic Physics Variables
private double positionX;
private double positionY;
private double velocityX = 0;
private double velocityY = 0;
private double accelerationX = 0;
private double accelerationY = 0;
//Force Values
private double gravityY = 0.1;
private double jumpForce = 3.5;
public void addedToWorld(World w){
//We set our position to the position which we were added to the world at.
positionX = getX();
positionY = getY();
}
/**
* 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()
{
//Apply Forces to change acceleration to move the person
applyGravity();
applyJumpForce();
//Basic Physics
velocityX += accelerationX;
velocityY += accelerationY;
positionX += velocityX;
positionY += velocityY;
accelerationX = 0;
accelerationY = 0;
setLocation((int)positionX,(int)positionY);
}
/**
* Accelerates the person downwards except for when they are on a platform
*/
private void applyGravity(){
// Check For collision with platform
Actor coll = getOneIntersectingObject(Platform.class);
if(coll == null){
//This is run when the person is not touching a platform
//This code adds gravity to our total acceleration.
accelerationY += gravityY;
} else {
//This is run once we hit a platform
//We make our person stop moving in the y direction. (up/down direction).
velocityY = 0;
}
}
/**
* Accelerates the person upwards if space is pressed and we are on a platform
*/
public void applyJumpForce(){
Actor coll = getOneIntersectingObject(Platform.class);
if(coll != null){
//This is run when the person is touching a platform
if(Greenfoot.isKeyDown("space")){
accelerationY -= jumpForce;
}
}
}
}