

If(Greenfoot.isKeyDown("down")) // Detect if down key is pressed Private void rotateImage() // Rotate Subject003 in the direction of arrow keys pressed Reload- // Decrease reload by 1 every act aySound("AWP.mp3") // Play sound whenever mouse is clicked and reload equals 0 Reload = 80 - abc // Reload resets to 80 every time mouse is clicked GetWorld().addObject(new DormousBullet(getRotation()),getX(),getY()) // Adds a new bullet object when moused is clicked and reload equals 0 If(reload <= 0) // When reload is 0, a bullet can be fired If(Greenfoot.mouseClicked(null)) // Detect if the mouse is clicked SetLocation(getX() + speed, getY()) // Increase position on the X axis to move right If(Greenfoot.isKeyDown("right")) // Check if right arrow key is pressed SetLocation(getX() - speed, getY()) // Decrease position on the X axis to move left If(Greenfoot.isKeyDown("left")) // Check if left arrow key is pressed SetLocation(getX(), getY() + speed) // Increase position on Y axis to move downwards If(Greenfoot.isKeyDown("down")) // Check if down arrow key is pressed SetLocation(getX(), getY() - speed) // Decrease position on Y axis to move upwards If(Greenfoot.isKeyDown("up")) // Check if up arrow key is pressed Private void checkKeys() // Moves Subject003 in the direction of the arrow keys pressed. TouchInfectedDormous() // Receive health buff when Captive2 is touchedĬollectCheese() // Increase the score by 25 when cheese is collected TouchControlPanel() // Detect if intersecting with control panel Killed() // Detect if health falls below 1 TouchPortal() // Send to level 2 when touched TouchCaptive() // Receive movement speed and firerate buff when Captive is touched RotateImage() // Rotate the image when the correct keys are pressed Reload = newReload // Keep new increased reloadĬheckKeys() // Check which keys are pressed and move in the appropriate direction Speed = newSpeed // Keep new increased speed If(powerMeUp = true) // If Subject003 has picked up the powerup Public Subject003(boolean powerMeUp, int newSpeed, int newReload) // When Subject003 has picked up the captive Public Subject003() // When Subject003 hasn't picked up the Captive Public boolean poweredUp = false // Default setting for poweredUp Private int healthPoints = 1 // healthPoints variable Public class Subject003 extends Characters JOptionPane.Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) If(scoreCounter.getValue() < highScoreCounter.getValue()) Public void act()//makes one virus spawn in a random location for every 100 calls of the act methodĪddObject(new Virus(), Greenfoot.getRandomNumber(680) + 100, Greenfoot.getRandomNumber(710) + 70 ) tValue(ORIGINAL_BEST_TIME) īestTimeHolder = ORIGINAL_BEST_TIME_HOLDER

HighScoreCounter = new Counter("Best Time: " + bestTimeHolder + ": ") ScoreCounter = new Counter(player1.getName() + "'s Time: ") \nGood luck!") ĪddObject(new Key(), Greenfoot.getRandomNumber(680) + 100, Greenfoot.getRandomNumber(710) + 70 ) \nViruses will try to attack you but I have equipped you with weapons that will aid you on your quest. JOptionPane.showMessageDialog(null, "Nice to meet you" + " " + inputstr + "! \nI am sorry to tell you this but you are trapped in my system and the only way to get out is to collect the 9 keys in this world. String inputstr = JOptionPane.showInputDialog("Hello, thank you for playing 9 keys.\n What is your Name?") \n Be Careful!!! Bombs will destroy everything in range including keys and yourself")

JOptionPane.showMessageDialog(null, "Instructions: \n \n Arrow Keys: Movement \n Q Key: fire arrow \n W Key: drop bomb \n Spacebar: pick up key \n Pick up all 9 keys to win. The player and the original virus start in the same spot but the keys are spawned in random locations which makes the game different every time. Public void populateWorld()//creates the player, all of the keys, and one virus. Create a new world with 600x400 cells with a cell size of 1x1 pixels. Public GameWorld1()//construcotr sets the spawnCounter to 100, populates the world, and starts the game * Constructor for objects of class GameWorld. Public static final String ORIGINAL_BEST_TIME_HOLDER = "Nobody" Public static final int ORIGINAL_BEST_TIME = 36000 Private int spawnCounter //the rate at which enemies spawn in the world.

Public class GameWorld1 extends World//Class heading In the future I will have different levels which are the other GameWorlds.
Greenfoot score counter code#
* At the moment this is the only gameworld class that has code in it. This class represents the world in which the game takes place. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
