2019年12月26日 星期四

week16

PImage []Bg = new PImage[4];
PImage []imgRole = new PImage[4];
PImage imgTemp, imgNow, imgBuilding;
float roleX=50, roleY=620, roleVX=3, roleVY=0;
;
int roleID=0, jumping=0;
void setup() {
  size(800, 800);
  Bg[1] = loadImage("bg.png");
  Bg[1].loadPixels();
  for (int i=0; i<4; i++) imgRole[i]=loadImage("Cat"+i+".png");
  rectMode(CENTER);
}
float x=0;
float shiftX=0;
void draw() {
  int nextX=int(roleX)+int(roleVX);
  int nextY=int(roleY);
  if(nextY>=800-1){
    nextY=800-2;
    roleY=800-2;
  }
  background(255);
  image(Bg[1], -shiftX, 0);

  if (keyCode==RIGHT||keyCode==UP||keyCode==DOWN||keyCode==LEFT) {

    if (jumping==1) {
      roleY +=roleVY; 
      roleVY +=0.9;
      if(nextY>=800){
        jumping=0;
        roleVY=0;
        nextY=800-2;
        roleY=800-2;
      }
      if (nextY>=0 && Bg[1].pixels[(int(nextX)+int(shiftX))+int(nextY)*3500]==color(0)) 
      {
        println(nextY);
        roleY--;
        jumping=0;
        roleVY=0;
      }
    } else if (Bg[1].pixels[(int(nextX)+int(shiftX))+int(nextY+1)*3500]!=color(0)) {
      roleY++;
    }

    if (nextY>=0 && Bg[1].pixels[(int(nextX)+int(shiftX))+int(nextY)*3500] == color(255)) {
      roleX=nextX;
      if (roleX>400) {
        shiftX += roleX-400;
        roleX=400;
      }
      for (int y=nextY; y<800; y++) {
        if (Bg[1].pixels[(int(nextX)+int(shiftX))+int(y)*3500] == color(0)) {
          if (abs(roleY-y)>80&&abs(roleY-y)>80-10) {
          } else roleY = y-80;
          break;
        }
      }
    }
    image(imgRole[roleID], roleX, roleY-20, 100, 100);
    if (frameCount%30==0) {
      roleID=(roleID+1)%4;
      if (roleID==0) roleX+=1;
    }
  }
}

void keyPressed() {
  if (keyCode==UP) {
    jumping=1;
    roleVY=-10;
    if (roleY<0) roleY=0;
  }
  if (keyCode==DOWN) {
  }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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