2013年1月20日 星期日

Week11,HW09


1.結合可做出什麼:
感覺電腦的遊戲改善之後都可以利用Arduino來玩
原本只是鍵盤滑鼠操作,現在可以變成按鈕,機器人等等
會更栩栩如生,更有趣

2.一個相關Arduino的影片:
他結合了魔術方塊,很有趣的遊戲跟結合
令人佩服~


Week15,hw12

本週進度:
我們大致都討論出來,靈感是來自於其中的作品
把它運用到麵包版上,感覺又有另一種感覺
主要是運用4個按鈕,代表不同顏色
一種反應遊戲~
希望我們可以成功!

心得:
原本覺得這是一個無法成功的遊戲
沒想到我們一步一步地接近了
詢問學長跟不斷改善
我們的作品快完成了
很開心上這堂課有這機會,這真的是不一樣的體驗和感受
希望大家會喜歡玩我們的作品

大致半成品:




arduino程式碼:

int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;

int buttonState5 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
void setup() {,tgy

  pinMode(buttonPin5, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT); 
  pinMode(buttonPin4, INPUT);

  Serial.begin(9600);

}
void loop() {
  buttonState5 = digitalRead(buttonPin5);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);

  if (buttonState5 == HIGH) {
   //tone(8, 131, 300);
   Serial.write('A');
  }
  else if (buttonState5 == LOW) {
   //Serial.write('Z');
  }

  if (buttonState2== HIGH) {
   //tone(8, 147 , 300);
   Serial.print('S');
  }
  else if (buttonState2 == LOW) {
   //Serial.write('X');
  }

  if (buttonState3 == HIGH) {
   //tone(8, 165 , 300);
   Serial.print('D');
  }
   else if (buttonState3 == LOW) {
   //Serial.write('C');
  }

  if (buttonState4 == HIGH) {
   //tone(8, 175 , 300);
   Serial.print('F');
  }
   else if (buttonState4 == LOW) {
   //Serial.write('V');
  }
  if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW){
  Serial.write('H');
  }
   delay(500);
}

Week13,HW11

影片:


心得:
我們成功做出五個按鈕,個代表五個音階,簡直就是簡易型的小鋼琴,
一開始有些瓶頸,後來詢問修改後,成功的做出來了,
很有趣也很好玩,感覺又學到了一些東西!
曲子是小蜜蜂~

WEEK 19,Final




程式碼:
processing:


import processing.serial.*;
Serial myPort;

int i,d1=0,d2=0,d3=0,d4=0;
int score=0, lastTime=60;
int[] value = new int[50000];
color[] c=new color[4];
int a,count=0;
int tmp=0;
int startt;
int val;
void setup(){
  size(500,600);
  myPort = new Serial(this, "COM4", 9600);
 
  c[0]=color(255,0,0);
  c[1]=color(0,255,0);
  c[2]=color(0,0,255);
  c[3]=color(255,255,255);
  for(i=0;i<10000;i++)
  {
    a=int(random(0,3.99));
    /*
    if(i%25==0)
      fill(255,0,0);
      else  if(i%30==0)
          fill(0,255,0);
          else  if(i%40==0)
              fill(0,0,255);
              else
              fill(255,255,255);
    */
    count%=50000;
    value[count++]=a;
  }
}
void draw(){
  background(255,200,100);
  if(myPort.available()>0){
    val = myPort.read();//
第三個重點:如果讀到數字就拿出來用
    //println("123");
  }
textSize(30);
fill(100,0,50);
text("Time:"+lastTime, 50,80);
text("Score:"+score, 0,220);
 if(lastTime==0){
      stop();
      textFont(createFont("3", 60));
      background(100,100,100);
      fill(255,255,255);
      text("Game Over ",120,250);
      text("Your score:"+score,0,350);
 }
lastTime=30-millis()/1000;

    i=200;
    for(int k=startt;k<startt+20;k++){
    fill(c[value[k]]);
    rect(i,100,80,80);
    i+=20;
    }
 




  fill(255,200,100);
  rect(0,100,200,80);

  if(d1==1){
    fill(128,128,128);
  }else{
    fill(255,0,0);
  }
  rect(60,400,80,80);
 
  if(d2==1){
    fill(128,128,128);
  }else{
    fill(0,255,0);
  }
  rect(360,400,80,80);
  if(d3==1){
    fill(128,128,128);
  }else{
    fill(0,0,255);
  }
  rect(260,400,80,80);
  if(d4==1){
    fill(128,128,128);
  }else{
    fill(255,255,255);
  }
  rect(160,400,80,80);
 
  if(val=='A'){
    d1=1;
    if(value[startt]==0){
      startt++;
      score+=10;
    }
  }
  else if(val=='S'){
 
    d2=1;if(value[startt]==1){
      startt++;
      score+=10;
    }
  }
  else if(val=='D'){
    d3=1;if(value[startt]==2)
    {  startt++;
    score+=10;
    }
  }else if(val=='F'){
    d4=1;if(value[startt]==3)   
     { startt++;
     score+=10;
     }
  }
  else if(val=='H'){
   d1=0;
  d2=0;
 d3=0;
d4=0;
  }
}
void keyPressed(){
  if(key=='4'){
    d1=1;
    if(value[startt]==0){
      startt++;
      score+=10;
    }
  }else if(key=='5'){
 
    d2=1;if(value[startt]==1){
      startt++;
      score+=10;
    }
  }else if(key=='r'){
    d3=1;if(value[startt]==2)
    {  startt++;
    score+=10;
    }
  }else if(key=='t'){
    d4=1;if(value[startt]==3)   
     { startt++;
     score+=10;
     }
  }
}
void keyReleased(){
  if(key=='4'){
    d1=0;
  }else if(key=='5'){
    d2=0;
  }else if(key=='r'){
    d3=0;
  }else if(key=='t'){
    d4=0;
  }
}


arduino:

int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;

