initial
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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 Actor
|
||||
{
|
||||
int velocityY = 0;
|
||||
int speed = 5;
|
||||
public void act()
|
||||
{
|
||||
player_movement();
|
||||
}
|
||||
|
||||
public void player_movement(){
|
||||
if (Greenfoot.isKeyDown("D")){
|
||||
setLocation(getX()+speed, getY());
|
||||
}
|
||||
if (Greenfoot.isKeyDown("A")){
|
||||
setLocation(getX()-speed, getY());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onGround(){
|
||||
int height = getImage().getHeight();
|
||||
|
||||
Actor floor = getOneObjectAtOffset(
|
||||
0,
|
||||
height / 2 + 1,
|
||||
Ground.class
|
||||
);
|
||||
|
||||
return floor != null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user