• fullscreen
  • boss.pde
  • game14.pde
  • intermission.pde
  • mon1.pde
  • mon2.pde
  • mon3.pde
  • mon4.pde
  • movement.pde
  • spawn.pde
  • //This class controls the animations of the boss. It occupies locations 4 and 1 on the left hand side of the window. 
    class boss {
      int count;
      float last;
      PImage[] bossimage = new PImage[3]; 
    
    void update () {                                                                                //Load the images into the array.
      for (int i = 0; i < bossimage.length; i++) {
        bossimage[i] = loadImage("boss" + i + ".png");
      }
    }
    
    void display () {                                                                               //Display the images for each stage of formation. Using a flag ensures atomicity. 
      if (count == 1) { image(bossimage[0], -20, 90);; }
        else if (count == 2) { image(bossimage[1], -20, 90);; } 
        else if (count == 3) { image(bossimage[2], -20, 90);; }             
    }
    
    void spawn () {                                                                                 //Only allows the animation to update once every 0.5 seconds. 
      if (((millis() - last) > 500) && (count == 1)) { last = millis(); count = 2; }
        else if (((millis() - last) > 500) && (count == 2)) { last = millis(); count = 3; } 
        else if (((millis() - last) > 2500) && (count == 3)) { last = millis(); count = 0; } 
        else if (((millis() - last) > 500) && (count == 0)) { last = millis(); count = 1; }  
    }                                                                                               //Add an extra image featuring the boss death for level 3.   
    
    }
    
    //Colossal Castle Adventure. Iteration 14, Version 0.7.0
    
    //This game has 3 levels. The goal is to collect items off the ground over each level, requiring 5 item pick ups to progress to the next stage. 
    //Monsters spawn randomly in 4 different quadrants. Occupying a quadrant at the same time as a monster results in the loss of a life. There are 5 lives in total, and no way to regain lost lives.
    //It also requires ammunition to be picked up. Only a single stack of ammunition may be carried at any given time. Use ammunition to attack monsters, removing them from the screen.
    //At the third and final level, use ammunition to attack the boss 3 times to win the game. 
    
    //Use the W,A,S,D keys to maneuver through the 3 wings of the Bolide Citadel. Avoid the guards and pick up 5 arcane crystals to remove the arcane wards and progress to the next wing of the Citadel.
    //Pick up Ammunition for your repeating crossbow using the P key and fire at enemies using the O key. Fight your way to the heart of the Citadel until you encounter Warlord Tunguska himself, and strike him 3 fatal blows to lift the maisma of death from the Realms...
    //  - A little ostentatious, but it'll do.
    
    //Changes include new background images and the introduction of a victory image. 
    //Arranged ordering of the intermission screens and included a new mechanism to prevent the game from being forcibly continued using the loop(); function of the Enter keystroke.
    //Font has been changed back to Arial, which was deemed more user friendly.
    //Attemped to add a mechanism to reset the timers on a game pause, but it threw out the synchronization between the location flagging mechanism and the animations. 
    //Also considered was a mechanism to store a variable on Pausing, this allowing pause to be toggled with the enter keystroke. This failed due to the rapid number of times the loop would execute with a single keystroke.
    
    //June 18, 2008.
    
    //These classes control the monster animations, and the spawning mechanism. Also controls the movement algorithm to convert movement into quadrants and intermission screens.
    mon1 monster1;
    mon2 monster2;
    mon3 monster3;
    mon4 monster4;
    boss bossmon;
    spawn monspawn;
    movement move;
    intermission inter;
    
    //Used to control the timing of the player animation.
    float lastcount = 0;
    int animcount = 1;
    
    //Controls the item pick ups.                 
    int totalpicks = 0;                                   //How many items have been picked up for a particular level. 
    int pickloc = 5;                                      //Location of the items. 
    int pickspawn = 0;                                    //How long ago an item was spawned.
    int picklast = 0;                                     //How long ago an item was picked up. 
    
    PFont font;                                           //Font for on screen messages.
    PImage[] runimage = new PImage[6];                    //Stores the images for the player character
    PImage[] pickimage = new PImage[2];                   //Stores the images for pick up items. 
    PImage[] bgimage = new PImage[4];                     //The background image. 
    PImage[] icons = new PImage[4];                       //Icons used in the interface.
    
    boolean ammo = false;                                  //If the player has any ammo.
    int plives = 5;                                        //How many lives the player has. 
    int lasttime = 0;                                      //How long ago the player took damage. 
    int level = 0;                                         //Level counter. Starts at 0, but is displayed as level+1. This is so that it can be used to cycle through the background image array.
    int bossshoot = 0;                                     //How many times the boss has been shot. 
    
    int scoretime = 0;                                     //Score based on the time the program has been running. 
    int scorepicks = 0;                                    //Score based on how many items were picked up.
    int tscore = 0;                                        //Total score from items and time. 
    int start = 0;                                         //Controls stages, intermissions and level progression.
    
    int livex = 7;                                         //Controls the X value of the life and crystal display counters.
    int crystalx = 625;
    String sscore, slevel, level1, level2, level3;         //Strings to output the data to the interface.
    
      
    void setup() {
      size (800,600);
      smooth();
      noStroke();
      frameRate(30);
      font = loadFont("ArialRoundedMTBold-34.vlw");
        for (int i = 0; i < bgimage.length; i++) {                 //Load the background images into their respective array. 
          bgimage[i] = loadImage("background" + i + ".jpg");
        }
        for (int i = 0; i < runimage.length; i++) {                //Load the player images into their respective array. 
          runimage[i] = loadImage("run" + i + ".png");
        }
        for (int i = 0; i < pickimage.length; i++) {               //Load the item images into their respective array. 
          pickimage[i] = loadImage("pick" + i + ".png");
        }  
        for (int i = 0; i < icons.length; i++) {                   //Load icon images for the UI. 
          icons[i] = loadImage("icon" + i + ".png");
        }
    //These calls update the monster images into their respective arrays. 
        monster1 = new mon1();
          monster1.update();
        monster2 = new mon2();
          monster2.update();
        monster3 = new mon3();
          monster3.update();
        monster4 = new mon4();
          monster4.update();
        bossmon = new boss();
          bossmon.update();
        monspawn = new spawn();
        move = new movement();
        inter = new intermission();
          inter.update();
     }
    
    
    void draw() {
      image(bgimage[level], 0, 0);                                                                                       //Image changes as the level increases. 
    
      if (start==0) {               //Force the intro screens. 
        noLoop();
          inter.intro1();
      }
      if (start==1) {               //Move to the next intro screen once the enter key has been pressed.
        noLoop();
          inter.intro2();
      }
      if (start==2) {               //Enable level one once the enter key has been pressed again. 
        noLoop();
          inter.levelone();
      }
    
    if (start > 2) {                //Nest everything in an IF statement. This only allows the game to proceed once the start counter is at 2. (The first 2 intro screens have executed)
      
      if ((keyPressed == true) && (key == 'w' || key == 'W')) { move.py = move.py - 1; }                                                //Up
        else if ((keyPressed == true) && (key == 'a' || key == 'A')) { move.px = move.px - 1; }                                         //Left
        else if ((keyPressed == true) && (key == 's' || key == 'S')) { move.py = move.py + 1; }                                         //Down
        else if ((keyPressed == true) && (key == 'd' || key == 'D')) { move.px = move.px + 1; }                                         //Right
    
      move.convert();                                        //Parse the movement data into quadrant data. 
      move.throttle();
      move.flag();
      
      running();                                             //Call the function that controls the player's running animation.         
      collision();                                           //Call the function that controls collision between the player and monsters. 
      pickups();                                             //Call the function that controls the spawning of pick ups. 
      itemget();                                             //Call the function that controls collision between player and items. 
      monspawn.spawn1();                                     //Call the classes that control the spawning of the monsters. 
      shoot();                                               //Call the function that controls shooting from the player at the monsters.  
    
      if(level == 1) { monspawn.spawn2(); }                  //IF statements control the additional monster spawns for each level. 
      if(level == 2) { monspawn.spawn3(); }
    
      if (plives < 0) {                                       //Game Over screen.
        inter.gameover();
        noLoop();
        start = -5;
      }
      
    
      if ((level == 0) && (totalpicks > 5)) {                //Once 5 items have been picked up, proceed to level 2.
        level = level + 1; 
    //Reset all the variables to default. This prevents the monster spawning animation and the location flagging from falling out of synchronization. 
          monster4.count = 0; monster4.last = 0;
          monster3.count = 0; monster3.last = 0; 
          monster2.count = 0; monster2.last = 0; 
          monster1.count = 0; monster1.last = 0; 
          bossmon.count = 0; bossmon.last = 0;
          monspawn.monran = 5; monspawn.spawn = -2000; 
          monspawn.monran2 = 5; monspawn.spawn2 = -2000; 
          monspawn.monran3 = 5; monspawn.spawn3 = -2000; 
          totalpicks = 0;
        noLoop();                                  //Pause the game on progress to next level. 
          inter.leveltwo();                        //Call the class for the level intermission screen.
      }
      if ((level == 1) && (totalpicks > 5)) {      //Proceed to level 3.
        level = level + 1; 
          monster4.count = 0; monster4.last = 0; 
          monster3.count = 0; monster3.last = 0; 
          monster2.count = 0; monster2.last = 0; 
          monster1.count = 0; monster1.last = 0; 
          bossmon.count = 0; bossmon.last = 0;
          monspawn.monran = 5; monspawn.spawn = -2000; 
          monspawn.monran2 = 5; monspawn.spawn2 = -2000; 
          monspawn.monran3 = 5; monspawn.spawn3 = -2000; 
          totalpicks = 0;
        noLoop(); 
          inter.levelthree();
      }
      
      
      if ((level == 2) && (totalpicks > 5)) { totalpicks = 5; }        //Throttle the crystal counter at 5 visible crystals in the third stage. 
      
      scoretime = millis()/1000;                                       //Increment 1 point per second. 
      tscore = scoretime + scorepicks;                                 //Points are awarded for picking up items and shooting things. Points lost for taking damage and wasting ammunition.
    
      if (bossshoot > 2) {                                  //Victoly! A winner is you!
        noLoop(); 
        image(bgimage[3], 0, 0);                            //Call the Game Over image at the end, on top of all the other images. 
          inter.victory();    
        start = -5;
      }
    
      UI();                                                 //Put the User Interface on top of everything. 
      }
    }
    
    
    
    //Pause the game if the Enter key is pressed. Resume if released.
    void keyPressed() { if ((key == ENTER) || (key == RETURN)) { 
      if (start > -3) { start = start + 1; }                                      //Increment the start counter. This is to control the intro screen mechanic.
      if (start > 2) { inter.pause(); }                                           //If the intro screens have executed, call the Paused function when game is paused. 
      noLoop(); 
      } 
    }
    void keyReleased() { if ((key == ENTER) || (key == RETURN)) { 
      if (start > -3) { loop(); }                                                  //Prevents the user from forcing the loop to update by pressing enter if the game is over.
      } 
    }
    
    
    
    //Function to control the running animation timing.
    void running () {
      if (((millis() - lastcount) > 300) && (animcount == 1)) { lastcount = millis(); animcount = 2; }               //Only allow the running animation to update a frame once every 0.3 seconds. 
        else if (((millis() - lastcount) > 300) && (animcount == 2)) { lastcount = millis(); animcount = 1; } 
        else if (((millis() - lastcount) > 500) && (animcount == 3)) { lastcount = millis(); animcount = 2; } 
     if ((move.loc == 2) || (move.loc == 3)) { 
       if (animcount == 1) { image(runimage[0], move.x, move.y);; }
          else if (animcount == 2) { image(runimage[1], move.x, move.y);; }  
          else if (animcount == 3) { image(runimage[2], move.x-47, move.y+2);; }    }      //Shooting animation. Only activated when the shooting function is called, and resets after 0.5 seconds.
     if ((move.loc == 4) || (move.loc == 1)) { 
       if (animcount == 1) { image(runimage[4], move.x, move.y);; }
          else if (animcount == 2) { image(runimage[5], move.x, move.y);; }  
          else if (animcount == 3) { image(runimage[2], move.x-47, move.y+2);; }    }                                   //Shooting animation. Only activated when the shooting function is called, and resets after 0.5 seconds.
    
    }                                                                                                                //Add an extra image featuring the victory dance for level 3. 
    
    
    
    //Function to control whether or not the player has been hit by a monster.
    void collision () {
      if ((millis() - lasttime) > 1000) {            //Count the number of seconds since the player was last hit. If this is greater than 1 second, set flag to allow player to take damage.
        if ((monster4.count == 3) && (move.loc == 4)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; }              //If the monster and player are in the same quadrant, subtract one life.
          else if ((monster3.count == 3) && (move.loc == 1)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; }   
          else if ((monster2.count == 3) && (move.loc == 3)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; } 
          else if ((monster1.count == 3) && (move.loc == 2)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; } 
          else if ((bossmon.count == 3) && (move.loc == 4)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; }        //Boss occupies 2 quadrants for the purpose of damaging the player. 
          else if ((bossmon.count == 3) && (move.loc == 1)) { lasttime = millis(); plives = plives - 1; scorepicks = scorepicks - 20; }
      }
    }
    
    
    
    //Function to control the spawning of pick up items. Uses the same random algorithm as the monster spawning function.
    void pickups () {
        if ((millis() - pickspawn) > 3000) { pickloc = int(random(9));  pickspawn = millis(); }
          if (pickloc == 0) { image(pickimage[0], 253, 240);; }
            else if (pickloc == 2) { image(pickimage[0], 253, 490);; }                                       //Spawn regular level progression pick ups every 3 seconds. 
            else if (pickloc == 4) { image(pickimage[0], 476, 490);; }
            else if (pickloc == 6) { image(pickimage[0], 476, 240);; }
            else if (pickloc == 3) { image(pickimage[1], 243, 490);; }                                       //Ammunition only spawns in locations 3 and 2, on the bottom quadrants.
            else if (pickloc == 7) { image(pickimage[1], 466, 490);; }
    }
    
    
    
    //Function to flag items as they are picked up. 
    void itemget () {                                    //SHINE GET!
      if ((millis() - picklast) > 1000) {                                       //Can only pick up 1 item per second.
      if ((keyPressed == true) && (key == 'p') || (key == 'P')) {               //Only pick up the item when P is pressed. 
        if ((pickloc == 0) && (move.loc == 4) ) { picklast = millis(); totalpicks = totalpicks + 1; pickloc = 5; scorepicks = scorepicks + 20; }                    //Level progression items merely add points and increment the level progression counter.
            else if ((pickloc == 2) && (move.loc == 1) ) { picklast = millis(); totalpicks = totalpicks + 1; pickloc = 5; scorepicks = scorepicks + 20; }   
            else if ((pickloc == 4) && (move.loc == 3) ) { picklast = millis(); totalpicks = totalpicks + 1; pickloc = 5; scorepicks = scorepicks + 20; } 
            else if ((pickloc == 6) && (move.loc == 2) ) { picklast = millis(); totalpicks = totalpicks + 1; pickloc = 5; scorepicks = scorepicks + 20; } 
            else if ((pickloc == 3) && (move.loc == 1) ) { picklast = millis(); ammo = true; pickloc = 5; scorepicks = scorepicks + 25; }                                      //Ammunition pickups add points and flag the ammunition boolean to TRUE.
            else if ((pickloc == 7) && (move.loc == 3) ) { picklast = millis(); ammo = true; pickloc = 5; scorepicks = scorepicks + 25; } 
        }
      }
    }
    
    
    
    //Function to shoot monsters with.
    void shoot () {
      if ((keyPressed == true) && (key == 'o') || (key == 'O')) {               //Only shoot when the O key is pressed.
        if (ammo) {                     //If the ammunition boolean is TRUE, remove all monsters from the screen. 
          if ((monster1.count != 3) && (monster2.count != 3) && (monster3.count != 3) && (monster4.count != 3) && (bossmon.count != 3)) { scorepicks = scorepicks - 10; }  //Check quadrants. If each quadrant is empty, remove 10 points. 
            else {                      //If there is a monster present in a quadrant, clear all flags and set ammunition boolean to FALSE. Monsters can only be shot at at stage 3 of their spawning animation.        
                animcount = 3;          //Switch to the shooting animation if there is something to shoot at. 
                monster4.count = 0; monster4.last = 0;                          //Set all variables to default.
                monster3.count = 0; monster3.last = 0; 
                monster2.count = 0; monster2.last = 0; 
                monster1.count = 0; monster1.last = 0; 
                monspawn.monran = 5; monspawn.spawn = -2000; 
                monspawn.monran2 = 5; monspawn.spawn2 = -2000; 
                monspawn.monran3 = 5; monspawn.spawn3 = -2000; 
                ammo = false;                                                   //Remove ammo from the player. 
                scorepicks = scorepicks + 15;
            }
          if (bossmon.count == 3) { bossshoot = bossshoot + 1; scorepicks = scorepicks + 20; bossmon.count = 0; bossmon.last = 0; }          //Check to see if the boss is present when shooting. If so, increment the boss shooting counter, then reset the boss class variables.
        } 
      }
    }
    
    
    
    //Function that controls the UI. Has a graphical counter to represent progression items and player lives, as well as to indicate the presence of ammunition.
    //Also presents the score and level next to a portrait of the PC. Objects superimposed upon blue rectangles to help distinguish them. 
    void UI () {
      noStroke();                                           //Low opacity retangles. Helps distinguish individual UI objects.
        fill(18,137,228,50);
        rect(3,3,175,38);  
        rect(3,41,52,40);  
        rect(3,525,115,68); 
        rect(118,559,80,34); 
        rect(622,3,167,38);  
      image(icons[3], 5, 530);                              //Icon of the player. 
        sscore = ""+ tscore;                                //Convert the INT values of the score and levels into STRING values.
        slevel = ""+ (level+1);
        textFont(font);
        fill(212,142,32);
          text(slevel,90 , 535, 250, 50);                   //Display the level and score next to the player icon.
          text(sscore,90 , 565, 250, 50);
      if (ammo) { image(icons[2], 10, 40); }                //Toggle the ammo icon off according to the boolean variable.      
      for (int i = 0; i < plives; i = i + 1) {              //Iterate for every life left. 
        image(icons[0], livex, 7); 
        livex = livex + 33;
          if (livex > ((33 * plives))) { livex = 7; }       //Reset the X coordinate for the life counters. 
      }      
      for (int i = 0; i < totalpicks; i = i + 1) {          //Reuse the same FOR loop as the life counter, but count progression crystals instead.
        image(icons[1], crystalx, 7); 
        crystalx = crystalx + 33;
          if (crystalx > (592 + (33 * totalpicks))) { crystalx = 625; }         //Add the default value of crystalx to the IF check. This was unnecessary in the previous FOR loop because the X variable was considerably smaller than the value being appended to it.
      }  
    }
    
    //This class controls the intermissions displayed when the game pauses to change levels.
    class intermission { 
      PFont font;    //Font for on screen messages.
      PFont sma_font;
    
    void update() {                                       //Load the required fonts.
      font = loadFont("ArialRoundedMTBold-34.vlw");
      sma_font = loadFont("ArialRoundedMTBold-22.vlw");
    }
    
    void gameover() {                                     //Game Over screen. 
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,40);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Game Over";                        //You have been eaten by a Grue.
        text(intro1, 300 ,300, 200, 50);     
    }
    
    void victory() {                                     //Victory screen. Like Intro, but replace image of burning castle, dead boss and victory dance. Put this image on top of everything else, then call the UI on top of it.
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,40);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Victory!";
        text(intro1, 300 ,300, 200, 50);     
    }
    
    void intro1() {                                     //Intro page. Includes keystroke commands. 
      noStroke();
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(150,110,515,140);  
        rect(150,275,515,150);  
      textFont(font);
      fill(212,162,32);
      String intro1 = "Colossal Castle Adventure";      //Like Colossal Cave Adventure, just not as renowned or brilliantly programmed. Also not as good as Zork...
        text(intro1, 170 ,140, 500, 100); 
      String intro2 = "Press Enter to continue";
        text(intro2, 170 ,200, 500, 100); 
      textFont(sma_font);
      String intro3 = "- Use the W,A,S,D keys to maneuver.";
        text(intro3, 170, 295, 480, 100);
      String intro4 = "- Pick up crystals and ammunition using the P key.";
        text(intro4, 170, 325, 480, 100);
      String intro5 = "- Use the O key to fire your weapon.";
        text(intro5, 170, 375, 480, 100);
      textFont(font);
    }
    
    void intro2() {                                     //Intro page, number 2. Includes gameplay mechanics.
      noStroke();
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(150,110,515,140);  
        rect(150,275,515,150);  
      textFont(font);
      fill(212,162,32);
      String intro1 = "ITERATION 14, version 0.7.0";
        text(intro1, 160 ,170, 600, 100); 
      textFont(sma_font);
      String intro2 = "- Avoid enemies and collect 5 crystals to progress to the next level. ";
        text(intro2, 170, 295, 480, 100);
      String intro3 = "- Attack the boss in Level 3 three times to win.";
        text(intro3, 170, 365, 480, 100);
      textFont(font);
    }
    
    void levelone() {                                     //Intermission for level 1.
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,132);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Level 1; White Ramparts";
        text(intro1, 300 ,300, 200, 200);    
    }
    
    void leveltwo() {                                     //Intermission for level 2.
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,132);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Level 2; Forbidden Halls";
        text(intro1, 300 ,300, 200, 200);    
    }
    
    void levelthree() {                                     //Intermission for level 3.
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,132);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Level 3; The Inner Cloister";
        text(intro1, 300 ,300, 200, 200);    
    }
    
    void pause() {                                          //Game Paused screen.
      fill(18,137,228,50);
        rect(0,0,800,600);  
        rect(290,290,223,95);  
      textFont(font);
      fill(212,142,32);
      String intro1 = "Game Paused";
        text(intro1, 340 ,305, 200, 100);   
    }
    
    }
    
    //This class controls the animations of monster 1. This is located in the top right hand corner. Location 2.
    class mon1 {
      int count;
      float last;
      PImage[] monimage = new PImage[3]; 
    
    void update () {                                                                                //Load the images into the array.
      for (int i = 0; i < monimage.length; i++) {
        monimage[i] = loadImage("monTR" + i + ".png");
      }
    }
    
    void display () {                                                                               //Display the images for each stage of formation. Using a flag ensures atomicity. 
      if (count == 1) { image(monimage[0], 565, -35);; }
        else if (count == 2) { image(monimage[1], 565, -35);; } 
        else if (count == 3) { image(monimage[2], 565, -35);; }             
    }
    
    void spawn () {                                                                                 //Only allows the animation to update once every 0.5 seconds. 
      if (((millis() - last) > 500) && (count == 1)) { last = millis(); count = 2; } 
        else if (((millis() - last) > 500) && (count == 2)) { last = millis(); count = 3; } 
        else if (((millis() - last) > 2500) && (count == 3)) { last = millis(); count = 0; } 
        else if (((millis() - last) > 500) && (count == 0)) { last = millis(); count = 1; }  
    }
    
    }
    
    //This class controls the animations of monster 2. This is located in the bottom right hand corner. Location 3.
    class mon2 {
      int count;
      float last;
      PImage[] monimage = new PImage[3]; 
    
    void update () {                                                                                //Load the images into the array.
      for (int i = 0; i < monimage.length; i++) {
        monimage[i] = loadImage("monBR" + i + ".png");
      }
    }
    
    void display () {                                                                               //Display the images for each stage of formation. Using a flag ensures atomicity. 
      if (count == 1) { image(monimage[0], 560, 375);; }
        else if (count == 2) { image(monimage[1], 560, 375);; } 
        else if (count == 3) { image(monimage[2], 560, 375);; }             
    }
    
    void spawn () {                                                                                 //Only allows the animation to update once every 0.5 seconds. 
      if (((millis() - last) > 500) && (count == 1)) { last = millis(); count = 2; }
        else if (((millis() - last) > 500) && (count == 2)) { last = millis(); count = 3; } 
        else if (((millis() - last) > 2500) && (count == 3)) { last = millis(); count = 0; } 
        else if (((millis() - last) > 500) && (count == 0)) { last = millis(); count = 1; }  
    }
    
    }
    
    //This class controls the animations of monster 3. This is located in the bottom left hand corner. Location 1.
    class mon3 {
      int count;
      float last;
      PImage[] monimage = new PImage[3]; 
    
    void update () {                                                                                //Load the images into the array.
      for (int i = 0; i < monimage.length; i++) {
        monimage[i] = loadImage("monBL" + i + ".png");
      }
    }
    
    void display () {                                                                               //Display the images for each stage of formation. Using a flag ensures atomicity. 
      if (count == 1) { image(monimage[0], 0, 301);; }
        else if (count == 2) { image(monimage[1], 0, 301);; } 
        else if (count == 3) { image(monimage[2], 0, 301);; }             
    }
    
    void spawn () {                                                                                 //Only allows the animation to update once every 0.5 seconds. 
      if (((millis() - last) > 500) && (count == 1)) { last = millis(); count = 2; }
        else if (((millis() - last) > 500) && (count == 2)) { last = millis(); count = 3; } 
        else if (((millis() - last) > 2500) && (count == 3)) { last = millis(); count = 0; } 
        else if (((millis() - last) > 500) && (count == 0)) { last = millis(); count = 1; }  
    }
    
    }
    
    //This class controls the animations of monster 4. This is located in the top left hand corner. Location 4.
    class mon4 {
      int count;
      float last;
      PImage[] monimage = new PImage[3]; 
    
    void update () {                                                                                //Load the images into the array.
      for (int i = 0; i < monimage.length; i++) {
        monimage[i] = loadImage("monTL" + i + ".png");
      }
    }
    
    void display () {                                                                               //Display the images for each stage of formation. Using a flag ensures atomicity. 
      if (count == 1) { image(monimage[0], 0, 75);; }
        else if (count == 2) { image(monimage[1], 0, 75);; } 
        else if (count == 3) { image(monimage[2], 0, 75);; }             
    }
    
    void spawn () {                                                                                 //Only allows the animation to update once every 0.5 seconds. 
      if (((millis() - last) > 500) && (count == 1)) { last = millis(); count = 2; }
        else if (((millis() - last) > 500) && (count == 2)) { last = millis(); count = 3; } 
        else if (((millis() - last) > 2500) && (count == 3)) { last = millis(); count = 0; } 
        else if (((millis() - last) > 500) && (count == 0)) { last = millis(); count = 1; }    
    }
    
    }
    
    //This class controls player movement.
    class movement {
      int x, y, px, py, loc;                                   //X and Y are the values used by animations to align themselves.
                                                               //PX and PY are the values used to identify the quadrants arranged into a 2 * 2 grid.
                                                               //LOC is the location value assigned to each quadrant.
    //Takes the PX and PY values from the keystrokes and converts them into raw X and Y values.
    void convert () {
      if (px == 1) { x = 453; }                                //Assign X and Y coordinates to each grid quadrant. 
      if (px == 0) { x = 248; }
      if (py == 1) { y = 350; }
      if (py == 0) { y = 100; }
    }
    
    //Prevents the PX and PY values from extending outside of the grid.
    void throttle () {
      if (px > 1) { px = 1; }                                  //Prevent the grid values from exceeding 1 or 0.
      if (px < 0) { px = 0; }
      if (py > 1) { py = 1; }
      if (py < 0) { py = 0; }
    }
    
    //Assigns each PX and PY combination a LOC value. 
    void flag () {
      if ((px == 1) && (py == 0)) { loc = 2; }                       //Top right
      if ((px == 1) && (py == 1)) { loc = 3; }                       //Bottom right
      if ((px == 0) && (py == 0)) { loc = 4; }                       //Top left
      if ((px == 0) && (py == 1)) { loc = 1; }                       //Bottom left
    }
    
    }
    
    //This class controls the lists from which monsters spawn in each level. 
    class spawn {
      int monran = 5;                                           //Random number between 1 - 4. Determines the monster that spawns. Set to 5 initially to prevent monsters spawning as soon as the game starts.
      int spawn = -2000;                                        //Last time the monster was spawned.
      int monran2 = 5;                                          //Monsters for second level.  
      int spawn2 = -2000;
      int monran3 = 5;                                          //Monsters for second level.
      int spawn3 = -2000;
    
    void spawn1 () {                                                                              //Always spawn this one set of monsters.
      if ((millis() - spawn) > 4000) { monran = int(random(5));  spawn = millis(); }              //Generate a random number.
        if (monran == 0) { monster4.spawn(); monster4.display(); }                                //Use this number to determine which monster is spawned. Possible to get a NULL value, indicating no monster is spawned.
          else if (monran == 1) { monster3.spawn(); monster3.display(); }
          else if (monran == 2) { monster2.spawn(); monster2.display(); }
          else if (monran == 3) { monster1.spawn(); monster1.display(); }    
    }
    
    void spawn2 () {                                                                              //Spawn these monsters only for the second level. Allows 2 monsters to spawn.       
      if (level == 1 ) {
        if ((millis() - spawn2) > 4000) { monran2 = int(random(5)); spawn2 = millis(); }             
        if (monran2 == 0 && monran != 4) { monster4.spawn(); monster4.display(); }                //Do not allow 2 monsters to spawn in the same quadrant.
          else if (monran2 == 1 && monran != 1) { monster3.spawn(); monster3.display(); }
          else if (monran2 == 2 && monran != 2) { monster2.spawn(); monster2.display(); }
          else if (monran2 == 3 && monran != 3) { monster1.spawn(); monster1.display(); }
      }
    }
    
    void spawn3 () {                                                                               //Spawn these monsters only for the third level. Adds the final boss to the monster list. 
      if (level == 2 ) {
        if ((millis() - spawn3) > 4000) { monran3 = int(random(5)); spawn3 = millis(); } 
          if (monran3 == 2 && monran != 2) { monster2.spawn(); monster2.display(); }
            else if (monran3 == 3 && monran != 3) { monster1.spawn(); monster1.display(); }
            else if (monran3 == 0 || monran3 == 1) {                                               //Spawn the boss if random is a 0 or 1. 
              if (monran == 0 || monran == 1) { monran = 5; monster3.count = 0; monster4.count = 0; spawn = millis(); } //Despawn any monsters in locations 3 and 4. This is to prevent the player taking double damage in the occupied quadrant.
          bossmon.spawn(); bossmon.display(); 
        }   
      }
    }
    
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    eric neo

    game14

    Add to Faves Me Likey@! 2
    You must login/register to add this sketch to your favorites.

    game made in processing.

    Hey,
    They always tell Processing is not for game development. You prove that it is wrong!!
    dramathis
    20 May 2011
    can you help me about my school homework.? Because i haven't got enough information about processing. Waiting your reply.This is very important for me
    You need to login/register to comment.