int buttonState5 = 0; 
int buttonState2 = 0; 
int buttonState3 = 0; 
int buttonState4 = 0; 
void setup() {,tgy

  pinMode(buttonPin5, INPUT);    
  pinMode(buttonPin2, INPUT);    
  pinMode(buttonPin3, INPUT);     
  pinMode(buttonPin4, INPUT);
 
  Serial.begin(9600);

}
void loop() {
  buttonState5 = digitalRead(buttonPin5);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
 
  if (buttonState5 == HIGH) {    
   //tone(8, 131, 300);
   Serial.write('A');
  } 
  else if (buttonState5 == LOW) {
   //Serial.write('Z');
  }
 
  if (buttonState2== HIGH) {    
   //tone(8, 147 , 300);
   Serial.print('S');
  }
  else if (buttonState2 == LOW) {
   //Serial.write('X');
  }

  if (buttonState3 == HIGH) {    
   //tone(8, 165 , 300);
   Serial.print('D');
  }
   else if (buttonState3 == LOW) {
   //Serial.write('C');
  }

  if (buttonState4 == HIGH) {    
   //tone(8, 175 , 300);
   Serial.print('F');
  }
   else if (buttonState4 == LOW) {
   //Serial.write('V');
  }
  if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW){
  Serial.write('H');
  }
   delay(500);
}


心得:
在眾多的課程當中我覺得這是最需要創意且最有難度的一堂課,要會打程式要會麵包板還需要很多靈感來完成作品,而這堂課除了要感謝老師也要感謝助教、學長還有同學的幫忙,讓我們這組能順利的打完程式碼。雖然這堂課困難重重,但我又比別人多會了一樣的東西。

組員分工:
程式碼:朱席寬
電路板:林品妤
找題材:朱席寬
期末上台報告:林品妤

2013年1月19日 星期六

Week19,final

1.作品名稱:撈漁撈不完
2.影片:

















3.程式碼:
(1)arduino:
int buttonPin2 = 4;
int buttonPin3 = 3;
int buttonState2 = 0;
int buttonState3 = 0;

void setup() {

pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.begin(9600);

}
void loop() {
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);


if (buttonState2 == HIGH) {
Serial.print('A');
}

else if (buttonState3== HIGH) {
Serial.print('S');
}

else {
Serial.print('H');
}
delay(500);
}

(2)processing:
import processing.serial.*;
Serial myPort;
PImage fish, fisher,background;
float []fishX=new float[10];
float []fishY=new float[10];
int []fishLive =new int[10];
float []fishSpeed = new float[10];
int key;
int x,y=300,level=0;
void setup(){
size(900,600);
myPort = new Serial(this, "COM6", 9600);
fish=loadImage("fish.png");
fisher=loadImage("fisher.png");
background=loadImage("ocean.jpg");
for(int i=0;i<5;i++){
fishX[i]=i*-200;
fishY[i]=300+random(200);
fishLive[i]=1;
fishSpeed[i]=random(2) + 2;
}
}
int a=0,live=100,end=0;
int shift=4;
void draw(){
if(myPort.available()>0){
key = myPort.read();
println(key);

}
if(end==1){
background(255,0,255);
shift=0;a=100;}
background(225);
image(background, 0, 0);
if(a>0){
a--;
background(255,0,0);
live--;
if(live<0) live=0; }
if(live<=0) end=1;
textSize(80);
text("Life: "+live,100,100);
for(int i=0;i<5;i++){
if(fishX[i]+100>400 && fishX[i]<400+100 && fishY[i]+100>y && fishY[i]<y+100)
{fishLive[i]=0; }
if(fishLive[i]==1) image(fish,fishX[i],fishY[i]);
fishX[i]+=fishSpeed[i];;
if(fishX[i]>900){
fishX[i]-=1000;
fishY[i]=300+random(200);
if(fishLive[i]==1){ a=10; }
fishLive[i]=1;
} }
if(key=='A')
{y+=5;}
else if(key=='S')
{ y-=5;}
else if(key=='H')
{y+=0; }
image(fisher, 400,y,100,100);
if(end==1){
text("sorry,fisher is broken ", 60,300);
}
}

4.心得:
這次的作業從一開始不懂到問了同學,也請教很多學長姊,得到很多人的幫助之後理解,但是也花了我們很多的時間,因為基礎沒有很好,但是我們也盡力去理解程式碼,雖然說可能很多都是老師上課講解過或者是同學教過的東西,但是我們不懂也有去問他們,最後雖然沒有很精緻,但是也努力去完成它了,上完老師的課,讓我收穫十足,但要是回家沒複習,下次要在連接上就會困難重重,這是我們這組要改進的部分,期待下次能再做得更好,讓大家更欣賞我們的作品

5.組員分工狀況 :
寫部落格:賴冠戎,程柔淇
撰寫processing遊戲主要程式:賴冠戎
將processing遊戲作修改:程柔淇
撰寫arduion程式:程柔淇
找素材:賴冠戎,程柔淇
電路板之連結:賴冠戎,程柔淇
拍攝影片:賴冠戎

Week14,hw12

1.這周進度:
(1).討論出主題
(2).更改processing(細修,方便接上Arduino)
(3).將Arduino程式碼完成
(4).電路板都接上並也能執行


2.心得
processing需要配合Arduino,所以要更改的地方很多,目前進度在processing,還有很多不了解的地方,但是有在問會的人,會盡力搞懂並且用好程式碼,等搞懂後arduino就可以很快地打出來了,電路也可以快速地接好,雖然說很多地方不懂,但是會積極去問別人並且理解程式碼的意思.因次把之前做的processing都修了一遍,組內討論時間允許的話,要在期末發表前把電路版加上更多花樣,例如將寶麗容求切一半貼於按鍵上,或是製作一個盒子,如此能更吸引大家遊戲,也能更高分,希望大家會喜歡

3.Arduino程式碼

int buttonPin2 = 4;
int buttonPin3 = 3;
int buttonState2 = 0;
int buttonState3 = 0;

void setup() {

pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.begin(9600);

}
void loop() {
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);


