1本周進度
這禮拜完成了計分和小人移動的部分,洞穴會越來越窄,而小人會不斷的往下掉,不管他會觸碰到洞穴邊緣死掉,所以我們要一直按空白健讓小人往上移動,不要碰到洞穴邊緣。每次玩遊戲結束或是game over之後可以按Enter重玩一遍.遊戲的最高分數會記錄於左上角。
遊戲失敗畫面
遊戲畫面
2本週程式碼
int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;
float dir = 1;
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1; // 遊戲狀態
float cur_space = 450;
float factor = 0.5;
//穴邊
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];
float[] yplayer = new float[cfg_width/2];
PFont myFont;
void initcave() {
score = 0;
dir = 1;
push = 0;
cur_space = 400;
body=loadImage("body.png");
for(int i = 0; i < width; i++) {
ylinetop[i] = height/2-int(cur_space)/2;
ylinebottom[i] = ylinetop[i]+int(cur_space);
}
for(int i = 0; i < width/2; i++) {
yplayer[i] = height/2;
}
}
void drawframe () {
background(0,0,0);
stroke(255,0,0);
for(int i=1; i<width; i++) {
line(i, 0, i, ylinetop[i]);
line(i, ylinebottom[i], i, height);
}
for(int i=1; i<width/2; i++) {
image(body,i, int(yplayer[i]),80,80);
if ( ylinetop[i]==10 & ylinebottom[i]==100){
background(255);
}
}
if (mode < 1) {
stroke(0,255,0);
strokeWeight(5);
fill(100,255,0);
ellipse(width/2, yplayer[width/2 - 1], 150, 150);
}
}
void setup()
{
size(cfg_width, cfg_height);
initcave();
frameRate(100);
}
void drawscore()
{
stroke(0);
strokeWeight(3);
fill(0);
text("最高分紀錄: " + int(maxscore/10) + " 分數: " + int(score/10), 1, 12);
if (mode == -1) {
text("Game Over!再玩一次.", 2, 26);
}
}
void draw()
{
if (mode == 1) {
for(int i = 1; i < width; i++) {
ylinetop[i-1] = ylinetop[i];
ylinebottom[i-1] = ylinebottom[i];
}
for(int i = 1; i < width/2; i++) {
yplayer[i-1] = yplayer[i];
}
ylinetop[width-1] =
constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
+ ylinetop[width-1]
, 0, height-int(cur_space+1));
ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);
dir = pow(cfg_gravity, dir) * dir;
yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);
if (yplayer[width/2-1] < ylinetop[width/2] ||
yplayer[width/2-1] > ylinebottom[width/2]) {
mode = 0;
}
cur_space *= cfg_space_mod;
score += 1;
if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
factor *= -1;
}
} else {
if (mode == 0) {
maxscore = maxscore > score ? maxscore : score;
mode = -1;
}
}
drawframe();
drawscore();
}
void keyPressed() {
if (mode == 1 && key == ' ') {
dir *= 0.997;
}
if (mode == -1 && (keyCode == ENTER || keyCode == RETURN)) {
mode = 1;
initcave();
}
}
3尚未完成吃金幣的功能
4本周心得
這禮拜將小人用貼圖方式放進遊戲中,讓它可以順利執行,很開心
今天老師又說明了音樂怎麼進程式中,這樣一來我們也考慮放背景音樂至遊戲裡。
沒有留言:
張貼留言