互動技術期末作品
作品名稱:LED Cube 8x8x8
作品介紹:
此作品欲達成裸視3D的效果,並使觀眾能從任何角度欣賞動畫,創作過程使用512顆燈泡並依照8x8x8的架構進行焊接,底板晶片使用Arduino UNO來燒錄動畫程式,未來展望欲將體感裝置和此作品藉由PC溝通產生出新的體感操作模式,讓觀眾和展演者能不拘泥於任何方位demo都無觀賞死角,謝謝大家。
2014年1月12日 星期日
Week19_Final_彈珠台
##Demo影片
##製作到完成照片
一開始的拆箱、定尺寸、畫位置


測試電路、設計開關(感應區)

電路和版面組合

展開的樣子
##製作到完成照片
一開始的拆箱、定尺寸、畫位置


測試電路、設計開關(感應區)

電路和版面組合

展開的樣子
玩的照片~
全亮燈的樣子
## Arduino程式碼
import processing.serial.*;
PFont font;
Serial serial;
int pon=0;
void setup()
{
size(600, 400);
background(0,0,0);
serial=new Serial(this, "COM3", 9600);
}
void draw()
{
background(0,0,0);
if (serial.available()>0)
{
int a=serial.read();
print(a+" ");
if(a==97) { pon+=0; }//a
else if(a==98) { pon+=20; }//b
else if(a==99) { pon+=0; }//c
else if(a==100) { pon+=25; }//d
else if(a==101) { pon+=0; }//e
else if(a==102) { pon+=50; }//f
else if(a==103) { pon+=0; }//g
else if(a==104) { pon+=20; }//h
//else if(a==105) { pon+=0; }//i
//else if(a==106) { pon+=10; }//j
textFont(createFont("calibri",40));
textSize(100);
text("Score:"+pon,50,210);
}
}
## Processing 程式碼
import processing.serial.*;
PFont font;
Serial serial;
int pon=0;
void setup()
{
size(600, 400);
background(0,0,0);
serial=new Serial(this, "COM3", 9600);
}
void draw()
{
background(0,0,0);
if (serial.available()>0)
{
int a=serial.read();
print(a+" ");
if(a==97) { pon+=0; }//a
else if(a==98) { pon+=20; }//b
else if(a==99) { pon+=0; }//c
else if(a==100) { pon+=25; }//d
else if(a==101) { pon+=0; }//e
else if(a==102) { pon+=50; }//f
else if(a==103) { pon+=0; }//g
else if(a==104) { pon+=20; }//h
//else if(a==105) { pon+=0; }//i
//else if(a==106) { pon+=10; }//j
textFont(createFont("calibri",40));
textSize(100);
text("Score:"+pon,50,210);
}
}
week19 期末作業:瘋狂吉他手
左邊的4個按鈕就像吉他左手按玹 ,右手類似播玹,只是我改成按鍵而已。當左手按住某個按鈕時,右手也要跟著按,該鈕顯示的打擊方塊才會亮起,這時只要有韻律方塊也在該位置附近,這樣才能形成有效打擊,Score會加分數,也會有combo顯現。
遊戲執行時,視窗的左邊會有背景影片出現和分數,右邊則是
遊戲進行的畫面,4條通道和1條血條,有有效打擊會有combo出現還會加血,沒有的話漏掉方塊的話則會扣血。血量歸0,遊戲則結束並且有失敗畫面。不然就是等到背景影片播完,即勝利,會有勝利圖片然後計算總分。
心得:
一開始接線的時候,按鈕都沒接電阻,就一直短路,也不知道為啥。接了電阻就好了,不知道是不是因為沒電阻電壓太大,arduino的板子,就直接掛給你看。
然後起初當然是卡在processing如何和arduino做配合~
之後配合processing裡面的函示庫,很多問題都迎刃而解,
不過兩者的配合有一定程度上的lag,這時候就一直在嘗試改arduino的delay()值。
之後又卡在,如何讓方塊跟著音樂有節奏~~
還有方塊與方塊間,避免他們連在一起。
血條用兩張圖片做配合~~沒有意外。
只是悲劇的是processing的版本好像跟學校的不合
影片展示時就顯得很亂~~Q.Q
以下是所使用程式
arduino;
int switchStateRed = 0;
int switchStateBlue = 0;
void setup(){
pinMode(2 , INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
}
int a=0,b=0;
void loop(){
switchStateRed = digitalRead(2);
switchStateBlue = digitalRead(3);
if(switchStateRed == LOW) a=0;
if(switchStateRed == HIGH && a==0){Serial.write('a');a=1;}
if(switchStateRed == LOW) b=0;
if(switchStateRed == HIGH && b==0){Serial.write('b');b=1;}
}
processing
import ddf.minim.*;
import processing.video.*; //導入 video 程式庫
import processing.serial.*;
Minim minim;
AudioPlayer in;
Serial serial;
Movie movie; //宣告 Movie 物件
int hand,handX;
PImage rback,lb,blood,bblood,rbb,blue,red,green,yellow,push,bg,die,win;
int score,blo,plo;
int a,i,j,dieo,winn,sum,com;
float []msX=new float[200],msY=new float[200];//x,y
float []msVX=new float[200],msVY=new float[200];
float []bl=new float[200];
int []thing = new int[200];
void setup() {
com=0;
dieo=1;
winn=0;
size(1300, 600);
score=0;
sum=0;
a=0;
j=0;
blo=0;
plo=565;
movie = new Movie(this, "aaa.mov");
minim=new Minim(this);
rback=loadImage("rback.jpg");
lb=loadImage("lb.jpg");
blood=loadImage("blood.jpg");
rbb=loadImage("rbb.jpg");
bblood=loadImage("bblood.jpg");
red=loadImage("red.jpg");
blue=loadImage("blue.jpg");
yellow=loadImage("yellow.jpg");
push=loadImage("yellow.jpg");
green=loadImage("green.jpg");
bg=loadImage("bg.jpg");
die=loadImage("die.jpg");
win=loadImage("winn.jpg");
// 開啟 Serial port,通訊速率為 9600 bps
// 注意! 如果你 Arduino 不是接在 COM4,請做適當調整
serial = new Serial(this, "COM4", 9600);
movie.play();
for (int i=0;i<200;i++) {
newms(i);
thing[i]=0;
bl[i]=0;
}
}
void movieEvent(Movie movie){
//讓 quicktime movie 通知 Processing 有一個畫格已經準備好可以被播放
movie.read();
/* 由 Movie 類別中呼叫 read() 函數,以便讀入當前畫格資料至 Movie 類別中,準備呈像 */
}
void draw() {
if(dieo==0)
{
movie.stop();
last(0);
stop();
}
else if(sum>1500)
{
movie.stop();
last(1);
stop();
}
else
{
image(lb,0, 0,900,522);
image(movie, 40, 30);
image(bblood, 0,522,900, 100);
image(rbb, 900, 0,405, 605);
image(rback, 920, 15,360, 570);
image(blood,1200, 15,72,565 );
image(bg,1200, 15,72, blo );
textSize(32);
text("Score:", 0, 572);
text(score,100, 572);
fill(255, 255, 255);
if(com!=0)
{
textSize(60);
text("COMBO", 928, 100);
text(com,1028, 150);
fill(0, 255, 0);
}
handX = 0;
hand = 0;
/*
image(blue, 928, 15,60, 20);
image(yellow, 996, 15,60, 20);
image(green, 1064,15,60, 20);
image(red,1132, 15,60,20 );*/
for ( i=0;i<a;i++) {
if (msX[i]==928.0)
image(blue, msX[i], msY[i], 60, 20);
else if (msX[i]==996.0)
image(yellow, msX[i], msY[i], 60, 20);
else if (msX[i]==1064.0)
image(green, msX[i], msY[i], 60, 20);
else if (msX[i]==1132.0)
image(red, msX[i], msY[i], 60, 20);
if(msY[i]<610)
{
msY[i]+=10;
}
}
if ( serial.available() > 0) {
// 讀取從 Serial Port 傳進來的 Sensor 讀值
hand = serial.read();
if(hand=='A'){
handX = 928;
image(push, handX, 450.0, 60, 20);
for ( i=0;i<a;i++) //有效打擊範圍+combo+分數+血量
{
if(msY[i]<471 && msY[i]>439)
{
if(msX[i]==928)
{
if ((461.0 > msY[i]) && (447.0 < msY[i]));
{
score=score+100;
msY[i]=610;
com=com+1;
if(plo<=535)
plo=plo+30;
}
}
}
}
}
else if(hand=='B'){
handX=996;
image(push, handX, 450, 60, 20);
for ( i=0;i<a;i++)
{
if(msY[i]<471 && msY[i]>439)
{
if(msX[i]==996)
{
if ((461.0 > msY[i]) && (447.0 < msY[i]));
{
score=score+100;
msY[i]=610;
com=com+1;
if(plo<=535)
plo=plo+30;
}
}
}
}
}
else if(hand=='C'){
handX = 1064;
image(push, handX, 450.0, 60, 20);
for ( i=0;i<a;i++)
{
if(msY[i]<471 && msY[i]>439)
{
if(msX[i]==1064)
{
if ((461.0 > msY[i]) && (447.0 < msY[i]));
{
score=score+100;
msY[i]=610;
com=com+1;
if(plo<=535)
plo=plo+30;
}
}
}
}
}
else if(hand=='D'){
handX=1132;
image(push, handX, 450.0, 60, 20);
for ( i=0;i<a;i++)
{
if(msY[i]<471 && msY[i]>439)
{
if(msX[i]==1132)
{
if ((461.0 > msY[i]) && (447.0 < msY[i]));
{
score=score+100;
msY[i]=610;
com=com+1;
if(plo<=535)
plo=plo+30;
}
}
}
}
}
/*
if(sensorValue0=='Z'){
sensorValue0=1000;
}*/
}
if(com!=0) //combo累計
{
textSize(60);
text("COMBO", 928, 100);
text(com,1028, 150);
fill(0, 255, 0);
}
for(int u=0;u<a;u++) //損寫機制+combo歸0+失敗檢測
{
if(msY[u] >600 && bl[u]==0 )
{
if(blo<570)
{
blo=blo+3;
image(bg,1200, 15,72, blo );
bl[u]=1;
com=0;
}
else
dieo=0;
}
}
if(i<200 && j%10==0)
++a;
++j;
sum++;
println(com);
}
}
void newms(int i) {
//float angle=random(2*PI);
if(i%3==0 && i<196) //方塊速度
{
msVY[i]=8;
msVY[i+1]=8;
msVY[i+2]=8;
}
int dir=int(random(4)); //隨機在4個通道產生方塊
if (dir==0) {
msX[i]=928.0;
msY[i]=0.0;
}
else if (dir==1) {
msX[i]=996.0;
msY[i]=0.0;
}
else if (dir==2) {
msY[i]=0.0;
msX[i]=1064.0;
}
else if (dir==3) {
msY[i]=0.0;
msX[i]=1132.0;
}
}
void last(int i){ //失敗畫面和勝利畫面
if(i==0)
{
image(die, 0,0,1200, 600);
in=minim.loadFile("hdie.mp3");
in.play();
textSize(50);
text("Score:", 100, 422);
text(score,300, 422);
fill(255, 255, 255);
}
else if(i==1)
{
image(win, 0,0,1200, 600);
in=minim.loadFile("hwin.mp3");
in.play();
textSize(50);
text("Score:", 800, 272);
text(score,980, 272);
fill(255, 0, 0);
}
}
第10組-互動技術期末作品-節奏音感-99163116,99163186
遊戲名稱:節奏音感
遊戲玩法:在放音樂的過程中,會有音階隨機掉下來,操作的方法就是將Processing與Arduino的程式碼互相連接,再利用Arduino硬體組成的5個按鍵來操作,當音階到達指定的位置時按下,程式碼就會依照所設定的預設值範圍來判斷有無按到,在按到的過程中會出現閃光的特效,每按成功一次就加分數100分,直到音樂放完為止,遊戲結束後,在最後的畫面會出現總分。
Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
Arduino硬體程式碼:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;
int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState6 = 0;
void setup() {
pinMode(buttonPin5, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin6, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState5 = digitalRead(buttonPin5);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState6 = digitalRead(buttonPin6);
if (buttonState5 == HIGH) {
Serial.write('1');
}
if (buttonState2== HIGH) {
Serial.print('2');
}
if (buttonState3 == HIGH) {
Serial.print('3');
}
if (buttonState4 == HIGH) {
Serial.print('4');
}
if (buttonState6 == HIGH) {
Serial.print('5');
}
else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
Serial.write('0');
}
delay(100);
}
Arduino硬體電路連接:
圖片結果截圖:
影片DEMO:
遊戲執行結果:
電腦側錄結果:
遊戲玩法:在放音樂的過程中,會有音階隨機掉下來,操作的方法就是將Processing與Arduino的程式碼互相連接,再利用Arduino硬體組成的5個按鍵來操作,當音階到達指定的位置時按下,程式碼就會依照所設定的預設值範圍來判斷有無按到,在按到的過程中會出現閃光的特效,每按成功一次就加分數100分,直到音樂放完為止,遊戲結束後,在最後的畫面會出現總分。
Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
Arduino硬體程式碼:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;
int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState6 = 0;
void setup() {
pinMode(buttonPin5, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin6, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState5 = digitalRead(buttonPin5);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState6 = digitalRead(buttonPin6);
if (buttonState5 == HIGH) {
Serial.write('1');
}
if (buttonState2== HIGH) {
Serial.print('2');
}
if (buttonState3 == HIGH) {
Serial.print('3');
}
if (buttonState4 == HIGH) {
Serial.print('4');
}
if (buttonState6 == HIGH) {
Serial.print('5');
}
else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
Serial.write('0');
}
delay(100);
}
Arduino硬體電路連接:
圖片結果截圖:
影片DEMO:
遊戲執行結果:
電腦側錄結果:
Week19 張智棠,陳奕汎
互動技術概論期末
Demo影片 :
Code:
import ddf.minim.*;
import processing.serial.*;
AudioPlayer player,SE;
Minim minim;
Serial myPort;
int val;
int angle;
PImage img1,img2,img3,bg,win,copyright,copyright2;;
PImage imgMan,leftwalk,rightwalk;
PImage imgface,imgface2,imgface3,symbol;
int Alpha=255,Alpha2=255;
float z2=int(random(150)+50);
float z3=int(random(150)+80);
float z4=int(random(150)+100);
float ac=0.03;
int BuildingX,BuildingX2,BuildingX3;
int stage=4;
int N=6;
int []thingType = new int [6] ;
float []thingX = new float [6];
int BGX=0;
float Reac,Rez2,Rez3,Rez4;
boolean sw=false;
boolean left=false,right=false,start=true;
int a=3;
int Time=800;
float GameTime=0;
int Score=0;
int move=0;
int blood=100;
//stage1 run
//stage2 gameover
//stage3 win
//stage4 menu
void setup(){
size(600,600);
String [] all = Serial.list();
String portName = all[all.length-1];
myPort = new Serial(this, portName, 9600);
img1=loadImage("monster1.png");
img2=loadImage("monster2.png");
img3=loadImage("monster3.png");
imgface=loadImage("image1.png");
imgface2=loadImage("image.png");
imgface3=loadImage("image3.png");
symbol = loadImage("symbol.png");
imgMan=loadImage("start.png");
leftwalk=loadImage("leftwalk.png");
rightwalk=loadImage("rightwalk.png");
bg=loadImage("bg.jpg");
win=loadImage("");
copyright = loadImage("copyright.bmp");
copyright2 = loadImage("copyright2.bmp");
imageMode(CENTER);
for ( int i = 0 ; i < N ; i++)
{
newThing(i);
}
minim = new Minim(this);
player = minim.loadFile("ST1.mp3");
SE = minim.loadFile("ken.mp3");
}
float newH;
float newH2;
float newH3;
float newH4=50;
int b;
void draw(){
if ( myPort.available() > 0)
{
val = myPort.read(); //Arduino Control
//angle = myPort.read();
println("val "+val);
println("ac "+ac);
// println("angle "+angle);
}
if (stage==3)
{
if (val==180) stage=4;
}
if (stage==4)
{
if (val==180) stage=1;
}
if (stage==1)
{
if (val==181)
{
if (sw==false)
{
z2-=ac;
ac+=0.001;
if (ac>0.88) ac=0.88;
}
}
/* if (val==179)
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (sw ==true)
{
if (val==181)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}*/
else z2-=ac;
if (val>79 && val<180)
{
if (sw==false)
{
if (val%79<10){thingX[0]-=val%79; thingX[1]-=val%79; thingX[2]-=val%79;thingX[3]-=val%79;thingX[4]-=val%79; thingX[5]-=val%79;}
if (val%79>10){thingX[0]-=10; thingX[1]-=10; thingX[2]-=10;thingX[3]-=10; thingX[4]-=10; thingX[5]-=10;}
right=true;
left=false;
start=false;
}
}
if (val>0 && val<79)
{
if (sw==false)
{
if (val%79<10) {thingX[0]+=val%79; thingX[1]+=val%79; thingX[2]+=val%79;thingX[3]+=val%79; thingX[4]+=val%79; thingX[5]+=val%79;}
if (val%79>10){ thingX[0]+=10; thingX[1]+=10; thingX[2]+=10;thingX[3]+=10; thingX[4]+=10; thingX[5]+=10;}
left=true;
right=false;
start=false;
}
}
}
if (stage==1&&sw==false)//stage01 runnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if (a==1)
{
player.close();
player=minim.loadFile("ST1.mp3");
player.setGain(-20);
player.play();
player();
ac=0.03;
z2=int(random(150)+50);
z3=int(random(150)+80);
z4=int(random(150)+100);
blood=100;
Time=1000;
GameTime=0;
Score=0;
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
}
a=2;
GameTime+=0.5;
background(255);
image(bg,300,300,600,600);
fill(255,0,0);
rect(100,500,blood+GameTime*0.05-Score*20,50);
fill(255);
textSize(15);
text("HP "+(int)(blood+GameTime*0.05-Score*20),100,580);
text("GameTime"+GameTime,400,580);
fill(255,255,0);
textSize(15);
text("Press S To PAUSE",100,100);
text("Press R To Continue",100,150);
text("Press A To Access",400,100);
text("Press X or x To Move",400,150);
if ((blood+GameTime*0.05-Score*20)<0) stage=2;
//if (GameTime>3000) stage=3;
for ( int i = 0 ; i < N ; i++)
{
if (thingType[i]%6==1)
{
draw1(i);
if (z2<5&&(newH4-newH)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==2)
{
draw2(i);
if (z3<5&&(newH4-newH2)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==3)
{
draw3(i);
if (z4<5&&(newH4-newH3)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
drawMan();
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
if(z2<5||thingX[i]<0 ||thingX[i]>600)
{
z2=int(random(150)+50);
newH= 1360*atan(10/z2)/PI;
newThing(i);
}
if(z3<5||thingX[i]<0 ||thingX[i]>600)
{
z3=int(random(150)+80);
newH2= 1360*atan(10/z3)/PI;
newThing(i);
}
else if(z4<5||thingX[i]<0||thingX[i]>600)
{
z4=int(random(150)+100);
newH3= 1360*atan(10/z4)/PI;
newThing(i);
}
}
z2-=ac;
z3-=ac;
z4-=ac;
if (GameTime>1000){ stage=3;a=4;}
}
if (stage==2)//stage02 game overrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
{
if(a==2)
{
player.close();
player=minim.loadFile("ending.mp3");
player.setGain(-20);
player();
}
a=3;
background(255,0,0);
fill(0);
textSize(32);
text("Game Over", 200, 300);
text("ReStart Time :"+Time,200,400);
Time--;
line(230,150,215,180);
line(215,180,230,210);
line(230,210,400,210);
line(400,210,400,150);
line(400,150,230,150);
if (Time<800 && Time>600)
{
image(imgface,200,200,50,50);
textSize(16);
text("outch!",250,180);
}
if (Time<600 && Time>300)
{
image(imgface2,200,200,50,50);
textSize(16);
text("It's Really Hurt..",250,180);
}
if (Time<300)
{
image(imgface3,200,200,50,50);
textSize(16);
text("I Can Do Again!",250,180);
}
if (Time<0) stage=4;
}
if (stage==3) //stage03 winnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if(a==4)
{
player.close();
player=minim.loadFile("win.mp3");
player.setGain(-10);
player();
}
background(0);
fill(255);
textSize(32);
text("You Make It! ", 200, 100);
text("Thanks For Your Playing!",100,200);
text(" This Game Design by↓",100,300);
text("&",285,360);
image(copyright,250,350,39,33);
image(copyright2,350,350,39,33);
text("Press W To ReStart Game",110,500);
a=3;
}
if (stage==4) //stage04 menuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
{
background(0);
if(a==3)
{
player.close();
player=minim.loadFile("start.mp3");
player.setGain(-10);
player();
}
textSize(16);
fill(255,0,0,Alpha);
text("run for life",250,80);
textSize(64);
stroke(50);
text("Monster Run",100,120);
if (Alpha>0) Alpha--;
if (Alpha==0) Alpha=255;
fill(255);
textSize(16);
text("Do Your Best To Avoid Monster",180,200);
text("Press Q To Start Game",200,300);
textSize(8);
text("TW",95,545);
text("Monster Run @2013 From Software",50,550);
image(symbol,300,450,200,200);
text("Tang Fan Gaming House @2013",430,550);
a=1;
}
}
void keyPressed()
{
if (stage==3)
{
if (key=='w' ||key=='W') stage=4;
}
if (stage==4)
{
if (key=='q' ||key=='Q') stage=1;
}
if (stage==1)
{
if (key=='a'||key=='A')
{
if (sw==false)
{
z2-=ac;
ac+=0.01;
if (ac>0.88) ac=0.88;
}
}
if (key=='s' ||key=='S')
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (key=='r' || key=='R')
{
if (sw ==true)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}
else z2-=ac;
if (key=='x')
{
if (sw==false)
{
thingX[0]-=20; thingX[1]-=20; thingX[2]-=20;
right=true;
left=false;
start=false;
}
}
if (key=='X')
{
if (sw==false)
{
thingX[0]+=20; thingX[1]+=20; thingX[2]+=20;
left=true;
right=false;
start=false;
}
}
}
}
void newThing(int i )
{
thingType[i] = int (random(3)+1) ;
thingX[i] = int(random(600)+1) ;
}
void draw1(int i)
{
if(newH>0)
{
tint(255, 255-z2);
image(img1,thingX[i],300, newH, newH);
}
}
void draw2(int i)
{
if(newH2>0)
{
tint(255, 255-z3);
image(img2,thingX[i],300, newH2, newH2);
}
}
void draw3(int i)
{
if(newH3>0)
{
tint(255, 255-z4);
image(img3,thingX[i],300, newH3, newH3);
}
}
void stop()
{
player.close();
minim.stop();
super.stop();
}
void drawMan()
{
if (start==true)
{
tint(255, 255);
image(imgMan, 300,450,newH4,newH4);
}
if (right==true)
{
tint(255, 255);
image(rightwalk, 300,450,newH4,newH4);
}
if (left==true)
{
tint(255, 255);
image(leftwalk, 300,450,newH4,newH4);
}
}
void player()
{
player.loop();
}
Demo影片 :
Code:
import ddf.minim.*;
import processing.serial.*;
AudioPlayer player,SE;
Minim minim;
Serial myPort;
int val;
int angle;
PImage img1,img2,img3,bg,win,copyright,copyright2;;
PImage imgMan,leftwalk,rightwalk;
PImage imgface,imgface2,imgface3,symbol;
int Alpha=255,Alpha2=255;
float z2=int(random(150)+50);
float z3=int(random(150)+80);
float z4=int(random(150)+100);
float ac=0.03;
int BuildingX,BuildingX2,BuildingX3;
int stage=4;
int N=6;
int []thingType = new int [6] ;
float []thingX = new float [6];
int BGX=0;
float Reac,Rez2,Rez3,Rez4;
boolean sw=false;
boolean left=false,right=false,start=true;
int a=3;
int Time=800;
float GameTime=0;
int Score=0;
int move=0;
int blood=100;
//stage1 run
//stage2 gameover
//stage3 win
//stage4 menu
void setup(){
size(600,600);
String [] all = Serial.list();
String portName = all[all.length-1];
myPort = new Serial(this, portName, 9600);
img1=loadImage("monster1.png");
img2=loadImage("monster2.png");
img3=loadImage("monster3.png");
imgface=loadImage("image1.png");
imgface2=loadImage("image.png");
imgface3=loadImage("image3.png");
symbol = loadImage("symbol.png");
imgMan=loadImage("start.png");
leftwalk=loadImage("leftwalk.png");
rightwalk=loadImage("rightwalk.png");
bg=loadImage("bg.jpg");
win=loadImage("");
copyright = loadImage("copyright.bmp");
copyright2 = loadImage("copyright2.bmp");
imageMode(CENTER);
for ( int i = 0 ; i < N ; i++)
{
newThing(i);
}
minim = new Minim(this);
player = minim.loadFile("ST1.mp3");
SE = minim.loadFile("ken.mp3");
}
float newH;
float newH2;
float newH3;
float newH4=50;
int b;
void draw(){
if ( myPort.available() > 0)
{
val = myPort.read(); //Arduino Control
//angle = myPort.read();
println("val "+val);
println("ac "+ac);
// println("angle "+angle);
}
if (stage==3)
{
if (val==180) stage=4;
}
if (stage==4)
{
if (val==180) stage=1;
}
if (stage==1)
{
if (val==181)
{
if (sw==false)
{
z2-=ac;
ac+=0.001;
if (ac>0.88) ac=0.88;
}
}
/* if (val==179)
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (sw ==true)
{
if (val==181)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}*/
else z2-=ac;
if (val>79 && val<180)
{
if (sw==false)
{
if (val%79<10){thingX[0]-=val%79; thingX[1]-=val%79; thingX[2]-=val%79;thingX[3]-=val%79;thingX[4]-=val%79; thingX[5]-=val%79;}
if (val%79>10){thingX[0]-=10; thingX[1]-=10; thingX[2]-=10;thingX[3]-=10; thingX[4]-=10; thingX[5]-=10;}
right=true;
left=false;
start=false;
}
}
if (val>0 && val<79)
{
if (sw==false)
{
if (val%79<10) {thingX[0]+=val%79; thingX[1]+=val%79; thingX[2]+=val%79;thingX[3]+=val%79; thingX[4]+=val%79; thingX[5]+=val%79;}
if (val%79>10){ thingX[0]+=10; thingX[1]+=10; thingX[2]+=10;thingX[3]+=10; thingX[4]+=10; thingX[5]+=10;}
left=true;
right=false;
start=false;
}
}
}
if (stage==1&&sw==false)//stage01 runnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if (a==1)
{
player.close();
player=minim.loadFile("ST1.mp3");
player.setGain(-20);
player.play();
player();
ac=0.03;
z2=int(random(150)+50);
z3=int(random(150)+80);
z4=int(random(150)+100);
blood=100;
Time=1000;
GameTime=0;
Score=0;
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
}
a=2;
GameTime+=0.5;
background(255);
image(bg,300,300,600,600);
fill(255,0,0);
rect(100,500,blood+GameTime*0.05-Score*20,50);
fill(255);
textSize(15);
text("HP "+(int)(blood+GameTime*0.05-Score*20),100,580);
text("GameTime"+GameTime,400,580);
fill(255,255,0);
textSize(15);
text("Press S To PAUSE",100,100);
text("Press R To Continue",100,150);
text("Press A To Access",400,100);
text("Press X or x To Move",400,150);
if ((blood+GameTime*0.05-Score*20)<0) stage=2;
//if (GameTime>3000) stage=3;
for ( int i = 0 ; i < N ; i++)
{
if (thingType[i]%6==1)
{
draw1(i);
if (z2<5&&(newH4-newH)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==2)
{
draw2(i);
if (z3<5&&(newH4-newH2)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
if (thingType[i]%6==3)
{
draw3(i);
if (z4<5&&(newH4-newH3)<30)
{
Score++;
SE.close();
SE = minim.loadFile("ken.mp3");
SE.setGain(-20);
SE.play();
}
}
drawMan();
newH= 1360*atan(10/z2)/PI;
newH2= 1360*atan(10/z3)/PI;
newH3= 1360*atan(10/z4)/PI;
if(z2<5||thingX[i]<0 ||thingX[i]>600)
{
z2=int(random(150)+50);
newH= 1360*atan(10/z2)/PI;
newThing(i);
}
if(z3<5||thingX[i]<0 ||thingX[i]>600)
{
z3=int(random(150)+80);
newH2= 1360*atan(10/z3)/PI;
newThing(i);
}
else if(z4<5||thingX[i]<0||thingX[i]>600)
{
z4=int(random(150)+100);
newH3= 1360*atan(10/z4)/PI;
newThing(i);
}
}
z2-=ac;
z3-=ac;
z4-=ac;
if (GameTime>1000){ stage=3;a=4;}
}
if (stage==2)//stage02 game overrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
{
if(a==2)
{
player.close();
player=minim.loadFile("ending.mp3");
player.setGain(-20);
player();
}
a=3;
background(255,0,0);
fill(0);
textSize(32);
text("Game Over", 200, 300);
text("ReStart Time :"+Time,200,400);
Time--;
line(230,150,215,180);
line(215,180,230,210);
line(230,210,400,210);
line(400,210,400,150);
line(400,150,230,150);
if (Time<800 && Time>600)
{
image(imgface,200,200,50,50);
textSize(16);
text("outch!",250,180);
}
if (Time<600 && Time>300)
{
image(imgface2,200,200,50,50);
textSize(16);
text("It's Really Hurt..",250,180);
}
if (Time<300)
{
image(imgface3,200,200,50,50);
textSize(16);
text("I Can Do Again!",250,180);
}
if (Time<0) stage=4;
}
if (stage==3) //stage03 winnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
{
if(a==4)
{
player.close();
player=minim.loadFile("win.mp3");
player.setGain(-10);
player();
}
background(0);
fill(255);
textSize(32);
text("You Make It! ", 200, 100);
text("Thanks For Your Playing!",100,200);
text(" This Game Design by↓",100,300);
text("&",285,360);
image(copyright,250,350,39,33);
image(copyright2,350,350,39,33);
text("Press W To ReStart Game",110,500);
a=3;
}
if (stage==4) //stage04 menuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
{
background(0);
if(a==3)
{
player.close();
player=minim.loadFile("start.mp3");
player.setGain(-10);
player();
}
textSize(16);
fill(255,0,0,Alpha);
text("run for life",250,80);
textSize(64);
stroke(50);
text("Monster Run",100,120);
if (Alpha>0) Alpha--;
if (Alpha==0) Alpha=255;
fill(255);
textSize(16);
text("Do Your Best To Avoid Monster",180,200);
text("Press Q To Start Game",200,300);
textSize(8);
text("TW",95,545);
text("Monster Run @2013 From Software",50,550);
image(symbol,300,450,200,200);
text("Tang Fan Gaming House @2013",430,550);
a=1;
}
}
void keyPressed()
{
if (stage==3)
{
if (key=='w' ||key=='W') stage=4;
}
if (stage==4)
{
if (key=='q' ||key=='Q') stage=1;
}
if (stage==1)
{
if (key=='a'||key=='A')
{
if (sw==false)
{
z2-=ac;
ac+=0.01;
if (ac>0.88) ac=0.88;
}
}
if (key=='s' ||key=='S')
{
if (sw==false)
{
textSize(32);
fill(255,128,0);
text("PAUSE",250,300);
Reac = ac;
Rez2 = z2;
Rez3 = z3;
Rez4 = z4;
z2+=ac;
ac=0;
sw = true;
}
}
if (key=='r' || key=='R')
{
if (sw ==true)
{
sw = false;
ac = Reac;
z2 = Rez2;
z3 = Rez3;
z4 = Rez4;
}
}
else z2-=ac;
if (key=='x')
{
if (sw==false)
{
thingX[0]-=20; thingX[1]-=20; thingX[2]-=20;
right=true;
left=false;
start=false;
}
}
if (key=='X')
{
if (sw==false)
{
thingX[0]+=20; thingX[1]+=20; thingX[2]+=20;
left=true;
right=false;
start=false;
}
}
}
}
void newThing(int i )
{
thingType[i] = int (random(3)+1) ;
thingX[i] = int(random(600)+1) ;
}
void draw1(int i)
{
if(newH>0)
{
tint(255, 255-z2);
image(img1,thingX[i],300, newH, newH);
}
}
void draw2(int i)
{
if(newH2>0)
{
tint(255, 255-z3);
image(img2,thingX[i],300, newH2, newH2);
}
}
void draw3(int i)
{
if(newH3>0)
{
tint(255, 255-z4);
image(img3,thingX[i],300, newH3, newH3);
}
}
void stop()
{
player.close();
minim.stop();
super.stop();
}
void drawMan()
{
if (start==true)
{
tint(255, 255);
image(imgMan, 300,450,newH4,newH4);
}
if (right==true)
{
tint(255, 255);
image(rightwalk, 300,450,newH4,newH4);
}
if (left==true)
{
tint(255, 255);
image(leftwalk, 300,450,newH4,newH4);
}
}
void player()
{
player.loop();
}
第十九週期末報告
期末報告
主題:鋼鋼好朋友
介紹:鋼鐵超人要利用手上的武器診拯救好朋友。
Arduino程式碼:
int switchStateRed = 0;
int switchStateBlue = 0;
int switchStateB = 0;
int switchStateW = 0;
int switchStateA = 0;
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100;
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(9600);
}
//int a=0,b=0;
void loop(){
sensorReading = analogRead(knockSensor);
switchStateRed = digitalRead(2);
switchStateBlue = digitalRead(3);
switchStateW = digitalRead(4);
switchStateA = digitalRead(5);
switchStateB = digitalRead(6);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
}
if(switchStateRed == HIGH) {Serial.write('1');}
if(switchStateBlue == HIGH) {Serial.write('2');}
if(switchStateW == HIGH) {Serial.write('3');}
if(switchStateA == HIGH) {Serial.write('4');}
if(switchStateB == HIGH) {Serial.write('5');}
delay(33);
}
Processing程式碼:
PImage img;
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img0;
PImage img10;
PImage img11;
PImage img12;
PImage img13;
PImage img14;
PImage img15;
PImage img16;
import processing.serial.*;//
Serial serial;//
import ddf.minim.*;
AudioPlayer player;
AudioPlayer player1;
AudioPlayer player2;
AudioPlayer player3;
AudioPlayer player4;
AudioPlayer player5;
Minim minim;//audio context
char c=' ';
float z;
int ss;
int btime;
int [] start = new int[50];
float [] bulletX=new float[50];
float [] bulletY=new float[50];
int [] mstart = new int[50];
float [] monsterX=new float[50];
float [] monsterY=new float[50];
int bo;
int top=0;
int i;
int a;
int b;
int m=0;
int s;
int ba;
int bc;
int hl;
int ml;
int f;
float bl;
int ud;
int bossY;
float []thingAA = new float[50];
float mt;
float md;
void setup() {
mt=150;
size(1000, 300);
btime=1800;
ss=0;
i=0;
a=0;
b=0;
s=0;
ba=0;
bo=15;
bc=100;
f=0;
z=15;
img = loadImage("01.png");
img1 = loadImage("pic4.bmp");
img2 = loadImage("dragon.png");
img3 = loadImage("a.png");
img4 = loadImage("b.png");
img5 = loadImage("c.png");
img6 = loadImage("d.png");
img7 = loadImage("e.png");
img8 = loadImage("f.png");
img9 = loadImage("g.png");
img0 = loadImage("h.png");
img10 = loadImage("02.png");
img11 = loadImage("blood.png");
img12 = loadImage("magic.png");
img13 = loadImage("1.png");
img14 = loadImage("blood2.png");
img15 = loadImage("win.jpg");
img16 = loadImage("lose.jpg");
m=0;
bl=600;
bossY=int(random(85, 185));
imageMode(CENTER);
hl=400;
ml=0;
minim = new Minim(this);
player = minim.loadFile("file.mp3", 2048);
player1 = minim.loadFile("01.wav", 2048);
player2 = minim.loadFile("02.wav", 2048);
player3 = minim.loadFile("03.wav", 2048);
player4 = minim.loadFile("winner.wav", 2048);
player5 = minim.loadFile("loser.WAV", 2048);
serial=new Serial(this, "COM3", 9600);
player.play();
}
void draw() {
if (serial.available()>0)
{
c=(char)serial.read();
if (c=='1')mt=mt+10;
if (c=='2')mt=mt-10;
if (c == '3') {
if (bc==100) {
if (bo!=0) {
bulletX[top]=120;
bulletY[top]=mt-25;
start[top]=1;
top++;
if (top>=50) top=0;
bo--;
player1 = minim.loadFile("01.wav");
player1.play();
}
}
z--;
}
if (c == '4')
{
ba=1;
z=0;
}
if (c=='5')
if (a==0&&ml==300) {
a=1;
}
}
if (ss==0) {
background(img1);
image(img, 70, mt, 63, 80);
image(img11, 0, 0, hl, 30);
image(img12, 0, 25, ml, 15);
if (a==0)i=0;
if (a==1&&i<=60) {
i=i+1;
}
if (a==1&&i==61)
i=31;
if (a==2&&i<=160)
i=i+1;
if (i>0&&i<=30) {
image(img3, 1600, mt, 3000, 100);
player3 = minim.loadFile("03.wav");
player3.play();
}
if (i>30&&i<=40) {
image(img4, 1600, mt, 3000, 100);
}
if (i>40&&i<=50) {
image(img5, 1600, mt, 3000, 100);
}
if (i>50&&i<=60) {
image(img6, 1600, mt, 3000, 100);
}
if (i>60&&i<=100) {
image(img7, 1600, mt, 3000, 100);
}
if (i>100&&i<=120) {
image(img0, 1600, mt, 3000, 100);
}
if (i>120&&i<=140) {
image(img8, 1600, mt, 3000, 100);
}
if (i>140&&i<=160) {
image(img9, 1600, mt, 3000, 100);
}
if (a==1&&ml>0)
ml=ml-2;
if (btime>0)s=int(random(0, 15));
else {
s=int(random(0,10));
}
if ( s == 5) {
monsterX[m]=900;
monsterY[m]=random(50, 950);
mstart[m]=1;
m++;
if (m>=50)m=0;
}
for (int i=0;i<50;i++) {
if (mstart[i]==1) {
image(img2, monsterX[i], monsterY[i], 64, 64);
monsterX[i]-=3;
if (monsterY[i]>500) {
monsterY[i]=0;
mstart[i]=0;
}
}
}
for (int i=0;i<50;i++) {
if (start[i]==1) {
image(img10, bulletX[i], bulletY[i]+30, 30, 10);
bulletX[i]+=3;
if (bulletY[i]>500) {
bulletY[i]=0;
start[i]=0;
}
}
}
for (int k=0;k<50;k++)
for (int j=0;j<50;j++) {
if (monsterY[j]<=bulletY[k]+50 && monsterY[j]>=bulletY[k]-50)
if (monsterX[j]<=bulletX[k]+10&& monsterX[j]>=bulletX[k]-10 && mstart[j]==1) {
start[k]=0;
mstart[j]=0;
monsterY[j]=0;
bulletY[k]=0;
if (ml<300)
ml=ml+10;
}
if (btime<=0)
{
if (bossY<=bulletY[k]+85 && bossY >=bulletY[k]-85)
if (800<=bulletX[k]+10&& 800>=bulletX[k]-10)
{
start[k]=0;
bl=bl-0.0025;
}
}
}
for (int k=0;k<50;k++)
{
if (a==1) {
if (monsterY[k]<= mt +50&&monsterY[k]>= mt-50) {
mstart[k]=0;
monsterY[k]=0;
}
if (bossY <= mt+150&&bossY>= mt-150)
bl=bl-0.025;
}
}
if (ba==1) {
if (bc!=0) {
bc--;
}
else
{
bo=15;
bc=100;
ba=0;
}
if (z<15)
{
z=z+0.15;
}
}
if (a==1&&ml==0)
{
a=0;
}
for (int j=0;j<50;j++)
if (monsterY[j]<=mt+50 && monsterY[j]>=mt-50)
if (monsterX[j]<=70+10 && mstart[j]==1)
{
hl=hl-50;
mstart[j]=0;
}
for (int i=0;i<=z;i++)
image(img13, 940, 10+i*10, 30, 10);
if (z>15)
z=15;
if (btime>0)
btime--;
if (btime==0) {
image(img14, 980, 300, 20, bl);
image(img2, 800, bossY, 240, 240);
if (bossY<=185&&bossY>=85) {
if (ud==0)bossY++;
if (ud==1)bossY--;
if (bossY>=185)ud=1;
if (bossY<=85)ud=0;
}
else
{
if (bossY==84)
bossY=85;
if (bossY==186)
bossY=185;
}
}
if (bl<=0) {
ss=1;
player4 = minim.loadFile("winner.wav");
player4.play();
}
if (hl<=0) {
ss=2;
player5 = minim.loadFile("loser.WAV");
player5.play();
}
}
if (ss==1)
image(img15,500,150,1000,300);
if (ss==2)
image(img16,500,150,1000,300);
}
void keyPressed() {
if (key=='q')
ml=300;
if (key == 'p')
btime=0;
if (key == 'o')
bl=0;
}
void stop()
{
player.close();
minim.stop();
super.stop();
}
訂閱:
文章 (Atom)












































