So I am new to Greenfoot and found out how to make a character have gravity and be able to jump, but I have no clue how to make certain parts of my world to be solid and have my actor be able to "stand" on them...
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Player extends Actor
{
private int ySpeed;
private int apexTimer;
public int iN = 1;
public int count;
public Player()
{
}
public void act()
{
int groundLevel = getWorld().getHeight() - getImage().getHeight()/2;
boolean onGround = (getY() == groundLevel);
Movement();
Aump();
Dump();
if (!onGround)
{
if (ySpeed == 0 && apexTimer > 0) apexTimer--;
if (ySpeed == 0 && apexTimer > 0) return;
ySpeed++;
setLocation(getX(), getY()+ySpeed);
if (getY()>=groundLevel)
{
setLocation(getX(), groundLevel);
Greenfoot.getKey();
}
}
else
{
if ("w".equals(Greenfoot.getKey()))
{
ySpeed = -15;
setLocation(getX(), getY()+ySpeed);
apexTimer = 5;
}
}
}
public void Movement()
{
if (Greenfoot.isKeyDown("S"))
{
setLocation(getX() , getY() + 3);
}
if (Greenfoot.isKeyDown("A"))
{
setLocation(getX() - 3, getY());
_Animation();
}
if (Greenfoot.isKeyDown("D"))
{
setLocation(getX() + 3, getY() );
Animation();
}
}
public void Animation()
{
if(count % 3 == 0)
iN++;
if(iN == 8)
{
iN = 1;
}
setImage("W" + iN + ".png");
count++;
}
public void _Animation()
{
if(count % 3 == 0)
iN++;
if(iN == 8)
{
iN = 1;
}
setImage("-W" + iN + ".png");
count++;
}
public void Dump()
{
if(Greenfoot.isKeyDown("W"))
{
if(Greenfoot.isKeyDown("D"))
{
setImage("J1.png");
}
}
}
public void Aump()
{
if(Greenfoot.isKeyDown("W"))
{
if(Greenfoot.isKeyDown("A"))
{
setImage("-J1.png");
}
}
}
}