Hi, I'm new to greenfoot and I'm trying to make a game where my character moves across the screen using the arrow keys to maneuver it. I used the setLocation method instead of move because I did not want to have to deal with direction and when I pressed the arrow keys, my character just wen to the corner instead of moving one coordinate.
Here's the code for the character class
I'm still in the beginning stages of the game but the methods I'm having issue with are the moveUp, moveDown, MoveLeft, and moveRight methods. My guess is that the the third number in the world constructor which according to the comments makes the world a 1X1 pixel is the problem but if I set it to a number higher than 1 it creates an error. Someone please help!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Character extends Actor
{
private String name;
public static int walkingSpeed = 1;
public static int numberOfCombosPossible;
public static int range;
public static int lives = 3;
public static String specialAbility;
public Character()
{
super();
}
public void act()
{
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if(Greenfoot.isKeyDown("up"))
{
moveUp();
}
if(Greenfoot.isKeyDown("right"))
{
moveRight();
}
if(Greenfoot.isKeyDown("down"))
{
moveDown();
}
if(Greenfoot.isKeyDown("q"))
{
comboAttack();
}
if(Greenfoot.isKeyDown("w"))
{
//bigAttack();
}
if(Greenfoot.isKeyDown("space"))
{
//pickUp();
}
}
public String getName()
{
return name;
}
public String getSpecialAbility()
{
return specialAbility;
}
public void moveLeft()
{
setLocation(getX() - walkingSpeed, getY());
}
public void moveUp()
{
setLocation(getX(), getY()- walkingSpeed);
}
public void moveRight()
{
setLocation(getX() + walkingSpeed, getY());
}
public void moveDown()
{
setLocation(getX(), getY()+ walkingSpeed);
}
public void comboAttack()
{
}
}
