Penulisan kali ini membahas tentang game processing yang dikerjakan berkelompok yang terdiri dari citra dewi riska, annisa tri handayani, dan rahmat ardi prastyo, masing-masing anggota kelompok memiliki bagian dari game ini, kodingan dibawah ini merupakan sebagian kodingan yang ada :
void draw()
{
background (#E75B90);
ellipse(xPos, height/2,40,40);
xPos=xPos+(speed*xDir) ;
if (xPos > width-20 || xPos<20)
perintah diatas untuk mengatur warna background, dan membentuk bola dengan ukuran yang ditetapkan (xPos, height/2,40,40). variabel xPos berisikan perintah untuk menambah kecepatan dan mengatur arah gerak bola.
{
xDir=-xDir;
}
text("score = "+score,10,10);
text("lives = "+lives,width-80,10);
if (lives<=0)
menampilkan output text dan live dengan posisi 10,10 untuk score dan width-80,10 untuk lives dan variabel score serta variabel lives dipanggil hingga tampil pada output.
{
textSize(20);
text("Click to Restart", 125,100);
noLoop();
lost=true;
textSize(13);
}
}
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
}
}
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