2019年12月19日 星期四

week15

1、期末作業


 移動畫布: 


PImage []bgMountain = new PImage[4];
void setup(){
  size(800,400);
  bgMountain[1] = loadImage("bg2.png");
}
float x=0;
void draw(){
 background(255);
 int i=2;
 float newX=-i*x;
 image(bgMountain[1],newX,2*i);
}
void keyPressed(){
 if(keyCode==RIGHT) x+=4; 
}




 人物+畫布移動: 


PImage []bgMountain = new PImage[4];
int roleX=50,roleY=300,roleVX=1;
void setup() {
  size(800, 350);
  bgMountain[1] = loadImage("bg2.png");
}
float x=0;
void draw() {
  int nextX=roleX+roleVX,nextY=roleY;
  background(255);
  int i=1;
  float newX=-i*roleX;
  image(bgMountain[1], newX, 2*i);
  if (bgMountain[1].pixels[nextX+nextY*+3000] == color(255)) {
    println("1");
    roleX=nextX;
  }println("no");
  ellipse(roleX, roleY, 50, 50);
}
void keyPressed() {
}


 改善畫布和球的位置差: 


PImage []bgMountain = new PImage[4];
int roleX=50, roleY=295, roleVX=1, roleVY=4;
void setup() {
  size(800, 350);
  bgMountain[1] = loadImage("bg2.png");
}
float x=0;
void draw() {
  int nextX=roleX+roleVX;
  int nextY=roleY;
  background(255);
  int i=1;
  float newX=-i*roleX;
  image(bgMountain[1], newX, 0);
  println(nextX + " " + nextY);
  if (bgMountain[1].pixels[(int)(nextX-newX)+nextY*3000] == color(255)) {
    println(nextX);
    roleX=(int)nextX;
  }
  println("no");
  ellipse(roleX, roleY, 50, 50);
}
void keyPressed() {
  if (keyCode==UP) {
    roleY=roleY-roleVY;
    if (roleY<0) roleY=0;
  }
}





 改善畫布和球的速度差: 



PImage []bgMountain = new PImage[4];
int roleX=50, roleY=295, roleVX=1, roleVY=4;
void setup() {
  size(800, 350);
  bgMountain[1] = loadImage("bg2.png");
}
float x=0;
float shiftX=0;
void draw() {
  int nextX=roleX+roleVX;
  int nextY=roleY;
  background(255);
  image(bgMountain[1], -shiftX, 0);
  println(nextX + " " + nextY);
  if (bgMountain[1].pixels[(int)(nextX+shiftX)+nextY*3000] == color(255)) {
    println(nextX);
    roleX=(int)nextX;
    if(roleX>400){
      shiftX += roleX-400;
      roleX=400;
    }
  }
  ellipse(roleX, roleY, 50, 50);
}
void keyPressed() {
  if (keyCode==UP) {
    roleY=roleY-roleVY;
    if (roleY<0) roleY=0;
  }
}


 主角可跳: 


PImage []bgMountain = new PImage[4];
int roleX=50, roleY=295, roleVX=1;
float roleVY=0;
void setup() {
  size(800, 350);
  bgMountain[1] = loadImage("bg2.png");
}
float x=0;
float shiftX=0;
void draw() {
  int nextX=roleX+roleVX;
  int nextY=roleY;
  roleY += roleVY;
  if(roleY<=295) roleVY += 0.9;
  else roleY=295;
  background(255);
  image(bgMountain[1], -shiftX, 0);
  println(nextX + " " + nextY);
  if (bgMountain[1].pixels[(int)(nextX+shiftX)+nextY*3000] == color(255)) {
    println(nextX);
    roleX=(int)nextX;
    if(roleX>400){
      shiftX += roleX-400;
      roleX=400;
    }
  }
  ellipse(roleX, roleY, 50, 50);
}
void keyPressed() {
  if (keyCode==UP) {
    roleVY=-15;
    if (roleY<0) roleY=0;
  }
}

 主角爬坡: 


PImage []bgMountain = new PImage[4];
PImage imgTemp,imgPixels,stage,imgNow,imgBuilding;
int roleX=50, roleY=420, roleVX=1;
float roleVY=0;
void setup() {
  size(800, 500);
  bgMountain[1] = loadImage("bg.png");
}
float x=0;
float shiftX=0;
void draw() {
  int nextX=roleX+roleVX;
  int nextY=roleY;
  roleY += roleVY;
  if(roleY<=420) roleVY += 0.9;
  else roleY=420;
  background(255);
  image(bgMountain[1], -shiftX, 0);
  println(nextX + " " + nextY);
  if (bgMountain[1].pixels[(int)(nextX+shiftX)+nextY*3000] == color(255)) {
    println(nextX);
    roleX=nextX;
    if(roleX>400){
      shiftX += roleX-400;
      roleX=400;
    }
    for (int y=nextY; y<500; y++) {
        if (bgMountain[1].pixels[(int)(nextX+shiftX)+y*3000] == color(0)) {
          if (abs(roleY-y)>20) {
            imgTemp=imgPixels;
            imgNow=imgBuilding;
          } else roleY = y-1;
          break;
        }
    }
  }
  ellipse(roleX+2, roleY+2, 50, 50);
}
void keyPressed() {
  if (keyCode==UP) {
    roleVY=-15;
    if (roleY<0) roleY=0;
  }
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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