互動技術概論
week15
Processing憤怒鳥小遊戲
PVector user1,Y,y,v=null;
PImage sky,brid;
float time=0;
int n=0;
void setup(){
size(500,500);
user1 = new PVector(168,345);
Y = new PVector(168,345);
y = new PVector(160,365);
sky = loadImage("01.png");
brid = loadImage("brid2.png");
}
void draw(){
background(sky);
textSize(50);
fill(0);
text("Y",y.x,y.y);
fill(#537972);
imageMode(CENTER);
image(brid,user1.x,user1.y,40,40);
if(mousePressed)line(user1.x,user1.y,Y.x,Y.y);
if(v!=null){
user1.add(v);
v.y+=0.98;//重力加速度
}
if(n==1)time++;
if(time>200){
user1 = new PVector(168,345);
v=null;
time=0;
n=0;
}
println(time);
}
void mouseDragged(){
user1.x=mouseX;
user1.y=mouseY;
v=null;
}
void mouseReleased(){
PVector diff = PVector.sub(Y,user1);
v = diff.div(4);//除法
time++;
n=1;
}
Joystrick控制球球
Arduino程式碼
import processing.serial.*;
Serial myPort;
void setup(){
size(500,500);
myPort = new Serial(this, "COM5",9600);
}
int ballX=0, ballY=0;
void draw(){
background(255);
while(myPort.available()>=3){
int x = myPort.read();
int y = myPort.read();
int sw = myPort.read();
ballX = x;
ballY = y;
}
fill(#2F5A52);
ellipse(ballX,ballY,40,40);
}
Processing程式碼
PVector user1,Y,y,v=null;
PImage sky,brid;
float time=0;
int n=0;
void setup(){
size(500,500);
user1 = new PVector(168,345);
Y = new PVector(168,345);
y = new PVector(160,365);
sky = loadImage("01.png");
brid = loadImage("brid2.png");
}
void draw(){
background(sky);
textSize(50);
fill(0);
text("Y",y.x,y.y);
fill(#537972);
imageMode(CENTER);
image(brid,user1.x,user1.y,40,40);
if(v!=null){
user1.add(v);
v.y+=0.98;//重力加速度
}
if(n==1)time++;
if(time>200){
user1 = new PVector(168,345);
v=null;
time=0;
n=0;
}
println(time);
}
void mouseDragged(){
user1.x=mouseX;
user1.y=mouseY;
v=null;
}
void mouseReleased(){
PVector diff = PVector.sub(Y,user1);
v = diff.div(4);//除法
time++;
n=1;
}

沒有留言:
張貼留言