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

2015年1月19日 星期一

HW19, Week19, 期末作品

期末作品-Row, row, row your boat 
(version 2-2) 

[Version 2-2]遊戲規則與解說:

●操控:
◎向右=>滑左槳
◎向左=>滑右槳

●開始畫面:
◎player玩家
◎help幫助=>score+100
◎avoid避開=>score-100

◎Row to right=>Practice
 向右可以進入練習模式
◎Row to left=>Start
 向左可以直接遊戲

練習模式:
◎Row to right=>good!
◎Row to left=>good!

●遊戲畫面:
◎失敗
分數為0即失敗
失敗後
Row to right=>Start

◎勝利
救到3隻水獺即可勝利
救到1隻水獺以圖式告知還需救幾隻(右下方)
勝利後
Row to right=>Start

◎遊戲中有音樂
◎碰到avoid與help均有音效
◎失敗與勝利之後
 Row to right=>Start
 向右均可再次遊戲


已改進:

●有練習模式,讓玩家可以先熟知玩法
●開始畫面:
 向右可以進入練習模式
 向左可以直接遊戲


作品第二版本影片:


Practice 模式 


互動概論期末作品-Row, row, row your boat (version 2-2) Demo Practice 模式 




失敗畫面

互動概論期末作品-Row, row, row your boat (version 2-2) Demo 失敗畫面 




勝利畫面

互動概論期末作品-Row, row, row your boat (version 2-2) Demo 勝利畫面 




硬體介紹

互動概論期末作品-Row, row, row your boat (version 2-2) 硬體介紹




上課 Demo 側錄

互動概論期末作品-Row, row, row your boat (version 2-2) 上課 Demo 側錄




作品第一版本影片:

2015.0118互動概論期末作品-Row, row, row your boat (version 2-1)




硬體photo:

●船槳上的鐵絲與海平面上的鐵絲觸碰,
 Arduino 即可傳送訊息給 Processing




●船槳上的鐵絲部分
 藏在船槳的海綿裡與吸管裡


●船內有 Board 的固定位置
 Board 才不會滑動



●所有材料:
 粗吸管(船桿)
 海綿(船槳)
 紙箱(海平面30*30*3、船高20)
 鐵絲
 上色用具









Week 19 作品Demo影片

期末作品-電流急急棒
作品Demo影片


期末作品-快打旋風


遊戲名字:快打旋風



此遊戲為一個簡單的打擊遊戲,玩家可以使用箱子上的紅色按鈕,遊戲中會出現不同種臉部表情的頭,點擊不同的表情會有不同的分數,相反的點到有骨頭的圖示就會結束遊戲(影片中有介紹各個圖片對應到的分數),主要是考驗玩家的手速和反應力。


期末作品Demo

https://www.youtube.com/watch?v=GTA5T3UWfFg&feature=youtu.be

期末作品

跳跳跳的飛機
http://youtu.be/efHgw8PsC0E

2015年1月18日 星期日

Week19

-------------------------------↓↓太鼓達人↓↓-------------------------------

(外觀)


(內部接線)

-------------------------------↓↓Demo影片↓↓-------------------------------


Final_影片及程式碼

影片:




*******************程式碼*******************
ARDUINO:
void setup(){
  Serial.begin(9600);
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  pinMode(13,OUTPUT);
}
int now2=0,now=0,now3=0,now4=0;
void loop(){
  int pressButtonLeft = digitalRead(2);
  int pressButtonRight = digitalRead(3);
  int restart = digitalRead(5);
  int shoot = digitalRead(4);
  if(now==1 && pressButtonLeft==HIGH){//left
    digitalWrite(13,LOW);
    Serial.write('A');  
    now=0;
  }
  else if(now==0 && pressButtonLeft == LOW){
    digitalWrite(13, HIGH);
    Serial.write('a');
    now=1;
  }
  delay(10);

  if(now2==1 && pressButtonRight ==HIGH){//right
    digitalWrite(13,LOW);
    Serial.write('B');  
    now2=0;
  }
  if(now2==0 && pressButtonRight == LOW){
    digitalWrite(13, HIGH);
    Serial.write('b');
    now2=1;
  }
  delay(10);

  if(now3==1 && shoot ==HIGH){//shot
    digitalWrite(13,LOW);
    Serial.write('C');  
    now3=0;
  }
  if(now3==0 && shoot == LOW){
    digitalWrite(13, HIGH);
    Serial.write('c');
    now3=1;
  }
  delay(10);

  if(now4==1 && restart ==HIGH){//shot
    digitalWrite(13,LOW);
    Serial.write('D');  
    now4=0;
  }
  if(now4==0 && restart == LOW){
    digitalWrite(13, HIGH);
    Serial.write('d');
    now4=1;
  }
  delay(10);

}




