
2019年1月20日 星期日
2019年1月5日 星期六
AHSU interaction week15
void setup() {
Serial.begin(9600);
pinMode(5,INPUT);
digitalWrite(5,HIGH);
}
byte data[3];
void loop() {
int valX=analogRead(A0);
int valY=analogRead(A1);
data[0]=valX/8;
data[1]=valY/8;
if(digitalRead(5)==LOW) data[2]=1;
else data[2]=0;
Serial.write(data,3);
delay(100);
}
Serial.begin(9600);
pinMode(5,INPUT);
digitalWrite(5,HIGH);
}
byte data[3];
void loop() {
int valX=analogRead(A0);
int valY=analogRead(A1);
data[0]=valX/8;
data[1]=valY/8;
if(digitalRead(5)==LOW) data[2]=1;
else data[2]=0;
Serial.write(data,3);
delay(100);
}
AHSU interaction week 16
import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
Serial myPort;
int state=0;
PImage bg, playing, cat87, cat887, ending, end, again;
PImage []rock=new PImage[5];
float catx=300, caty=400, catvx=0, catvy=0;
float []rockx=new float[5];
float []rocky=new float[5];
float []rockvx=new float[5];
float []rockvy=new float[5];
boolean catL=false, catR=false;
int time, score;
void setup() {
size(600, 800);
myPort = new Serial(this, "COM3", 9600);
minim =new Minim(this);
player=minim.loadFile("Bongo Cat - Nyan Cat.mp3");
bg=loadImage("title.png");
playing=loadImage("universe.png");
cat87=loadImage("nyan-cat.png");
cat887=loadImage("nyan-cat87.png");
ending=loadImage("game over.png");
end=loadImage("god_logo_800.jpg");
again=loadImage("play-again.png");
imageMode(CENTER);
for (int i=0; i<5; i++) {
rock[i]=loadImage("ball.png");
rockx[i]=random(50, 550);
rocky[i]=random(50, 750);
rockvx[i]=5*random(-1, 1);
rockvy[i]=5*random(-1, 1);
}
player.loop();
}
void draw() {
frameRate=30;
getData();
if (state==0) {
image(bg, width/2, height/2, width, height);
if (data[2]==1)
state=1;
} else if (state==1) {
image(playing, width/2, height/2, width, height);
if (data[0]==64 || data[1]==64) {
catvx=0;
catvy=0;
}
catvx=(data[0]-64)/5.0;
catvy=(data[1]-64)/5.0;
catx+=catvx;
caty+=catvy;
if (!(catR) && !(catL)) {
image(cat87, catx, caty, 133, 100);
}
if (catvx<0) {
image(cat887, catx, caty, 133, 100);
catL=true;
catR=false;
} else if (catvx>0) {
image(cat87, catx, caty, 133, 100);
catR=true;
catL=false;
} else {
if (catL) image(cat887, catx, caty, 133, 100);
else if (catR) image(cat87, catx, caty, 133, 100);
}
if (catx<60) catx=60;
if (catx>538) catx=538;
if (caty<30) caty=30;
if (caty>763) caty=763;
for (int i=0; i<5; i++) {
image(rock[i], rockx[i], rocky[i], 75, 73);
rockx[i]+=rockvx[i];
rocky[i]+=rockvy[i];
if (frameCount%30==0) {
rockvx[i]=rockvx[i]*random(1.0, 1.1);
rockvy[i]=rockvy[i]*random(1.0, 1.1);
}
if (rockx[i]<=30 || rockx[i]>=566)
rockvx[i] = -rockvx[i];
if (rocky[i]<=30 || rocky[i]>=763)
rockvy[i] = -rockvy[i];
if ((time+29)/30>1 && dist(rockx[i], rocky[i], catx, caty)<(75/2+45/2)) {
state=2;
catx=300;
caty=400;
}
}
time++;
fill(255);
textSize(50);
if ((time+29)/30<10) text(((time+29)/30), 300-10, 60);
else text(((time+29)/30), 300-15-10, 60);
score=(time+29)/30*10;
} else if (state==2) {
image(end, width/2, height/2, width, height);
image(ending, 300, 400+20, 870/4, 460/4);
image(again, 300, 650, 200, 100);
text("your score is "+score, 150-40, 220);
if (data[0]==64 || data[1]==64) {
catvx=0;
catvy=0;
}
catvx=(data[0]-64)/5.0;
catvy=(data[1]-64)/5.0;
catx+=catvx;
caty+=catvy;
if (!(catR) && !(catL)) {
image(cat87, catx, caty, 133, 100);
}
if (catvx<0) {
image(cat887, catx, caty, 133, 100);
catL=true;
catR=false;
} else if (catvx>0) {
image(cat87, catx, caty, 133, 100);
catR=true;
catL=false;
} else {
if (catL) image(cat887, catx, caty, 133, 100);
else if (catR) image(cat87, catx, caty, 133, 100);
}
if (catx<60) catx=60;
if (catx>538) catx=538;
if (caty<30) caty=30;
if (caty>763) caty=763;
if (catx>200-50 && catx<400+50 && caty>550-50 && caty<650+50 && data[2]==1) {
time=0;
score=0;
catx=300;
caty=400;
for (int i=0; i<5; i++) {
rockx[i]=random(50, 550);
rocky[i]=random(50, 750);
rockvx[i]=5*random(-1, 1);
rockvy[i]=5*random(-1, 1);
}
state=1;
}
}
}
byte [] data = new byte[3];
void getData() {
if (myPort.available()>0) {
myPort.readBytes(data);
}
}
import ddf.minim.*;
Minim minim;
AudioPlayer player;
Serial myPort;
int state=0;
PImage bg, playing, cat87, cat887, ending, end, again;
PImage []rock=new PImage[5];
float catx=300, caty=400, catvx=0, catvy=0;
float []rockx=new float[5];
float []rocky=new float[5];
float []rockvx=new float[5];
float []rockvy=new float[5];
boolean catL=false, catR=false;
int time, score;
void setup() {
size(600, 800);
myPort = new Serial(this, "COM3", 9600);
minim =new Minim(this);
player=minim.loadFile("Bongo Cat - Nyan Cat.mp3");
bg=loadImage("title.png");
playing=loadImage("universe.png");
cat87=loadImage("nyan-cat.png");
cat887=loadImage("nyan-cat87.png");
ending=loadImage("game over.png");
end=loadImage("god_logo_800.jpg");
again=loadImage("play-again.png");
imageMode(CENTER);
for (int i=0; i<5; i++) {
rock[i]=loadImage("ball.png");
rockx[i]=random(50, 550);
rocky[i]=random(50, 750);
rockvx[i]=5*random(-1, 1);
rockvy[i]=5*random(-1, 1);
}
player.loop();
}
void draw() {
frameRate=30;
getData();
if (state==0) {
image(bg, width/2, height/2, width, height);
if (data[2]==1)
state=1;
} else if (state==1) {
image(playing, width/2, height/2, width, height);
if (data[0]==64 || data[1]==64) {
catvx=0;
catvy=0;
}
catvx=(data[0]-64)/5.0;
catvy=(data[1]-64)/5.0;
catx+=catvx;
caty+=catvy;
if (!(catR) && !(catL)) {
image(cat87, catx, caty, 133, 100);
}
if (catvx<0) {
image(cat887, catx, caty, 133, 100);
catL=true;
catR=false;
} else if (catvx>0) {
image(cat87, catx, caty, 133, 100);
catR=true;
catL=false;
} else {
if (catL) image(cat887, catx, caty, 133, 100);
else if (catR) image(cat87, catx, caty, 133, 100);
}
if (catx<60) catx=60;
if (catx>538) catx=538;
if (caty<30) caty=30;
if (caty>763) caty=763;
for (int i=0; i<5; i++) {
image(rock[i], rockx[i], rocky[i], 75, 73);
rockx[i]+=rockvx[i];
rocky[i]+=rockvy[i];
if (frameCount%30==0) {
rockvx[i]=rockvx[i]*random(1.0, 1.1);
rockvy[i]=rockvy[i]*random(1.0, 1.1);
}
if (rockx[i]<=30 || rockx[i]>=566)
rockvx[i] = -rockvx[i];
if (rocky[i]<=30 || rocky[i]>=763)
rockvy[i] = -rockvy[i];
if ((time+29)/30>1 && dist(rockx[i], rocky[i], catx, caty)<(75/2+45/2)) {
state=2;
catx=300;
caty=400;
}
}
time++;
fill(255);
textSize(50);
if ((time+29)/30<10) text(((time+29)/30), 300-10, 60);
else text(((time+29)/30), 300-15-10, 60);
score=(time+29)/30*10;
} else if (state==2) {
image(end, width/2, height/2, width, height);
image(ending, 300, 400+20, 870/4, 460/4);
image(again, 300, 650, 200, 100);
text("your score is "+score, 150-40, 220);
if (data[0]==64 || data[1]==64) {
catvx=0;
catvy=0;
}
catvx=(data[0]-64)/5.0;
catvy=(data[1]-64)/5.0;
catx+=catvx;
caty+=catvy;
if (!(catR) && !(catL)) {
image(cat87, catx, caty, 133, 100);
}
if (catvx<0) {
image(cat887, catx, caty, 133, 100);
catL=true;
catR=false;
} else if (catvx>0) {
image(cat87, catx, caty, 133, 100);
catR=true;
catL=false;
} else {
if (catL) image(cat887, catx, caty, 133, 100);
else if (catR) image(cat87, catx, caty, 133, 100);
}
if (catx<60) catx=60;
if (catx>538) catx=538;
if (caty<30) caty=30;
if (caty>763) caty=763;
if (catx>200-50 && catx<400+50 && caty>550-50 && caty<650+50 && data[2]==1) {
time=0;
score=0;
catx=300;
caty=400;
for (int i=0; i<5; i++) {
rockx[i]=random(50, 550);
rocky[i]=random(50, 750);
rockvx[i]=5*random(-1, 1);
rockvy[i]=5*random(-1, 1);
}
state=1;
}
}
}
byte [] data = new byte[3];
void getData() {
if (myPort.available()>0) {
myPort.readBytes(data);
}
}
AHSU interaction week 17作品
2019年1月3日 星期四
week17 互動技術筆記@
期末作品展示
影片連結:https://youtu.be/h7PBZZPgU4w
操作:玩家利用搖桿操控畫面中的貓咪,來躲避隨著時間加快的五顆隕石。一旦被隕石碰到即結束遊戲,結束後會顯示得分(存活秒數*10)以及再玩一次的畫面。
影片連結:https://youtu.be/h7PBZZPgU4w
操作:玩家利用搖桿操控畫面中的貓咪,來躲避隨著時間加快的五顆隕石。一旦被隕石碰到即結束遊戲,結束後會顯示得分(存活秒數*10)以及再玩一次的畫面。
2018年12月6日 星期四
AHSU interaction week13
2018年11月1日 星期四
week08 互動技術筆記@
Ice Hocket
影片連結:https://www.youtube.com/watch?v=0G64yvSQOGA&feature=youtu.be
操作:這個遊戲有兩個玩家,藍色(左邊)用WASD移動、紅色(右邊)用8456移動。玩家需操控推盤,將中間的黑盤推入畫面左右兩邊黑色部分,得分後可獲得發球權。遊戲時間為20秒,先得到三分或是時間到最高分者為贏家。
影片連結:https://www.youtube.com/watch?v=0G64yvSQOGA&feature=youtu.be
操作:這個遊戲有兩個玩家,藍色(左邊)用WASD移動、紅色(右邊)用8456移動。玩家需操控推盤,將中間的黑盤推入畫面左右兩邊黑色部分,得分後可獲得發球權。遊戲時間為20秒,先得到三分或是時間到最高分者為贏家。
2018年10月18日 星期四
2018年10月11日 星期四
AHSU interaction week 5
掉雞蛋範例