if (buttonState2 == HIGH) {
Serial.print('A');
}

else if (buttonState3== HIGH) {
Serial.print('S');
}

else {
Serial.print('H');
}
delay(500);
}


Week 11 , HW 09

1.尋找:有關Arduino的影片




2.寫下:有了 Processing + Arduino 可以做出甚麼?





















我們想到的是一樣可以做我們期中時的射擊遊戲,但是我們把它從滑鼠的射酒瓶改成直升機攔截飛彈可以搭配按鈕(搖桿)左右移動跟射擊的形式,來做互動遊戲

2013年1月18日 星期五

Week11,HW09

1.有關arduino的影片
http://www.youtube.com/watch?v=jjvy_jzGlAQ

這是將Arduino做一個可以模擬打鼓的裝置,做這項東西的想法很厲害,能夠簡化電子鼓的複雜度,很適合給小朋友玩。

2.心得:
看了一些影片,Aduino根processing可以結合,作一些按鍵,或是可以用一些可變電阻來做控制方向等等的一些小遊戲,我覺得很有趣。

Week 19 , Final

系統名稱: 直升機保衛戰


1. 遊戲進行和裝置介紹

 

遊戲剛開始畫面















直升機射擊時的畫面

  

攔截失敗時的畫面(損失生命)














操作裝置(搖桿+射擊按鈕)






2. 遊戲玩法說明

        一開始進入遊戲, 畫面上方會隨機出現轟炸飛彈,此時必須使用搖桿控制直升機左右移動,並且按射擊鍵攔截飛彈,如果攔截飛彈失敗或是碰到機身,此時就會扣掉右下角的生命值,當生命值為0時,遊戲結束並且秀出得分狀況。


3. 遊戲Demo影片

 

4.程式碼

 
 /*Arduino*/
int pushButton = 2;
int pushButton2 = 6;
int pushButton3 = 7;
void setup() {

 Serial.begin(9600);
 pinMode(pushButton, INPUT_PULLUP);
 pinMode(pushButton2, INPUT_PULLUP);
 pinMode(pushButton3, INPUT_PULLUP);
}
int a=0;
int a2=0;
int a3=0;
// the loop routine runs over and over again forever:
void loop() {
 // read the input pin:
 int buttonState = digitalRead(pushButton);
 int buttonState2 = digitalRead(pushButton2);
  int buttonState3 = digitalRead(pushButton3);
 // print out the state of the button:
 if (buttonState == HIGH && a==0 ) { // If switch is ON,
   Serial.print(1); 
   a=1; // send 1 to Processing
 }
 if (buttonState == LOW && a==1) { // If the switch is not ON,
   Serial.println(0); 
   a=0; // send 0 to Processing
 }
 if (buttonState2 == HIGH && a2==0 ) { // If switch is ON,
   Serial.print(2); 
   a2=2; // send 1 to Processing
 }
 if (buttonState2 == LOW && a2==1) { // If the switch is not ON,
   Serial.println(3); 
   a2=3; // send 0 to Processing
 }
 if (buttonState3 == HIGH && a3==0 ) { // If switch is ON,
   Serial.print(4); 
   a3=4; // send 1 to Processing
 }
 if (buttonState3 == LOW && a3==1) { // If the switch is not ON,
   Serial.println(5); 
   a2=5; // send 0 to Processing
 }
 // Serial.println(buttonState);
 delay(10); // delay in between reads for stability
}
   

/*Processing*/
import processing.serial.*;
Serial myPort;  
int val;
PImage bg,helicopter,bomb;
PImage [] life = new PImage[5];
float hx=350,hy=400;
PImage [] missile = new PImage[5];
int[] mx = new int [5];
int[] my = new int [5];
int bx=0,by=0;

void setup(){
  size(840,525);
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM5", 9600);
  
  bg =loadImage("sky.jpg");
  helicopter= loadImage ("Helicopter.png");
  for(int i=0;i<5;i++){
   life[i]= loadImage("Life.png");
  }
  for(int i=0;i<5;i++){
   missile[i]= loadImage("Missile.png");
  }
  for(int i=0;i<5;i++){
    mx[i]=i*200;
    my[i]=(-300+i*40);
  }
  bomb= loadImage ("bomb.png");
}
void draw(){
  background(bg);
  life();
  helicopterA();
  missilefly();
  myserial();
  bomb();
}
void  helicopterA(){
  image(helicopter,hx,hy);
}
void life(){
  fill(180,180,180);
  rect(740,340,60,160);
  fill(255,0,0);
  rect(740,300,60,40);
  fill(255,255,255);
  textFont(createFont("Georgia", 25));
  text("LIFE ",742,330);
  for(int i=0;i<5;i++){
  image(life[i],690,320+(30*i),150,100);
  }

}
void missilefly(){
  for(int i=0;i<5;i++){
    image(missile[i],mx[i],my[i],50,100);
  }
  for(int i=0;i<5;i++){
    my[i]+=2;
  }
  for(int i=0;i<5;i++){
    if(my[i]==600){
      my[i]=(-300+i*40);
    }
  }
}

void myserial(){
  if ( myPort.available() &rt; 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  if (val == 0) {              // If the serial value is 0,
    translate(hx,hx+=10);
  } 
  else if(val == 2){                       // If the serial value is not 0,
    translate(hx,hx-=10);   
  }

}
void bomb(){
 int p=0;
  image(bomb,hx+90,hy+by,10,15);  
    if(val != 4 && by!=0){
      by-=10;
    }
  
    if (val == 4){
       by-=10;
    }
  if((hy+by)<=0){
    by=0;
 }
} 


5.心得

這次得專題製作跟以前碰過的都不太相同,除了還是有程式的撰寫之外,還必須同時結合到2個程式,所以中間的連結很重要。

此外在接Arduino線路時,必須克服許多問題(ex.接觸不良、接腳錯誤.....等)因此也花了較多的時間在處理硬體上面的問題,但是還好最後都有想出辦法解決(ex.絕緣膠帶,多接幾次線路並檢查)。

麒時後來在Demo時還覺得蠻有成就感的,畢竟是自己從無到有生出來的, 所以很開心!!

也謝謝各位同學在票選時對我們的厚愛,害我們自己都下了一跳呢! 謝謝大家 :)


