Hi!
I have been creating a game in which you have a motionX and a motionY and when you hold down left, X will go down meaning the person will keep moving left. What I can't understand is how my program doesn't appear to subtract the motionX value. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import greenfoot.*; /** * Write a description of class Person here. * * @author (your name) * @version (a version number or a date) */ public class Person extends Actor { int MotionX = 0 ; int MotionY = 0 ; /** * Act - do whatever the Person wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setLocation( getX() + MotionX , getY() ) ; if (Greenfoot.isKeyDown( "left" )) { int sum = MotionX - 1 ; } } } |