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

2014年1月17日 星期五

期末作品-天才小釣手

 
期末成果~

天才小釣手


材料:兩片L型鐵片,一盒迴紋針工具盒,兩雙竹筷子,瞬間膠,一隻原子筆

過程:首先用L型鐵片做出電路,中間用筆筒配合竹筷子做出一個軸,垂吊著一個迴紋針讓它可以以軸轉圈圈讓電路通電,利用電路通電的原理來達成計算次數上的功能,在利用瞬間膠和竹筷子做出釣魚竿把手的部分,可以順時針轉動,讓電路不段通電,程式就不段的計算次數,讓我們遊戲裡面的主角收竿,最後將魚釣起!

製作流程 實體部分1天、程式部分約一星期。

謝謝小葉老師的用心!!

新年快樂!

0%

2014年1月12日 星期日

99163116鄭祥斌期中作品進度(1)

Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
  myPort = new Serial(this, "COM4", 9600);
  imgPub=loadImage("Pub.jpg");
  imgMusic=loadImage("Music.jpg");
  imgPop=loadImage("Pop.jpg");
  image(imgPop,400,600);
  image(imgMusic,400,600);
  image(imgPub,400,600);
 
  bg = loadImage("background.jpg");
  blue = loadImage("blue.jpg");
  orange = loadImage("orange.gif");
  green = loadImage("green.jpg");
  blue1 = loadImage("blue1.gif");
  orange1 = loadImage("orange1.jpg");
 
  m = new Minim(this);
  player = m.loadFile("DNA.mp3");
  size(400,600);
  for(int i=0;i<N;i++){
    newThing(i);
  }
}
int countDown=10*30;
void draw(){
  player.play();
  val = myPort.read();
  image(imgPop,0,0,400,600);
  if(keyPressed)
     
        textSize(40);
        text("Start!!", 250, 300);
   
   if(key=='s')
 
      image(imgMusic,0,0,400,600);
      if(countDown>0){
      //background(255,0,255);
    countDown--;
    text("Time: "+countDown/50,170,300);
   
    return;
      }
 
  image(bg,0,0, 400,600);
  image(blue,0,575,80,40);
  image(orange,80,575,80,40);
  image(green,160,575,80,40);
  image(blue1,240,575,80,40);
  image(orange1,320,575,80,40);
 
 
  for(int i=0;i<N;i++){
    if(thingType[i]==1)
    {
     drawblue(i);
      //if (keyPressed)
     
        //if(key=='d'|| key=='D')
       
     
        println(val);
        if(525<thingY[i] && thingY[i]<700 && val==50)
        {
          thingY[i] = 650; grade+=100; //println(grade);
          fill(#0046FF,90);
          rect(0,575,80,-600);
        }
     
     
    }
    else if(thingType[i]==2)
    {
      draworange(i);
      //if (keyPressed)
     
      {
        //if(key=='f'|| key=='F')
       
        //println(val);
        if(525<thingY[i] && thingY[i]<600 && val==51)
        {
        thingY[i] = 650; grade+=100; println(grade);
        fill(#FF7D00,90);
        rect(80,575,80,-600);
        }
      }
    }
    else if(thingType[i]==3)
    {
      drawgreen(i);
      //if (keyPressed)
     
      {
        //if(key=='b'|| key=='B')
       
        //println(val);
        if(525<thingY[i] && thingY[i]<600 && val==52)
        {
        thingY[i] = 650; grade+=100; println(grade);
        fill(#10FF00,90);
        rect(160,575,80,-600);
      }
      }
    }
    else if(thingType[i]==4)
    {
      drawblue1(i);
      //if (keyPressed)
     
      {
        //if(key=='k'|| key=='K')
       
        //println(val);
        if(525<thingY[i] && thingY[i]<600 && val==49)
        {
        thingY[i] = 650; grade+=100; println(grade);
        fill(#0046FF,90);
        rect(240,575,80,-600);
      }
      }
    }
    else if(thingType[i]==5)
    {
      draworange1(i);
      //if (keyPressed)
     
      {
        //if(key=='j'|| key=='J')
       
        println(val);
        if (525<thingY[i] && thingY[i]<600 && val==53)
        {
          thingY[i] = 650; grade+=100; println(grade);
          fill(#FF7D00,90);
          rect(320,575,80,-600);
        }
      }
    }
    thingY[i]+=3;
    if(thingY[i]>600) newThing(i);
   }
  if(count>0){
    count--;
    text("Time: "+count/50,170,300);
    }
    if(count==0){
      //background(#FF0015);
      //background(imgMusic,400,600);
      image(imgMusic,0,0,400,600);
      fill(255,0,0);
      text("Score: "+grade,122,300);
   
    }
}
void newThing(int i){
  thingY[i] = -random(200);
  thingX[i] = random(400);
  thingType[i] = int(random(5))+1;
}
void drawblue(int i){
  thingX[i]=int(random(0,0));
  image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
  thingX[i]=int(random(80,80));
  image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
  thingX[i]=int(random(160,160));
  image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
  thingX[i]=int(random(240,240));
  image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
  thingX[i]=int(random(320,320));
  image(orange1,thingX[i],thingY[i],80,22);
}

99163116鄭祥斌期中作品進度

Arduino硬體程式碼更新版:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin6 = 6;

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

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

}
void loop() {
  buttonState5 = digitalRead(buttonPin5);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState6 = digitalRead(buttonPin6);
 
  if (buttonState5 == HIGH) {    
 
   Serial.write('1');
  }
  if (buttonState2== HIGH) {    
 
   Serial.print('2');
  }
  if (buttonState3 == HIGH) {    
 
   Serial.print('3');
  }
  if (buttonState4 == HIGH) {    
 
   Serial.print('4');
  }
  if (buttonState6 == HIGH) {    
 
   Serial.print('5');
  }
  else if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW&&buttonState6 == LOW){
  Serial.write('0');
  }
  delay(100);
 
}

2013年12月30日 星期一

Week17 葉玉婷 期末作品

影片:

因為上面的影片有點看不清楚螢幕中的遊戲畫面
因此上傳前幾週用滑鼠玩的影片
讓大家知道我們在玩什麼

前幾週用滑鼠玩的遊戲畫面影片:





解說:
改良自"打磚塊"遊戲
把磚塊變成豬
搖桿上也崁了一隻豬
變成"珠珠(豬珠)打豬豬"
有三顆愛心三條命(左下角)
只要死一次就會少一顆心
如果全部打完後畫面會停止
按下滑鼠左鍵便會進入下一關
第二關會有兩排豬、第三關有三排豬
以此類推
遊戲方式為左右移動搖桿
雖然是個簡單的遊戲
玩起來也十分有趣味呢


NG影片:






Processing的程式碼:

import processing.serial.*;
Serial serial;
int sensorValue;

//音樂
import ddf.minim.*;
Minim m;
AudioPlayer player;

float x = 300;
float y = 300;
float dx = 3;
float dy = -5;
int t;
int bloom=3;
int n=0;
int count=0;
int points=0; //得分
PImage pig; //豬頭的圖
PImage ban; //金箍棒的圖
PImage back; //背景圖
PImage heart; //生命值

float heightbounce=450;

//層級
boolean[][] inside=new boolean[1][11];

void setup()
{
  serial=new Serial(this, "COM4", 9600); //連結arduino
  size(600, 600); //視窗尺寸
  frameRate(60);
  smooth();

  m = new Minim(this);

  player=m.loadFile("music.mp3");
  player.play(); 

  pig=loadImage("pig.png"); //讀入豬頭圖
  ban=loadImage("ban.png"); //讀入金箍棒圖
  back=loadImage("back.jpg"); //讀入背景圖
  heart=loadImage("heart.png"); //讀入愛心
}

void draw()
{

  if (t==0) //新級別
  {

    background(back); //背景

    stroke(0);

    if (count<120) //前兩秒顯示第幾關
    {
      fill(0); //填入黑色
      textAlign(CENTER);
      text("LEVEL " + inside.length, 300, 400); //顯示第幾關
    }

    strokeWeight(10); //球的大小
    point(x, y); //顯示球球
    strokeWeight(1); //打擊框框大小

    randomSeed(1); //隨機

    //打豬頭
    for (int j=0;j<inside.length;j++)
    {
      for (int k=0;k<inside[0].length;k++)
      {
        //豬頭及球的距離
        float dx2=50+50*k-x;
        float dy2=50+50*j-y;
        float dis2=sqrt(pow(dx2, 2)+pow(dy2, 2));

        if (dis2>=25. && inside[j][k]==false) //畫豬
        {
          image(pig, 25+50*k, 50+50*j, 50, 50); //被打的豬豬豬豬
        }

        //關於反彈
        else if (dx2<=(dis2*cos(PI/4))&& dy2<=-(dis2*sin(PI/4)) && inside[j][k]==false)
        {
          dy*=-1;
          inside[j][k]=true;
          points++;
        }
        else if (dx2<=(dis2*cos(PI/4)) && dy2>=(dis2*sin(PI/4)) && inside[j][k]==false)
        {
          dy*=-1;
          inside[j][k]=true;
          points++;
        }
        else if (dy2<=(dis2*sin(PI/4)) && dx2<=-(dis2*cos(PI/4)) && inside[j][k]==false)
        {
          dx*=-1;
          inside[j][k]=true;
          points++;
        }
        else if (dy2<=(dis2*sin(PI/4)) && dx2>=(dis2*cos(PI/4)) && inside[j][k]==false)
        {
          dx*=-1;
          inside[j][k]=true;
          points++;
        }
      }
    }

    float barsize=50;
    strokeWeight(3);

    if (serial.available()>0)
    {
      sensorValue = serial.read();
      println(sensorValue);
    }
    image(ban, (sensorValue*4)-barsize, heightbounce-50, 150, 100);

    //image(ban, mouseX-barsize, heightbounce-50, 150, 100);
    strokeWeight(1);

    // 打到邊界的話
    if (x>=width || x<=0)
    {
      dx*=-1;
    }
    if (y<=0)
    {
      dy*=-1;
    }

    // 設定方位
    if (y>=heightbounce && y<heightbounce+10)
    {
      if (x>((sensorValue*4)-barsize) && x< ((sensorValue*4)-(1./3)*barsize) && dx>0 && dy>0)
      {
        dy*=-0.95;
        dx*=-1.05;
      }
      else if (x>((sensorValue*4)-barsize) && x< ((sensorValue*4)-(1./3)*barsize) && dx<0 && dy>0)
      {
        dy*=-0.95;
        dx*=1.05;
      }
      else if (x>((sensorValue*4)+(1./3)*barsize) && x< ((sensorValue*4)+barsize) && dx>0 && dy>0)
      {
        dy*=-0.95;
        dx*=1.05;
      }
      else if (x>((sensorValue*4)+(1./3)*barsize) && x< ((sensorValue*4)+barsize) && dx<0 && dy>0)
      {
        dy*=-0.95;
        dx*=-1.05;
      }
      else if (x>((sensorValue*4)-(1./3)*barsize) && x< ((sensorValue*4)+(1./3)*barsize) && dy>0) {
        dy*=-1.05;
        dx*=0.95;
      }
    }

    //顯示分數
    textAlign(RIGHT);
    fill(0);
    text(points, 300, 350);

    //遊戲結束
    if (y>height)
    {
      if (bloom>1) //生命值
      {
        t=1;
        fill(0);
        textAlign(CENTER);
        text("CLICK TO RESTART GAME", 300, 400);
        text("PRESS SPACE TO RESTART LEVEL", 300, 500);
        bloom--;
      }
      else
      {
        text("GAME OVER", 300, 300);
      }
    }

    //完成關卡
    if (checkinside()) {
      t=2;
      fill(0);
      textAlign(CENTER);
      text("FINISHED", 300, 300);
      text("CLICK FOR NEXT LEVEL", 300, 400);
    }

    x=x+dx;
    y=y+dy;

    count++;
  }

  //遊戲結束
  else if (t==1)
  {
    x = 300;
    y = 300;
    dx = 3;
    dy = -5;
    count=0;
    points=0;
    if (mousePressed==true)
    {
      t=0;
      inside=new boolean[inside.length][inside[0].length];
    }
    if (keyPressed)
    {
      if (key == ' ')
      {
        t=0;
        inside=new boolean[1][11];
      }
    }
  }

  //關卡完成
  else
  {
    x = 300;
    y = 300;
    dx = 3;
    dy = -5;
    count=0;
    if (mousePressed==true)
    {
      t=0;
      inside=new boolean[inside.length+1][inside[0].length];
    }
  }

  //生命值
  if (bloom==3)
  {
    image(heart, 10, 500, 50, 50);
    image(heart, 70, 500, 50, 50);
  }
  else if (bloom==2)
  {
    image(heart, 10, 500, 50, 50);
  }
  else if (bloom==1)
  {
  }
}

boolean checkinside()
{
  for (int j=0;j<inside.length;j++)
  {
    for (int k=0;k<inside[0].length;k++)
    {
      if (inside[j][k] == false)
      {
        return false;
      }
    }
  }
  return true;
}



Arduino的程式碼:


int potPin = 0; // 可變電阻接在 pin 0 上

void setup() 
{

  Serial.begin(9600);

}

void loop() 

{

  int sensorValue = analogRead(potPin);

  Serial.write(sensorValue/4);

  delay(100);

}

第十七週 課堂作業及回家作業

老師不在請學長來
這週我們把Arduino和processing的部份結合起來
再做一些修改,例如加了分數計算和時間限制...等等
然後這週也討論了外型要怎麼做

/////processing////
import ddf.minim.*; import ddf.minim.analysis.*; Minim minim; AudioPlayer song;
PImage bg; PImage Aircraft; float Px=500; float Py=470; PImage boom; int off=0; PImage die; int score=-80, lastTime=60;
import processing.serial.*;
Serial serial;
void setup() { minim = new Minim(this); song = minim.loadFile("1.mp3", 2048);
serial=new Serial(this, "COM4", 9600);
frameRate(25); size (1100, 600); song.play(); bg = loadImage("sky.jpg"); Aircraft = loadImage("1.jpg"); Random(); }
float [] x= new float [8]; float y; char c=' ';
void draw() {
if (serial.available()>0) { c=(char)serial.read(); print(c); if (c=='3') { Px-=10; } if (c=='4') { Px+=10; } }
background(bg); image(Aircraft, Px, Py); boom=loadImage("boom.jpg"); int m=millis(); textSize(30); fill(m/10%10,m/10%10,m/10%255); text("Time:"+lastTime, 10,40); text("Score:"+score, 330,40); lastTime=60-millis()/1000;
if (off==0) { for (int i=0;i<8;i++) { image(boom, x[i], y++); if (dist(Px+35, Py+42.5, x[i]+45, y+45)<90.6) { off=1; print("boom"); song.close();//音樂停止 minim.stop(); super.stop(); } } if (y>525) { Random(); y=0; } } if (off==1) { die=loadImage("booms.jpg"); image(die, 0, 0); textSize(70); fill(255,0,0); text("Your score:"+score,500,100); } if(lastTime==0) { stop();
textSize(75); fill(255,0,0); text("Times up!", 150,140); text("You Win!", 150,220); text("Your score:"+score,150,300);
} }
void Random() { for (int i=0;i<8;i++) x[i]=random(1100); score+=80; }
/*void keyPressed() { if (keyCode==RIGHT) Px+=10; else if (keyCode==LEFT) Px-=10; } */


////Arduino////
int switchStateRed = 0; int switchStateBlue = 0; int switchStateW = 0; int switchStateA = 0; const int ledPin = 13; // led connected to digital pin 13 const int knockSensor = A0; // the piezo is connected to analog pin 0 const int threshold = 100; int sensorReading = 0; // variable to store the value read from the sensor pin int ledState = LOW;
void setup(){ pinMode(ledPin, OUTPUT); pinMode(4,INPUT); pinMode(5,INPUT); Serial.begin(9600); }
//int a=0,b=0;
void loop(){ sensorReading = analogRead(knockSensor); switchStateW = digitalRead(4); switchStateA = digitalRead(5);
if (sensorReading >= threshold) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
} if(switchStateW == HIGH) {Serial.write('3');} if(switchStateA == HIGH) {Serial.write('4');} delay(33); }

2013年12月29日 星期日

Week17 期末作品

硬體程式碼
int const potPin = A1;
int const potPin1 = A0;
int potValue;
int potValue1;
int angle;
int angle1;


void setup () {

  Serial.begin(9600);
}

void loop () {

  potValue = analogRead(potPin);
  potValue1 = analogRead(potPin1);

  Serial.print("Potentiometer Value: ");
  Serial.print(potValue);
  Serial.print("Potentiometer Value1: ");
  Serial.print(potValue1);
// potValue = constrain(potValue,0,1000);
  angle= map(potValue, 0, 1023, 0, 179);
  angle1= map(potValue1, 0, 1023, 0, 179);

  Serial.print("\t \t Motor Angle: ");
  Serial.println(angle);

  Serial.print("\t \t Motor Angle1: ");
  Serial.println(angle1);


  delay(15);
}
硬體部分

硬體操作外觀

內部細節