• fullscreen
  • enemy.pde
  • h.pde
  • mouse_game9.pde
  • soundplayer.pde
  • boolean enemy;
    int speed = 3;
    int speed2 = 3;
    int enemyx=rectsize*8+rectsize/2;
    int enemyy=rectsize*4+rectsize/2;
    int enemyx2=rectsize*6+rectsize/2;
    int enemyy2=rectsize*3+rectsize/2;
    //level 3
    int enemylx = rectsize*6+rectsize/2; int enemyly = rectsize*7+rectsize/2; int speedl = 10;
    int enemylx2 = rectsize*8+rectsize/2; int enemyly2 = rectsize*5+rectsize/2; int speedl2 = 10;
    int enemylx3 = rectsize*6+rectsize/2; int enemyly3 = rectsize*3+rectsize/2; int speedl3 = 10;
    
    int enemylx4 = rectsize/2; int enemyly4 = rectsize*7+rectsize/2; int speedl4 = 3;
    int enemylx5 = rectsize/2; int enemyly5 = rectsize*3+rectsize/2; int speedl5 = 3;
    int enemylx6 = rectsize*4+rectsize/2; int enemyly6 = rectsize/2; int speedl6 = 3;
    int enemylx7 = rectsize*7+rectsize/2; int enemyly7 = rectsize/2; int speedl7 = 3;
    
    
    void enemy(){
      //enemy1
      fill(0);
      rect(enemyx,enemyy,rectsize,rectsize);
      fill(0,0,0,60);
      rect(enemyx+28,enemyy+28,rectsize,rectsize);
      enemyy = enemyy + speed;
      if(enemyy>=rectsize*5+rectsize/2+2){
        speed = -3;
       
      }
      if(enemyy<=rectsize*4-rectsize/2-2){
        
        speed = 3;
      }
      if(y-ballsize/2<=enemyy+rectsize/2&&y>=rectsize*2&&x>=rectsize*8){
        gameover = true;
        
      }
      //enemy2
      fill(0);
      rect(enemyx2,enemyy2,rectsize,rectsize);
      fill(0,0,0,60);
      rect(enemyx2+28,enemyy2+28,rectsize,rectsize);
      enemyy2 = enemyy2 + speed2;
      if(enemyy2>=rectsize*5+rectsize/2+2){
        speed2 = -3;
     
      }
      if(enemyy2<=rectsize*4-rectsize/2-2){
        speed2 = 3;
        
      }
      if(y-ballsize/2<=enemyy2+rectsize/2&&y>=rectsize*2&&x -ballsize/2>=rectsize*6&&x-ballsize/2<=rectsize*7){
        gameover = true;
        
      }
    }
    
    void enemylevel3(){
      //enemy1
      fill(0);
      rect(enemylx,enemyly,rectsize,rectsize);
      rect(enemylx2,enemyly2,rectsize,rectsize);
      rect(enemylx3,enemyly3,rectsize,rectsize);
      rect(enemylx4,enemyly4,rectsize,rectsize);
      rect(enemylx5,enemyly5,rectsize,rectsize);
      rect(enemylx6,enemyly6,rectsize,rectsize);
      rect(enemylx7,enemyly7,rectsize,rectsize);
      
      fill(0,0,0,60);
      rect(enemylx+28,enemyly+28,rectsize,rectsize);
      rect(enemylx2+28,enemyly2+28,rectsize,rectsize);
      rect(enemylx3+28,enemyly3+28,rectsize,rectsize);
      rect(enemylx4+28,enemyly4+28,rectsize,rectsize);
      rect(enemylx5+28,enemyly5+28,rectsize,rectsize);
      rect(enemylx6+28,enemyly6+28,rectsize,rectsize);
      rect(enemylx7+28,enemyly7+28,rectsize,rectsize);
      
      enemylx = enemylx + speedl;
      enemylx2 = enemylx2 + speedl2;
      enemylx3 = enemylx3 + speedl3;
      enemylx4 = enemylx4 + speedl4;
      enemylx5 = enemylx5 + speedl5;
      enemyly6 = enemyly6 + speedl6;
      enemyly7= enemyly7 + speedl7;
      
      //1
      if(enemylx>=rectsize*8+rectsize/2){
        speedl = -10;
      }
      if(enemylx<=rectsize*7-rectsize/2){
        speedl = 10;
      }
      //2
      if(enemylx2>=rectsize*8+rectsize/2){
        speedl2 = -10;
      }
      if(enemylx2<=rectsize*7-rectsize/2){
        speedl2 = 10;
      }
        //3
        if(enemylx3>=rectsize*8+rectsize/2){
        speedl3 = -10;
      }
      if(enemylx3<=rectsize*7-rectsize/2){
        speedl3 = 10;
      
    }//4
    if(enemylx4>=rectsize*2+rectsize/2){
        speedl4 = -3;
      }
      if(enemylx4<=rectsize/2){
        speedl4 = 3;
      
    }//5
    if(enemylx5>=rectsize*2+rectsize/2){
        speedl5 = -3;
      }
      if(enemylx5<=rectsize/2){
        speedl5 = 3;
      
    }//6
    if(enemyly6>=height-rectsize/2){
        speedl6 = -3;
      }
      if(enemyly6<=rectsize/2){
        speedl6 = 3;
      
    }//7
    if(enemyly7>=rectsize*2+rectsize/2){
        speedl7 = -3;
      }
      if(enemyly7<=rectsize/2){
        speedl7 = 3;
      
    }
    if(s){
      soundplayer();
      if(enemylx>=rectsize*8+rectsize/2){
        speedl = -1;
      }
      if(enemylx<=rectsize*7-rectsize/2){
        speedl = 1;
      }
    }
    
    if(s2){
      soundplayer();
      if(enemylx2>=rectsize*8+rectsize/2){
        speedl2 = -1;
      }
      if(enemylx2<=rectsize*7-rectsize/2){
        speedl2 = 1;
    }
    }
    
    if(s3){
      soundplayer();
      if(enemylx3>=rectsize*8+rectsize/2){
        speedl3 = -1;
      }
      if(enemylx3<=rectsize*7-rectsize/2){
        speedl3 = 1;
    }
    }
      
    
    //1
    if(y-ballsize/2<=enemyly+rectsize/2&&y+ballsize/2>=enemyly-rectsize/2
    &&x -ballsize/2<=enemylx+rectsize/2&&x+ballsize/2>=enemylx){
        gameover = true;
    }//2
    if(y-ballsize/2<=enemyly2+rectsize/2&&y+ballsize/2>=enemyly2-rectsize/2
    &&x -ballsize/2<=enemylx2+rectsize/2&&x+ballsize/2>=enemylx2){
        gameover = true;
    }//3
    if(y-ballsize/2<=enemyly3+rectsize/2&&y+ballsize/2>=enemyly3-rectsize/2
    &&x -ballsize/2<=enemylx3+rectsize/2&&x+ballsize/2>=enemylx3){
        gameover = true;
    }//4
    if(y-ballsize/2<=enemyly4+rectsize/2&&y+ballsize/2>=enemyly4-rectsize/2
    &&x -ballsize/2<=enemylx4+rectsize/2&&x+ballsize/2>=enemylx4){
        gameover = true;
    }//5
    if(y-ballsize/2<=enemyly5+rectsize/2&&y+ballsize/2>=enemyly5-rectsize/2
    &&x -ballsize/2<=enemylx5+rectsize/2&&x+ballsize/2>=enemylx5){
        gameover = true;
    }//6
    if(y-ballsize/2<=enemyly6+rectsize/2&&y+ballsize/2>=enemyly6-rectsize/2
    &&x -ballsize/2<=enemylx6+rectsize/2&&x+ballsize/2>=enemylx6){
        gameover = true;
    }//7
    if(y-ballsize/2<=enemyly7+rectsize/2&&y+ballsize/2>=enemyly7-rectsize/2
    &&x -ballsize/2<=enemylx7+rectsize/2&&x+ballsize/2>=enemylx7){
        gameover = true;
    }
    }
    
    boolean level1,gameover,startover,player,Switch,level2,switch2,highlight,
    blockade,level3,s,s2,s3,youwin;
    
    void mouse(){
      highlight = false;
      startover = true;
      
      if(startover){
        player = false;
      if(mouseX>width/8.3&&mouseX<width/5.6&&mouseY>height/8.3&&mouseY<height/5.6){
        highlight=true;
        
        
        if (mousePressed==true){
          level1 = true;
          player = true;
          
        }
        
      }
      }
      
       
      //
      
      if(level1){
        gcount = 0;
        
        player = true;
        //boundarys
        if(x-ballsize/2<=rectsize||
        y-ballsize/2<=rectsize||
        x+ballsize/2>=width-rectsize||
        y+ballsize/2>=height-rectsize||
        x+ballsize/2>=rectsize*2&&x-ballsize/2<=rectsize*4&&y-ballsize/2<=rectsize*8||//middle
        x+ballsize/2>=rectsize*6&&x-ballsize/2<=rectsize*8&&y-ballsize/2<=rectsize*8)
        {
          gameover = true;
          
      }
      
      if(x-ballsize/2>=rectsize*4&&x+ballsize/2<=rectsize*6&&y-ballsize/2<rectsize*2){
        Switch = true;
      }
      if(Switch) {
        soundplayer();
      if(
      y-ballsize/2<=rectsize+ballsize&&
        x-ballsize/2>=rectsize*8&&
        x+ballsize/2<=rectsize*9){
        level2 = true;
        level1=false;
      }
      }
      }
      
        if(level2){
          
        player = true;
        if(x+ballsize/2>=rectsize*8+ballsize/2&&y>rectsize*9){
          switch2 = true;
          level2 = false;
          level3 = true;
        }
      
        if(switch2==false){
        blockade = true;
        if(blockade){
          if(x+ballsize/2>=rectsize*3&&y>=rectsize*3){
            gameover = true;
          }
        }
        }
        if(switch2==true){
          soundplayer();
        blockade = false;
        }
        if(x-ballsize/2<=rectsize+rectsize-10&&y+ballsize/2>=rectsize*8)
        {
          switch2=true;
        }
        enemy();
          if(y-ballsize/2<=rectsize&&x-ballsize/2<=width-rectsize*2||//1
       x+ballsize/2>=width-rectsize||//2
       x+ballsize/2>=rectsize&&y-ballsize/2<=rectsize*3&&y+ballsize/2>=rectsize*2||//3
       x+ballsize/2>=rectsize&&x-ballsize/2<=rectsize*2&&y+ballsize/2>=rectsize*2&&y-ballsize/2<=rectsize*6||
       x+ballsize/2>=rectsize*3&&x-ballsize/2<=rectsize*4&&y+ballsize/2>rectsize*4||//5
       x-ballsize/2<=rectsize*4&&y+ballsize/2>=height-rectsize||//6
       x-ballsize/2<=rectsize&&y+ballsize/2>=rectsize*7||//7
       x-ballsize/2<=rectsize*2&&y+ballsize/2>=rectsize*7&&y-ballsize/2<=rectsize*8||//8
       x-ballsize/2<=rectsize*8&&x>=rectsize*4&&y+ballsize/2>=rectsize*6&&y-ballsize/2<=rectsize*7||//9
       x+ballsize/2>=rectsize*5&&x-ballsize/2<=rectsize*6&&y>rectsize*3&&y-ballsize/2<=rectsize*5||//10
       x+ballsize/2>=rectsize*7&&x-ballsize/2<=rectsize*8&&y>rectsize*3&&y-ballsize/2<=rectsize*5||
       x+ballsize/2>=rectsize*5&&y+ballsize/2>=height-rectsize*2&&y-ballsize/2<=height-rectsize){//12
         gameover = true;
       }
          
        
        }
        
      if(level3){
        
        
        
        player = true;
        enemylevel3();
        if(x+ballsize/2>=rectsize&&x-ballsize/2<=rectsize*2&&y-ballsize/2<=height-rectsize&&y+ballsize/2>=rectsize||//1
        x-ballsize/2<=rectsize*7&&x+ballsize/2>=rectsize&&y-ballsize/2<=rectsize*9&&y+ballsize/2>=rectsize*8||//2
        x-ballsize/2<=rectsize*7&&x+ballsize/2>=rectsize*6&&y-ballsize/2<=height-rectsize&&y+ballsize/2>=rectsize||//3
        x+ballsize/2>=rectsize*8&&y-ballsize/2<=rectsize*9&&y+ballsize/2>=rectsize*8||
        x+ballsize/2>=rectsize*8&&x-ballsize/2<=rectsize*9&&y-ballsize/2<=rectsize*9&&y+ballsize/2>=rectsize||
        x+ballsize/2>=rectsize*3&&x-ballsize/2<=rectsize*9&&y+ballsize/2>=rectsize&&y-ballsize/2<=rectsize*2||
        x+ballsize/2>=rectsize*3&&x-ballsize/2<=rectsize*4&&y+ballsize/2>=rectsize&&y-ballsize/2<=rectsize*7||
        x+ballsize/2>=rectsize*4&&x-ballsize/2<=rectsize*5&&y+ballsize/2>=rectsize&&y-ballsize/2<=rectsize*3||
        x+ballsize/2>=rectsize*5&&x-ballsize/2<=rectsize*6&&y+ballsize/2>=rectsize*4&&y-ballsize/2<=rectsize*5||
        x>=rectsize*4&&x-ballsize/2<=rectsize*5&&y+ballsize/2>=rectsize*6&&y-ballsize/2<=rectsize*7){
          gameover = true;
          
        }
        if(x-ballsize/2<=rectsize/2+20){
          s = true;
        }
        if(y-ballsize/2<=rectsize*2.5+20&&y>rectsize*2&&x>rectsize*5&&x<rectsize*6){
          s2 = true;
        }
        if(y+ballsize/2>=rectsize*7.5-20&&x>rectsize*9&&y<rectsize*8){
          s3 = true;
        }
        if(y-ballsize/2<=rectsize*2.5&&y>rectsize*2&&x<rectsize*8&&x>rectsize*7){
          youwin = true;
          
        }
      }
    if(youwin){
      level3 = false;
      Switch = false;
      switch2 = false;
      s=false;
      s2=false;
      s3=false;
      scount = 0;
      scount2 = 0;
      scount3 = 0;
      scount4 = 0;
      scount5 = 0;
      chiptune.pause();
      chiptune.rewind();
      image(f,0,0,width,height);
      if(mousePressed==true){
        youwin = false;
      }
      
    }
    
      if(gameover){
        level1 = false;
        scount = 0;
        level2 = false;
        scount2 = 0;
        level3 = false;
        scount3 = 0;
        scount4 = 0;
        scount5 = 0;
        Switch = false;
        switch2 = false;
        s = false;
        s2 = false;
        s3 = false;
        if(mousePressed==true){
          
          gameover = false;
          
    }
      }
    }
    
    
    
    import ddf.minim.*;
    import ddf.minim.signals.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;
    
    Minim m;
    AudioPlayer chiptune;
    AudioPlayer explode;
    AudioPlayer switchsound;
    AudioPlayer squaresound;
    AudioPlayer squaresound2;
    AudioPlayer theme;
    
    int ballsize = 25;
    int rectsize = 60;
    int wallcol = 255;
    int emptycol = 0;
    int x = 500/2;
    int y = 500/2;
    int ballcol = 0;
    PImage a,b,c,d,e,f,g;
    int gcount = 0;
    int scount = 0;
    int scount2 = 0; 
    int scount3 = 0;
    int scount4 = 0;
    int scount5 = 0;
    
    //button
    int br = 255; int bg = 10; int bb = 10;
    int b2r = 255; int b2g = 10; int b2b = 10;
    int br3 = 255; int bg3 = 10; int bb3 = 10;
    int br4 = 255; int bg4 = 10; int bb4 = 10;
    int br5 = 255; int bg5 = 10; int bb5 = 10;
    int br6 = 255; int bg6 = 10; int bb6 = 10;
    
    
    void setup(){
      size(600,600);
      noStroke();
      background(0);
      rectMode(CENTER);
      
      
      b = loadImage("click here with arrow.jpg");
      c = loadImage("background3.jpg");
      a = loadImage("gameover.jpg");
      d = loadImage("level2improved.jpg");
      e = loadImage("level3.jpg");
      f = loadImage("youwin.jpg");
      g = loadImage("click here with arrow highlight.jpg");
      
      m = new Minim(this);
      chiptune = m.loadFile("chiptune.wav");
      explode = m.loadFile("explosion2.wav");
      switchsound = m.loadFile("switch2.wav");
      squaresound = m.loadFile("squaresound.wav");
      squaresound2 = m.loadFile("squaresound.wav");
      theme = m.loadFile("theme.wav");
    
    }
    
    void draw(){
      
    
      maze();
      mouse();
      
      mazeChecks();
      mouseChecks();
      
    }
    
    
    void maze(){
      
     
      if(startover){
        theme.play();
      
        
      cursor();
      fill(emptycol);
      rect(width/2,height/2,width,height);
      image(b,0,0,width,height);
         if(highlight){
        image(g,0,0,width,height);
        }
      
      if(level1){
      background(255,255,255,50);
      noCursor();
      image(c,0,0,width,height);
      //button
      fill(br,bg,bb);
      rect(rectsize*5,rectsize*2*.8,rectsize*2*.8,rectsize*2*.4);
      //exit sign 
      rect(rectsize*8+rectsize/2,rectsize+5,rectsize,10);
      //light
      fill(br,bg,bb,50);
      rect(rectsize*5,rectsize*2*.8,rectsize*2*.8 + 5,rectsize*2*.4 + 5);
      rect(rectsize*5,rectsize*2*.8,rectsize*2*.8 + 10,rectsize*2*.4 + 10);
      }
      }
      if(Switch){
        br = 83; bg = 255; bb = 10;
        
      }
      if(Switch == false){
        br = 255;  bg = 10;  bb = 10;
      }
      if(level2){
        noCursor();
        image(d,0,0,width,height);
        if(blockade){
          fill(0);
          rect(rectsize*3+rectsize/2+1,rectsize*3+rectsize/2,rectsize+1,rectsize);
        }
        //button
        fill(b2r,b2g,b2b);
        rect(rectsize+rectsize/2,rectsize*8+rectsize/2,30,30);
        //exit sign 
        rect(rectsize*9,rectsize*9+rectsize/2,10,rectsize);
        fill(b2r,b2g,b2b,50);
        rect(rectsize+rectsize/2,rectsize*8+rectsize/2,35,35);
        rect(rectsize+rectsize/2,rectsize*8+rectsize/2,40,40);
        if(switch2){
          b2r = 83; b2g = 255; b2b = 10;
        }
        if(switch2==false){
          b2r = 255;  b2g = 10;  b2b = 10;
        }
      }
      if(level3){
     
        noCursor();
        image(e,0,0,width,height);
           //exit sign 
        fill(br5,bg5,bb5);
        rect(rectsize*7+rectsize/2,rectsize*2+5,rectsize,10);
        if(s==true&&s2==true&&s3==true){
           br5 = 83;  bg5 = 255;  bb5 = 10;
        }
        fill(br3,bg3,bb3);
        rect(rectsize/2,width-rectsize/2,30,30);
        fill(br3,bg3,bb3,50);
        rect(rectsize/2,width-rectsize/2,35,35);
        rect(rectsize/2,width-rectsize/2,40,40);
        fill(br4,bg4,bb4);
        rect(rectsize*5+rectsize/2,rectsize*2+rectsize/2,30,30);
        fill(br4,bg4,bb4,50);
        rect(rectsize*5+rectsize/2,rectsize*2+rectsize/2,35,35);
        rect(rectsize*5+rectsize/2,rectsize*2+rectsize/2,40,40);
        fill(br5,bg5,bb5);
        rect(rectsize*9+rectsize/2,rectsize*7+rectsize/2,30,30);
        fill(br5,bg5,bb5,50);
        rect(rectsize*9+rectsize/2,rectsize*7+rectsize/2,35,35);
        rect(rectsize*9+rectsize/2,rectsize*7+rectsize/2,40,40);
       if(s){
        br3 = 83; bg3 = 255; bb3 = 10;
       
       } 
       if(s == false){
         br3 = 255;  bg3 = 10;  bb3 = 10;
       }
       if(s2){
        br4 = 83; bg4 = 255; bb4 = 10;
       
       } 
       if(s2 == false){
         br4 = 255;  bg4 = 10;  bb4 = 10;
       }
       if(s3){
        br5 = 83; bg5 = 255; bb5 = 10;
       
       } 
       if(s3 == false){
         br5 = 255;  bg5 = 10;  bb5 = 10;
       }
      }
    }
    boolean played;
    void mazeChecks(){
      
     
        if(gameover){
          theme.pause();
          theme.rewind();
         image(a,0,0,width,height);    
        soundplayer();
      
         
        }
        
      }
    
    
    void mouseChecks() {
     if(player){
        x = mouseX;
        y = mouseY;
      fill(ballcol);
      rect (x,y,ballsize,ballsize);
      //shadow
      fill(0,0,0,20);
      int i = 0;
      while(i<10){
        rect (x+i,y+i,ballsize,ballsize);
        i++;
      }
      
    }
    
    }
    
    void soundplayer()
    {
      if(gameover){
      if(gcount<1)
      {
        explode.pause();
        explode.rewind();
      }
      gcount++;
      explode.play();
    }
    if(Switch){
      if(scount<1)
      {
        switchsound.pause();
        switchsound.rewind();
        
      }
      scount++;
      switchsound.play();
    }
    if(switch2){
    if(scount2<1)
      {
        switchsound.pause();
        switchsound.rewind();
        
      }
      scount2++;
      switchsound.play();
    }
    if(s){
    if(scount3<1)
      {
        switchsound.pause();
        switchsound.rewind();
        
      }
      scount3++;
      switchsound.play();
    }
    if(s2){
    if(scount4<1)
      {
        switchsound.pause();
        switchsound.rewind();
        
      }
      scount4++;
      switchsound.play();
    }
    if(s3){
    if(scount5<1)
      {
        switchsound.pause();
        switchsound.rewind();
        
      }
      scount5++;
      switchsound.play();
    }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Sebastian Petravic

    Maze game

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

    Game made to show the meaning of if/else

    CgRobot
    14 Aug 2012
    So frustrating! So fun! I call it Funstrating!
    urzq
    16 Aug 2012
    sweet because it's polished !
    But i have detected a "design bug": if I move the cursor out of the screen, the player is not controlled anymore, and you can then teleport it on the other side of the screen if you re enter your cursor (makes lvl 3 easy).
    An easy fix would be to add wall all around the screen.
    Pierre MARZIN
    17 Aug 2012
    great!
    thomas ricordeau
    27 Aug 2012
    excellent... but the download file is empty!
    André Vidal
    3 Apr 2013
    Very nice, the download sketch is empty though. Can you fix it please? Thanks. :)
    You need to login/register to comment.