加上分數後

程式碼:
float[] eggx=new float[100];
float[] eggy=new float[100]; //雞蛋有100顆
boolean[] eggd=new boolean[100];
void setup(){
size(800,600);
for(int i=0;i<100;i++){
eggx[i]=random(100,700);//隨機x座標
eggy[i]=-random(2000);//隨機y座標
eggd[i]=false;
}
}
int score=0;
void draw(){
fill(255);
background(255);
rect(mouseX-50,mouseY-25,100,50);//雞蛋籃
for(int i=0;i<100;i++){
if(eggd[i])continue;
fill(255);
ellipse(eggx[i],eggy[i],80,100);//雞蛋
eggy[i]+=5;//+=5讓雞蛋下落
if(eggy[i]>700) eggy[i]=-2000+600;//雞蛋到視窗底下就在上方重生
if(dist(mouseX-50,mouseY-25,eggx[i],eggy[i])<50){
eggd[i]=true; score+=100;//接到蛋就消失 分數要+=100text的分數才會加
}
}
fill(255,0,0);
textSize(80);
text("Score:"+score,100,100);
}



加上分數後

程式碼:
float[] eggx=new float[100];
float[] eggy=new float[100]; //雞蛋有100顆
boolean[] eggd=new boolean[100];
void setup(){
size(800,600);
for(int i=0;i<100;i++){
eggx[i]=random(100,700);//隨機x座標
eggy[i]=-random(2000);//隨機y座標
eggd[i]=false;
}
}
int score=0;
void draw(){
fill(255);
background(255);
rect(mouseX-50,mouseY-25,100,50);//雞蛋籃
for(int i=0;i<100;i++){
if(eggd[i])continue;
fill(255);
ellipse(eggx[i],eggy[i],80,100);//雞蛋
eggy[i]+=5;//+=5讓雞蛋下落
if(eggy[i]>700) eggy[i]=-2000+600;//雞蛋到視窗底下就在上方重生
if(dist(mouseX-50,mouseY-25,eggx[i],eggy[i])<50){
eggd[i]=true; score+=100;//接到蛋就消失 分數要+=100text的分數才會加
}
}
fill(255,0,0);
textSize(80);
text("Score:"+score,100,100);
}

2018年10月4日 星期四
AHSU interaction week4
2018年9月27日 星期四
AHSU interaction week 03
2018年9月20日 星期四
AHSU interaction week02
2018年9月13日 星期四
AHSU interaction week1
訂閱:
文章 (Atom)






























