2020年1月10日 星期五

期末作業Week17

組員:溫鎮瑋06160291,林妘鎂06160052

作品:射擊遊戲

連結:https://youtu.be/gQT0Yh68xOU

簡介:這是簡單的射擊遊戲搭配著搖桿進行移動以及操作,來擊退符咒保護後面的貓咪。

操作方式:這次想說有新學到搖桿的部分,所以想說讓一定變成用搖桿一定,在加上SW往下壓即可發射子彈的方式讓操作在一個地方上完成

賣點:較為簡單,且在操作重鍵盤滑鼠轉移至搖桿上面

困難點:搖桿的使用以及arduino跟P語言的配合

下面是程式碼的部分
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);
  }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...