Created
April 11, 2019 03:10
-
-
Save thcrack/52933f6c2b0c324d3c1f21b17eca152f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final int GAME_STOP = 0, GAME_RUN = 1; | |
int gameState; | |
int balloonX = 35, balloonY, balloonW = 60, balloonH = 86; | |
int fireW = 15, fireH = 20; | |
int cameraOffsetX = 0; | |
boolean debugMode = false; | |
PImage bg, balloon, fire; | |
int hills[] = new int[8]; | |
final int HILL_W[] = {0, 100, 150, 200}; | |
final int HILL_H[] = {0, 50, 75, 100}; | |
PImage hillImage[] = new PImage[4]; | |
void setup() { | |
size(800,300); | |
noCursor(); //隱藏鼠標 | |
bg = loadImage("img/bg.png"); | |
balloon = loadImage("img/balloon.png"); | |
fire = loadImage("img/fire.png"); | |
hillImage[0] = null; | |
hillImage[1] = loadImage("img/sHill.png"); | |
hillImage[2] = loadImage("img/mHill.png"); | |
hillImage[3] = loadImage("img/lHill.png"); | |
gameState = GAME_RUN; | |
balloonY = 0; | |
for(int i = 0; i < hills.length; i++){ | |
hills[i] = floor(random(4)); | |
} | |
} | |
void draw() { | |
/* ------ Debug Function ------ | |
Please DO NOT edit the code here. | |
It's for reviewing other requirements when you fail to complete the camera moving requirement. | |
*/ | |
if (debugMode) { | |
pushMatrix(); | |
translate(cameraOffsetX, 0); | |
} | |
/* ------ End of Debug Function ------ */ | |
switch(gameState) { | |
case GAME_RUN: | |
// 顯示背景 | |
image(bg, -cameraOffsetX, 0, width, height); | |
// 顯示熱氣球 | |
if(balloonY < 0) { | |
balloonY = 0; | |
} else if(balloonY + balloonH > height) { | |
//balloonY = height - balloonH; | |
gameState=GAME_STOP; | |
} | |
image(balloon, balloonX, balloonY, balloonW, balloonH); | |
balloonY++; | |
// 顯示山坡 | |
for(int i = 0; i < hills.length; i++){ | |
int hillType = hills[i]; | |
PImage img = hillImage[hillType]; | |
int hillH = HILL_H[hillType], hillW = HILL_W[hillType]; | |
if(img != null){ | |
image(img, 200 * (i + 1) - hillW, height - hillH, hillW, hillH); | |
} | |
} | |
// 顯示越過山坡數 | |
// 滑鼠圖示 | |
imageMode(CENTER); | |
image(fire, mouseX, mouseY, fireW, fireH); | |
imageMode(CORNER); | |
break; | |
case GAME_STOP: | |
// 點擊鍵盤重啟遊戲 | |
if(keyPressed) { | |
gameState = GAME_RUN; | |
balloonY = 0; | |
} | |
break; | |
} | |
// DO NOT REMOVE OR EDIT THE FOLLOWING 3 LINES | |
if (debugMode) { | |
popMatrix(); | |
} | |
} | |
void mouseClicked() { | |
if (gameState == GAME_RUN){ | |
// 點擊滑鼠熱氣球上升 50px | |
balloonY -= 50; | |
} | |
} | |
void keyPressed() { | |
// DO NOT REMOVE OR EDIT THE FOLLOWING SWITCH/CASES | |
switch(key) { | |
case 'a': | |
if(cameraOffsetX < 0) { | |
debugMode = true; | |
cameraOffsetX += 25; | |
} | |
break; | |
case 'd': | |
if(cameraOffsetX > -width) { | |
debugMode = true; | |
cameraOffsetX -= 25; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment