I want my Player to set the Speed slower, if the key is not pressed.
And on every field a bit slower.
A bit like an accerleration.
But my Player don't do it.
He stops when i don't press the buttom.
And when i press the buttom on, he gets faster.
His maximum Speed should be 5 and without pressing it should be 0.
The Code is:
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 Mover { int Speed; int bSpeed; int Blockade; int xOffset; int yOffset; int speed; public Player() { Speed = 1; bSpeed = 1; Blockade = -3; speed = Speed + bSpeed; } /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.isKeyDown("up||down||left||right||a||s||d||w")) { Speed = 0; bSpeed = 0; } } public void up() { setLocation( getX() , getY() - Speed ); Speed = Speed + bSpeed; } public void down() { setLocation( getX() , getY() + Speed ) ; Speed = Speed + bSpeed; } public void right() { setLocation( getX() + Speed , getY()) ; Speed = Speed + bSpeed; } public void left() { setLocation( getX() - Speed , getY() ) ; Speed = Speed + bSpeed; } //public boolean onActor() //{ // Actor under = getOneObjectAtOffset ( 0, //getImage().getHeight()/2, Player.class); // return under != null; // }