顯示具有 HW12 標籤的文章。 顯示所有文章
顯示具有 HW12 標籤的文章。 顯示所有文章

2013年1月20日 星期日

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);
}

2013年1月19日 星期六

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);
}


2013年1月18日 星期五

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;
    }
}

2013年1月15日 星期二

Week15,HW12

期末進度

原本打算做出新的程式,但是沒有好的想法
可能還是使用期中作品的修改
但是其中的操作是使用滑鼠,要對應到Arduino可能還有問題
首先得先把鍵盤部分做出來。

2013年1月14日 星期一

Week16,HW12

將期末作品的進度寫出來~

目前進度:

processing程式碼:

import processing.serial.*;
Serial myPort;

PImage bg1,Do,Re,Mi,Fa,So,La,Si;

void setup() {
  size(800, 600);
  bg1 = loadImage("piano.jpg");  //載入圖檔
  Do = loadImage("piano-Do1.jpg");
  Re = loadImage("piano-Re1.jpg");
  Mi = loadImage("piano-Mi1.jpg");
  Fa = loadImage("piano-Fa1.jpg");
  So = loadImage("piano-So1.jpg");
  La = loadImage("piano-La1.jpg");
  Si = loadImage("piano-Si1.jpg"); 
  myPort = new Serial(this, "COM15", 9600);
}

void draw() {
  image(bg1, 0, 0, 800, 600);
  image(Do, 86, 82, 89, 333);
  image(Re, 169, 80, 89, 333);   
  image(Mi, 253, 81, 89, 333);;
  image(Fa, 338.5, 84, 89, 333);
  image(So, 425, 81, 89, 333);;
  image(La, 509, 82, 89, 333);
  image(Si, 593, 82, 89, 333);
}

----------------------------------------------------------------------------------------

arduino程式碼:

const int inPin1 = 1;
const int inPin2 = 2;
const int inPin3 = 3;
const int inPin4 = 4;
const int inPin5 = 5;
const int inPin6 = 6;
const int inPin7 = 7;

int val1 = 0, val2 = 0, val3 = 0, val4 = 0, val5 = 0, val6 = 0, val7 = 0;

void setup() {
   Serial.begin(9600);
  
   pinMode(inPin1, INPUT);
   pinMode(inPin2, INPUT);
   pinMode(inPin3, INPUT);
   pinMode(inPin4, INPUT);
   pinMode(inPin5, INPUT);
   pinMode(inPin6, INPUT);
   pinMode(inPin7, INPUT);
}

void loop() {
   val1 = digitalRead(inPin1);
   val2 = digitalRead(inPin2);
   val3 = digitalRead(inPin3);
   val4 = digitalRead(inPin4);
   val5 = digitalRead(inPin5);
   val6 = digitalRead(inPin6);
   val7 = digitalRead(inPin7);

      if(val1==HIGH){
         tone(8,524,8);
      }
      if(val2==HIGH){
         tone(8,588,8);
      }
      if(val3==HIGH){
         tone(8,660,8);
      }
      if(val4==HIGH){
         tone(8,698,8);
      }
      if(val5==HIGH){
         tone(8,784,8);
      }
       if(val6==HIGH){
         tone(8,880,8);
      }
       if(val7==HIGH){
         tone(8,988,8);
      }
}


----------------------------------------------------------------------------------------

找素材(圖片):




素材:一包冰棍、黑白色膠帶各一綑、一片珍珠板、
            七個方形按鈕、七個電阻、一個喇叭等。

----------------------------------------------------------------------------------------

心得:

  這次的期末作業,我們想要用冰棍來製作小型的鋼琴鍵。
  可以發出:Do、Re、Mi、Fa、So、La、Si的音階,並
  可以錄音由玩家彈奏的一段旋律,並有儲存、播放的功能。




2012年12月27日 星期四

Week15.HW12

本周將銜接上禮拜的繼續增加按鈕操控的部分
本已大致安排好按鈕位置與功能鍵

但好像跟其他組類似 所以我們有意改做其他的
因為計畫敢不上變化 重新會導致整個作業將從零開始
所以我們也將斟酌情況 製作出遊戲
因為時間緊迫 若成果未如預期 敬請包含
我們將繼續加油 。

