import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.util.List; import java.util.ArrayList; import java.awt.*; import java.awt.image.*; import java.awt.geom.*; import javax.swing.*; public class Tux extends Mouse { private static final int EAST = 0; private static final int WEST = 1; private static final int NORTH = 2; private static final int SOUTH = 3; private int direction; private GreenfootImage tuxRight; private GreenfootImage tuxLeft; public Tux() { super("Tux","Ryan","Orcimsoft"); tuxRight = getImage(); tuxLeft = new GreenfootImage(getImage()); tuxLeft.mirrorHorizontally(); tuxLeft.scale(20,20); tuxRight.scale(20,20); } public void act() { int x = getX(); int y = getY(); int num; World myWorld = getWorld(); num = Greenfoot.getRandomNumber(4) +1; if(num ==1) { List Brick = myWorld.getObjectsAt(x, y-2, Brick.class); if (Brick.isEmpty()) { y = getY() -4; } } if(num ==2) { List Brick = myWorld.getObjectsAt(x, y+2, Brick.class); if (Brick.isEmpty()) {y = getY() + 4; } } if(num ==3) { List Brick = myWorld.getObjectsAt(x-2, y, Brick.class); if (Brick.isEmpty()) {x = getX() - 4; } } if(num ==4) { List Brick = myWorld.getObjectsAt(x+2, y, Brick.class); if (Brick.isEmpty()) {x = getX() + 4; } } } /* Cosmetic stuff, just setting direction of image */ public void setDirection(int direction) { this.direction = direction; switch(direction) { case SOUTH : setImage(tuxRight); setRotation(90); break; case EAST : setImage(tuxRight); setRotation(0); break; case NORTH : setImage(tuxLeft); setRotation(90); break; case WEST : setImage(tuxLeft); setRotation(0); break; default : break; } } }