2020年1月6日 星期一

week17-2020/01/02

Week17-09:23到 

                                                          
---------------------------------------------------------------------------------------------------------------------------------
期末作品展示
1.Youtube連結:https://youtu.be/MbG9xONBCzE
2.作品名稱:BT21保衛大作戰-part2
3.遊戲說明:藉由操作搖桿上下左右移動角色,時間內看能吃到多少食物,若碰到鬼就結束遊戲。

《程式碼》
import processing.serial.*;
Serial serial;
PImage imgBGGG, imgBGG, imgBG, imgtata, imgRJ, imgboom, imgjim1, imgjim2, imgjim3;
int []foodX={80, 80, 80, 80, 80, 180, 230, 280, 330, 380, 430, 480, 530, 580, 630, 
  680, 730, 780, 830, 880, 930, 980, 1030, 1080, 110, 130, 130, 130, 130, 130, 150, 200, 250, 
  190, 260, 320, 290, 340, 300, 350, 400, 400, 400, 430, 430, 430, 460, 520, 590, 650, 710, 710, 
  710, 710, 710, 710, 710, 400, 400, 400, 450, 500, 550, 600, 600, 650, 650, 700, 750, 760, 810, 
  860, 910, 960, 980, 980, 980, 980, 930, 880, 980, 930, 880, 1010, 1030, 1030, 800, 850, 900, 950, 1000, 1050, 1100, };
int []foodY={350, 400, 440, 480, 530, 530, 530, 530, 530, 530, 530, 530, 530, 530, 530, 
  530, 530, 530, 530, 530, 530, 530, 530, 530, 82, 130, 190, 240, 300, 350, 82, 82, 82, 
  350, 350, 350, 210, 210, 82, 82, 82, 150, 200, 390, 440, 490, 240, 240, 240, 240, 240, 180, 
  130, 300, 350, 400, 450, 250, 300, 350, 82, 82, 82, 82, 380, 380, 82, 82, 82, 395, 395, 
  395, 395, 395, 350, 290, 230, 180, 180, 180, 130, 290, 290, 395, 440, 480, 82, 82, 82, 82, 82, 82, 82, 82, };

int foodN;
int stage=0;
int score=0;
int time=1200;//1820
boolean foodAlive[]=new boolean [100];

void setup() {
  size(1200, 600);
  imgBG=loadImage("BG.PNG");
  imgBGG=loadImage("BGG.png");
  imgBGGG=loadImage("BGGG.PNG");
  imgjim1=loadImage("jin.png");
  imgboom=loadImage("ghost.png");
  serial = new Serial(this, "COM3", 9600);
  imgBGG.loadPixels();
  foodN=foodX.length;
  reset();
}
int ax=1000, ay=50, avx=1, avy=0;
int ghostx=50, ghosty=50, gvx=0, gvy=0;
float x=20, y=55, vx=0, vy=0;
void draw() {
  /*-----------stage0-----------------*/
  if (stage==0) {
    background(imgBG);
    if (mousePressed) {
      stage=1;
    }
  }
  /*-----------stage1-----------------*/
  else if (stage==1) {
    background(imgBGG);
    for (int i=0; i<foodN; i++) {
      if ( foodAlive[i] ) { 
        ellipse(foodX[i], foodY[i], 15, 15);
      }  
      /*----------吃掉食物---------------*/
      if ( dist(foodX[i], foodY[i], x, y)<40 && foodAlive[i]) {
        score+=10;
        foodAlive[i]=false;
      }
    }

    textSize(50); 
    fill(255);
    text("score:" +score, 20, 40);
    text("Time: " +int(time/60), 900, 40);
    time--;
    /*-------------主角移動-----------*/
    if (serial.available()>0) {
      String now=serial.readString();
      String[]xy=splitTokens(now);
      vx= (int(xy[0])-511)/200.0;
      vy= (int(xy[1])-509)/200.0;
    }
    image(imgjim1, x, y, 80, 60);
    if ( imgBGG.pixels[int(x+vx) + int(y)*1200] ==#000000) {
      x+=vx;
    }
    if (imgBGG.pixels[int(x) + int(y+vy)*1200] ==#000000) {
      y+=vy;
    }

    /*-----時間到就結束------*/
    if (time<0) stage=2;
   /*-------------鬼Boom-----------*/
       image(imgboom, ax, ay, 55, 55);
    if ( imgBGG.pixels[int(ax+vx) + int(ay)*1200] ==#000000) {
      ax--;
    }
    if (ax-x<=0) {
      stage=2;
    }
  
  } 


  /*-----------stage2-----------------*/
  else if (stage==2) {  
    background(imgBGGG);
    fill(255);
    textSize(50); 
    text("score:" +score, 510, 400);
    if (450<mouseX &&mouseX<750 && 450<mouseY && mouseY<550 && mousePressed) {
      stage=1;
      reset();
      time=1200;
    }
  }
}

void reset() {
  score=0;
  x=20; 
  y=55; 
  vx=0; 
  vy=0;
  ax=1000; 
  ay=50;
  avx=1;
  avy=0;
  for (int i=0; i<foodN; i++) {
    foodAlive[i]=true;
  }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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