6.工作分配



遊戲作品構思:

李之寧 、邱垂傑



遊戲程式:

Arduino + 合併 李之寧

Processing 邱垂傑




遊戲硬體:

Arduino 各線路連接 李之寧

搖桿本體製作 邱垂傑

 

  

我們的期末作業是將期中做的打地鼠遊戲,由滑鼠控制改成用按鈕來決定要打擊的位置。

arduino
import processing.serial.*;
Serial myPort; 
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
   
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
  size(800, 600);
  noStroke();
  bang = loadImage("bang.png");
  bang1 = loadImage("bang1.png");
  mouse=loadImage("mouse1.jpg");
  mouse2=loadImage("mouse2.png");
  savetime = millis();
  minim = new Minim(this); 
  player = minim.loadFile("123.mp3");
  player.play();
  size(200, 200);
 
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM1", 9600);
}
void draw(){
  if ( myPort.available() > 0) { 
    val = myPort.read();        
  }
  background(255);            
  if (val == 0) {            
    fill(0);                  
  }
  else {                    
    fill(204);               
  }
  rect(50, 50, 100, 100);
}
void draw() {
  image(mouse, 0, 0);
  float targetX = mouseX;
  if (mousePressed) {
    image(bang1, mouseX-60, mouseY-60);
    }
    else {
      image(bang, mouseX-60, mouseY-60);
    }
    if(millis()%1000<30){  
      hole=int(random(1,10)); 
    }
  
   
   fill(255,0,0); 
   if(hole==1){   image(mouse2, 80, 25);  } 
   if(hole==2){   image(mouse2, 340, 25); } 
   if(hole==3){   image(mouse2, 600,25);  } 
   if(hole==4){   image(mouse2, 50,190);   } 
   if(hole==5){   image(mouse2, 350,190);   } 
   if(hole==6){   image(mouse2, 620,190);}
   if(hole==7){   image(mouse2, 40,370);   }
   if(hole==8){   image(mouse2, 350,370);   }
   if(hole==9){   image(mouse2,645,370);   }  
   fill(255,255,255); 
    fill(255,255,255);
    textSize(24);
    text("S  C  O  R  E   : "+score, 100, 550);
    int passtime = millis() - savetime;
    int gametime = 15-passtime/1000;
    textSize(24);
    text("T I M E : "+gametime,500,550);
    if( gametime <= 0 ){
    background(255,255,0);
    fill(255,0,0);
    textSize(30);
  
    text(" T I M E    IS    UP ",200,200);
    text(" Y O U R    S  C  O  R  E  :  "+score, 200,300);
 
 
 }
}
void keyPressed(){
  if(key=='1' && hole==7){
    score=score+=100;
     }
  if(key=='2' && hole==8){
    score=score+=100;
     }
  if(key=='3' && hole==9){
    score=score+=100;
     }
  if(key=='4' && hole==4){
    score=score+=100;
     }
  if(key=='5' && hole==5){
    score=score+=100;
     }
  if(key=='6' && hole==6){
    score=score+=100;
     }
  if(key=='7' && hole==1){
    score=score+=100;
     }
  if(key=='8' && hole==2){
    score=score+=100;
     }
  if(key=='9' && hole==3){
    score=score+=100;
     }  
   minim=new Minim(this);
   bm=minim.loadFile("kk.wav", 2048);
   bm.play();
   }

processing
import processing.serial.*;
Serial myPort; 
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
   
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
  size(800, 600);
  noStroke();
  bang = loadImage("bang.png");
  bang1 = loadImage("bang1.png");
  mouse=loadImage("mouse1.jpg");
  mouse2=loadImage("mouse2.png");
  savetime = millis();
  minim = new Minim(this); 
  player = minim.loadFile("123.mp3");
  player.play();
  size(200, 200);
 
  String portName = Serial.list()[0];
  myPort = new Serial(this, "COM1", 9600);
}
void draw(){
  if ( myPort.available() > 0) { 
    val = myPort.read();        
  }
  background(255);            
  if (val == 0) {            
    fill(0);                  
  }
  else {                    
    fill(204);               
  }
  rect(50, 50, 100, 100);
}
void draw() {
  image(mouse, 0, 0);
  float targetX = mouseX;
  if (mousePressed) {
    image(bang1, mouseX-60, mouseY-60);
    }
    else {
      image(bang, mouseX-60, mouseY-60);
    }
    if(millis()%1000<30){  
      hole=int(random(1,10)); 
    }
  
   
   fill(255,0,0); 
   if(hole==1){   image(mouse2, 80, 25);  } 
   if(hole==2){   image(mouse2, 340, 25); } 
   if(hole==3){   image(mouse2, 600,25);  } 
   if(hole==4){   image(mouse2, 50,190);   } 
   if(hole==5){   image(mouse2, 350,190);   } 
   if(hole==6){   image(mouse2, 620,190);}
   if(hole==7){   image(mouse2, 40,370);   }
   if(hole==8){   image(mouse2, 350,370);   }
   if(hole==9){   image(mouse2,645,370);   }  
   fill(255,255,255); 
    fill(255,255,255);
    textSize(24);
    text("S  C  O  R  E   : "+score, 100, 550);
    int passtime = millis() - savetime;
    int gametime = 15-passtime/1000;
    textSize(24);
    text("T I M E : "+gametime,500,550);
    if( gametime <= 0 ){
    background(255,255,0);
    fill(255,0,0);
    textSize(30);
  
    text(" T I M E    IS    UP ",200,200);
    text(" Y O U R    S  C  O  R  E  :  "+score, 200,300);
 
 
 }
}
void keyPressed(){
  if(key=='1' && hole==7){
    score=score+=100;
     }
  if(key=='2' && hole==8){
    score=score+=100;
     }
  if(key=='3' && hole==9){
    score=score+=100;
     }
  if(key=='4' && hole==4){
    score=score+=100;
     }
  if(key=='5' && hole==5){
    score=score+=100;
     }
  if(key=='6' && hole==6){
    score=score+=100;
     }
  if(key=='7' && hole==1){
    score=score+=100;
     }
  if(key=='8' && hole==2){
    score=score+=100;
     }
  if(key=='9' && hole==3){
    score=score+=100;
     }
 minim=new Minim(this);
     bm=minim.loadFile("kk.wav", 2048);
     bm.play();
   }
  
 

  
 

