Basic Platform, but when my character jumps it disappears. Wondered if anyone could help fix it.
public class Player extends Actor
public class Player extends Actor
{
private int Timer;
private int Jump_Height = 12;
private int Walk_Speed = 3;
private double Fall_Speed = 0.4;
private boolean In_The_Air = false;
private double Delta_X = 0;
private double Delta_Y = 0;
private int Ground_Height = getImage().getHeight()/2;
private int Side_Width = getImage().getWidth()/2;
private World myWorld;
int World_Height;
int World_Width;
public void Added_To_World(World myWorld)
{
this.myWorld = myWorld;
this.World_Height = myWorld.getHeight();
this.World_Width = myWorld.getWidth();
}
public void act()
{
if (In_The_Air)
{
Fall();
}
else
{
Get_Command();
}
Move();
int Pos_Y = getY()+10;
if (Timer > 0)
{
Timer--;
}
if (Timer == 0 && Greenfoot.isKeyDown("space"))
{
Bullet bullet = new Bullet();
getWorld().addObject(bullet, 250, Pos_Y);
Timer = 30;
}
}
private void Run (String Direction)
{
if (Direction =="left")
{
Delta_X = Walk_Speed*-1;
}
else
{
Delta_X = Walk_Speed*-1;
}
}
private void Stop()
{
Delta_X = 0;
}
private void Jump()
{
Delta_Y += Jump_Height;
In_The_Air = true;
}
private void Fall()
{
Delta_Y-=Fall_Speed;
}
private void Move()
{
double New_X = getX() + Delta_X;
double New_Y = getY() - Delta_Y;
Actor Platform_Below = getOneObjectAtOffset(0, Ground_Height, Platform.class);
if (Platform_Below != null)
{
if (Delta_Y < 0)
{
Delta_Y = 0;
In_The_Air = false;
GreenfootImage platformImage = Platform_Below.getImage();
int Top_Of_Platform = Platform_Below.getY() - platformImage.getHeight()/2;
New_Y = - Ground_Height;
}
}
else if (getY() >= World_Height - Ground_Height)
{
if (Delta_Y < 0)
{
Delta_Y = 0;
In_The_Air = false;
New_Y = - Ground_Height;
}
}
else
{
In_The_Air = true;
}
setLocation((int)New_X, (int)New_Y);
}
private void Get_Command()
{
if (Greenfoot.isKeyDown("up"))
{
Jump();
}
}
public void act_Two()
{
if (isTouching(EnemyOne.class))
{
removeTouching(EnemyOne.class);
getWorld().addObject(new EnemyOne(), 1000, 2);
Level_1.HP.Add(-1);
if (Level_1.HP.Get_Value() == 0)
{
Greenfoot.setWorld(new RetryWorld());
}
}
}
}
