Hi I'm making a 2D game where you're looking down on the player and he turns where he's moving, also, I can't figure out how to let him move up and down
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class explorer here.
*
import greenfoot.*;
/**
*
*/
public class explorer extends players
{
// The following field will be controlled by a bar that will tell the world to change it
private int speed = 1;
/**
* Method act:
* checks for keypresses and moves the robot the appropriate speed until it comes upon a barrier
*/
public void act()
{
move();
}
private void move()
{
int dx = 0;
if (Greenfoot.isKeyDown("a")) dx--;
if (Greenfoot.isKeyDown("d")) dx++;
for (int i=0; i<speed; i++)
{
setLocation(getX() + dx, getY());
if (getOneIntersectingObject(floortiles.class) == null) continue;
setLocation(getX(), getY() + 1);
if (getOneIntersectingObject(floortiles.class) == null) continue;
setLocation(getX(), getY() - 2);
if (getOneIntersectingObject(floortiles.class) == null) continue;
setLocation(getX() - dx, getY() + 1);
return;
}
}
}