Week19, Final


這次的期末作品是拿我們的期中作品來改良的,把原本用滑鼠移動的海綿寶寶改用Arduino的按鍵來坐上下左右的移動

Arduino程式碼:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;

int buttonState5 = 0;  
int buttonState2 = 0;  
int buttonState3 = 0;  
int buttonState4 = 0;  
void setup() {

  pinMode(buttonPin5, INPUT);     
  pinMode(buttonPin2, INPUT);     
  pinMode(buttonPin3, INPUT);      
  pinMode(buttonPin4, INPUT);
  
  Serial.begin(9600);

}
void loop() {
  buttonState5 = digitalRead(buttonPin5);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  
  if (buttonState5 == HIGH) {     
   //tone(8, 131, 300);
   Serial.write('A');
  }  
  else if (buttonState5 == LOW) { 
   //Serial.write('Z');
  }
  
  if (buttonState2== HIGH) {     
   //tone(8, 147 , 300);
   Serial.print('S');
  }
  else if (buttonState2 == LOW) { 
   //Serial.write('X');
  }

  if (buttonState3 == HIGH) {     
   //tone(8, 165 , 300);
   Serial.print('D');
  }
   else if (buttonState3 == LOW) { 
   //Serial.write('C');
  }

  if (buttonState4 == HIGH) {     
   //tone(8, 175 , 300);
   Serial.print('F');
  }
   else if (buttonState4 == LOW) { 
   //Serial.write('V');
  }
  if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW){
  Serial.write('H');
  }
   delay(500);
}







processing程式碼:


import processing.serial.*;
Serial myPort;

int popox=0,popoy=0,popoy1=0,popoy2=0,popoy3=0,popoy4=0,popoy5=0;
int fishx=0,fishy=0;
int score=600;
int lasttime=60;

import ddf.minim.*;
AudioPlayer  player,wate,cheers;
Minim minim;

PImage popo;
//PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
  size(800,600);
  myPort = new Serial(this, "COM3", 9600);
  fish=loadImage("fish.png"); //游動的魚
  bobo=loadImage("bobo.png"); //海綿寶寶
  //finger=loadImage("finger.png"); //手指
  popo=loadImage("popo.png"); //泡泡
  back=loadImage("back.jpeg"); //背景圖
  minim=new Minim(this);
  //wate=minim.loadFile("wate.wav", 2048);
player=minim.loadFile("file.mp3"); //背景音樂
player.play();
}
int val;
int b_x=400,b_y=300;
int w=5,s=5,a=5,d=5;
void draw()
{
  if(myPort.available()>0){
    val = myPort.read();//第三個重點:如果讀到數字就拿出來用
    println(val);
}

  image(back,0,0);
  //image(bobo,250,100);


  popoy-=3; //泡泡移動量
  image(popo,popox+300,popoy+600,100,100);  //泡泡坐標,大小
 
  if (b_x > popox+300 && b_x< popox+400 && b_y<popoy+700 && b_y>popoy+600) //判斷滑鼠是否點到泡泡的範圍
   {
     popoy=600; //泡泡回到下面再跑一次
   score-=10; //碰到泡泡減十分
   wate=minim.loadFile("wate.wav"); //戳到泡泡時播放音效
   wate.play();
   }
 
   if (b_x > popox+200 && b_x< popox+300 && b_y<popoy1+600 && b_y>popoy1+500)
  {
    popoy1=500;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
  }
   if (b_x > popox+100 && b_x< popox+200 && b_y<popoy2+800 &&  b_y>popoy2+700)
  {
    popoy2=700;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
 }
   if (b_x > popox+500 && b_x< popox+600 && b_y<popoy3+750 && b_y>popoy3+650)
   {
     popoy3=600;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
   }
  if (b_x > popox+400 && b_x< popox+500 && b_y<popoy4+950 && b_y>popoy4+850)
  {
    popoy4=600;
  score-=10;
  wate=minim.loadFile("wate.wav");
   wate.play();
  }
    if (b_x > popox+600 && b_x< popox+700 &&  b_y<popoy5+1050 && b_y>popoy5+950)
  {
    popoy5=700;
  score-=10;
  wate=minim.loadFile("wate.wav");
   wate.play();
  }
 
  if(popoy+600<0) //判斷泡泡是否跑出視窗
  {

    popoy=0; //泡泡回到原點再跑一次
  }
   popoy1-=2;
  image(popo,popox+200,popoy1+500,100,100);
   if(popoy1+500<0)
  {

    popoy1=0;
  }
   popoy2-=3;
  image(popo,popox+100,popoy2+700,100,100);
   if(popoy2+700<0)
  {

    popoy2=0;
  }
   popoy3-=5.5;
  image(popo,popox+500,popoy3+650,100,100);
   if(popoy3+650<0)
  {
    popoy3=0;
  }
  popoy4-=2;
  image(popo,popox+400,popoy4+850,100,100);
   if(popoy4+850<0)
  {
    popoy4=0;
  }
  popoy5-=3;
  image(popo,popox+600,popoy5+950,100,100);
   if(popoy5+950<0)
  {
    popoy5=0;
  }

  image(bobo,b_x,b_y,60,60);
  fishx++;
  image(fish,fishx,fishy+200);
  {
    if(fishx>800) //判斷魚是否跑出視窗
    {
    fishx=0;
    fishy=250;
    }
  }
  world();

 if(val=='A'){
    b_x-=4;
  }
 if(val=='S'){
    b_x+=4;
  }
 if(val=='F'){
    b_y-=4;
  }
 if(val=='D'){
    b_y+=4;
  }
  if(val=='H'){
   b_y+=0;
    b_x+=0;
  }
 
  if(b_x<0)
  {
    b_x=0;
  }
 
    if(b_x>745)
  {
    b_x=745;
  }
 
    if(b_y<0)
  {
    b_y=0;
  }

   if(b_y>540)
  {
    b_y=540;
  }
}

  void world()
  {
     textFont(createFont("Georgia", 48));
      fill(255);
  text("score:"+score, 20, 550); //分數
 
  textFont(createFont("Georgia", 48));
      fill(255);
  text("Time:"+lasttime, 250, 550); //計時器
  lasttime=60-millis()/1000;
 
      if(lasttime==0) //當時間=0,秀出得分
      {
      stop();
      textFont(createFont("Georgia", 80));
      background(51,102,51);
      fill(255,255,255);
      text("Game Over",200,300);
      text("Your score:"+score,180,400);
      cheers=minim.loadFile("cheers.wav");
      cheers.play();
      }
  }