PROCESSING:

import processing.serial.*;
import ddf.minim.*;
AudioPlayer player1, player2, player3;
Minim minim;//audio context
Serial myPort;
PImage plane[]=new PImage[3], imgBG, canon, bullet;
int pX[]= {
  0, 0, 0
}
, pY[]= {
  0, 0, 0
}
, cX[]= {
  375
}
, cY[]= {
  500
}
, bX[]= {
  387
}
, bY[]= {
  520
};
float pVX[]= {
  1, 1, 1
}
, pVY[]= {
  1, 1, 1
}
, bVY=2, bLife[]= {
  0
}
, pbX[]= {
  0, 0, 0
}
, pbY[]= {
  0, 0, 0
}
, pbv=1;
int shoot=0, gameover=-10, score=0;
void setup() {
  size(800, 600);
  myPort = new Serial(this, "COM3", 9600);
  imgBG=loadImage("sky.png");
  canon=loadImage("canon.png");
  bullet=loadImage("bullet.png");
  for (int i=0; i<3; i++)  plane[i]=loadImage("plane"+int(random(3))+".png");
  for (int i=0; i<3; i++) {//plane and planeBullet begin
    pX[i]=int(random(30))*25;
    pbX[i]=pX[i]+30;
    pY[i]=int(random(7))*25+25;
    pbY[i]=pY[i]+31;
  }
  minim = new Minim(this);
  player1 = minim.loadFile("BGM.mp3", 2048);
  player2 = minim.loadFile("bomb.mp3", 2048);
  player3 = minim.loadFile("shoot.mp3", 2048);
  player1.play();
}
void draw() {
  background(255);

  if (myPort.available()>0) {
    int a=myPort.read();
    if (a=='b') {
      cX[0]+=50;
      bX[0]+=50;
    }
    if (a=='a') {
      cX[0]-=50;
      bX[0]-=50;
    }
    if (a=='c')shoot++;
    if (a=='d') {
      gameover=-1;
      score=0;
    }
  }
  if (gameover>0) {//Gameover
    fill(255, 0, 0);
    rect(0, 0, 800, 600);
    textSize(100);
    fill(0);
    text("GameOver!", 125, 200);
    textSize(80);
    text("Score = "+score, 125, 300 );
    textSize(40);
    text("click backspace to replay", 125, 400 );
  } else {
    image(imgBG, 0, 50);
    image(bullet, bX[0], bY[0], 40, 40);
    image(canon, cX[0], cY[0], 80, 100);
    fill(0);
    textSize(18);
    text("use <- and -> to control canon location, click Ctrl to shoot.", 5, 20);
    for (int i=0; i<3; i++) {//hit
      if (abs(pX[i]-bX[0])<100 &&abs(pY[i]-bY[0])<15) {
        score+=1;
        pY[i]=-100;
        pbY[i]=-100;
        player2 = minim.loadFile("bomb.mp3", 2048);
        player2.play();
      }
    }
    text("Score = "+score, 5, 40);
    for (int i=0; i<3; i++) {//canon hit
      if (abs(pbX[i]-cX[0])<=20 &&pbY[i]>500 ) gameover++;
    }
    for (int i=0; i<3; i++) {//draw plane and planeBullet
      fill(0);
      ellipse(pbX[i], pbY[i], 10, 10);
      image(plane[i], pX[i], pY[i], 100, 60);
    }
    for (int i=0; i<3; i++) {//plane speed and pBspeed
      if (pX[i]>700) {
        pX[i]=0;
        pbX[i]=30;
        plane[i]=loadImage("plane"+int(random(3))+".png");
        pY[i]=int(random(7))*25+25;
        pVX[i]=1;
      } else if (pbY[i]>600) {
        pbY[i]=pY[i]+31;
        pbv=1;
      } else {
        pX[i]+=pVX[i];
        pbX[i]+=pVX[i]-0.02;
        pVX[i]+=0.05;
        pbY[i]+=pbv;
        pbv+=0.05;
      }
    }
    if (shoot>0) {
      //image(bullet,bX[0],bY[0],40,40);

      for (int j=0; j<1; j++) {//canonBullet speed
        if (bY[j]<30) {
          bX[j]=cX[0]+20;
          bY[j]=500;
          bVY=2;
          shoot=0;
        } else {
          bY[j]-=bVY;
          bVY+=0.5;
        }
      }
    }
  }
}
void keyPressed() {
  if (keyCode==RIGHT && cX[0]<725 && bY[0]<500) cX[0]+=50;
  else if (keyCode==RIGHT && cX[0]<725 ) {
    cX[0]+=50;
    bX[0]+=50;
  }
  if (keyCode==LEFT && cX[0]>0&& bY[0]<500) cX[0]-=50;
  else if (keyCode==LEFT && cX[0]>0) {
    cX[0]-=50;
    bX[0]-=50;
  }
  if (keyCode==CONTROL) {
    shoot++;
    player3 = minim.loadFile("shoot.mp3", 2048);
    player3.play();
  }
  if (keyCode==32) {
    gameover=0;
    score=0;
    for (int i=0; i<3; i++) {
      pbY[i]=0;
      pbX[i]=0;
      pX[i]=0;
      pY[i]=0;
    }
  }
}

