顯示具有 期末 標籤的文章。 顯示所有文章
顯示具有 期末 標籤的文章。 顯示所有文章

2013年1月18日 星期五

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的程式上,我們花了不少時間去研究,也學到了不少的東西.

2013年1月15日 星期二

Week19,final,project

作品名稱:划船遊戲

1. 遊戲進行及裝置介紹

首先是開頭畫面



再來是進入到遊戲畫面



然後努力滑要到終點了 ! !



















如果在時間內趕上終點  你就贏了

就會顯示贏的畫面




















如果沒辦法就會顯示輸的畫面



















這是我們 arduino 的裝置圖 - 划船裝置




這張是裝置的內部

是採用彈簧與桿子的槓桿原理做出划船力道的模擬








我們把按鈕黏上彈簧讓控制時需要力道才能順利案到按鍵

然後利用保麗龍塊固定按鈕位置


















接者是控制示意圖



























下面是遊戲進行畫面 方向示意圖

右上角是剩餘時間





















2. 遊戲玩法說明

        當畫面一開始,就按下紅色開始鍵開始遊戲,雙手放在桿子上,模擬划船的槳
當手往前推動,遊戲畫面中的船就會往該方向前去,而在 30 秒內要到達終點
如果 30 秒內抵達就是任務達成,否則就是任務失敗遊戲結束


3. 心得

        這個划船遊戲能夠完整的利用裝置來操控,真的是非常的幸運
在整個遊戲作品的製作過程中,遇見了許許多多的問題,有和一些同學們共同討論解決
謝謝他們提供的建議和解決方式,也謝謝助教建議的軟體與硬體操控的方向 :)

         在完成裝置之前都是理想中的設計裝置,製作過程中便是狀況一堆
不僅僅是按鈕和搖桿的結合,再加上 arduino 接線、程式撰寫等等搭配,遇到的問題真不少
尤其是裝置的方形按鈕與接線處頻頻出錯,一下是按鈕壞掉接觸不良,一下是接線鬆掉
後來嘗試用了課堂上做的小鋼琴按鈕,結果卻是如我們預期的控制船的方向移動

        但這樣就要捨棄掉利用桿子進行操控裝置的方法,讓我們非常挫折與無奈
也因為捨棄掉操控裝置的方法可惜,我們不斷地的嘗試,看還有甚麼方式能補救
運氣很好的,在我們裝上小按鈕,再接上方形按鈕後卻可以操控了 ! ! ! ! !
划船裝置也在那時候如我們預期成果般地完成,順利地完成 demo
也很感謝同學和老師、助教的肯定,讓我們獲得了獎品,謝謝大家 :D

        很開心這學期學到了這麼多和互動相關的東西,這堂課很充實 :P 
我們從同學、老師、助教身上學到很多寶貴的經驗、程式撰寫技巧以及遊戲設計概念等等
也完成兩個簡單的小作品,雖然這兩個小作品不是非常的完整 ˊ  ˇ  ˋ
但對我們來說是很好的經驗,也讓我們更了解自己不足的地方,希望之後能表現得更好:D

4. 遊戲 demo 影片



5. 作品分工狀況


遊戲作品構思:王靚暄、詹中豪
遊戲背景素材貼圖:王靚暄
遊戲程式:王靚暄、詹中豪
遊戲裝置構思:詹中豪
遊戲裝置製做:王靚暄、詹中豪


6. 程式碼
*processing

import processing.serial.*;
Serial myPort;
PImage sence1;
PImage sence3;
PImage sence4;
PImage ship;
PImage bg;
int W=1000,H=700;
float boatX=320,boatY=100, boatVX=0, boatVY=0;
float bgX=0,bgY=-1232;
int gameTime,s;
boolean ctrl=true;
int lastTime;
import ddf.minim.*; 
Minim minim; 
int testState=0;
AudioPlayer player;


void setup(){
  size(W,H);
  sence1 = loadImage("sence1.jpg");
  sence3 = loadImage("sence3.jpg");
  sence4 = loadImage("sence4.jpg");
  image(sence1,0,0);
  ship = loadImage("ship.png");
  bg=loadImage("bg.jpg");
  s=millis()/1000;
  minim = new Minim(this);
  myPort = new Serial(this,"COM3", 9600); 
   player = minim.loadFile("abdc.mp3");
  player.play();
}

void draw(){
  
  testState = myPort.read();
  println(testState);
  
  if (testState=='G') {
    ctrl=false;
  }
   if(ctrl==true){
    s = millis();
    image(sence1,0,0); 
    } 
    else if(ctrl==false){{
    image(bg, bgX, bgY);
    if (bgY>0)
    bgY=0;
    boat(boatX, boatY);
    boatMove();
    
  }
  
    fill(255,0,0);
    textSize(60);

    lastTime = millis()- s; 
    gameTime = 30-lastTime/1000;  
    text(gameTime,900,70); 
  
  
  
    if(gameTime>0 && bgY==0){
    image(sence4,0,0);
    
    } 
    else if(gameTime <=0){
    image(sence3,0,0);
    gameTime = 0;
    
    }
  
    }
}
boolean [] keys=new boolean[250];
void boatMove() {
  if ( testState == 'A') {
    boatVY-=1;
    boatVX+=1;
    if (boatVX<0)boatVX=0;
    if (boatVY>-0.5)boatVY=-0.5;
  }
  if (testState == 'S') {
    boatVX-=0.5;
    boatVY-=0.5;
    if (boatVX<-1)boatVX=-1;
    if (boatVY>-0.5)boatVY=-0.5;
  }
  
  boatX+=boatVX;
  boatY+=boatVY;
  if (boatY<H/2) {
  bgY-=(boatY-H/2);
  boatY=H/2;
  }
  if (boatX<0) {
    boatX=0;
  }
   if (boatX>600) {
    boatX=600;
  }
  
  if (boatY>650) {
    boatY=650;
  }
  
  
  boatVY*=0.9;
  boatVX*=0.9;
}





