I am making a video game scroll world and so far i have typed this for the actor. It allows them to move left and right and jump. However, so far with compiling, when i get to the part that says " private GreenfootImage_playerStart= new GreenfootImage("Images/Idle/Idle_0.png");" it gives the <identifier> expected error. what am i doing wrong? thanks! =)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Animal
{
//Basics 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;
private GreenfootImage_playerStart= new GreenfootImage("Images/Idle/Idle_0.png");
private int speed = 2;
public void addedToWorld(Worldw){
//we set out 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
{
If(Greenfoot.isKeyDown("right"))
move (-30);
If(Greenfoot.isKeyDown("left"))
move (30);
}
applygravity();
applyjumpForce();
velocityX+=accelerationX;
velocityY+=accelerationY;
positionX+=velocityX;
positionY+=velocityY;
accelerationX=0;
accelerationY=0;
SetLocation((int)postionX,(int)postionY);
}
/**
* Accelerates the person downwards except for when they are on a platform
*/
private void apply Gravity(){
//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 out 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(){
Action coll = getOneIntersectionObject(Platform.class);
if(coll!=null){
//This is run when the person is touching a platform
If(Greenfoot.isKeyDown("Space")){
accelerationY-=jumpForce;
}
}
}
}

