用PVector來做運算(間減乘除)
電流急急棒
用pixel去偵測像素典
程式碼
PImage imgMap;
void setup(){
size(400,400);
imgMap=loadImage("Map.png");
imgMap.loadPixels();
}
void draw(){
background(imgMap);
if( imgMap.pixels[mouseX+mouseY*400] == color(237,28,36)){
background(255,0,0);
}
fill(imgMap.pixels[mouseX+mouseY*400]);
rect(255,250,100,100);
}
產生子彈
程式碼
int[] value=new int[100];
PVector[] bullet =new PVector[100];
PVector[] bulletV =new PVector[100];
void setup(){
size(500,500);
for(int i=0;i<100;i++){
bullet[i]=new PVector( random(500),random(500)); ///讓他隨便跑
bulletV[i]=new PVector( random(4)-2,random(4)-2);
}
}
void draw(){
background(0);
for(int i=0;i<100;i++){
fill(255);
bullet[i].add(bulletV[i]);
ellipse(bullet[i].x,bullet[i].y,5,5);
if(bullet[i].x<0){ ///碰到邊界會彈回來
bullet[i].x=0;
bulletV[i].x=random(2);
}
if(bullet[i].x>500){
bullet[i].x=500;
bulletV[i].x=-random(2);
}
if(bullet[i].y<0){
bullet[i].y=0;
bulletV[i].y=random(2);
}
if(bullet[i].y>500){
bullet[i].y=500;
bulletV[i].y=-random(2);
}
}
}
期中
PVector user;
PVector userv;
int[] value=new int[100];
PVector[] bullet =new PVector[100];
PVector[] bulletV =new PVector[100];
void setup(){
size(500,500);
user = new PVector(0,450);
userv = new PVector(0,0);
for(int i=0;i<10;i++){
bullet[i]=new PVector( random(500),random(500)); ///讓他隨便跑
bulletV[i]=new PVector( random(4)-2,random(4)-2);
}
}
void draw(){
background(255);
fill(0);
rect(user.x,user.y,50,50);
user.add(userv);
if(user.x>500-50) userv.x=0;
if(user.y>500-50) userv.y=0;
if(user.x<0) userv.x=0;
if(user.y<0) userv.y=0;
for(int i=0;i<10;i++){
fill(128);
bullet[i].add(bulletV[i]);
ellipse(bullet[i].x,bullet[i].y,5,5);
if(bullet[i].x<0){ ///碰到邊界會彈回來
bullet[i].x=0;
bulletV[i].x=random(2);
}
if(bullet[i].x>500){
bullet[i].x=500;
bulletV[i].x=-random(2);
}
if(bullet[i].y<0){
bullet[i].y=0;
bulletV[i].y=random(2);
}
if(bullet[i].y>500){
bullet[i].y=500;
bulletV[i].y=-random(2);
}
}
fill(255,0,0);
rect(450,0,50,50);
if(user.x>449&&user.y<1){
background(220);
}
}
訂閱:
張貼留言 (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就會使整個圓跑出去 於是就讓他往回彈 就變成成功的彈彈球 自己製作迷宮 先畫一張自己設計的地圖 並先試看看能不能匯入 並且...
沒有留言:
張貼留言