Final(打殭屍加強版)-接蘋果遊戲




倒數 開始
左上角倒數計時30秒
紅蘋果,一顆1分
得30分後 有綠蘋果,一顆2分
畫面中由左到右籃子 分別對應8個按鍵
遊戲結束後 算總分

import ddf.minim.*;
Minim m;
AudioPlayer player;
int []bz=new int[1000];
PImage imgZombie;
PImage imgRZombie;
PImage imgShoot;
PImage imgBG;

import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;

void setup() {

  size(800, 600);
  imgZombie=loadImage("apple01.png");
  imgRZombie=loadImage("apple02.png");
  imgShoot=loadImage("shoot.png");
  imgBG=loadImage("sky.png");
  for (int i=0;i<1000;i++) {
    bz[i]=int(random(8));

  }


  m = new Minim(this);
  player = m.loadFile("apple.mp3");
  //player.play();
 
  String [] all = Serial.list();
  String portName = all[all.length-1];
      player.play();
  myPort = new Serial(this, portName, 9600);
}

int now=0;
int a;
int total=0;
int countDown=300;
int countDown2=1860;//1860

void draw() { 
  background(imgBG);
 
   print("val=" + val);

  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  } 
 
  int a=0;
  if (a==0) {
    if (countDown>0) {
      countDown--;
      textSize(100);
      text(countDown/30+"Seconds", 200, 300);
      return;
    }
    a++;
  }
 
  if (a==1) { 

    if (countDown2>0) {
      countDown2--;
      textSize(50);
      text(countDown2/60+"Second", 20, 40);
      for (int i=now;i<now+5;i++) {
        if (now<=30)image(imgZombie, bz[i]*100, 400-(i-now)*100);
        if (now>30)image(imgRZombie, bz[i]*100, 400-(i-now)*100);
      }
      image(imgShoot, 0, 500);
      image(imgShoot, 100, 500);
      image(imgShoot, 200, 500);
      image(imgShoot, 300, 500);
      image(imgShoot, 400, 500);
      image(imgShoot, 500, 500);
      image(imgShoot, 600, 500);
      image(imgShoot, 700, 500);
    }
    a++;
  }
 
  if (a==2) {
    if (countDown2/60==0)text("Score:"+total, 300, 350);
  }
 
    if (val-48==bz[now])
  {
    if (total<50)a=1;
    if (total==50)a=2;
    if (countDown2/60==0)a=0;
    now++;
    total=total+a;
  }
}