void keyPressed() {
 if (testState=='G') {
   ctrl=false;
  }
  else if (testState=='A') {
    boatVY-=1;
    boatVX+=1;
  }
  else if (testState=='S') {
    boatVX-=0.5;
    boatVY-=0.5;
  }
  
}

void keyReleased() {
 if (testState=='A') {
    boatVY=0;
    boatVX=0;
  }
  else if (testState=='S') {
    boatVX=0;
    boatVY=0;
  }
} 

void boat(float X, float Y) {
  image(ship, boatX, boatY);
}



*arduino
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton2= 2;
int pushButton3 = 3;
int pushButton4 = 4;
int buttonState2 =0;
int buttonState3 =0;
int buttonState4 =0;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton2, INPUT);
pinMode(pushButton3,INPUT);
pinMode(pushButton4,INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState2 = digitalRead(pushButton2);
int buttonState3 = digitalRead(pushButton3);
int buttonState4 = digitalRead(pushButton4);
// print out the state of the button:
if (buttonState2 == HIGH) {     
   Serial.write('A');
  } 
  if (buttonState3== HIGH) {     
   Serial.print('S');
  }
  if (buttonState4 == HIGH ) {     
    Serial.print('G');
    buttonState4 = 1;}

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

2013年1月14日 星期一

Week 19, Final Project

processing
import processing.serial.*;
Serial myPort;
int now=1;
int val;
int ballY=607;
int ballX=367;
float monsterX,monster2X,monster3X,monster4X,monster5X;
float monsterY,monster2Y,monster3Y,monster4Y,monster5Y;
float startX=0;
float start2X=0;
float start3X=0;
float start4X=0;
float start5X=0;
import ddf.minim.*;
AudioPlayer backmusic,stopcar,frogsound;
Minim minim;
PImage img0,img1,img2,img3,img4,img5,
img6,img7,img8,img9;

void setup()
{
size(800,700);
img0=loadImage("background.png
");
img1=loadImage("frog.gif");
img2=loadImage("show3.png");
img3=loadImage("car1.gif");
img4=loadImage("car2.gif");
img5=loadImage("car3.gif");
img6=loadImage("car4.gif");
img7=loadImage("car5.gif");
img8=loadImage("show4.png");
img9=loadImage("show0.png");
monsterX=0;
monster2X=0;
monster3X=0;
monster4X=0;
monster5X=0;
String portName=Serial.list()[0];
myPort=new Serial(this,"COM3",9600);
minim=new Minim(this);
backmusic=minim.loadFile("back
music.mp3", 2048); //music
backmusic.play();
}
void show1(){
image(img9,0,0);
}
void show2(){
image(img0,0,0);
image(img1,ballX,ballY,70,90);
}
void show3(){
image(img2,0,0);
}
void show4(){
image(img8,0,0);
}
void draw(){
while(myPort.available() >0) val=myPort.read();


if(now==1){
show1();
if(mousePressed&&mouseX>=0&&mo
useX<=700&&mouseY>=0&&mouseY<=800) now=2;
if (val=='a') now=2;
if (val=='c') now=2;
if (val=='e') now=2;
if (val=='g') now=2;

}
if(now==2){
show2();

monsterX-=4;
monsterY=520;
image(img3,monsterX,520);
if (monsterX<-100) {
monsterX +=800;
}
monster2X-=8;
monster2Y=440;
image(img4,monster2X,440);
if (monster2X<-100) {
monster2X +=800;
}
monster3X+=5;
monster3Y=360;
image(img5,monster3X,360);
if (monster3X>+800) {
monster3X -=900;
}
monster4X-=8;
monster4Y=270;
image(img6,monster4X,monster4Y
);
if (monster4X<-100) {
monster4X +=800;
}
monster5X+=6;
monster5Y=190;
image(img7,monster5X,monster5Y
);
if (monster5X>+800) {
monster5X -=800;
}
if(ballX<monsterX+45&&ballX>mo
nsterX-45&&ballY>monsterY-45&&ballY<monsterY+45)
{
now=4;
stopcar=minim.loadFile("stop.w
av", 2048);
stopcar.play();
monsterX+=800;
ballY=607;
ballX=367;
}
if(ballX<monster2X+45&&ballX>m
onster2X-45&&ballY>monster2Y-45&&ballY<monster2Y+45)
{
now=4;
stopcar=minim.loadFile("stop.w
av", 2048);
stopcar.play();
monster2X+=800;
ballY=607;
ballX=367;
}
if(ballX<monster3X+45&&ballX>m
onster3X-45&&ballY>monster3Y-45&&ballY<monster3Y+45)
{
now=4;
stopcar=minim.loadFile("stop.w
av", 2048);
stopcar.play();
monster3X+=800;
ballY=607;
ballX=367;
}
if(ballX<monster4X+45&&ballX>m
onster4X-45&&ballY>monster4Y-45&&ballY<monster4Y+45)
{
now=4;
stopcar=minim.loadFile("stop.w
av", 2048);
stopcar.play();
monster4X+=800;
ballY=607;
ballX=367;
}
if(ballX<monster5X+45&&ballX>m
onster5X-45&&ballY>monster5Y-45&&ballY<monster5Y+45)
{
now=4;
stopcar=minim.loadFile("stop.w
av", 2048);
stopcar.play();
monster5X+=800;
ballY=607;
ballX=367;
}
if (val=='a')ballY-=6; //top
if (val=='c')ballY+=6; //down
if (val=='e')ballX+=8; //right
if (val=='g')ballX-=8; //left
if(ballY>608)ballY=607;
if(ballY<-5)ballY=-4;
if(ballX>728)ballX=727;
if(ballX<2)ballX=3;
if(ballY<20&&ballX<410&&ballX>
325)now=3;
if(ballY<20&&ballX<410&&ballX>
325)ballY=607;
if(ballY<20&&ballX<410&&ballX>
325)ballY=367;
println("monster5Y:"+ballY+" monster5X:"+monster5X);
}
if(now==3){
show3();
if(mousePressed&&mouseX>=680&&
mouseX<=770&&mouseY>=590&&mouseY<=690)
now=2;
}
if(now==4){
show4();
if(mousePressed&&mouseX>=680&&
mouseX<=770&&mouseY>=590&&mouseY<=690)
now=2;
}
}
arduino

/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
int pushButton2 = 3;
int pushButton3 = 4;
int pushButton4 = 5;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
pinMode(pushButton2, INPUT);
pinMode(pushButton3, INPUT);
pinMode(pushButton4, INPUT);
}
int a1=0;
int a2=0;
int a3=0;
int a4=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);
int buttonState4 = digitalRead(pushButton4);
// print out the state of the button:
if (buttonState == HIGH && a1==0 ) { // If switch is ON,
Serial.print('a');
a1=1; // send 1 to Processing
}
if (buttonState == LOW && a1==1) { // If the switch is not ON,
Serial.println('b');
a1=0; // send 0 to Processing
}
if (buttonState2 == HIGH && a2==0 ) { // If switch is ON,
Serial.print('c');
a2=1; // send 1 to Processing
}
if (buttonState2 == LOW && a2==1) { // If the switch is not ON,
Serial.println('d');
a2=0; // send 0 to Processing
}
if (buttonState3 == HIGH && a3==0 ) { // If switch is ON,
Serial.print('e');
a3=1; // send 1 to Processing
}
if (buttonState3 == LOW && a3==1) { // If the switch is not ON,
Serial.println('f');
a3=0; // send 0 to Processing
}
if (buttonState4 == HIGH && a4==0 ) { // If switch is ON,
Serial.print('g');
a4=1; // send 1 to Processing
}
if (buttonState4 == LOW && a4==1) { // If the switch is not ON,
Serial.println('h');
a4=0; // send 0 to Processing
}
// Serial.println(buttonState);
delay(10); // delay in between reads for stability
}

http://www.youtube.com/watch?v=g0ORjiFmzmU

Week 19, Final Project

系統名稱: 傳奇戰役 (Rise of The Argonauts)


目的: 

  能夠單純使用一支手控制、遊玩一個2D橫軸的遊戲,能夠控制英雄在眾多怪獸中生存,依據殺敵數量不同而得到不同的分數。並能夠在排行榜中爭取高分!

遊戲畫面:

開始畫面(按下即可開始)


進入遊戲畫面,怪物一定間格時間會產生一隻,並隨機產生其中一種及方向


攻擊畫面,成功擊殺怪物分數增加


可以跳躍迴避攻擊


受到攻擊時,左上角的血量會減少


成績排行(白色代表你當次遊戲的成績)


遊戲設備介紹及控制方法:

  控制手套(正面)


控制手套(背面)


以下同時為控制介紹:

正面(同時為遊戲初始狀態,靜止不動)


控制人物左移


控制人物右移


紅色按鈕為攻擊



附註:手向上甩,人物跳躍

如何製作:

  環境:

    作業系統:Windows 7
    硬體主機板:Arduino
    軟體撰寫:Processing(Java) + Arduino(C)

  製作重點:
      遊戲分為main、Hero Class以及Monster Class,主要撰寫的部分
    是Class。在那二個Class中分別記錄大小、生命值、座標、方向、
    向上跳躍的向量以及攻擊力及攻擊間隔,再各別撰寫函式去控制
    。

      而Serial傳遞數值的部分全部放在serialControl()函數裡面,以便
    於撰寫及控制。排行部分則是使用reader and writer去讀取以及寫檔
    。

程式碼:

Arduino:

#include <string.h>

int btn_left = 2;
int btn_right = 3;
int btn_atk = 4;
int past_leftState =1;
int past_rightState = 1;
int past_atkState = 1;
void setup() {
  Serial.begin(9600);
  pinMode(btn_left, INPUT_PULLUP);
  pinMode(btn_right, INPUT_PULLUP);
  pinMode(btn_atk, INPUT_PULLUP);
}
void loop(){
  int leftState = digitalRead(btn_left);
  int rightState = digitalRead(btn_right);
  int atkState = digitalRead(btn_atk);
  if(past_leftState != leftState) Serial.print(0);
  if(past_rightState != rightState) Serial.print(1);
  if(past_atkState != atkState && atkState == 0) Serial.print(2);
  past_leftState = leftState ;
  past_rightState = rightState ;
  past_atkState = atkState ;
  delay(10);        // delay in between reads for stability
}
Processing 

main

import processing.serial.*;
import java.io.*;
import java.util.*;
import ddf.minim.*;
import java.util.Arrays;
//define
final static int SIZE = 3;
final static int ATK_TIME = 15;

//file process about (in fact , is about rank )
BufferedReader rank;
PrintWriter rankin;

//Music about
Minim minim;
AudioPlayer groove,p;
//Serial
Serial myPort;
//linked list
List<monsterClass> lt;
//hero class
heroClass hero = new heroClass(50,75);
//control kind of avtivity
boolean[] ctl = new boolean[SIZE] ;
//Number Image
PImage[] num = new PImage[10];
//back ground img
PImage img_bg_game = loadImage(basicPath + "background\\gameBg.png");
PImage img_start = loadImage(basicPath + "background\\start.jpg");
//parameter
int ctlEnd = 0;
int grade=0;
int count;
int monsterNumber=0;
int nowRunFrame=0;
int monsterNewTime=50;
int dtime = 0;
//0:: game , 1:: rank ,  2::start
int type = 2;
void setup()
{
  size(640, 480);
  //load music
  minim = new Minim(this);
  groove = minim.loadFile(basicPath + "sound\\1.mp3", 512);
  p = minim.loadFile(basicPath + "sound\\atk.mp3", 512);
  groove.loop();
  //initialize
  lt = new LinkedList<monsterClass>();
  myPort = new Serial(this,"COM3", 9600);
  for(int i=0;i<SIZE;i++) ctl[i] = false;
  for(int i=0;i<10;i++) num[i] = loadImage(basicPath + "number\\" + i + "b.png");
}

void draw()
{
  if(type == 0){
    ctlEnd = 0 ;
    //contorl monster create time
    if(++nowRunFrame>monsterNewTime){
      monsterNewTime = 50;
      //add to list
      monsterClass m = new monsterClass(50,75,(int)random(0,199.99));
      lt.add(m); 
      monsterNumber++;
      nowRunFrame=0;
    }
    
    image(img_bg_game,0,0);
    fill(255,0,0);
    rect(0,0,hero.getHealth()*2,50);
    //show hero
    hero.showImage();
    //show grade
    showGrade();
    //detector monsters motion and attack
    for(int i=0;i<lt.size();i++){
      lt.get(i).move(hero.getPoint());
      lt.get(i).showImage();
      hero.setHealth(lt.get(i).atkDetector(hero.getPoint()));
      if(hero.getHealth() <=0) type =1;
    }
    //serial control about
    serialControl();
    if(count>0) grade += hero.atk(lt);
    //control attack img show time
    count--;
  }
  else if(type == 2 ){
     serialControl();
     image(img_start,0,0,640,480);
     dtime--;
  }
  else{
    dtime--;
    serialControl();
    background(0);
    rank=createReader(basicPath + "data\\rank.txt");
    int[] rankArr = new int[11];
    for(int i=0;i<10;i++){
      try{
          rankArr[i] = int(rank.readLine());
          println(rankArr[i]);
       } 
       catch (IOException e) {
          e.printStackTrace();
       }  
    }
    rankArr[10] = grade;
    Arrays.sort(rankArr);
    for(int k=1;k<11;k++){
      int temp=rankArr[k]*10;
      fill(255);
      if(grade == rankArr[k]) rect(650-240-k*25-5,100+(9-k)*35,230,35);
      image(num[10-k],650-240-k*30-60,100+(9-k)*35,50,50);
      for(int i=3;i>=0;i--)
         image(num[(temp/=10)%10],650-60*(4-i)-k*25,100+(9-k)*35,40,40);
    }
     if(ctlEnd == 1 && dtime<=0){
       rankin=createWriter(basicPath + "data\\rank.txt");
       for(int i=1;i<11;i++) rankin.println(rankArr[i]);
       rankin.flush();
       rankin.close();
       type = 2;
       for(int i=0;i<lt.size();i++) lt.remove(i--);
       hero.setHealth(100);
       grade = 0;
       dtime = 500;
     }
  }
}
void showGrade()
{
  
   int temp=grade*10;
   for(int i=3;i>=0;i--)
     image(num[(temp/=10)%10],640-60*(4-i),0,60,60);
   
}
void serialControl()
{
  int temp;
  if ( myPort.available() > 0){
    temp =myPort.read();
    //If btn push is attack
    if((temp - 48) == 2){
      if(type == 1 ) ctlEnd = 1;
      else if(type == 2 && dtime <= 0){
        type = 0;
        dtime = 500; 
      }
      else if(type== 0){
        grade += hero.atk(lt);
        count=ATK_TIME; 
        p.play(0);
      }
    }
    else ctl[temp-48] = !ctl[temp-48];
  }
  // if left and right together is jump
  if(ctl[0] == true && ctl[1] == true) hero.setJump(17);
  //left
  else if(ctl[0] == true){
     hero.setPoint(hero.getPoint().x-3,hero.getPoint().y);
     hero.setState(FACE_LEFT);
  }
  //right
  else if(ctl[1] == true){
     hero.setPoint(hero.getPoint().x+3,hero.getPoint().y);
     hero.setState(FACE_RIGHT);
  }
}

//Keyboard use

void keyPressed() {
  if (key == CODED) {
    if (keyCode == RIGHT || ctl[1] == true) {
      hero.setPoint(hero.getPoint().x+3,hero.getPoint().y);
      hero.setState(FACE_RIGHT);
    } 
    else if (keyCode == LEFT ) {
      hero.setPoint(hero.getPoint().x-3,hero.getPoint().y);
      hero.setState(FACE_LEFT);
    }
    else if(keyCode == UP){
      hero.setJump(17);
    }
    else if(keyCode == DOWN){
      grade += hero.atk(lt);
      count=ATK_TIME; 
      p.play(0);
    }
  }
}

class

final static String basicPath = "D:\\修\\學校課業\\大三\\互動技術\\期末作業\\game\\"; 
final static int ATK_DURING = 100;

//This class use to save site and size ( 2D information )
class Index2D
{
  public int x;
  public int y;
  public Index2D(int x,int y)
  {
    this.x = x;
    this.y = y; 
  }
};

//define :: To make me more easy to know
final static int FACE_RIGHT = 1;
final static int FACE_LEFT = 0;

class heroClass
{
  private Index2D point,size;
  private int health ;
  private int state ;  //Face 0 :: left , 1 :: right
  private PImage img,img_mirro ; 
  private PImage atk,atk_mirro ;
  private int w,h;
  private int vector;
  private boolean lock;
  
  public heroClass(int w,int h)
  {
     img = loadImage(basicPath + "role\\hero.png");
     img_mirro= loadImage(basicPath + "role\\hero_mirro.png");
     atk = loadImage(basicPath + "role\\attack.png");
     atk_mirro= loadImage(basicPath + "role\\attack_mirro.png");
     point = new Index2D(320-w,350-h);
     size = new  Index2D(w,h);
     state = vector = 0;
     lock = false;
     health = 100;
  }
  
  public void setHealth(int x)
  {
    health += x ;
  }
  public int getHealth()
  {
    return health; 
  }
  public PImage getImage()
  {
    return img;
  }
  public Index2D getPoint()
  {
    return point; 
  }
  public Index2D getSize()
  {
    return size; 
  }
  public void showImage()
  {
    point.y -= vector;
    
    //Jump parameter
    if(point.y +size.y!=350){
      vector-=1;
      lock = true;
    }else{
      vector = 0;
      lock = false ; 
    }
    //do not over the window board
    point.x = point.x < 0 ? 0 : point.x;
    point.x = point.x > 640-size.x ? 640-size.x : point.x;
    //control face which site
    if(state == FACE_LEFT ) image(img,point.x,point.y,size.x,size.y);
    else image(img_mirro,point.x,point.y,size.x,size.y);
  }
  public void setPoint(int x , int y)
  {
    point.x = x;
    point.y = y;
  }
  public void setState(int type)
  {
    state = type; 
  }
  public void setJump(int h)
  {
    if(lock == false ) vector = h ;
  }
  public int atk(List<monsterClass> lt)
  {
    //return value is kill number and will add to grade
    int tmp;
    int killNum = 0;
    if(state == FACE_LEFT ) image(atk,point.x-size.x,point.y,size.x,size.y);
    else image(atk_mirro,point.x+size.x,point.y,size.x,size.y);
    
    for(int i=0;i<lt.size();i++){
      //get monster's x site
      tmp =lt.get(i).getPoint().x;
      if(state == FACE_LEFT){
        //if is in range      reduce their life point
         if(tmp >= point.x-size.x && tmp <= point.x){
           lt.get(i).setHealth(-5);
           if( lt.get(i).getHealth()<=0){
             lt.remove(i--);
             killNum++; 
           }
         }
      }
      else{
        if(tmp >= point.x && tmp <= point.x+size.x){
           lt.get(i).setHealth(-50);
           if( lt.get(i).getHealth()<=0){
             lt.remove(i--);
             killNum++;
           }
         }
      }
    }
    return killNum;
  }
 
};

class monsterClass
{
  private Index2D point,size;
  private int health ;
  private int state ;  //Face 0 :: left , 1 :: right
  private PImage img,img_mirro ; 
  private PImage atk;
  private int w,h;
  private int type; 
  private int during,atkPower; //during is how long will attack hero
  private boolean lock ;
  private int count;
  
  public monsterClass(int w,int h,int t)
  {
    count = 0;
    lock = false;
    //t use to decide which kind monster will appear and their parameter
     if( t < 10){
       img = loadImage(basicPath + "role\\monster.png");
       img_mirro= loadImage(basicPath + "role\\monster_mirro.png");
       atk = loadImage(basicPath + "role\\matk.png");
       health = (int)random(200,1000.99);
       during = 40;
       atkPower = -25;
       type = 0;
     }
     else{
       img = loadImage(basicPath + "role\\monster2.png");
       img_mirro= loadImage(basicPath + "role\\monster2_mirro.png");
       atk = loadImage(basicPath + "role\\matk.png");
       health = 50;
       during = 30;
       atkPower = -5;
       type = 1;
     }
     //decide which site will appear
     if(t%2 == 1) state = FACE_LEFT;
     else state = FACE_RIGHT;
     if(state == FACE_LEFT) point = new Index2D(640,350-h);
     else point = new Index2D(0-w,350-h);
     //if is a stronge monster will become bigger;
     if(type == 0){
       size = new Index2D(w*2,h*2);
       point.x -= w;
       point.y -= h; 
     }
     else size = new Index2D(w,h);
  }
  public void setHealth(int x)
  {
    health+=x;  
  }
  public int getHealth()
  {
     return health; 
  }
  public Index2D getPoint()
  {
    return point; 
  }
  public void move(Index2D hero)
  {
    if(lock == false){
      if (point.x < hero.x ) state = FACE_RIGHT ;
      else state = FACE_LEFT ;
      
      if(state == FACE_LEFT ){
        if(type == 0) point.x -= 1;
        else point.x-=2; 
      }
      else{
         if(type == 0) point.x += 1;
        else point.x+=2; 
      }
    }
    
  }
  public int atkDetector(Index2D hero)
  {
    //detector is hero in the attack range 
    //if yes !!  will increase the during time
    //when is over the threshold will attack and do not miss!! XD
    if(hero.y >= point.y-5){
      if(state == FACE_LEFT) {
         if(hero.x > point.x - size.x && hero.x < point.x){
            during++;
            lock = true;
         }
         else lock = false;
      } 
      else{
         if(hero.x < point.x+size.x && hero.x > point.x){
            during++;
            lock = true;
         } 
         else lock = false;
      }
      if(during > ATK_DURING){
         during = 0;
         count = 12;
         return atkPower; 
      }
      else return 0;
    }
    else return 0;
  }
  public void showImage()
  {
    if(state == FACE_LEFT ) image(img,point.x,point.y,size.x,size.y);
    else image(img_mirro,point.x,point.y,size.x,size.y);
    if(count-->0) atk();
  }
  public void atk()
  {
    if(state == FACE_LEFT ) image(atk,point.x-size.x,point.y,size.x,size.y);
    else image(atk,point.x+size.x,point.y,size.x,size.y);
  }
};

小組分工:

Processing、Arduino、硬體部分:徐修謙
購買硬體:謝睿峰

心得:

在這次的作業當中,深深的體會到接駁硬體的困難。不過在製作的過程中,雖然困難但是是非常有趣的,將一段段的線路銜接,最後所製作而成的作品出現,這是非常有成就感的。而程式部分,由於沒有直接使用期中作業去更改,在最後的製作過程其實並不輕鬆。每一個怪物以及英雄所寫成的class,其實也耗費的不少的力氣。雖然以後不太會用到它,不過這個class其實寫出來有不錯的後續延伸性,如果未來我有需要用到相關的功能也可以直接套用就好,不過這好像短期內不太可能。總而言之、言而總之,在這次作業讓我對java更加熟悉,而且也了解到硬體以及電腦軟體之間的通訊,是甚麼一回事,有很大的收穫,也很開心。

Week19 Final Project



系統名稱:接香菇瑪利歐


圖片:

此圖為遊戲開始畫面

此圖為遊戲進行畫面

此圖為硬體arduino線路接法
 
 
 
 

心得介紹

這次期末作業從單純的processing加上硬體arduino,一開始我們不太會接arduino到後來自己成功的做出自己的期末作品,雖然只是按鈕功能,但還是很有趣。我們的遊戲計分方式分別是紅色的香菇代表得五分,綠色的香菇代表得一分,怪物代表減生命值,金幣可以讓生命值增加一個。我們設計這樣的遊戲計分方面玩遊戲的人可以增加遊戲的刺激度。

影片

這是遊戲失敗的影片



這是遊戲過關的影片




組員分工情況

邱舒曼之負責工作:

1 撰寫部落格
2.寫processing遊戲的計分程式
3.寫arduion連接processing部分的程式

潘瀅玉 之負責工作:

1.拍攝成果的影片
2.寫processing遊戲的兩種香菇、怪物、金幣的掉落方式
3.接arduion的按鈕,負責接硬體




2013年1月13日 星期日

Week19,Final project

期末作業
遊戲名稱:角子老虎


影片介紹&課堂DEMO




<程式部分 後面有全部的程式>

遊戲方法:
<遊戲登入畫面一  進入畫面>
1. 按任意鍵進入遊戲

<遊戲畫面二 介紹畫面>
2. 配錢方式:7--100$,其他水果--10$

<遊戲畫面三 開始拉罷>
3. 首先滑鼠左鍵點任意位置,下注金額Bet(左下角)

<遊戲畫面四 停止>
4.  接著按Arduino箱子Start按鈕--開始,1按鈕--第一格停止,2按鈕--第二格停止




先使用 processing 建置遊戲畫面


Processing  程式碼


PImage logo; // 登入畫面
PImage logo2; // 登入畫面
PImage gamebg;  //遊戲畫面
PImage bingo; int bingo_show=0; //當bingo時 顯示時間
int value = 0,login=0; int a1=1,a2=1,a3=1;
int sx=125,sy=150,sp=0,sp_2=0,sp_3=0,stop_1,stop_2,stop_3; //sx,sy水果大小
int h=-590; //h-&rt;小於h回到bp點
int x1=70,x2=200,x3=337;
int y11=160,y12=y11+150,y13=y12+150,y14=y13+150,y15=y14+150,y16=y15+150;
int y21=160,y22=y21+150,y23=y22+150,y24=y23+150,y25=y24+150,y26=y25+150;
int y31=160,y32=y31+150,y33=y32+150,y34=y33+150,y35=y34+150,y36=y35+150;
int total=1000,bet,bet_t,money_state=0;
int userlogin=1,login_y=0,login_h=560;//登入畫面
int[] sum = new int[3]; //計分 sum[0]=第一區,sump[1]=第二區...
PImage[] img1 = new PImage[6];//  載入圖片
PImage[] img2 = new PImage[6];//  載入圖片
PImage[] img3 = new PImage[6];//  載入圖片

int state1=0,state2=0,state3=0;

void setup(){
  size(560,520);
  logo = loadImage("login.jpg");  //背景圖
  logo2 = loadImage("fruit.png");  //背景圖
  gamebg = loadImage("gamebg.png"); //遊戲畫面
  bingo = loadImage("bingo.png");
  for(int i=0,j=1;i<6;i++,j++) //載注水果圖
    img1[i] = loadImage(j+".png");
  for(int i=0,j=1;i<6;i++,j++) //載注水果圖
    img2[i] = loadImage(j+".png");
  for(int i=0,j=1;i<6;i++,j++) //載注水果圖
    img3[i] = loadImage(j+".png");
  
  for(int i=0,j=1;i<3;i++,j++) //初始為0;
    sum[i]=0;
}

void draw(){
  
  background(255);
  keyPressed();
  
  if(userlogin==0)  
  {
    sp_rect1(x1,sp);
    sp_rect2(x2,sp_2);
    sp_rect3(x3,sp_3);
  }
  image(gamebg,0,0);
  
  if(sum[0]&rt;0&&sum[1]&rt;0&&sum[2]&rt;0){ //比較停格後的圖是否為相同
    println(sum[0]+" "+sum[1]+" "+sum[2]);
    if(sum[0]==sum[1]&&sum[1]==sum[2]){ 
      money(sum[0]);
      println("bingo");
      sum[0]=0;
      bingo_show=100;      
    }
    sum[0]=0;
    bet=0;
  }
  if(bingo_show&rt;0){  //bingo 圖 出現 , 顯示時間 bingo_show --
    image(bingo,180,300,174,48);
    bingo_show--;
  }
  fill(0, 102, 153);
  String mm = String.valueOf(total);  //顯示金額
  String b = String.valueOf(bet);    //顯示下注金額
  textSize(30);
  text(b, 165, 460,110,50);
  text(mm,445,460,110,50);
  money();
  
  loginimage();
  //println(userlogin);
} 
void loginimage(){
  if(userlogin==1) image(logo,0,0);
  if(mousePressed&&userlogin==1)
  {
    userlogin=2; image(logo2,0,login_y);
  }
  if(userlogin==2&&login_h&rt;=0){
    image(logo2,0,login_y--);
    login_h--;
  }
  if(userlogin==2&&login_h==0){
    userlogin=0; println("-----start game!!-----");
  }
}
void money(){  //下注 下注金額 不得超過100元
  if(bet<100){
    if(mousePressed&&userlogin==0){
        bet+=10;
        total-=10;
      }
    if (keyPressed == true&&userlogin==0){
      if(key=='.'){
        bet+=10;
        total-=10;
      }
    }
  }
}

void money(int sum){  //計算獎金
  switch(sum) {
    case 1: 
      print("total="+total+"+"+bet*100);
      total=total+bet*100;
      //print("total:"+bet_t);
      break;
    case 2:
      print("total="+total+"+"+bet*10); 
      total=total+bet*10;
      break;
    case 3: 
      print("total="+total+"+"+bet*10); 
      total=total+bet*10;
      break;
    case 4: 
      print("total="+total+"+"+bet*10); 
      total=total+bet*10;
      break;  
    case 5: 
      print("total="+total+"+"+bet*10); 
      total=total+bet*10;
      break;
    case 6: 
      print("total="+total+"+"+bet*10); 
      total=total+bet*10;
      break;
  }
}

void keyPressed() {
  if (key == ' '&&bingo_show==0&&bet&rt;=10) {  //start
    sp=5;
    sp_2=5;
    sp_3=5;
    state1=0;
    state2=0;
    state3=0;
    sum[0]=0;
    sum[1]=0;
    sum[2]=0;
    bet_t=bet;
    //print("bet:"+bet_t);
  }
  if (key == '1') {  //stop
    sp=0;
    state1=1;
    photo_up1(x1);
    //print("state:"+state);
  }
  if (key == '2') {  //stop
    sp_2=0;
    state2=1;
    photo_up2(x2);
    //print("state:"+state);
  }
  if (key == '3') {  //stop
    sp_3=0;
    state3=1;
    photo_up3(x3);
    //print("state:"+state);
  }

}

void sp_rect1(int x1,int sp_y1){  //讓水果轉動
       // 每張圖大小為 150*125 開始位置 70,160
      image(img1[0],x1,y11=y11-sp_y1,sx,sy); //sp=speed, sx,sy=scale
      image(img1[1],x1,y12=y12-sp_y1,sx,sy);
      image(img1[2],x1,y13=y13-sp_y1,sx,sy);
      image(img1[3],x1,y14=y14-sp_y1,sx,sy);
      image(img1[4],x1,y15=y15-sp_y1,sx,sy);
      image(img1[5],x1,y16=y16-sp_y1,sx,sy);
      if(y11<h){  //當圖y1小於h 就 貼到最後一張
        y11=y16+sy;
      }
      if(y12<h){
        y12=y11+sy;
      }
      if(y13<h){
        y13=y12+sy;
      }
      if(y14<h){
        y14=y13+sy;
      }
      if(y15<h){
        y15=y14+sy;
      }
      if(y16<h){
        y16=y15+sy;
      }
}

void sp_rect2(int x2,int sp_y2){  //讓水果轉動
       // 每張圖大小為 150*125 開始位置 70,160
      image(img2[0],x2,y21=y21-sp_y2,sx,sy); //sp=speed, sx,sy=scale
      image(img2[1],x2,y22=y22-sp_y2,sx,sy);
      image(img2[2],x2,y23=y23-sp_y2,sx,sy);
      image(img2[3],x2,y24=y24-sp_y2,sx,sy);
      image(img2[4],x2,y25=y25-sp_y2,sx,sy);
      image(img2[5],x2,y26=y26-sp_y2,sx,sy);
      if(y21<h){  //當圖y1小於h 就 貼到最後一張
        y21=y26+sy;
      }
      if(y22<h){
        y22=y21+sy;
      }
      if(y23<h){
        y23=y22+sy;
      }
      if(y24<h){
        y24=y23+sy;
      }
      if(y25<h){
        y25=y24+sy;
      }
      if(y26<h){
        y26=y25+sy;
      }
}
void sp_rect3(int x2,int sp_y2){  //讓水果轉動
       // 每張圖大小為 150*125 開始位置 70,160
      image(img3[0],x2,y31=y31-sp_y2,sx,sy); //sp=speed, sx,sy=scale
      image(img3[1],x2,y32=y32-sp_y2,sx,sy);
      image(img3[2],x2,y33=y33-sp_y2,sx,sy);
      image(img3[3],x2,y34=y34-sp_y2,sx,sy);
      image(img3[4],x2,y35=y35-sp_y2,sx,sy);
      image(img3[5],x2,y36=y36-sp_y2,sx,sy);
      if(y31<h){  //當圖y1小於h 就 貼到最後一張
        y31=y36+sy;
      }
      if(y32<h){
        y32=y31+sy;
      }
      if(y33<h){
        y33=y32+sy;
      }
      if(y34<h){
        y34=y33+sy;
      }
      if(y35<h){
        y35=y34+sy;
      }
      if(y36<h){
        y36=y35+sy;
      }
}
//--------------------------------------------------------------------

void photo_up1(int ux1)
{
  //-----第一張圖--------------------------
  if(state1==1) {  //偵測Y停點 ,儲存y數值
      //println("start");
        if(160<=y11&&y11<310){
          stop_1=y11;
          //print("y1");
          sum[0]=1;
        }
        if(160<=y12&&y12<310){
          stop_1=y12;
          //print("y2");
          sum[0]=2;
        }
        if(160<=y13&&y13<310){
          stop_1=y13;
          //print("y3");
          sum[0]=3;
        }
        if(160<=y14&&y14<310){
          stop_1=y14;
          //print("y4");
          sum[0]=4;
        }
        if(160<=y15&&y15<310){
          stop_1=y15;
          //print("y5");
          sum[0]=5;
        }
        if(160<=y16&&y16<310){
          stop_1=y16;
          //print("y6");
          sum[0]=6;
        }
        
    }
    

  if(stop_1&rt;160) //圖片往上到偵測區塊定點
  {
    //println(stop_y);
    //testsp(stop_y);
    image(img1[0],ux1,y11=y11-1,sx,sy); 
    image(img1[1],ux1,y12=y12-1,sx,sy);
    image(img1[2],ux1,y13=y13-1,sx,sy);
    image(img1[3],ux1,y14=y14-1,sx,sy);
    image(img1[4],ux1,y15=y15-1,sx,sy);
    image(img1[5],ux1,y16=y16-1,sx,sy);
    stop_1-=1;
  }
  
}


void photo_up2(int ux2)
{
  //--------第二張圖-----------------------------

  if(state2==1) {  //偵測Y停點 ,儲存y數值
      //println("start");
        if(160<=y21&&y21<310){
          stop_2=y21;
          //print("y1");
          sum[1]=1;
        }
        if(160<=y22&&y22<310){
          stop_2=y22;
          //print("y2");
          sum[1]=2;
        }
        if(160<=y23&&y23<310){
          stop_2=y23;
          //print("y3");
          sum[1]=3;
        }
        if(160<=y24&&y24<310){
          stop_2=y24;
          //print("y4");
          sum[1]=4;
        }
        if(160<=y25&&y25<310){
          stop_2=y25;
          //print("y5");
          sum[1]=5;
        }
        if(160<=y26&&y26<310){
          stop_2=y26;
          //print("y6");
          sum[1]=6;
        }
        
    }
  if(stop_2&rt;160) //圖片往上到偵測區塊定點
  {
    //println(stop_y);
    //testsp(stop_y);
    image(img2[0],ux2,y21=y21-1,sx,sy); 
    image(img2[1],ux2,y22=y22-1,sx,sy);
    image(img2[2],ux2,y23=y23-1,sx,sy);
    image(img2[3],ux2,y24=y24-1,sx,sy);
    image(img2[4],ux2,y25=y25-1,sx,sy);
    image(img2[5],ux2,y26=y26-1,sx,sy);
    stop_2-=1;
  }
} 
  
void photo_up3(int ux3)
{
  //---------第三張圖---------------------------
  
  if(state3==1) {  //偵測Y停點 ,儲存y數值
      //println("start");
        if(160<=y31&&y31<310){
          stop_3=y31;
          //println("y1");
          sum[2]=1;
        }
        if(160<=y32&&y32<310){
          stop_3=y32;
          //println("y2");
          sum[2]=2;
        }
        if(160<=y33&&y33<310){
          stop_3=y33;
          //println("y3");
          sum[2]=3;
        }
        if(160<=y34&&y34<310){
          stop_3=y34;
          //println("y4");
          sum[2]=3;
        }
        if(160<=y35&&y35<310){
          stop_3=y35;
          //println("y5");
          sum[2]=5;
        }
        if(160<=y36&&y36<310){
          stop_3=y36;
          //println("y6");
          sum[2]=6;
        }
    }
    

  if(stop_3&rt;160) //圖片往上到偵測區塊定點
  {
    //println(stop_y);
    //testsp(stop_y);
    image(img3[0],ux3,y31=y31-1,sx,sy); 
    image(img3[1],ux3,y32=y32-1,sx,sy);
    image(img3[2],ux3,y33=y33-1,sx,sy);
    image(img3[3],ux3,y34=y34-1,sx,sy);
    image(img3[4],ux3,y35=y35-1,sx,sy);
    image(img3[5],ux3,y36=y36-1,sx,sy);
    stop_3-=1;
  }
} 
 左邊第一顆按鈕為開始(Start),右邊第一顆按鈕為第一格停止鍵,
第二顆按鈕為第二格停止鍵,第三顆按鈕為第三格停止鍵。
 
Arduino 程式碼

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton1 = 7;
int pushButton2 = 6;
int pushButton3 = 8;
int pushButton4 = 9;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton1, INPUT);
  pinMode(pushButton2, INPUT);
}

int oldState1=0;
int oldState2=2;
int oldState3=4;
int oldState4=6;
// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState1 = digitalRead(pushButton1);
  int buttonState2 = digitalRead(pushButton2);
  int buttonState3 = digitalRead(pushButton3);
  int buttonState4 = digitalRead(pushButton4);
  //----按鈕1----
  if(buttonState1==LOW && oldState1==0){  //按鈕1不按,訊號為0
  // print out the state of the button:
    Serial.print(0);
    oldState1=1;
  }
   if(buttonState1==HIGH && oldState1==1){  //按鈕1按下,訊號為1
  // print out the state of the button:
    Serial.print(1);
    oldState1=0;
  }
  //----按鈕2----
  if(buttonState2==LOW && oldState2==2){  //按鈕2不按,訊號為2
  // print out the state of the button:
    Serial.print(2);
    oldState2=3;
  }
  if(buttonState2==HIGH && oldState2==3){  //按鈕2按下,訊號為3
  // print out the state of the button:
    Serial.print(3);
    oldState2=2;
  }
  //----按鈕3----
  if(buttonState3==LOW && oldState3==4){  //按鈕2不按,訊號為2
  // print out the state of the button:
    Serial.print(4);
    oldState3=5;
  }
  if(buttonState3==HIGH && oldState3==5){  //按鈕2按下,訊號為3
  // print out the state of the button:
    Serial.print(5);
    oldState3=4;
  }
  //----按鈕4----
  if(buttonState4==LOW && oldState4==6){  //按鈕2不按,訊號為2
  // print out the state of the button:
    Serial.print(6);
    oldState4=7;
  }
  if(buttonState4==HIGH && oldState4==5){  //按鈕2按下,訊號為3
  // print out the state of the button:
    Serial.print(7);
    oldState4=6;
  }
  delay(10);        // delay in between reads for stability
}
心得介紹/組員分工情況 

由於這學期十分忙碌,許多課程都需要繳交期末作品,我們星期四考完期末考後便把時間都獻給互動期末作品了,星期五也繼續來在學校研究。主要分為兩大部分:Processing和Arduino,而工作分配由鍾毅軍負責Processing和吳姿儀負責Arduino。
Processing部分程式需要花時間Debug,這種方法不行就換別種方法。
Arduino部分線路常常接觸不良或者不牢固,導致在arduino接收訊號時會有問題,不是沒接收到就是一次跳太多訊號。以及按鈕的選擇似乎不恰當。
最後雖然還有些不足要修改,但還是謝謝和辛苦了!