心得:
這次的期末作業我們覺得沒有做得很好,Demo到後面的時候有點乾
按鍵道具的部分也是用課堂上的案件,並沒有花心思在其他道具上,但在Arduino的程式上,我們花了不少時間去研究,也學到了不少的東西.

Week19, Final



期末DEMO
聲音不夠大聲,所以有後製補上聲音。
畫面稍嫌小,不過仔細看還是看的到音符落點。

這學期這堂課學到很多,
也感謝老師的獎品鼓勵,
未來將會用它做出更棒更完整的作品。

Week15, HW12

呃,正確來說,我們好像是這周就發表了。
因為主遊戲程式是用C#寫的,所以有點複雜,不知道怎麼解釋,
不過Arduino部分就很簡單,
一號按鈕有按,就送出1,反之則0
二號按鈕有按,就送出3,反之則2
以此類推,遊戲側的程式會判定傳來的值代表哪個按鈕。

另外補上幾張製作控制器時的圖:



Arduino的程式碼:

int switchPin1 = 2;
int switchPin2 = 3;
int switchPin3 = 4;
int switchPin4 = 5;
int switchPin5 = 6;
boolean oldStage1 = false;
boolean oldStage2 = false;
boolean oldStage3 = false;
boolean oldStage4 = false;
boolean oldStage5 = false;

void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
Serial.begin(9600);
}

void loop()
{
    if (digitalRead(switchPin1) == LOW)
    {
      if(oldStage1)
      {
        Serial.print(0,DEC);
      }
      oldStage1 = false;
    }
    else
    {
      if(!oldStage1)
      {
        Serial.print(1,DEC);
      }
      oldStage1 = true;
    }
 
    if (digitalRead(switchPin2) == LOW)
    {
      if(oldStage2)
      {
        Serial.print(2,DEC);
      }
      oldStage2 = false;
    }
    else
    {
      if(!oldStage2)
      {
        Serial.print(3,DEC);
      }
      oldStage2 = true;
    }
 
    if (digitalRead(switchPin3) == LOW)
    {
      if(oldStage3)
      {
        Serial.print(4,DEC);
      }
      oldStage3 = false;
    }
    else
    {
      if(!oldStage3)
      {
        Serial.print(5,DEC);
      }
      oldStage3 = true;
    }
 
    if (digitalRead(switchPin4) == LOW)
    {
      if(oldStage4)
      {
        Serial.print(6,DEC);
      }
      oldStage4 = false;
    }
    else
    {
      if(!oldStage4)
      {
        Serial.print(7,DEC);
      }
      oldStage4 = true;
    }
 
    if (digitalRead(switchPin5) == LOW)
    {
      if(oldStage5)
      {
        Serial.print(8,DEC);
      }
      oldStage5 = false;
    }
    else
    {
      if(!oldStage5)
      {
        Serial.print(9,DEC);
      }
      oldStage5 = true;
    }
}

秒咪記憶遊戲
一,遊戲構思和介紹
動機:
由於現在人使用大量的電子產品,很多事情都賴於墊子產品的紀錄功能,而使用到腦袋來記憶的機會越來越少,因此我們想設計出一個記憶遊戲,除了富含娛樂功能,有能激活大家的記憶細胞:D
介紹;
就跟大部分的記憶遊戲玩法差不多。主遊戲畫面上共排列不同的五張貓咪圖片,當遊戲開始時,會依照所選擇的難度,隨機亮起不同的圖片,而玩家須要記得圖片的排列順序,依照順序按下按鈕後,再按下確認鍵確認答案,接著遊戲會給予回饋,看是答對或失敗,也可在選擇難度繼續遊戲,或是離開。

二,畫面介紹
↓ 剛進入的遊戲起始畫面:
↓ 按下確認鍵後,會進入到選擇難度的畫面:


↓ 選擇難度後,會進入到遊戲主畫面:
 
↓ 會隨機出現
 
 ↓ 遊戲過關畫面:
↓ 遊戲失敗畫面: 
 
↓ 遊戲離開畫面:



↓ 成功破最難關卡的畫面: 
  
三,硬體
遊戲裝置上有六個按鈕,其中五個白色保麗龍按鈕是用來回答題目順序的,而右下角的紅色按鈕則是確認紐。


四,程式碼
Arduino:
//大的圓形鈕
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;
const int buttonPin6 = 7;  //確認鈕

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int input=0, oldInput=0, a=0;

void setup(){
  Serial.begin(9600);   
  
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);
  pinMode(buttonPin6, INPUT);
}