/*void keyPressed(int val) {

  //if (val==bz[now])
  //{
  //  if (total<50)a=1;
  //  if (total==50)a=2;
   // if (countDown2/60==0)a=0;
  //  now++;
  //  total=total+a;
 // }
 
}*/

期末作品:賽車小遊戲加強版



我們的做的是一個賽車的小遊戲,賽車會隨著分數的增加,而加快,我們是設定1500分會增加一次難度,增加到了7500分後就是最後難度,然後撞到車子就會結束遊戲。

期末作品




期末作品


太鼓達人


import ddf.minim.*; Minim minim; AudioPlayer mu0,mu1,mu2,mu3,mu4,mu5; import processing.serial.*; Serial myPort; PImage img,imgBG,drum,B,R,P; int time=450*4; int runX[] = new int[100]; int drumcolor[] = new int[100]; int score=0; int but; void setup() { myPort = new Serial(this, "COM3", 9600); size(1200,390); imgBG = loadImage("BG.png"); drum = loadImage("drum.png"); B = loadImage("B.png"); R = loadImage("R.png"); P = loadImage("P.png"); imgBG.resize(1200,390); imageMode(CENTER); runX[0]=1050; for(int i=1;i<100;i++) { runX[i] = runX[i-1] + int(random(100,400)); } for(int i=0;i<100;i++) { drumcolor[i] = int(random(1,3)); } minim = new Minim(this); mu0 = minim.loadFile("Do_Do_Do.mp3"); mu1 = minim.loadFile("hitclap.mp3"); mu2 = minim.loadFile("slidertick.mp3"); mu0.rewind(); mu0.play(); } void draw() { background(imgBG); time--; textSize(30); fill(0, 0, 0); text(time/60,80,120); textSize(20); fill(0, 0, 0); text("Time:",75,80); if (myPort.available()>0) { but = myPort.read(); } col(); button(); image(drum,102,288,205,205); textSize(40); fill(0, 0, 0); text("Score:",850,150); textSize(40); fill(0, 0, 0); text(score,980,150); if(time==0) { minim.stop(); background(0, 0, 0); textSize(30); fill(250, 150, 0); text("Time's up",470,100); text("Your score is",450,150); textSize(80); text(score, 445,250); noLoop(); } } void col() { for(int i=0;i<100;i++) { if(drumcolor[i]==1) { image(B,runX[i]-=5,276,130,130); } if(drumcolor[i]==2) { image(R,runX[i]-=5,276,130,130); } } } void button() { if(but =='B') { for(int i=0;i<100;i++) { if(drumcolor[i]==1) { if(runX[i]<310&&runX[i]>270) { image(P,runX[i]-=5,276,130,130); score+=50; mu1.rewind(); mu1.play(); } } } println("B"); } if(but=='R') { for(int i=0;i<100;i++) { if(drumcolor[i]==2) { if(runX[i]<310&&runX[i]>270) { image(P,runX[i],276,130,130); score+=50; mu2.rewind(); mu2.play(); } } } println("R"); } if(but=='N') { println("N"); } }








My teammate :-)





Week19_期末作品

跳跳火柴人:

玩法:
人需要穿上拖鞋,隨著遊戲人物一起跳躍,穿越障礙物來獲取高分。
開始和重新只需要用力在跳一下,即可再次遊戲。

 p語言:
import processing.serial.*;//
Serial myPort,myPort1;//
import ddf.minim.*;///
Minim minim;///
AudioPlayer bgMusic,jumpMusic,gg;///

people p = new people();
wall[] w = new wall[3];
boolean end=false;
boolean intro=true;
boolean over=true;///
boolean GG=true;///
int score=0;


