Tugas Sofskill Membuat Game Bola Pantul berbasis Procesing
Nama Kelompok :
Aditya akbar 50411210
Dio Kurniawan M 52411171
Muhamad Yunus 54411725
Pada tugas kali ini kami namakan game ini Bola
Pantul. Game ini berbasis procesing. Gambaran game ini memainkan bola yang
dipantulkan untuk mendapat nilai tertinggi dan semakin tinggi nilai kita akan
mempengaruhi kecepatan bola . Untuk kontrol game ini menggunakan navigasi pada
keyboard. Serta terdapat kesempatan kita mainnya.
Berikut listing program game bola pantul :
int y=560;
int a=280;
int b=30;
float ballX=random(0,300);
float ballY=random(0,300);
float ballA=random(0,300);
float ballB=random(0,300);
int
speed=4;
int xdir=speed;
int ydir=speed;
int adir=speed;
int bdir=speed;
int
lives=3;
int
score=0;
int
lives2=3;
int
score2=0;
boolean
square=false;
float
rectX=random(30,570);
float rectY=random(30,559);
boolean load=true;
boolean help=false;
boolean pause=false;
boolean pause2=false;
int
playX=200;
int playY=160;
int helpX=200;
int helpY=250;
int
backX=275;
int backY=500;
int
resumeX=200;
int resumeY=200;
int instructionsX=200;
int instructionsY=255;
int menuX=200;
int menuY=310;
int
back2X=275;
int back2Y=500;
boolean instructions=false;
boolean
modes=false;
float player1X=200;
float player1Y=160;
float player2X=200;
float player2Y=250;
boolean player1=false;
boolean player2=false;
int
resume2X=200;
int resume2Y=200;
void setup() {
size (600,600);
background (0,0,0);
textFont (createFont("Verdana",16));
}
void
draw() {
background (0,0,0);
noStroke();
noCursor();
fill(128,128,128);
ellipse(ballX,ballY,20,20);
if(score>=20) {
fill(128,128,128);
ellipse(ballA,ballB,20,20);
ballA=ballA+adir;
ballB=ballB+bdir;
speed=8;
}
if(score2>=20) {
fill(128,128,128);
ellipse(ballA,ballB,20,20);
ballA=ballA+adir;
ballB=ballB+bdir;
speed=8;
}
if(score>=30) {
speed=9;
}
ballX=ballX+xdir;
ballY=ballY+ydir;
if(ballX>=590) {
xdir=-speed;
}
if(ballA>=590) {
adir=-speed;
}
if(ballX<=10) {
xdir=speed;
}
if(ballA<=10) {
adir=speed;
}
if(ballY>=590) {
ydir=-speed;
lives=lives-1;
}
if(ballB>=590) {
bdir=-speed;
lives=lives-1;
}
if(player2==true&&ballY-10<=0) {
ydir=speed;
lives2=lives2-1;
}
if(player2==true&&ballB-10<=0) {
bdir=speed;
lives2=lives2-1;
}
text("Kesempatan:",14,570);
text(lives,73,590);
if(player2==false&&lives<=0) {
noLoop();
text("Game Over... Tekan R untuk
memulai lagi",150,290);
}
if(ballY<=10) {
ydir=speed;
}
if(ballB<=10) {
bdir=speed;
}
if(player2==true) {
text("Lives:",14,20);
text(lives2,73,20);
}
rect(mouseX,y,40,10);
if(mouseX>=560) {
mouseX=560;
}
if(ballX+10>mouseX&&ballX-10<mouseX+40&&ballY+10>y&&ballY+10<y+10) {
ydir=-speed;
score=score+1;
}
if(ballA+10>mouseX&&ballA-10<mouseX+40&&ballB+10>y&&ballB+10<y+10) {
bdir=-speed;
score=score+1;
}
if(player2==true&&ballX+10>a&&ballX-10<a+40&&ballY-10>b&&ballY-10<b+10) {
score2=score2+1;
ydir=speed;
}
if(player2==true&&ballA+10>a&&ballA-10<a+40&&ballB-10>b&&ballB-10<b+10) {
score2=score2+1;
bdir=speed;
}
text("Score:",500,590);
text(score,567,590);
if(score>=5) {
speed=6;
}
if(score>=10) {
speed=8;
}
if(score>=15) {
speed=9;
}
if(player2==true) {
text("Score:",500,20);
text(score2,567,20);
square=false;
}
if(score2>=5) {
speed=6;
}
if(score2>=10) {
speed=8;
}
if(score2>=15) {
speed=9;
}
if(player2==false&&ballX>rectX&&ballX<rectX+20&&ballY>rectY&&ballY<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballX+10>rectX&&ballX+10<rectX+20&&ballY>rectY&&ballY<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballX-10>rectX&&ballX-10<rectX+20&&ballY>rectY&&ballY<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballX>rectX&&ballX<rectX+20&&ballY+10>rectY&&ballY+10<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballX>rectX&&ballX<rectX+20&&ballY-10>rectY&&ballY-10<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballA>rectX&&ballA<rectX+20&&ballB>rectY&&ballB<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballA+10>rectX&&ballA+10<rectX+20&&ballB>rectY&&ballB<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballA-10>rectX&&ballA-10<rectX+20&&ballB>rectY&&ballB<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballA>rectX&&ballA<rectX+20&&ballB+10>rectY&&ballB+10<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(player2==false&&ballA>rectX&&ballA<rectX+20&&ballB-10>rectY&&ballB-10<rectY+20) {
lives=lives+1;
rectX=random(30,570);
rectY=random(30,559);
}
if(load==true)
{
noLoop();
background(255,255,255);
fill(128,128,128);
rect(playX,playY,200,80);
rect(helpX,helpY,200,80);
fill(255,255,255);
text("Mulai",playX+76,playY+47);
text("Bantuan",helpX+76,helpY+47);
fill(128,128,128);
text("copyright : adit, dio, yunus",200,400);
textFont (createFont("Verdana",30));
text("Bola Pantul",243,50);
textFont (createFont("Verdana",16));
cursor();
}
if(help==true)
{
background(255,255,255);
text("kontrol menggunkan mouse",175,200);
text("tekan p untuk berhenti",175,220);
fill(128,128,128);
rect(backX,backY,90,30);
fill(255,255,255);
text("Kembali",backX+10,backY+20);
fill(128,128,128);
cursor();
}
if(pause==true) {
noLoop();
background(255,255,255);
fill(128,128,128);
rect(resumeX,resumeY,200,50);
rect(instructionsX,instructionsY,200,50);
rect(menuX,menuY,200,50);
fill(255,255,255);
text("RESUME",resumeX+63,resumeY+30);
text("INSTRUCTIONS",instructionsX+36,instructionsY+30);
text("MENU",menuX+73,menuY+30);
fill(128,128,128);
textFont
(createFont("Verdana",30));
text("Paused",247,50);
textFont (createFont("Verdana",16));
cursor();
}
if(pause2==true) {
noLoop();
background(255,255,255);
fill(128,128,128);
rect(resume2X,resume2Y,200,50);
rect(instructionsX,instructionsY,200,50);
rect(menuX,menuY,200,50);
fill(255,255,255);
text("RESUME",resume2X+63,resume2Y+30);
text("INSTRUCTIONS",instructionsX+36,instructionsY+30);
text("MENU",menuX+73,menuY+30);
fill(128,128,128);
textFont (createFont("Verdana",30));
text("Paused",247,50);
textFont (createFont("Verdana",16));
cursor();
}
if(modes==true) {
background(255,255,255);
fill(128,128,128);
rect(player1X,player1Y,200,50);
fill(255,255,255);
text("1 Player",player1X+65,player1Y+30);
fill(128,128,128);
cursor();
loop();
}
}
void mouseReleased()
{
if(load==true&&mouseX>=playX&&mouseX<=playX+200&&mouseY>=playY&&mouseY<=playY+80) {
modes=true;
player1=false;
load=false;
cursor();
loop();
}
if(load==true&&mouseX>=helpX&&mouseX<=helpX+200&&mouseY>=helpY&&mouseY<=helpY+80) {
help=true;
loop();
}
if(help==true&&mouseX>=backX&&mouseX<=backX+50&&mouseY>=backY&&mouseY<=backY+20) {
help=false;
loop();
}
if(pause==true&&mouseX>=resumeX&&mouseX<=resumeX+200&&mouseY>=resumeY&&mouseY<=resumeY+50) {
pause=false;
load=false;
help=false;
square=true;
loop();
}
if(modes==true&&mouseX>=player1X&&mouseX<=player1X+200&&mouseY>=player1Y&&mouseY<=player1Y+50) {
load=false;
modes=false;
square=true;
lives=3;
score=0;
ballX=random(0,300);
ballY=random(0,300);
rectX=random(30,570);
rectY=random(30,559);
loop();
}
}
Output game Bola Pantul :
sumber : http://www.openprocessing.org/
0 komentar:
Post a Comment