2012年12月26日 星期三

Week15,HW12

期末作品進度

作品名稱: 划船遊戲


1、遊戲規則初步想法

利用兩個按鍵不斷輪替按著,讓船有加速度不斷前進,
接著計算其到達終點的時間,讓玩家挑戰最佳時間最短的紀錄。



2、確認作品操控以及進行的方向

我們的想法是由google和逆向思考的小遊戲所結合的,
這周我們討論遊戲的前進控制和玩法,
我們打算利用兩個按鈕控制他的前進方向,
小葉老師有建議我們利用旋鈕來做類似雙渦輪的設定,
但是後來發現,我們利用按鈕簡單的控制物體前進的加速度,
在配合他轉彎X值做加減以及背景地圖的不斷延伸,
就可以讓他有往左前和右前的方向以及速度控制。


3、素材貼圖





























4、心得

在規劃這作品前,我們最擔心的是按鈕的配合,
也就是arduino和processing的連接,因為沒有試過的經驗,
在小葉老師上課的範例中,我們有嘗試著做修改,
arduino是不是可以傳兩個不一樣的值,然後processing可以分別,
但是我們試了很久,還是搞不懂為甚麼他只給我們讀到一個按鈕的訊號,
這是我們這一周所遇到的問題,我們雖然只需要兩個按鍵,
但是這個問題會是我們期末作品最大的一個瓶頸,
所以我想可以馬上解決問題,往完整的作品邁向一大步。















2012年12月25日 星期二

Week15, HW12,

本周進度為成功時做了兩個按鈕,分別控制讓小人不掉落和重新開始遊戲的部分

本周電路板圖片



以下為本周程式碼

processing

import processing.serial.*;
Serial myPort;
int now;
int now2;
int testState=0;
//int testState2=0;
int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;
float dir = 1;  // current direction of the player (gravity vs pushing)
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1; // 遊戲狀態, 1=running, 0=lost, -1=lost and score printed
float cur_space = 450;  // space to play
float factor = 0.5;     // how far the cave can move max in the y axis for one x step
// the cave borders
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];
// the player (snake)遊戲的線
float[] yplayer = new float[cfg_width/2];
PFont myFont;
import ddf.minim.*;
Minim minim;
AudioPlayer player;

void initcave() {

  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;
  body=loadImage("bodyknife.png");

  for (int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for (int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}

void drawframe () {
  drawframe2 ();//我寫的背景變色程式
  // draw cave
  stroke(255, 0, 0);
  for (int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);
  }

  if (mode < 1) {
    stroke(0, 255, 0);
    strokeWeight(5);
    fill(100, 255, 0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
  people();
}
//背景變色程式在這邊~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void drawframe2 () {
  if (score/10<10) {//因為他計分我發現他是score有除以10 所以這邊也要把分數除10才會跟顯示的計分看起來一樣
    background(0, 0, 0);//小於10分
  }
  else if (score/10<=50) {
    background(0, 0, 255);//大於10分小於等於50分
  }
  else  if (score/10<100) {
    background(255, 255, 255);//大於等於50分小於100分
  }
  else  if (score/10>=100) {
    background(255, 255, 255);//大於等於100分
  } 
  //要把所有數值的情況考慮進去,不然畫面會閃一下。例如原本是小於100 和大於100 沒有寫道等於100的情況 那100分的時候遊戲畫面會閃一下
}
void people() {//小人改變大小
  for (int i=1; i<width/2; i++) {  
    if (score/10<50) {
      image(body, i, int(yplayer[i]), 80, 80);
    }
    else if (score/10<=100) {//大於50分 小於等於100分
      image(body, i, int(yplayer[i]), 60, 60);
    }
    else  if (score/10<150) {
      image(body, i, int(yplayer[i]), 30, 30);//大於100分小於150分
    }
    else  if (score/10>=150) {
      image(body, i, int(yplayer[i]), 30, 30);//大於等於150分
    }
  }
}

void setup()
{


  size(cfg_width, cfg_height);
  myPort= new Serial(this, "COM3", 9600);

  initcave();
  frameRate(100);
  minim = new Minim(this); //播音樂
  player = minim.loadFile("Kalimba.mp3");  //播音樂
   player.play();  //播音樂
    myFont = loadFont("SansSerif-12.vlw");
   textFont(myFont);
}

void drawscore()
{
  stroke(0);
  strokeWeight(3);
  fill(0);
  text("最高分紀錄: " + int(maxscore/10) + "  分數: " + int(score/10), 1, 12);//計分都有除10在這
  if (mode == -1) {
    text("Game Over!再玩一次.", 2, 26);
  }
}
void draw()
{

  while (myPort.available ()>0) {
    testState = myPort.read();
    println(testState);
    if (testState==49)
    {
      now = 1;
    }
    if (now==1)
      dir *= 0.997;
    if (testState=='a')
    {
      mode = 1;
      initcave();

    }

  if (mode == 1) {

    for (int i = 1; i < width; i++) {
      ylinetop[i-1] = ylinetop[i];
      ylinebottom[i-1] = ylinebottom[i];
    }
 
    for (int i = 1; i < width/2; i++) {
      yplayer[i-1] = yplayer[i];
    }
 
    ylinetop[width-1] =
      constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
      + ylinetop[width-1]
      , 0, height-int(cur_space+1));
    ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);

 
    dir = pow(cfg_gravity, dir) * dir;
 
    yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);


    if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
      mode = 0;
    }
 
    cur_space *= cfg_space_mod;

    score += 1;

    if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
      factor *= -1;
    }
  }
  else {  // collision detected
    if (mode == 0) {
      // save new max score
      maxscore = maxscore > score ? maxscore : score;
      mode = -1;
    }
  }
  drawframe();
  drawscore();
}

