Sebelumnya kita sudah mempelajari tahapan keempat
membuat game ping pong ini yaitu membuat sistem skor. Tahapan keempat bisa dilihat dengan klik tulisan biru ini Part 4
Pada tutorial kali ini kita akan mempelajari lanjutan
proses pembuatan game ping pong yaitu membuat random arah bola dan
kecepatannya. Berikut source code tahapan kelima :
int LrectY=350;
int RrectY=350;
float ellX=width/2;
float ellY=height/2;
boolean moveRight=true;
boolean moveDown=true;
float speedSide=3;
float speedVertical=4;
int countR=0;
int countL=0;
PFont font;
PImage img;
PImage img2;
PImage img3;
void setup(){
size(700,700);
background(0);
font= loadFont("Montserrat-Bold-48.vlw");
img = loadImage("ANDRIO.png");
img2=loadImage("RIDHO.png");
img3=loadImage("ALIN.png");
}
void draw(){
background(0);
textFont(font);
fill(242,60,6);
ellipse(ellX,ellY,50,50);
text("PONG", 300,50);
image(img3, 338, 10);
fill(156,218,6);
rect(20,LrectY,30,100);
image(img, 0, LrectY);
text(countL,200,50);
fill(53,211,218);
rect(630,RrectY,30,100);
image(img2, 630, RrectY);
text(countR, 500,50);
if(keyPressed==true && key=='w'){
LrectY=LrectY-6;
}
if(keyPressed==true && key=='s'){
LrectY=LrectY+6;
}
if(keyPressed==true && key=='i'){
RrectY=RrectY-6;
}
if(keyPressed==true && key=='k'){
RrectY=RrectY+6;
}
if(moveRight==true)
{
ellX=ellX+speedSide;
}
else{
ellX=ellX-speedSide;
}
if(moveDown==true)
{
ellY=ellY+speedVertical;
}
else{
ellY=ellY-speedVertical;
}
if(ellY<=10){
moveDown=true;
speedSide=random(3,6);
}
if(ellY>=690){
moveDown=false;
speedSide=random(3,6);
}
if(ellX>=690){
countL++;
ellX=width/2;
ellY=height/2;
speedSide=random(3,6);
}
if(ellX<=10){
countR++;
ellX=width/2;
ellY=width/2;
speedSide=random(3,6);
}
if(ellX >= 615 && ellY > RrectY && ellY < (RrectY+100)){
moveRight=false;
speedSide=random(3,6);
}
if(ellX <=75 && ellY>LrectY && ellY < (LrectY+100)){
moveRight=true;
speedSide=random(3,6);
}
}
Itu lah tahapan kelima
dari membuat game ini. Tahapan terakhir bisa dilihat dengan klik tulisan biru ini Part 6
Silahkan lihat tutorial lengkapnya di sini
Part 1 by Ridho Al Amzah
Part 2 by Alin Meisya Putri
Part 3 by Ridho Al Amzah
Part 4 by Andrio P Sirait
Part 5 by Alin Meisya Putri
Part 6 by Andrio P Sirait
Silahkan lihat tutorial lengkapnya di sini
Part 1 by Ridho Al Amzah
Part 2 by Alin Meisya Putri
Part 3 by Ridho Al Amzah
Part 4 by Andrio P Sirait
Part 5 by Alin Meisya Putri
Part 6 by Andrio P Sirait

No comments:
Post a Comment