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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import greenfoot.*; /** * This is the human, the last survivor on earth * * @author Eric Faltermeier * @version 12/6/2017 */ public class Human extends Actor { private boolean isDown; private GreenfootImage rightImage; public Human() // This makes the human more to scale with the rest of the world. { //myImage = new GreenfootImage("Human.gif"); GreenfootImage myImage = getImage(); int myNewWidth = ( int )myImage.getWidth()/ 8 ; int myNewHeight = ( int )myImage.getHeight()/ 8 ; myImage.scale(myNewWidth,myNewHeight); rightImage = myImage; } public void act() { move(); } public void move() // This is where the character is controlled it makes it so the character face the right way { if (Greenfoot.isKeyDown( "s" )) { setLocation(getX(), getY() + 2 ); } if (Greenfoot.isKeyDown( "w" )) { setLocation(getX(), getY() - 2 ); } if (Greenfoot.isKeyDown( "a" )) { move(- 2 ); if (Greenfoot.isKeyDown( "a" ) && !isDown) { getImage().mirrorHorizontally(); isDown = true ; } if (!Greenfoot.isKeyDown( "a" ) && isDown) { isDown = false ; } } if (Greenfoot.isKeyDown( "d" )) { setImage( "Human2.gif" ); GreenfootImage myImage = getImage(); int myNewWidth = ( int )myImage.getWidth()/ 8 ; int myNewHeight = ( int )myImage.getHeight()/ 8 ; myImage.scale(myNewWidth,myNewHeight); move( 2 ); } } } |