void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);  
  buttonState3 = digitalRead(buttonPin3); 
  buttonState4 = digitalRead(buttonPin4); 
  buttonState5 = digitalRead(buttonPin5); 
  buttonState6 = digitalRead(buttonPin6); 
  
  if(buttonState1== HIGH) input=1;
  else if(buttonState2== HIGH) input=2;
  else if(buttonState3== HIGH) input=3;
  else if(buttonState4== HIGH) input=4;
  else if(buttonState5== HIGH) input=5;
  else if(buttonState6== HIGH) input=6;
  else input=0;
  
  if(input!=oldInput){
    if(input==1){
      Serial.print(1);
      oldInput=input;
      a=1;
    }else if(input==2){
      Serial.print(2);
      oldInput=input;
      a=2;
    }else if(input==3){
      Serial.print(3);
      oldInput=input;
      a=3;
    }else if(input==4){
      Serial.print(4);
      oldInput=input;
      a=4;
    }else if(input==5){
      Serial.print(5);
      oldInput=input;
      a=5;
    }else if(input==6){
      Serial.print(6);
      oldInput=input;
      a=6;
    }
  }
}
Processing:
import processing.serial.*;
Serial myport;

PImage rule, start;  //開始
PImage easy, nor, hard, bEasy, bNormal, bHard;  //選單
PImage gmioumi1, gmioumi2, gmioumi3, gmioumi4, gmioumi5;  //底圖
PImage mioumi1, mioumi2, mioumi3, mioumi4, mioumi5;  //亮圖
PImage pass, over, win, End;//結果
float x=0, y=0, z=0, oldx=0, nowx=0;
float xTime=3;
String str="", str2="",oldstr2="", a="6",b="6", c="", oldc="";
int inByte=0, choose=0, end=3, e=0, f=0, g=0;

void setup(){
  myport=new Serial(this,"COM3",9600);
  //開始
  rule = loadImage("rule.jpg");
  start = loadImage("start.png");
  //選單
  easy = loadImage("easy.png");
  nor = loadImage("normal.png");
  hard = loadImage("hard.png");
  bEasy = loadImage("bEasy.jpg");
  bNormal = loadImage("bNormal.jpg");
  bHard = loadImage("bHard.jpg");
  //底圖
  gmioumi1 = loadImage("g1.jpg");
  gmioumi2 = loadImage("g2.jpg");
  gmioumi3 = loadImage("g3.jpg");
  gmioumi4 = loadImage("g4.jpg");
  gmioumi5 = loadImage("g5.jpg");
  //亮圖
  mioumi1 = loadImage("c1.png");
  mioumi2 = loadImage("c2.png");
  mioumi3 = loadImage("c3.png");
  mioumi4 = loadImage("c4.png");
  mioumi5 = loadImage("c5.png"); 
  //結果
  pass = loadImage("pass.jpg");
  over = loadImage("over.jpg");
  win = loadImage("win.jpg");
  End = loadImage("end.jpg");
  size(600,400);
  background(0,0,0);
}