void keyPressed() {

  if (mode == 1 && key == '2') {
    dir *= 0.997;
  }

  if (mode == -1 && (key == '0' )) { //按0重新開始
    mode = 1;
    initcave();
  }
}

ardino

/*
  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;
// 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);
}
int a=0;
int a2=0;
// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  int buttonState2 = digitalRead(pushButton2);
  // 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('a');
    a2=1;      // send 1 to Processing
  }
  if (buttonState2 == LOW && a2==1) {                               // If the switch is not ON,
    Serial.println('b'); 
     a2=0;    // send 0 to Processing
  }
 // Serial.println(buttonState);
  delay(10);        // delay in between reads for stability
}


以下為我們的電路板




week15,hw12

1.void setup() {
  size(400, 200);
  background(255);
  noStroke();
  fill(102);
}
void draw() {
  fill(255, 255, 255);
  stroke(0, 0, 0);
  strokeWeight(2);
  rect(20, 20, 72, 160);
  rect(92, 20, 72, 160);
  rect(164, 20, 72, 160);
  rect(236, 20, 72, 160);
  rect(308, 20, 72, 160);
  fill(0);
  rect(74, 20, 36, 80);
  rect(146, 20, 36, 80);
  rect(290, 20, 36, 80);
  rect(362, 20, 18, 80);
 
}



畫出一個鋼琴鍵盤,之後再跟arduino結合,按出一個音,鋼琴鍵盤就會變紅色。

Week15,HW11

我們這組目前期末作業的計劃是要延續期中作品:大方快吃小方塊,期末再加上Arduino來連接四顆按鈕,上下左右來控制紅色方塊。

              
    現在我們的進度是在思考和修正如何將其中程式碼的滑鼠事件,轉換成按鈕來控制,也因為之前的程式碼只輸入了方塊只要跟著滑鼠移動而已,所以簡單許多,而這次要在加上四顆按鈕對我們來說也相對較困難,再加上要將之前遊戲執行後的問題想要一併解決,也就是有時候會一開啟就碰到大方塊就馬上遊戲結束的問題,因此也讓期末作業困難度又增加了。

week15,hw12

我們是打算使用之前其中的程式,作出類似實體的jubeat的遊戲,可選歌並將透明鍵盤放螢幕上在進行遊戲。

Week15,HW12

期末構想:角子老虎機
 目前進度:
所需素材、登入畫面和遊戲畫面


       















登入畫面



















遊戲畫面







素材

2012年12月19日 星期三

Week15, HW12,




  本周專心於探討將期中的processing作品如何和arduino做結合的部分,我們的期中作品是利用空白鍵控制挖洞穴的小人不一直掉下來得以前進,將原本利用空白鍵來控制的部分改用數字鍵2,希望可將此訊息傳到arduino中,將我們製做好的按鈕可以取代鍵盤來實作。

  日後更希望可以將重新開始遊戲的按鍵也能夠讓我們做的第二顆按鈕取代,而其中困難的部分將是思考如何將processing所傳送的按鍵訊息讓arduino收到並得以實踐。


程式碼



import processing.serial.*;
Serial myPort;

int testState=0;

int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;

float dir = 1;
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1;
float cur_space = 450;
float factor = 0.5;  

// the cave borders
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];

// the player (snake)遊戲的線
float[] yplayer = new float[cfg_width/2];

PFont myFont;

import ddf.minim.*;
Minim minim;
AudioPlayer player;


void initcave() {
 
  // game variables
  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;
 
  body=loadImage("bodyknife.png");
 
 

  for(int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for(int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}


void drawframe () {

    drawframe2 ();//我寫的背景變色程式

   stroke(255,0,0);
 
  for(int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);

  }

  if (mode < 1) {
    stroke(0,255,0);
    strokeWeight(5);
    fill(100,255,0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
     people();
}
//背景變色程式在這邊~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  void drawframe2 () {
  if (score/10<10){//因為他計分我發現他是score有除以10 所以這邊也要把分數除10才會跟顯示的計分看起來一樣
  background(0,0,0);//小於10分
  }
  else if (score/10<=50) {
    background(0,0,255);//大於10分小於等於50分

  }
  else  if (score/10<100){
  background(255,255,255);//大於等於50分小於100分
  }
   else  if (score/10>=100){
  background(255,255,255);//大於等於100分
  }
 //要把所有數值的情況考慮進去,不然畫面會閃一下。例如原本是小於100 和大於100 沒有寫道等於100的情況 那100分的時候遊戲畫面會閃一下
}

void people(){//小人改變大小
  for(int i=1; i<width/2; i++) {  
  if (score/10<50){
     image(body,i, int(yplayer[i]),80,80);
  }
  else if (score/10<=100) {//大於50分 小於等於100分
     image(body,i, int(yplayer[i]),60,60);

  }
  else  if (score/10<150){
     image(body,i, int(yplayer[i]),30,30);//大於100分小於150分
  }
  else  if (score/10>=150){
     image(body,i, int(yplayer[i]),30,30);//大於等於150分
  }

  }

}


void setup()
{
 
 
  size(cfg_width, cfg_height);
  myPort= new Serial(this,"COM3",9600);
  initcave();
  frameRate(100);
 
  minim = new Minim(this); //播音樂
  player = minim.loadFile("Kalimba.mp3");  //播音樂
 // player.play();  //播音樂
//  myFont = loadFont("SansSerif-12.vlw");
 // textFont(myFont);
}



void drawscore()
{
  stroke(0);
  strokeWeight(3);
  fill(0);
  text("最高分紀錄: " + int(maxscore/10) + "  分數: " + int(score/10), 1, 12);//計分都有除10在這~~~~~~~~~~~~~~~~~~~
 
  // when lost tell the player how to restart
  if (mode == -1) {
    text("Game Over!再玩一次.", 2, 26);
  }
}

void draw()
{
  println(testState);
   while(myPort.available()>0){
    testState = myPort.read();
    print(testState);
  }

 if (mode == 1) {

  for(int i = 1; i < width; i++) {
    ylinetop[i-1] = ylinetop[i];
    ylinebottom[i-1] = ylinebottom[i];
  }
 

  for(int i = 1; i < width/2; i++) {
    yplayer[i-1] = yplayer[i];
  }
 

  ylinetop[width-1] =
    constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
                 + ylinetop[width-1]
              , 0, height-int(cur_space+1));
             
  ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);
 
 

  dir = pow(cfg_gravity, dir) * dir;
 

  yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);
 
 

  if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
    mode = 0;
  }

  cur_space *= cfg_space_mod;

  score += 1;

  if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
    factor *= -1;
  }
   
 } else {  // collision detected
   if (mode == 0) {
     // save new max score
     maxscore = maxscore > score ? maxscore : score;
   
     mode = -1;
   }
 }
 
 drawframe();
 drawscore();
 
}


void keyPressed() {
 

  if (mode == 1 && key == '1') {
    dir *= 0.997;
  }


  if (mode == -1 && (keyCode == ENTER || keyCode == RETURN)) {
    mode = 1;
    initcave();
  }
 
}

2012年12月18日 星期二

00葉正聖老師, Week15, HW12

1. 繳交校外教學心得報告 1頁半 Word檔
(沒有去的同學,就自行寫份實作期末作品的報告)
2. 今天專注在期末作品的實作
Week 15
Week 16
//Week 17
Week 19 (期中考後星期一下午繳交)
3. 今天要教 Arduino Button 對映 Processing 中,做對映的畫面
4. 老師挑選幾個作品進行實作示範
4.1. Processing 做

Week15,Hw12

1.1 如何將 ArduinoInput 與 期末作品做結合

想法:
 1.將期中作品的鍵盤按鍵,改制成使用Button輸入。或是稍微做一些改變,將遊戲玩法改成類似於吉他,必須事先按下對應的區域,然後使用紅外線感測當作琴弦。

 2.製作跳舞機,但不是使用雙腳,而是使用數個紅外線感測器,然後螢幕上游標到對應區域時,利用雙手伸到對應位置。

 3.將數個感應器,包括水銀、按鈕以及紅外線感測,製作二個手套,利用雙手不同的位置以及特定姿勢,製作一個許多小遊戲的組合。

 4.將Arduino與process以及opencv做結合,搭配opencv人臉偵測以及像素處裡,配合水銀感測製作比較精準的互動視訊。能夠將不同的帽子(眼鏡)結合到當下視訊,利用手部控制。

進度:
 今天練習時,欲先熟練Arduino Input,故選擇其中作業來做一些修正,將其按鈕改為使用Button輸入。目前已經完成,只是感覺太過簡單、敷衍,故址當作練習。

心得:
 Java本身其實是支援許多openSource的函式庫,而Processing又是基於java所產生的語言,在使用的時候其實有很大的自由度,但需要的是足夠的創意,否則又只是一個敷衍了事的產物。而使用opencv的想法,是覺得如果能夠有視訊,並與視訊互動,再搭配Arduino的按鈕。從頭到尾完全不需要鍵盤、滑鼠,只需要看著螢幕,做一些動作就能產生對應的效果及反應。這感覺不是很酷嗎?
 一直覺得在現在的科技上、產品上,最主要的都是在講求與人的互動性,所以我希望在這一次的期末作品中,不論各個部分所應用的多少,或是硬體用的多好,我是希望能夠有很好的、足夠的互動性。

Week15, HW12



我們要做一個迷宮,用Aduino的四個按鍵作前後左右的控制

Week 15, HW12


一、期末作品主題

期中時是做射擊酒瓶的遊戲,用滑鼠點擊移動中的酒瓶,並在限定的時間裡看可以得到多少分數。期末也打算做射擊方面的遊戲,但是會全部從新開始,我們想要做直升機的攔截遊戲,搭配arduino 的按鍵做出射擊的動作。

 

二、期末作品描述

直升機攔截遊戲,場景是銘傳大學,會讓直升機去攔截飛彈,畫面中會有從不同地方出現的飛彈,想轟炸我們美麗的校園。主要要搭配Arduino 的上、下、左、右 跟射擊鍵,操控直升機射擊出飛彈,來抵消從上方出現的飛彈,成功防禦我們的校園。當然期中時有做的功能,倒數計時、記分都會繼續保留,我們打算另外加上,如果沒有抵擋成功,使校園被炸到的話,會有失敗的畫面產生。

 

三、作品所需素材

畫面素材:

開始畫面












移動直升機













轟炸用飛彈






四、心得
後來跟老師討論過後,如果只做上下左右的按鈕再加一顆射擊鍵,這樣不如直接用鍵盤完還來的方便快速,因此後來稍稍的做了修改,可能會加入搖桿的功能,或是上下的功能改成用腳踏! 仿照值生機的內部操作。