• fullscreen
  • Beam.pde
  • Circle.pde
  • Enemy.pde
  • Player.pde
  • Salazar_the_Wizard_and_Brooms.pde
  • class Beam{
      float xloc1; 
      float yloc1; 
      float xloc2; 
      float yloc2;
      float xDir; 
      
      Beam(float txloc1, float tyloc1,float txloc2, float tyloc2, float xDir1){
        xloc1 = txloc1;
        xloc2 = txloc2; 
        yloc1 = tyloc1;
        yloc2 = tyloc2; 
        xDir = xDir1;
      }
      
      void display(){
        pushMatrix(); 
        strokeWeight(10); 
        strokeCap(SQUARE); 
        stroke(200, 0, 255); 
        line(xloc1, yloc1, xloc2, yloc2); 
        popMatrix();
      }
      
      void move(){
        xloc2+=  xDir;
      }
    }
    
    
    //although name says "Circle" this is an image class. 
    class Circle {
      float xPos; 
      float yPos; 
      float myColor;
      PImage img; 
       
      
      Circle(PImage p, float x, float y){
        img = p; 
        xPos = x; 
        yPos = y; 
        
      }
      
      void drawCirc() {
        image(img, xPos, yPos); 
      }
    }
    
    class Enemy{
      float xloc; 
      float yloc; 
      float xDir; 
      float hgt; 
      float wdt; 
      PImage img1;
      
      Enemy(PImage imgres1, float txloc, float tyloc, float tDir){
        xloc = txloc; 
        yloc = tyloc; 
        xDir = tDir; 
        img1 = imgres1;
      }
      
      void render() {
        fill(0, 255, 0); 
        image(img1, xloc, yloc); 
      }
      
      void move(){ 
        xloc += xDir; 
        if((xloc <= 0) || (xloc+wdt > width)){
          xDir = -xDir; 
        }
      }
    }
    
    
    
    class Player{
      float xloc; 
      float yloc; 
      PImage img; 
      
      Player(PImage ximg, float txloc, float tyloc){ 
        img = ximg; 
        xloc = txloc; 
        yloc = tyloc; 
      }
      
      void display() {
        image(img, xloc, yloc); 
      }
      
    
    }
    
    //classes and arrays
    Enemy[] brooms = new Enemy[300];
    Circle[] circleclass = new Circle[1];
    Player wizard; 
    Beam wizardbeam; 
    
    //game screens
    static final int START = 1; 
    static final int GAME  = 2;
    static final int LOSE  = 3; 
    static final int WIN   = 4; 
    
    
    //global variables
    int score = 0;
    boolean gameOver;
    boolean hit;
    float xDir= -10;
    //why is totz 0? shouldn't it be 300?
    int totz = 0; 
    int chance = 30; 
    int level; 
    //**add a limit for your loop
    int lmt =1;
    
    //game images
    PImage wiz; 
    PImage brm; 
    PImage bg; 
    PImage btl; 
    PImage strt;
    PImage fail; 
    PImage winner; 
    
    //goal loc variables
    float xCirc;
    float yCirc;
    float circDiam; 
    
    //broom variables
    float xbroom = 930;
    float ybroom = 480;
    
    //text
    PFont font; 
    PFont screenFont; 
    
    void setup() {
      background(255); 
      frameRate(30); 
      size(1000, 750); 
      smooth();
      wiz = loadImage("wizard.png"); 
      brm = loadImage("broom.png"); 
      bg  = loadImage("forestenviron.png");
      btl = loadImage("bottle.png");
      strt = loadImage("wiz.png"); 
      fail = loadImage("loser.png"); 
      winner = loadImage("win.png"); 
      screenFont = loadFont("Erasmus-32.vlw"); 
      font = loadFont("TrollBait-48.vlw"); 
      wizard = new Player(wiz, 150, 450);
      brooms = new Enemy[300];
      //use a loop to populate the array
      //set the loop limit to brooms.length 
      for(int i = 0; i<brooms.length; i++) {
        brooms[i] = new Enemy(brm, xbroom, random(10, height-100), xDir); 
      }
      xCirc = 30; 
      yCirc = 475; 
      circDiam = 40;  
      hit = false; 
      level = START; 
    }
    
    void checkLose(){
      for(int i = 0; i<totz; i++){
        if (brooms[i].xloc <= xCirc){
        println("Lives Left =" + chance);
        chance--; 
        }
      }
    }
    
    void checkHit(){
      for(int i = 0; i<brooms.length; i++){
          if ((lerp(wizardbeam.xloc1, wizardbeam.xloc2, 1) >= brooms[i].xloc) && (lerp(wizardbeam.xloc1, wizardbeam.xloc2, 1) <= brooms[i].xloc+250)){
            score++; 
            hit = true; 
            println("MINIONS OF EVIL FEEL MY WRATH!");
            brooms[i].xloc = 10000;
            brooms[i].xDir = 0; 
            brooms[i] = new Enemy(brm, xbroom, random(0, 600), xDir);
          }else{
            hit = false;
          }
        }
    }
    
    void keyPressed(){
      if (keyCode == UP){
        wizard.yloc-= 30;
        }
      if (keyCode == DOWN){
        wizard.yloc+= 30; 
        }
      if (keyCode == ' '){
        println("SHAZAM"); 
        float xloc1 = wizard.xloc + 152;
        float yloc1 = wizard.yloc + 135; 
        float xloc2 = wizard.xloc + 450; 
        float yloc2 = wizard.yloc + 135;
        float xDirect  = 1; 
        wizardbeam = new Beam(xloc1, yloc1, xloc2, yloc2, xDirect); 
        wizardbeam.display(); 
        checkHit();
        }  
      if (keyCode == ENTER){
        println("next lev"); 
        level++;    
        if ((level == WIN) || (level == LOSE) || (level == START)) {
          level++;
        }
      }
    }    
    void screenCheck(){
        if(score >= 300) {
          level = WIN;
        }
        if(chance <= 0) {
          level = LOSE; 
        }
        if (level == WIN) {
          level = GAME;
        }
        if (level == LOSE) {
          level = GAME;
        }
    }
    
    void killCount(){
      fill(255); 
      textFont(font); 
      text("Score: "+score, 700, 50); 
    }
    
    void showStart(){
      background(strt);  
      textFont(screenFont); 
      fill(255); 
      textSize(28); 
      textAlign(CENTER);
      text("Welcome to realm of Salazar the Great...the most powerful of wizard.\nThe evil Warlock Santorum have sent his minions to steal your magical potion.\nUse your wizardly powers to defeat Santorum's fiends!\nPress ENTER to begin", 500, 300);
    }
    
    void showLose(){
      background(fail); 
      textAlign(CENTER); 
      fill(255);
      textFont(screenFont);
      textSize(28); 
      text("You have failed to triumph over the forces of Santorum!\nThe Realm is now ridden with darkness due to your failure.  Great Job.\nPress ENTER to try again, otherwise, give up.", 500, 300); 
    }
    
    void showWin(){
      background(winner); 
      textAlign(CENTER); 
      textFont(screenFont); 
      fill(255); 
      textSize(28); 
      text("Santorum's broom minions are no match for a true wizard!\nPress ENTER to battle again!", 500, 300); 
    }
    
    void playGame(){
      background(bg);
      for (int i = 0; i< circleclass.length; i++){
          circleclass[i] = new Circle(btl, xCirc, yCirc);
          circleclass[i].drawCirc();
       }
      for(int i = 0; i< 1; i++){
         wizard.display();
       }
      //use brooms.length as the upper limit for i
      //**now use lmt to add things one by one
      for (int i = 0; i < lmt; i++){ 
        brooms[i].render();
        brooms[i].move(); 
      } 
      //**now increment lmt
      //if(lmt<brooms.length) lmt++;
      //**too fast? add another condition
      //88this one increments lmt every 100 frames
    //  if(frameCount%100==0) {
    //      if(lmt<brooms.length) lmt++;
    //  }
      checkLose();
      killCount();
    }
    
    void draw(){
      switch(level){
        case START:
          showStart();
          totz++; 
          break;
        case GAME:
          playGame(); 
          break;
        case LOSE:
          showLose(); 
          break; 
        case WIN:
          showWin();
          break;  
      }
      screenCheck(); 
      if (totz == 299) totz = 0; 
    }
    
    
    
    
    
    

    code

    tweaks (0)

    license

    advertisement

    Mick Kellogg

    Wizard and Broomsticks(Final!)

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

    Arrow keys to move, spacebar to unleash your wizardly powers!

    You need to login/register to comment.