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) { } }
2019年12月26日 星期四
week16
訂閱:
張貼留言 (Atom)
alanhc 互動技術-week17 [final]
回顧這學期的作品: 期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...
-
先把上次的程式覆蓋 void setup(){ pinMode(8,OUTPUT); pinMode(2,INPUT_PULLUP); } void loop(){ if(digitalRead(2)== LOW ) tone(8,520,...
-
1. 複習按住boutton可以發出聲音 void setup(){ pinMode(8, OUTPUT); pinMode(2, INPUT_PULLUP); } void loop(){ if(digitalRead(2)==LOW) tone(8,...
-
第一張圖是讓使用者的圈圈可以自己移動 但他有個缺點 就是圈圈會跑出視窗外面 於是加上了if 假使中心大於350就會使整個圓跑出去 於是就讓他往回彈 就變成成功的彈彈球 自己製作迷宮 先畫一張自己設計的地圖 並先試看看能不能匯入 並且...
沒有留言:
張貼留言