作品:射擊遊戲
連結:https://youtu.be/gQT0Yh68xOU
簡介:本遊戲屬於射擊遊戲,需用搖桿控制幽靈(主角)消滅符咒(怪物)來保護幽靈身後的貓咪,
若符咒觸碰到貓咪即顯示GAME OVER以及分數結束遊戲,若分數達到200分即成功過關。
操作方式:利用搖桿上下左右移動幽靈,往下壓即可射出子彈來攻擊符咒怪物。
賣點:可利用搖桿操作而不是單單只使用鍵盤及滑鼠操作。
困難點:要想辦法讓遊戲結合搖桿控制。
PImage soul; PImage ememy; PImage background; PImage gameover; PImage first; PImage cat; PImage first1; PImage endgame; float endgameX=0, endgameY=0; float first1X=0, first1Y=0; float catX=0, catY=0; float soulX=100, soulY=450; float gameoverX=0, gameoverY=0; float firstX=0, firstY=0; float backgroundX=0, backgroundY=0; float soulVX=0, soulVY=0; float []bulletX=new float[100]; float []bulletY=new float[100]; float []ememyX=new float[50]; float []ememyY=new float[50]; boolean[]bulletFlying=new boolean[100]; boolean[]ememyAlive=new boolean[50]; int bulletN=0; int softBrake=0,game=0,score=0; int m=0, dead=0, point=0; import processing.serial.*; Serial serial; void setup() { size(1600, 900); serial=new Serial(this, "COM3", 9600); soul=loadImage("soul.png"); cat=loadImage("cat.png"); ememy=loadImage("ememy.jpg"); gameover=loadImage("gameover.jpg"); background=loadImage("background.jpg"); first=loadImage("first.jpg"); first1=loadImage("first1.jpg"); endgame=loadImage("endgame.jpg"); endgame.loadPixels(); soul.loadPixels(); gameover.loadPixels(); background.loadPixels(); first.loadPixels(); first1.loadPixels(); cat.loadPixels(); for (int i=0; i<50; i++) { ememyX[i]=random(1500)+1300+i*50; ememyY[i]=random(750); ememyAlive[i]=true; } } int x=512, y=512, sw=577; void recycle() { for (int i=0; i<bulletN; i++) { if (bulletFlying[i]==false) { for (int k=i; k<bulletN-1; k++) { bulletX[k]=bulletX[k+1]; bulletY[k]=bulletY[k+1]; bulletFlying[k]=bulletFlying[k+1]; } bulletN--; } } } void draw() { if(game==0){ if (serial.available()>0) { String now=serial.readString(); String[] xy=splitTokens(now); x=int (xy[0]); y=int (xy[1]); sw=int (xy[2]); } image(first, firstX, firstY, 1600, 900); if(sw==0&&game==0){ game++; } println(game); } if(game==1){ if (serial.available()>0) { String now=serial.readString(); String[] xy=splitTokens(now); x=int (xy[0]); y=int (xy[1]); sw=int (xy[2]); } image(first1, first1X, first1Y, 1600, 900); if(sw==0&&game==1){ game++; } println(game); } if(game==2){ image(background, backgroundX, backgroundY, 1600, 900); image(cat, catX, catY, 125, 900); for (int i=0; i<50; i++) { if (ememyAlive[i]) { image(ememy, ememyX[i], ememyY[i], 80, 80); ememyX[i]-=10; } } for (int i=0; i<bulletN; i++) { if (bulletFlying[i]&&m==0) { fill(255, 0, 0); ellipse(bulletX[i], bulletY[i], 10, 10); bulletX[i]+=50; for (int k=0; k<50; k++) { if (dist(bulletX[i], bulletY[i], ememyX[k]+40, ememyY[k]+40)<40&&ememyAlive[k]==true) { ememyAlive[k]=false; bulletFlying[i]=false; if (ememyAlive[k]==false&&game==2) { point+=10; } score=point; } } if (bulletX[i]>1600) { bulletFlying[i]=false; } } textSize(72); text("score:"+point, 150, 100); } println(point); if (sw==0) { bulletX[bulletN]=soulX+50; bulletY[bulletN]=soulY+50; bulletFlying[bulletN]=true; bulletN++; if (bulletN>=100) bulletN=0; m=1; } else { m=0; } for (int k=0; k<50; k++) { if (ememyX[k]<100) { ememyAlive[k]=false; } if (ememyX[k]<100&& ememyAlive[k]==false) { game++; } } if (serial.available()>0) { String now=serial.readString(); String[] xy=splitTokens(now); x=int (xy[0]); y=int (xy[1]); sw=int (xy[2]); } image(soul, soulX, soulY, 100, 100); delay(100); if (soulX>1550) { soulX=1550; soulVX=0; } if (soulX<100) { soulX=100; soulVX=0; } if (soulY>750) { soulY=750; soulVY=0; } if (soulY<50) { soulY=50; soulVY=0; } if (x==1023) { softBrake=1; } else if (x==0) { softBrake=1; } if (x==1023) { { soulX+=10; soulVX=10; } softBrake=0; } else if (x==0) { soulX-=50; soulVX=-50; } softBrake=0; if (y==1023) { { soulY+=50; soulVY=50; } softBrake=0; } else if (y==0) { soulY-=50; soulVY=-50; } softBrake=0; } if(game==3){ image(gameover, gameoverX, gameoverY, 1600, 900); textSize(108); text("score:"+score, 575, 600); } if(point>=200){ game=4; } if(game==4){ image(endgame,endgameX,endgameY, 1600, 900); fill(#5FDFF7); textSize(108); text("score:"+score, 550, 750); } }
沒有留言:
張貼留言