Pada kesempatan kali ini penulis akan membagikan tutorial cara membuat game yang ada pada Google Chrome jika tidak ada koneksi internet. Tapi perbedaannya karakter T Rex diganti dengan PewDiePie dan rintangan Kaktus diganti dengan T - Series, burung Pterodactyl dengan Monetisasi / Demonetisasi YouTube. Langsung saja ke tutorial :
4. Selanjutnya adalah class Monetisasi dengan nama Bird.
- Pertama, install aplikasi processing >> https://processing.org/download/
- Estrak dan jalankan aplikasinya
- Pertama kita buat kelas yang menampilkan tampilan awal dari game. Simpan dengan nama file Game
int nextConnectionNo = 1000;
Population pop;int frameSpeed = 60;boolean showBestEachGen = false;int upToGen = 0;Player genPlayerTemp;boolean showNothing = false;//imagesPImage dinoRun1;PImage dinoRun2;PImage dinoJump;PImage dinoDuck;PImage dinoDuck1;PImage smallCactus;PImage manySmallCactus;PImage bigCactus;PImage bird;PImage bird1;ArrayList<Obstacle> obstacles = new ArrayList<Obstacle>();ArrayList<Bird> birds = new ArrayList<Bird>();ArrayList<Ground> grounds = new ArrayList<Ground>();int obstacleTimer = 0;int minimumTimeBetweenObstacles = 60;int randomAddition = 0;int groundCounter = 0;float speed = 10;int groundHeight = 250;int playerXpos = 150;ArrayList<Integer> obstacleHistory = new ArrayList<Integer>();ArrayList<Integer> randomAdditionHistory = new ArrayList<Integer>();//--------------------------------------------------------------------------------------------------------------------------------------------------void setup() {frameRate(60);fullScreen();dinoRun1 = loadImage("dinorun0000.png");dinoRun2 = loadImage("dinorun0001.png");dinoJump = loadImage("dinoJump0000.png");dinoDuck = loadImage("dinoduck0000.png");dinoDuck1 = loadImage("dinoduck0001.png");smallCactus = loadImage("cactusSmall0000.png");bigCactus = loadImage("cactusBig0000.png");manySmallCactus = loadImage("cactusSmallMany0000.png");bird = loadImage("berd.png");bird1 = loadImage("berd2.png");pop = new Population(500); //<<number of dinosaurs in each generation}//--------------------------------------------------------------------------------------------------------------------------------------------------------void draw() {drawToScreen();if (showBestEachGen) {//show the best of each genif (!genPlayerTemp.dead) {//if current gen player is not dead then update itgenPlayerTemp.updateLocalObstacles();genPlayerTemp.look();genPlayerTemp.think();genPlayerTemp.update();genPlayerTemp.show();} else {//if dead move on to the next generationupToGen ++;if (upToGen >= pop.genPlayers.size()) {//if at the end then return to the start and stop doing itupToGen= 0;showBestEachGen = false;} else {//if not at the end then get the next generationgenPlayerTemp = pop.genPlayers.get(upToGen).cloneForReplay();}}} else {//if just evolving normallyif (!pop.done()) {//if any players are alive then update themupdateObstacles();pop.updateAlive();} else {//all dead//genetic algorithmpop.naturalSelection();resetObstacles();}}}//---------------------------------------------------------------------------------------------------------------------------------------------------------//draws the display screenvoid drawToScreen() {if (!showNothing) {background(250);stroke(0);strokeWeight(2);line(0, height - groundHeight - 30, width, height - groundHeight - 30);drawBrain();writeInfo();}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------void drawBrain() { //show the brain of whatever genome is currently showingint startX = 600;int startY = 10;int w = 600;int h = 400;if (showBestEachGen) {genPlayerTemp.brain.drawGenome(startX, startY, w, h);} else {for (int i = 0; i< pop.pop.size(); i++) {if (!pop.pop.get(i).dead) {pop.pop.get(i).brain.drawGenome(startX, startY, w, h);break;}}}}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//writes info about the current playervoid writeInfo() {fill(200);textAlign(LEFT);textSize(40);if (showBestEachGen) { //if showing the best for each gen then write the applicable infotext("Score: " + genPlayerTemp.score, 30, height - 30);//text(, width/2-180, height-30);textAlign(RIGHT);text("Gen: " + (genPlayerTemp.gen +1), width -40, height-30);textSize(20);int x = 580;text("Distace to next obstacle", x, 18+44.44444);text("Height of obstacle", x, 18+2*44.44444);text("Width of obstacle", x, 18+3*44.44444);text("Bird height", x, 18+4*44.44444);text("Speed", x, 18+5*44.44444);text("Players Y position", x, 18+6*44.44444);text("Gap between obstacles", x, 18+7*44.44444);text("Bias", x, 18+8*44.44444);textAlign(LEFT);text("Small Jump", 1220, 118);text("Big Jump", 1220, 218);text("Duck", 1220, 318);} else { //evolving normallytext("Score: " + floor(pop.populationLife/3.0), 30, height - 30);//text(, width/2-180, height-30);textAlign(RIGHT);text("Gen: " + (pop.gen +1), width -40, height-30);textSize(20);int x = 580;text("Distace to next obstacle", x, 18+44.44444);text("Height of obstacle", x, 18+2*44.44444);text("Width of obstacle", x, 18+3*44.44444);text("Bird height", x, 18+4*44.44444);text("Speed", x, 18+5*44.44444);text("Players Y position", x, 18+6*44.44444);text("Gap between obstacles", x, 18+7*44.44444);text("Bias", x, 18+8*44.44444);textAlign(LEFT);text("Small Jump", 1220, 118);text("Big Jump", 1220, 218);text("Duck", 1220, 318);}}//--------------------------------------------------------------------------------------------------------------------------------------------------void keyPressed() {switch(key) {case '+'://speed up frame rateframeSpeed += 10;frameRate(frameSpeed);println(frameSpeed);break;case '-'://slow down frame rateif (frameSpeed > 10) {frameSpeed -= 10;frameRate(frameSpeed);println(frameSpeed);}break;case 'g'://show generationsshowBestEachGen = !showBestEachGen;upToGen = 0;genPlayerTemp = pop.genPlayers.get(upToGen).cloneForReplay();break;case 'n'://show absolutely nothing in order to speed up computationshowNothing = !showNothing;break;case CODED://any of the arrow keysswitch(keyCode) {case RIGHT://right is used to move through the generationsif (showBestEachGen) {//if showing the best player each generation then move on to the next generationupToGen++;if (upToGen >= pop.genPlayers.size()) {//if reached the current generation then exit out of the showing generations modeshowBestEachGen = false;} else {genPlayerTemp = pop.genPlayers.get(upToGen).cloneForReplay();}break;}break;}}}//---------------------------------------------------------------------------------------------------------------------------------------------------------//called every framevoid updateObstacles() {obstacleTimer ++;speed += 0.002;if (obstacleTimer > minimumTimeBetweenObstacles + randomAddition) { //if the obstacle timer is high enough then add a new obstacleaddObstacle();}groundCounter ++;if (groundCounter> 10) { //every 10 frames add a ground bitgroundCounter =0;grounds.add(new Ground());}moveObstacles();//move everythingif (!showNothing) {//show everythingshowObstacles();}}//---------------------------------------------------------------------------------------------------------------------------------------------------------//moves obstacles to the left based on the speed of the gamevoid moveObstacles() {println(speed);for (int i = 0; i< obstacles.size(); i++) {obstacles.get(i).move(speed);if (obstacles.get(i).posX < -playerXpos) {obstacles.remove(i);i--;}}for (int i = 0; i< birds.size(); i++) {birds.get(i).move(speed);if (birds.get(i).posX < -playerXpos) {birds.remove(i);i--;}}for (int i = 0; i < grounds.size(); i++) {grounds.get(i).move(speed);if (grounds.get(i).posX < -playerXpos) {grounds.remove(i);i--;}}}//------------------------------------------------------------------------------------------------------------------------------------------------------------//every so often add an obstaclevoid addObstacle() {int lifespan = pop.populationLife;int tempInt;if (lifespan > 1000 && random(1) < 0.15) { // 15% of the time add a birdtempInt = floor(random(3));Bird temp = new Bird(tempInt);//floor(random(3)));birds.add(temp);} else {//otherwise add a cactustempInt = floor(random(3));Obstacle temp = new Obstacle(tempInt);//floor(random(3)));obstacles.add(temp);tempInt+=3;}obstacleHistory.add(tempInt);randomAddition = floor(random(50));randomAdditionHistory.add(randomAddition);obstacleTimer = 0;}//---------------------------------------------------------------------------------------------------------------------------------------------------------//what do you think this does?void showObstacles() {for (int i = 0; i< grounds.size(); i++) {grounds.get(i).show();}for (int i = 0; i< obstacles.size(); i++) {obstacles.get(i).show();}for (int i = 0; i< birds.size(); i++) {birds.get(i).show();}}//-------------------------------------------------------------------------------------------------------------------------------------------//resets all the obstacles after every dino has diedvoid resetObstacles() {randomAdditionHistory = new ArrayList<Integer>();obstacleHistory = new ArrayList<Integer>();obstacles = new ArrayList<Obstacle>();birds = new ArrayList<Bird>();obstacleTimer = 0;randomAddition = 0;groundCounter = 0;speed = 10;}
4. Selanjutnya adalah class Monetisasi dengan nama Bird.
class Bird {
float w = 60;
float h = 50;
float posX;
float posY;
int flapCount = 0;
int typeOfBird;
//------------------------------------------------------------------------------------------------------------------------------------------------------
//constructor
Bird(int type) {
posX = width;
typeOfBird = type;
switch(type) {
case 0://flying low
posY = 10 + h/2;
break;
case 1://flying middle
posY = 100;
break;
case 2://flying high
posY = 180;
break;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//show the birf
void show() {
flapCount++;
if (flapCount < 0) {//flap the berd
image(bird,posX-bird.width/2,height - groundHeight - (posY + bird.height-20));
} else {
image(bird1,posX-bird1.width/2,height - groundHeight - (posY + bird1.height-20));
}
if(flapCount > 15){
flapCount = -15;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//move the bard
void move(float speed) {
posX -= speed;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//returns whether or not the bird collides with the player
boolean collided(float playerX, float playerY, float playerWidth, float playerHeight) {
float playerLeft = playerX - playerWidth/2;
float playerRight = playerX + playerWidth/2;
float thisLeft = posX - w/2 ;
float thisRight = posX + w/2;
if ((playerLeft<= thisRight && playerRight >= thisLeft ) || (thisLeft <= playerRight && thisRight >= playerLeft)) {
float playerUp = playerY + playerHeight/2;
float playerDown = playerY - playerHeight/2;
float thisUp = posY + h/2;
float thisDown = posY - h/2;
if (playerDown <= thisUp && playerUp >= thisDown) {
return true;
}
}
return false;
}
}
5. Selanjunya kita menambahkan rintangan kedalam game dengan nama file Obstacle
6. Tahap selanjutnya adalah pembuatan Jaringan Syaraf Tiruan yang tersedia DISINIclass Obstacle {
float posX;
int w ;
int h ;
int type;//------------------------------------------------------------------------------------------------------------------------------------------------------//constructorObstacle(int t) {posX = width;type = t;switch(type) {case 0://small cactusw = 40;h = 80;break;case 1://big cactusw = 60;h = 120;break;case 2://small cactiw = 120;h = 80;break;}}//------------------------------------------------------------------------------------------------------------------------------------------------------//show the cactusvoid show() {fill(0);rectMode(CENTER);switch(type) {case 0:image(smallCactus, posX - smallCactus.width/2, height - groundHeight - smallCactus.height);break;case 1:image(bigCactus, posX - bigCactus.width/2, height - groundHeight - bigCactus.height);break;case 2:image(manySmallCactus, posX - manySmallCactus.width/2, height - groundHeight - manySmallCactus.height);break;}}//------------------------------------------------------------------------------------------------------------------------------------------------------// move the obstaclevoid move(float speed) {posX -= speed;}//------------------------------------------------------------------------------------------------------------------------------------------------------//returns whether or not the player collides with this obstacleboolean collided(float playerX, float playerY, float playerWidth, float playerHeight) {float playerLeft = playerX - playerWidth/2;float playerRight = playerX + playerWidth/2;float thisLeft = posX - w/2 ;float thisRight = posX + w/2;if ((playerLeft<= thisRight && playerRight >= thisLeft ) || (thisLeft <= playerRight && thisRight >= playerLeft)) {float playerDown = playerY - playerHeight/2;float thisUp = h;if (playerDown <= thisUp) {return true;}}return false;}}
GAMEPLAY
Player Generasi Awal
Player Generasi Mahir
Source code dapat pembaca download DISINI
Terimakasih telah membaca, semoga bermanfaat :)

Game nya otomatis playing atau user yg playnya?
BalasHapusSilahkan langsung dicoba sendiri gan :)
HapusGamenya mantep . . . Cocok buat anak saya lebih sesuai umur di banding game m***** l***** . .
BalasHapusTerimakasih netizen budiman
HapusBagus game nya, keren
BalasHapusTerimakasih kak
HapusBagus game nya, keren
BalasHapusTerimakasih kak
Hapuskeren postingannya kak, sangat bermanfaat!
BalasHapusSemoga kak. Terimakasih :)
HapusBaguss
BalasHapusTerimakasih kak
HapusKeren cocok buat bocil milenial kekinian ni..
BalasHapusSegera di download gan dicoba sendiri hehe
HapusKeren,sangat bermanfaat
BalasHapusTerimakasih kak
Hapusterima kasih kak, infonya sangat bermanfaat
BalasHapusHehe iya kak :)
HapusGoks beut dah
BalasHapusTerimakasih om
HapusBagus juga ,tapi saya main dota
BalasHapusCoba sekali2 main game ini kak. Karena game dota tidak baik untuk kesehatan
HapusMantap dek gamesnya.. kembang kan terus dan sukses ya 😇
BalasHapusTerimakasih kak eci. Semoga ya hehe
Hapussemoga banyak di gemarin dan semakin berkembang
BalasHapusHehe iya terimakasih kakak :)
HapusSemoga lebih baik lagi. Terus kembangkan👍
BalasHapusKeren euy, mantap ni, bagus juga gamenya, best laah👏👏
BalasHapusHihi terimakasih kak
HapusNot bad sis
BalasHapusSegera dicoba ya kak hehe
Hapusmantap, keren game
BalasHapusTerimakasih kak
Hapus
BalasHapusBagus gamenya gan,cocok buat anak gua dirumah untuk menghibur waktu luang anak saya. Tpi itu klo bisa objeknya ganti agak lucuan begitu gan, jgn korsi haha
Thanks 👍🏻
Hehe iya next time inshaAllah akan dikembangkan lagi. Terimakasih masukkan nya kak :)
Hapusmantul
BalasHapusMantap betul gan
HapusMasukin di playstore doong
BalasHapusHehe setelah kami kembangkan lagi ya kak. Terimakasih :)
HapusIni buatnya pake aplikasi apa ya kak
BalasHapusProccessing kak :)
HapusCara maininin nya gmn??
BalasHapusPake proccessing kak, ntar copy codingnya baru run kan aplikasinya :)
HapusBagus, tpi kasihan si playernya scor udah jauh"
BalasHapusTapi mati ulang dari awal.
Maunya kasih nyawa biar dia gk nyerah
Terimakasih sarannya kak :)
HapusKeren sil mantap
BalasHapusKeren sil mantap
BalasHapus