Jumat, 14 Juni 2013

TUGAS GAME PROCESSING "GAME SOFT GUN"




 


 Listing
Alien myAlien; //object
    //PImage bg;
    PFont fontA;
    int sphereDiameter = 10;
    boolean shoot = false;
    int randx()
    {
      return int(random(600));
    }
    int[] sphereXCoords = {
      randx(), randx(), randx(), randx(), randx()
      };
    int[] sphereYCoords = {
      0, 0, 0, 0, 0
    };
    void setup()
    {
      //bg = loadImage("SpaceBG.png");
      size(600, 620);
      myAlien = new Alien(
      350, height-175,
      25, 25,
      3, 3); //Changeable Parameters
    }
    void draw()
    {
      background(0);
      fill(color(0, 255, 0));
      stroke(color(0, 255, 0));
      //triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
      //
      myAlien.bodyXLocation=mouseX;
      myAlien.draw_Face(); //draws alien
      myAlien.draw_left_ear(); //draws left ear
      myAlien.draw_right_ear();//draws right ear
      myAlien.draw_body();//draws the body
      myAlien.draw_eye();//draws the eye
      myAlien.draw_eye_ball();//draws the eyeball
      myAlien.draw_mouth();//draws the mouth
      myAlien.draw_nose();//draws the nose
        //
      fill(color(255, 0, 0));
      stroke(color(255, 0, 0));
      if (shoot==true)
      {
        sphereKiller(mouseX);
        shoot = false;
      }
      sphereDropper();
      gameEnder();
    }
    void mousePressed()
    {
      shoot = true;
    }
    void sphereDropper()
    {
      stroke(255);
      fill(255);
      for (int i=0; i<5; i++)
      {
        ellipse(sphereXCoords[i], sphereYCoords[i]++,
        sphereDiameter, sphereDiameter);
      }
    }
    void sphereKiller(int shotX)
    {
      boolean hit = false;
      for (int i = 0; i < 5; i++)
      {
        if ((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
          (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
        {
          hit = true;
          line(mouseX, 565, mouseX, sphereYCoords[i]);
          ellipse(sphereXCoords[i], sphereYCoords[i],
          sphereDiameter+25, sphereDiameter+25);
          sphereXCoords[i] = randx();
          sphereYCoords[i] = 0;
        }
      }
      if (hit == false)
      {
        line(mouseX, 565, mouseX, 0);
      }
    }
    void gameEnder()
    {
      for (int i=0; i< 5; i++)
      {
        if (sphereYCoords[i]==600)
        {
          fill(color(255, 0, 0));
          noLoop();
        }
      }
    }
    // ===========================================================
    class Alien {
      //Variables
      int bodyXLocation;
      int bodyYLocation;
      int bodyWidth;
      int bodyHeight;
      int eyeWidth;
      int eyeHeight;
      int eyeXLocation;
      int eyeYLocation;
      int eyeballWidth;
      int eyeballHeight;
      int eyeballXlocation;
      int eyeballYlocation;
      int earleftWidth;
      int earleftHeight;
      int earleftXlocation;
      int earleftYlocation;
      int earrightWidth;
      int earrightHeight;
      int earrightXlocation;
      int earrightYlocation;
      int mouthXlocation;
      int mouthYlocation;
      int mouthHeight;
      int mouthWidth;
      int noseXlocation;
      int noseYlocation;
      int noseHeight;
      int noseWidth;
      int speedXLocation;
      int speedYLocation;
      Alien(int tempX, int tempY,
      int tempWidth, int tempHeight,
      int tempXSpeed, int tempYSpeed) {
        bodyXLocation = tempX;
        bodyYLocation = tempY;
        bodyWidth = tempWidth;
        bodyHeight = tempHeight;
        speedXLocation = tempXSpeed;
        speedYLocation = tempYSpeed;
        //Changeable Parameters
      }
      //This method draws the alien
      void draw_Face() {
        this.draw_left_ear();
        this.draw_right_ear();
        this.draw_body();
        this.draw_eye();
        this.draw_eye_ball();
        this.draw_mouth();
        this.draw_nose();
        this.alien_bounce();
      }
      void draw_left_ear() {
        fill(255, 0, 0);
        earleftXlocation = bodyXLocation - 50;
        earleftYlocation = bodyYLocation - 50;
        earleftWidth = bodyWidth / 5;
        earleftHeight = bodyHeight - 50;
        ellipse(earleftXlocation, earleftYlocation, earleftWidth, earleftHeight);
      }
      void draw_right_ear() {
        earrightWidth = bodyWidth / 4;
        earrightHeight = bodyHeight - 50;
        earrightXlocation = bodyXLocation + 50;
        earrightYlocation = bodyYLocation - 50;
        ellipse(earrightXlocation, earrightYlocation, earrightWidth, earrightHeight);
      }
      void draw_body() {
        fill(0, 255, 0);
        ellipse(bodyXLocation, bodyYLocation, bodyWidth, bodyHeight);
      }
      void draw_eye() {
        int offSet = bodyWidth / 17;
        eyeXLocation = bodyXLocation - offSet;
        eyeYLocation = bodyYLocation - (bodyHeight / 4);
        eyeWidth = bodyHeight / 5;
        eyeHeight = bodyWidth / 5;
        ellipse(eyeXLocation, eyeYLocation, eyeWidth, eyeHeight);
      }
      void draw_eye_ball() {
        fill(255, 0, 0);
        int eyeballoffset = bodyWidth / 10;
        eyeballXlocation = bodyXLocation - eyeballoffset;
        eyeballXlocation = bodyXLocation - 8;
        eyeballYlocation = bodyYLocation - 60;
        eyeballWidth = bodyHeight / 10;
        eyeballHeight = bodyWidth / 10;
        ellipse(eyeballXlocation, eyeballYlocation, eyeballWidth, eyeballHeight);
      }
      void draw_mouth() {
        fill(255, 0, 0);
        mouthXlocation = bodyXLocation;
        mouthYlocation = bodyYLocation + 75;
        mouthWidth = bodyWidth - 150;
        mouthHeight = bodyHeight - 190;
        ellipse(mouthXlocation, mouthYlocation, mouthWidth, mouthHeight);
      }
      void draw_nose() {
        fill(0, 0, 255);
        noseXlocation = bodyXLocation - 5;
        noseYlocation = bodyYLocation + 3;
        noseWidth = bodyWidth - 200;
        noseHeight = bodyHeight - 200;
        ellipse(noseXlocation, noseYlocation, noseWidth, noseHeight);
      }
      void movement_of_alien() {
        //Movement
        bodyXLocation = bodyXLocation  + speedXLocation;
        bodyYLocation = bodyYLocation + speedYLocation;
        this.alien_bounce();//Links to Alien_Bounce
      }
      void alien_bounce() {
        //Bouncing
        if (bodyXLocation > width - (bodyWidth / 2 )) {
          speedXLocation = speedXLocation * -1;
        }
        if (bodyXLocation < 0 + (bodyWidth / 2 )) {
          speedXLocation = speedXLocation * -1;
        }
        if (bodyYLocation > height - (bodyHeight / 2 )) {
          speedYLocation = speedYLocation * -1;
        }
        if (bodyYLocation < 0 + (bodyHeight / 2 )) {
          speedYLocation = speedYLocation * -1;
        }
      }
    } //End Of Class Alien
    //




Output dari game processing




By :
Nama : Rina Aprilia
NPM  : 55410966
Kelas  : 3IA09

Link : http://forum.processing.org/search/games


0 komentar:

Posting Komentar