void draw(){
  if(myport.available()>0){  //測試有無訊號來
    inByte=myport.read();  //如果有來就read
    if(inByte==1+48) c="1";
    else if(inByte==2+48) c="2";
    else if(inByte==3+48) c="3";
    else if(inByte==4+48) c="4";
    else if(inByte==5+48) c="5";
    else if(inByte==6+48) c="6";
  }
  if(c!=oldc){
    println(c);
    oldc=c;
  }
  if(c==""){
    image(rule,50,50,500,250);
    image(start,200,320,200,50);
    e=1;
  }else if(c=="6" && e==1){
    fill(0,0,0);
    rect(0,0,600,400);
    image(easy,50,50,160,50);
    image(nor,220,50,160,50);
    image(hard,390,50,160,50);
    image(bEasy,50,100,160,250);
    image(bNormal,220,100,160,250);
    image(bHard,390,100,160,250);
    c="0";
  }  
  if(c=="1" && e==1){
    choose=1;
    e=2;
    c="0";
  }else if(c=="3" && e==1){ 
    choose=3;
    e=2;
    c="0";
  }else if(c=="5" && e==1){
    choose=5;
    e=2;
    c="0";
  }  
  if(choose==1){
    //easy
    if(y<6){
      if(millis()-xTime>1000){
        x=random(5); 
        b=a;
        nowx=(int)x/1;
        if(nowx==oldx){
          if(nowx==4){
            x=1;
            oldx=(int)x/1;
          }else if(nowx==5){
            x=2;
            oldx=(int)x/1;
          }else{ 
            x=x+1;
            oldx=(int)x/1;
          }  
        }else oldx=(int)x/1;
        if(x>0 && x<=1){
          fill(0,0,0);
          rect(0,0,600,400); 
          image(mioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="1";
        }else if(x>1 && x<=2){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi2,150,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="2";
        }else if(x>2 && x<=3){  
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi3,250,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="3";
        }else if(x>3 && x<=4){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi4,350,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="4";
        }else if(x>4 && x<=5){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi5,450,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          a="5";
        } 
        xTime=millis();
        y=y+1;
        if(y<6 && b!=a){ 
          str=str+a;
          println("*"+str);
          z=0;
        }else if(y<6 && z==0 && b==a){
          str=str+a;
          println("*"+str);
          z=1;
        } 
      }else if(millis()-xTime>600 && millis()-xTime<800){
        fill(0,0,0);
        rect(0,0,600,400);
        image(gmioumi1,50,100,100,100);
        image(gmioumi2,150,100,100,100);
        image(gmioumi3,250,100,100,100);
        image(gmioumi4,350,100,100,100);
        image(gmioumi5,450,100,100,100);
      }
    }else if(e==2){
      fill(0,0,0);
      rect(0,0,600,400);
      image(gmioumi1,50,100,100,100);
      image(gmioumi2,150,100,100,100);
      image(gmioumi3,250,100,100,100);
      image(gmioumi4,350,100,100,100);
      image(gmioumi5,450,100,100,100);
    }
    if(c!=oldstr2){
      if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ 
        oldstr2=c;
        str2=str2+c;
        println("**"+str2+"**");
      }
    } 
  }else if(choose==3){
    //normal
    if(y<8){
      if(millis()-xTime>1000){
        x=random(5); 
        b=a;
        nowx=(int)x/1;
        if(nowx==oldx){
          if(nowx==4){
            x=1;
            oldx=(int)x/1;
          }else if(nowx==5){
            x=2;
            oldx=(int)x/1;
          }else{ 
            x=x+1;
            oldx=(int)x/1;
          }  
        }else oldx=(int)x/1;
        if(x>0 && x<=1){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="1";
        }else if(x>1 && x<=2){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi2,150,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="2";
        }else if(x>2 && x<=3){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi3,250,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="3";
        }else if(x>3 && x<=4){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi4,350,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="4";
        }else if(x>4 && x<=5){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi5,450,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          a="5";
        } 
        xTime=millis();
        y=y+1;
        if(y<8 && b!=a){ 
          str=str+a;
          println(str);
          z=0;
        }else if(y<8 && z==0 && b==a){
          str=str+a;
          println(str);
          z=1;
        } 
      }else if(millis()-xTime>600 && millis()-xTime<800){
        fill(0,0,0);
        rect(0,0,600,400);
        image(gmioumi1,50,100,100,100);
        image(gmioumi2,150,100,100,100);
        image(gmioumi3,250,100,100,100);
        image(gmioumi4,350,100,100,100);
        image(gmioumi5,450,100,100,100);
      }
    }else if(e==2){
      fill(0,0,0);
      rect(0,0,600,400);
      image(gmioumi1,50,100,100,100);
      image(gmioumi2,150,100,100,100);
      image(gmioumi3,250,100,100,100);
      image(gmioumi4,350,100,100,100);
      image(gmioumi5,450,100,100,100);
    }
    if(c!=oldstr2){
      if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ 
        oldstr2=c;
        str2=str2+c;
        println("**"+str2+"**");
      }
    }
  }else if(choose==5){
    //hard
    if(y<9){
      if(millis()-xTime>500){
        x=random(5); 
        b=a;
        nowx=(int)x/1;
        if(nowx==oldx){
          if(nowx==4){
            x=1;
            oldx=(int)x/1;
          }else if(nowx==5){
            x=2;
            oldx=(int)x/1;
          }else{ 
            x=x+1;
            oldx=(int)x/1;
          }  
        }else oldx=(int)x/1;
        if(x>0 && x<=1){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="1";
        }else if(x>1 && x<=2){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi2,150,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="2";
        }else if(x>2 && x<=3){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi3,250,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi4,350,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="3";
        }else if(x>3 && x<=4){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi4,350,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi5,450,100,100,100);
          a="4";
        }else if(x>4 && x<=5){ 
          fill(0,0,0);
          rect(0,0,600,400);
          image(mioumi5,450,100,100,100);
          image(gmioumi1,50,100,100,100);
          image(gmioumi2,150,100,100,100);
          image(gmioumi3,250,100,100,100);
          image(gmioumi4,350,100,100,100);
          a="5";
        } 
        xTime=millis();
        y=y+1;
        if(b!=a){ 
          str=str+a;
          println(str);
          z=0;
        }else if(z==0 && b==a){
          str=str+a;
          println(str);
          z=1;
        } 
      }else if(millis()-xTime>200 && millis()-xTime<400){
        fill(0,0,0);
        rect(0,0,600,400);
        image(gmioumi1,50,100,100,100);
        image(gmioumi2,150,100,100,100);
        image(gmioumi3,250,100,100,100);
        image(gmioumi4,350,100,100,100);
        image(gmioumi5,450,100,100,100);
      }
    }else if(e==2){
      fill(0,0,0);
      rect(0,0,600,400);
      image(gmioumi1,50,100,100,100);
      image(gmioumi2,150,100,100,100);
      image(gmioumi3,250,100,100,100);
      image(gmioumi4,350,100,100,100);
      image(gmioumi5,450,100,100,100);
    }
    if(c!=oldstr2){
      if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ 
        oldstr2=c;
        str2=str2+c;
        println("**"+str2+"**");
        e=3;
      }
    }
  }
  
  if(str=="" || str2==""){
    str="1";
    str2="1";
  }
  
  f=Integer.parseInt(str);
  g=Integer.parseInt(str2);

  //f= new Integer(str).intValue();
  //g= new Integer(str2).intValue(); 
  
  if(c=="6" && e==2){
    if(f==g){
      image(pass,0,0,600,400);
    }else if(f!=g){
      image(over,0,0,600,400);
    }
  }else if(c=="6" && e==3){
    if(f==g){
      image(win,0,0,600,400);
    }else{
      image(over,0,0,600,400);
    }
  }
  if(mousePressed && mouseX>500 && mouseY>300){
    if(choose==1){ 
      choose=3;
      str="";
      str2="";
    }else if(choose==3){ 
      choose=5;
      str="";
      str2="";
    }
    e=1;
  }else if(mousePressed && mouseX<100 && mouseY>300){
    image(End,0,0,600,400);
    c="0";
    e=4;
  }  
}


五,影片
課堂Demo影片:


這是成功最難的關卡之後的影片和畫面:
是顛倒的,抱歉QQ



六,心得
這次的遊戲,在規則上和設計上其實不難,但是我們寫程式的經驗依然不多,導致在過程中遇到了不少有關判斷式與環境不熟悉的問題,也因為這學期實在太多大型作業擠在一起的關係,看到我們自己與各組的作品完成度都沒有很高,感覺有點失望。
我們也是在考完期末考後的幾天才開始趕工、拚到凌晨,雖然很辛苦,但是也學到不少東西,是個難忘的回憶。對我們來說,這作業不只是學到技術層面的東西,也讓我們學到人與人之間的互先幫助與默契。對我們而言,這才是最可貴的。
程式方面,還是有一些bug未修復,但是,我們想說還是有機會的話能把它解決,讓作品呈現最完美的狀態。最後,還是感謝老師、助教和所以同學對我們作品的幫忙與支持。
謝謝 : D