• fullscreen
  • Ball.pde
  • Ball2.pde
  • Ball3.pde
  • Ball4.pde
  • Bar.pde
  • COSMO.pde
  • class Ball {
      float x;
      float y;
    
      float w;
      float h;
    
    
    
      float xVel;
      float yVel; 
    
      float r, g, b;
    
      PImage pic;
      boolean showing;
    
      void setupBall(float n, float v) {
    
        pic = loadImage("asteroid.png");
        showing = true;
        x=n;
        y=v;
        w= (50);
        h= (50);
    
        yVel = random(4, 8);
        xVel = random(1, 6);
      }
    
      void updateBall() {
        x+=xVel;
        y+=yVel;
    
    
    
        if (y> height) {
          showing=true;
          y=random(0, 50);
        }
    
        if (x>width) {
          x=random(0, 50);
        }
      }
    
      void drawBall() {
    
        if(showing==true){
        image(pic, x, y);
        }
      }
    }
    
    
    class Ball2 {
      float x;
      float y;
    
      float w;
      float h;
    
      float xVel;
      float yVel;
    
      float r, g, b;
    
      PImage pic2;
    
      boolean showing;
    
    
    
    
    
      void setupBall(float n, float v) {
    
        pic2 = loadImage("asteroid2.png");
        showing = true;
    
        x=n;
        y=v;
    
        w= 50;
        h= 50;
    
        r=random(255);
        g=random(255);
        b=random(255);
    
        yVel = random(2, 10);
      }
    
      void updateBall() {
        x+=xVel;
        y+=yVel;
    
        
        if (y> height) {
          showing=true;
          y=random(0, 50);
        }
      }
    
      void drawBall() {
    
        if(showing==true){
        image(pic2, x, y);
        }
      }
    }
    
    
    class Ball3 {
      float x;
      float y;
    
      float w;
      float h;
    
      float xVel;
      float yVel;
    
      float r, g, b;
    
      PImage pic3;
    
      boolean showing;
    
    
    
    
      void setupBall(float n, float v) {
    
        pic3 = loadImage ("satelite.png");
        showing = true;
        x=n;
        y=v;
    
        w= 50;
        h= 50;
    
        r=random(255);
        g=random(255);
        b=random(255);
    
        yVel = random(3, 9);
      }
    
      void updateBall() {
        x+=xVel;
        y+=yVel;
    
        if (x<0 || x > width) {
          xVel*=-1;
        }
        if (y> height) {
          y=-10;
          showing=true;
        }
      }
    
      void drawBall() {
        if (showing==true) {
    
          image(pic3, x, y);
        }
      }
    }
    
    
    class Ball4 {
      float x;
      float y;
    
      float w;
      float h;
    
      float xVel;
      float yVel;
      
      PImage pic4;
    
      boolean showing;
    
    
    
      void setupBall(int n) {
        
        pic4= loadImage("star.png");
    
        x=n;
        y=30;
    
        w= 50;
        h= 50;
    
        showing = true;
        
        yVel = random(4,20);
      }
    
      void updateBall() {
        x+=xVel;
        y+=yVel;
    
      
        if (y> height) {
          y=-50;
          showing=true;
          x=random(width);
        }
      }
    
      void drawBall() {
        
        if(showing==true){
        image(pic4, x,y);
        }
      }
    }
    
    
    
    
    import ddf.minim.*;
    import ddf.minim.signals.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;
    
    AudioPlayer audio;
    AudioPlayer audio1;
    AudioPlayer audio2;
    Minim minim;
    
    Ball [] myBalls = new Ball [5];
    Ball2 [] myBalls2 = new Ball2 [10];
    Ball3 [] myBalls3 = new Ball3 [10];
    Ball4 [] myBalls4 = new Ball4 [10];
    PImage alien;
    PImage starry;
    
    int gameState;
    int playerHealth;
    int bonusPoints;
    
    PFont moon;
    
    
    
    
    
    void setup() {
      size(800, 800);
    
      minim= new Minim(this);
    
      moon = loadFont("moon.vlw");
    
      audio = minim.loadFile("theme.mp3", 2048);
      audio.play();
      audio.loop();
    
      audio1 = minim.loadFile("star1.wav", 2048);
      audio2 = minim.loadFile("Hit3.wav", 2048);
    
      starry = loadImage("starry.png");
    
      gameState = 0;
      playerHealth = 100;
    
      alien = loadImage("alien.png");
    
      for (int i=0; i <myBalls.length; i++) {
        myBalls[i]=new Ball();
        myBalls[i].setupBall(random(0, width), random(0, 50));
      }
    
    
    
      for (int i=0; i <myBalls2.length; i++) {
        myBalls2[i]=new Ball2();
        myBalls2[i].setupBall(random(50, width), random(0, 50));
      }
    
      for (int i=0; i <myBalls3.length; i++) {
        myBalls3[i]=new Ball3();
        myBalls3[i].setupBall(random(0, width), random(0, 50));
      }
      for (int i=0; i <myBalls4.length; i++) {
        myBalls4[i]=new Ball4();
        myBalls4[i].setupBall(i*120);
      }
    }
    
    void draw() {
      background (starry);
    
      if (gameState==0) {
    
        textFont(moon, 70);
        textAlign(CENTER);
        text("COSMO AND \n THE PERSEID \n METEOR SHOWER", width/2, height/2);
        textSize(20);
        text("Press space bar to start!", width/2, 700);
      }
    
    
    
    
      if (gameState==1) {
        fill(255);
        textSize (20);
    
        text("Health:" + playerHealth, width/2, 20);
        text("SCORE:" + bonusPoints, width - 120, 20);
    
        for (int i=0; i <myBalls.length; i++) {
          if (dist(mouseX, mouseY, myBalls[i].x, myBalls[i].y) < 25) {
            
            if (audio2.position() >= 667) {
            audio2.cue(400);
            }
            
            audio2.play();
            myBalls[i].showing = false;
            playerHealth--;
          }
        }
    
        for (int i=0; i <myBalls2.length; i++) {
          if (dist(mouseX, mouseY, myBalls2[i].x, myBalls2[i].y) < 25) {
            
            if (audio2.position() >= 667) {
            audio2.cue(400);
            }
            
            audio2.play();
            myBalls2[i].showing = false;
            playerHealth--;
          }
        }
        for (int i=0; i <myBalls3.length; i++) {
          if (dist(mouseX, mouseY, myBalls3[i].x, myBalls3[i].y) < 25) {
            
            if (audio2.position() >= 667) {
            audio2.cue(400);
            }
            
            audio2.play();
    
    //        audio = minim.loadFile("Hit3.wav", 2048);
    //        if (audio.isPlaying() == false) {
    //          audio.play();
    //        } else {
    //         audio.rewind(); 
    //        }
    
            myBalls3[i].showing = false;
            playerHealth--;
            /*bonusPoints++;*/
          }
        }
    
    
        for (int i=0; i <myBalls4.length; i++) {
          if (dist(mouseX, mouseY, myBalls4[i].x, myBalls4[i].y) < 25) {
            audio1.play();
    
            if (audio1.position() >= 750) {
              audio1.rewind();
            }
            myBalls4[i].showing = false;
            bonusPoints++;
          }
        }
    
        println(audio2.position());
        println(audio2.isPlaying());
    
    
    
        //    if (dist(mouseX, mouseY, width/2, height/2)< 20) {
        //      playerHealth--;
        //      println(playerHealth);
        //    }
    
    
        if (playerHealth<=0) {
          gameState=2;
        }
      }
    
    
      if (gameState==2) {
        textSize(80);
        fill(255, 0, 0);
        text("GAME OVER", width/2, height/2);
        textSize(60);
        fill(40, 120, 150);
        text("SCORE:" + bonusPoints, width/2, height/2+100);
      }
    
      for (int i=0; i <myBalls.length; i++) {
        myBalls[i].updateBall();
        myBalls[i].drawBall();
      }
      for (int i=0; i <myBalls2.length; i++) {
        myBalls2[i].updateBall();
        myBalls2[i].drawBall();
      }
    
      for (int i=0; i <myBalls3.length; i++) {
        myBalls3[i].updateBall();
        myBalls3[i].drawBall();
      }
      for (int i=0; i <myBalls4.length; i++) {
    
        myBalls4[i].updateBall();
        myBalls4[i].drawBall();
      }
    
      image(alien, mouseX, mouseY);
    }
    
    void keyPressed() {
      if (key==32) {
        audio = minim.loadFile("beam.mp3", 2048);
        audio.play();
        gameState++;
        if (gameState>2) {
          gameState=0;
          playerHealth = 100;
        }
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Anthony Driscoll

    COSMO

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

    You need to login/register to comment.