void setup()
{
  size(550, 750);
  myPort=new Serial(this, "COM4", 9600);//
  minim = new Minim(this);///
  for (int i = 0; i<3; i++)
  {
    w[i]=new wall(i);
  }
  strokeWeight(5);
}

void draw()
{
  background(255);
  if (end)
  {
    p.move();
  }
  p.people();
  if (end)
  {
    p.drag();
  }
  p.checkCollisions();
  for (int i = 0; i<3; i++)
  {
    w[i].drawwall();
    w[i].checkPosition();
  }
  fill(255);
  stroke(0);

  textSize(32);
  if (end)
  {
    rect(20, 20, 100, 50);
    fill(0);
    text(score, 30, 58);
  }
  else
  {
    rect(150, 100, 230, 50);
    rect(150, 200, 200, 50);
    fill(0);
    if (intro)
    {
      text("Press space or", 155, 140);
      text("Click to Play", 155, 240);
    }
    else
    {
      text("Game over", 170, 140);
      text("Score", 180, 240);
      text(score, 280, 240);
      bgMusic.close();///
    }
  }


  if (myPort.available()>0&&myPort.read()==100)
  {
    p.jump();
    intro=false;
    if (end==false)
    {
      reset();
    }
  }
  /*if (myPort.available()>0&&myPort.read()==97)
  {
    intro=false;
  if (end==false)
  {
    reset();
  }
  }*/
}

class people
{
  float xPos, yPos, ySpeed;
  people()
  {
    xPos = 250;
    yPos = 400;
  }

  void people()//people
  {
    fill(0, 0, 128);
    ellipse(xPos+5, yPos+40, 30, 30);
    rect(xPos, yPos+55, 10, 25); //body

    rect(xPos+5, yPos+60, 20, 5); //right hand
    rect(xPos+20, yPos+50, 5, 10); //right hand

    rect(xPos+5, yPos+75, 20, 5); //right feet
    rect(xPos+20, yPos+80, 5, 12); //right feet

    rect(xPos-15, yPos+60, 20, 5); //left hand
    rect(xPos-15, yPos+65, 5, 7); //left hand

    rect(xPos-15, yPos+75, 20, 5); //left feet
    rect(xPos-15, yPos+80, 5, 12); //left feet
  }

  void jump()
  {
    ySpeed=-10;
    jumpMusic = minim.loadFile("jump.mp3");///
    jumpMusic.play();
  }

  void drag()
  {
    ySpeed+=0.4;
  }

  void move()
  {
    yPos+=ySpeed;
    for (int i = 0; i<3; i++)
    {
      w[i].xPos-=3;
    }
  }

  void checkCollisions()
  {
    if (yPos>750)
    {
      end=false;
    }
    for (int i = 0; i<3; i++)
    {
      if ((xPos<w[i].xPos+15&&xPos>w[i].xPos-15)&&(yPos<w[i].wallY-125||yPos>w[i].wallY+45))
      {
        end=false;
      }
    }
  }
}

class wall
{
  float xPos, wallY, xObj;
  boolean cashed = false;
  wall(int i)
  {
    xPos = 100+(i*200);  
    wallY = random(500)+100;
  }

  void drawwall()
  {

    stroke(255, 0, 0);

    line( xPos, 0, xPos, wallY-100);
    line( xPos, wallY+130, xPos, 750);
  }

  void checkPosition()
  {
    if (xPos<0)
    {
      xPos+=(200*3);
      wallY = random(600)+100;
      cashed=false;
    }
    if (xPos<250&&cashed==false)
    {
      cashed=true;
      score++;
    }
  }
}

void reset()
{
  end=true;
  score=0;
  p.yPos=400;
  for (int i = 0; i<3; i++)
  {
    w[i].xPos+=550;
    w[i].cashed = false;
  }
  if(over)
    {
      bgMusic = minim.loadFile("bgmusic1.mp3");///
      bgMusic.play();
    }
 
}

void mousePressed()
{
  p.jump();
  intro=false;
  if (end==false)
  {
    reset();
  }
}

void keyPressed()
{
  p.jump();
  intro=false;
  if (end==false)
  {
    reset();
  }
}

