我們的期中作品是小朋友挖隧道的遊戲,我們將玩法改變成小人會不斷的挖隧道前進要離開山洞,利用按空白鍵的方式來讓小人不要碰到山壁,但隨著山洞的路越來越窄小人需要得到高分才可以變小,最後順利離開山洞!
當得分達50分之後便會縮小身體,得到100分之後便成功破關順利離開山洞。
期中作品程式碼
int cfg_width =500;
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,mn,e;
int now=1;
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;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void initcave() {
score = 0;
dir = 1;
push = 0;
cur_space = 400;
body=loadImage("bodyknife.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 () {
drawframe2 ();
if( score/10==98 ||score/10==99 ||score/10==100)
{ background(90,90,90);
e=loadImage("end.jpg");
image(e,220,80);
}
if(score/10==101)
{
size(500,450);
mn=loadImage("mn.jpg");
image(mn,0,0);
}
else{
for(int i=1; i<width; i++) {
stroke(255,0,0);
line(i, 0, i, ylinetop[i]);
line(i, ylinebottom[i], i, height);
}
}
if (mode < 1) {
stroke(0,255,0);
strokeWeight(5);
fill(100,255,0);
ellipse(width/2, yplayer[width/2 - 1], 150, 150);
}
people();
}
void drawframe2 () {
if (score/10<25){
background(20);
}
else if (score/10<=50) {
background(40,40,40);
}
else if (score/10<100){
background(90,90,90);
}
}
void people(){
for(int i=1; i<width/2; i++) {
if (score/10<50){
image(body,i, int(yplayer[i]),90,90);
}
else if (score/10<=100) {//大於50分 小於等於100分
image(body,i, int(yplayer[i]),60,60);
}
}
}
void drawscore()
{
if(mode==1 && score/10<=100)
{
stroke(0,255,0);
strokeWeight(3);
fill(0,255,0);
textSize(18);
text("The High Score: " + int(maxscore/10) +
" & Score: " + int(score/10), 2, 20);
}
if (mode == -1) {
fill(0,255,0);
text("Game Over!\n Try Again.", 2, 20);
}
}
void setup()
{
size(cfg_width, cfg_height);
initcave();
frameRate(100);
minim = new Minim(this); //播音樂
player = minim.loadFile("Kalimba.mp3"); //播音樂
player.play(); //播音樂
}
void draw()
{
if (mode == 1 && score/10<=100) {
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();
}
}
期中作品截圖遊戲畫面
開始遊戲畫面
失敗畫面
遊戲終點
過關畫面
沒有留言:
張貼留言