I made this widget at MyFlashFetish.com.

Rabu, 16 Juli 2014

GAME BOLA

Penulisan kali ini membahas tentang game processing yang diselesaikan berkelompok yang terdiri dari annisa tri handayani, citra dewi riska dan rahmat ardi prastyo. sebagian kodingan :


int xPos;                     
int yPos;
int speed=1;                  
int xDir=1;                   
int score=0
int lives=5;                  
boolean lost=false;           
            Perintah diatas merupakan deklarasi variable yang dimana xPos, yPos, speed, xDir, score, lives bertype integer. Untuk variable speed bernilai 1, variable ini berfungsi sebagai nilai kecepatan awal bola bergerak. xDir merupakan variable yang berfungsi mengarahkan bola bergerak.

void setup()                  
{
  size (400,400);
  smooth();
  xPos=height/2;               
  fill(255,0,0);              
  textSize(13);               
}
            Kodingan size (400,400) diatas menjelaskan tentang ukuran dari background, dan smooth berguna sebagai memperhalus bentuk bola.


 
keseluruhan kodingan :
 
 int xPos;                      //Position of the ball
int yPos;
int speed=1;                   //How fast is it moving?
int xDir=1;                    //what direction is the ball going?
int score=0;                   //Inital score
int lives=5;                   //Number of lives you start with
boolean lost=false;            //Have you lost yet?

void setup()                   //Runs once when program launches
{
  size (400,400);
  smooth();
  xPos=height/2;                //Centers our ball
  fill(0,250,0);               //Makes the ball and text
  textSize(13);                //Sets the size of our text
}

void draw()                                      //Loops over and over again
{
  background (#E75B90);                                // background
  ellipse(xPos, height/2,40,40);                 //Draw the ball
  xPos=xPos+(speed*xDir) ;                        //update the ball's position
  if (xPos > width-20 || xPos<20)   //Did the ball hit the side?
  {
    xDir=-xDir;                                  //If it did reverse the direction
  }
  text("score = "+score,10,10);                  //Print the score on the screen
  text("lives = "+lives,width-80,10);           
  if (lives<=0)                                 
  {
    textSize(20);
    text("Click to Restart", 125,100);
    noLoop();                                    //Stop looping at the end of the draw function
    lost=true;
    textSize(13);
  }
}

void mousePressed()                              //Runs whenever the mouse is pressed
{
  if (dist(mouseX, mouseY, xPos, 200)<=20)      //Did we hit the target?

  {
    score=score+speed;                           //Increase the speed
    speed=speed+1;                               //Increase the Score
  }
  else                                                 //We missed
  {
    if (speed<1)                                 //If speed is greater than 1 decrease the speed
    {
    speed=speed-1;
    }
    lives=lives-1;                               //Take away one life
  }
  if (lost==true)                                //If we lost the game, reset now and start over

  {
    speed=1;                                     //Reset all variables to initial conditions
    lives=5;
    score=0;
    xPos=height/2;
    xDir=1;
    lost=false;
    loop();                                     //Begin looping draw function again
  }
}

cara bermain game ini, mengklik bola yang bergerak. Semakin tinggi level maka semakin cepat bola bergerak. dalam permainan ini hanya terdapat 5 lives, jika berkurang maka game berakhir.

link cara bermain game :
http://www.youtube.com/watch?v=7us5ZeUqruo&feature=youtu.be


sumber :

http://processing.flosscience.com/processing-for-android/macul-2012/simple-game-code