arduino:
void setup(){
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(12, OUTPUT); 
  //pinMode(13, OUTPUT); 
}
int a=0;
void loop(){
  int sensorVal = digitalRead(2);
  int sensorVal2 = digitalRead(4);

  if (sensorVal == HIGH) {
    digitalWrite(13, LOW);
  } 
  else {
    digitalWrite(13, HIGH);
    Serial.write(100);
    delay(100);
  }
  
  if(sensorVal2 == LOW)a=0;
  if(sensorVal2 == HIGH && a==0){Serial.write(97); a=1;}
  /*if (sensorVal2 == HIGH) {
    digitalWrite(12, LOW);
  } 
  else {
    digitalWrite(12, HIGH);
    Serial.write(65);
    delay(100);
  }*/
}


Week19 期末作業

期末作業-電流急急棒

主要用兩顆按鈕來控制"上"和"下"

遊戲主畫面



 遊戲進行中


------------------------------------------Arduino--------------------------------------

void setup(){
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
}

void loop(){
  while(Serial.available() > 0){
   char data = Serial.read();
   Serial.print(data);
   }
  if(digitalRead(2)==HIGH) Serial.write(97);
  if(digitalRead(4)==HIGH) Serial.write(100);
  delay(100);
}


-----------------------------------------Processing-------------------------------------

import processing.serial.*;
Serial myPort;
import ddf.minim.*;
Minim minim;
AudioPlayer start, boom;
PImage over;
int [] cubeX = new int [17];
float [] high = new float [17];

void setup() {
  size(750, 300);
  minim = new Minim(this);
  start = minim.loadFile("spider man.mp3");
  boom = minim.loadFile("boom.mp3");
   start.play();
  for (int i=0; i<17; i++) {
    cubeX[i]=i*50;
    high[i]=random(100, 150);
  }
  //myPort = new Serial(this, "COM3", 9600);

  over = loadImage("gameover.png");
}
int posY = 180;
int a = 0;
int q=1;
int posX = 70;
int score = 0;
float speed = 1.0;
void draw() {
  background(255);

  if (a==0) {
    textSize(50);
    text("press T to START", 130, 150);
    fill(0, 102, 153, 500);

    if (keyPressed) {
      if(key == 't') a=1; 
    }
    
  } else if (a==1) {
    fill(255, 0, 0);
    ellipse(posX, posY, 40, 40);
    fill(0);
    if (keyPressed) {
      if (key=='w') posY-=3;
      if (key=='s') posY+=3;
    }
    for (int m=0; m<17; m++) {
      rect(cubeX[m], 0, 50, high[m]);
      rect(cubeX[m], high[m]+100, 50, 250-high[m]);
      if (cubeX[m]<-50) { 
        cubeX[m]+=800;
        score++;
        println(score);
        //speed+=0.05;
      }
      cubeX[m]-=3;      

      if (sqrt((cubeX[m]-posX)*(cubeX[m]-posX)+(high[m]-posY)*(high[m]-posY))<20 | sqrt((cubeX[m]-posX)*(cubeX[m]-posX)+(high[m]+100-posY)*(high[m]+100-posY))<20 | sqrt((cubeX[m]+50-posX)*(cubeX[m]+50-posX)+(high[m]-posY)*(high[m]-posY))<20 | sqrt((cubeX[m]+50-posX)*(cubeX[m]+50-posX)+(high[m]+100-posY)*(high[m]+100-posY))<20 && posX>cubeX[m] && posX<(cubeX[m]+50)) {
        a=2;
        //image(over, 0, 0, 800, 300);
        //println("Game Over");
      }
    }

    /*if (myPort.available()>0 ) {
     int index=myPort.read();
     //println(index);
     if (index==100)  posY+=3;
     else if (index==97) posY-=3;
     //println(posY);
     }*/
  } else if (a==2) {
    image(over, 0, 0, 800, 300);
    println("Game Over");
    start.close();
    boom.play();
    score = 0;
    if (keyPressed) {
      if (key=='r') {
        boom.close();
        a=0;
      }
    
    }
  }
}