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

2015年1月25日 星期日

WEEK17


遊戲開始時,會從最上面開始一起掉落



會漸漸的區分為三排(三種速度)


全部清除或失敗時則要顯示計分和經過時間(尚未完成)

2015年1月18日 星期日

week17

期末作品進度:

製作裝置,改良bug



裝置外觀

裝置裡面的樣子

HW17, Week17

Week17期末作品進度:

2015/01/05 12:50~13:40 二餐三樓,做硬體

船外觀:










組員合照:




遊戲畫面

遊戲中的畫面~
左右移動閃飛彈

被飛彈打到會有GameOver跑出來

道具

完成道具

期末作品展示

原始模板:










面紙盒內部構造:



~期末作業~

Pressing:

import processing.serial.*;
Serial myPort;



int mapSizex=480;       //map x >>>
int mapSizey=480;       //map y ↓↓↓
//int posX=mapSizex/2, posY=mapSizey/2;  //player place at mid

int i=0;   //for

int maxWalkSpeed=2;         //move speed
float walkAccelx=0;         //x++ speed
float walkAccelxtmp=0;      //x++ speed tmp
float walkSpeedx=0;         //x start speed
float walkAccely=0;         //y++speed
float walkAccelytmp=0;      //y++speed temp
float walkSpeedy=0;         //y start speed

int maxConnon=5;           //max rock how many
float minConnonSpeed=0.1;   //rock move low speed
float maxConnonSpeed=1;     //rock move fast speed

float[] connonv= new float[maxConnon+1]; //
float[] connonx= new float[maxConnon+1]; //
float[] connonxv= new float[maxConnon+1]; //
float[] connony= new float[maxConnon+1]; //
float[] connonyv= new float[maxConnon+1]; //
float[] connonw= new float[maxConnon+1]; //

boolean gamestart=false; //pan duan start or not
boolean gameover=false;  //pan duan die or not
int score=0;             //score

PImage img, imgBG;
int posX=0;
int posY=0;

void setup()
{
  myPort=new Serial(this,"COM3",9600);
  size(255,200);
 
  size(mapSizex, mapSizey+6);          //+5 or can't see score
  img=loadImage("spaceship.png");        //
  imgBG=loadImage("starworld.jpg");    //picture
  imgBG.resize(mapSizex, mapSizey+6);  //+5 or can't see score
  imageMode(CENTER);                  
  posX=floor(mapSizex/2);         //player place reset
  posY=floor(mapSizey/2);         //same



  for (i=1;i<=maxConnon;i++)
  {
    switch(floor(random(1,5))) // random come out ball
    {  
    case 1: //<< x place -10 y random place
      connonx[i]=-10;                
      connony[i]=random(-10, mapSizey+10);
      break;
    case 2: //↑↑ y place -10 x random place
      connonx[i]=random(-10, mapSizex+10);
      connony[i]=-10;
      break;
    case 3: //>> x place +10 y random place
      connonx[i]=mapSizex+10;
      connony[i]=random(-10, mapSizey+10);
      break;
    case 4://↓↓ y place +10 x random place+10
      connonx[i]=random(-10, mapSizex+10);
      connony[i]=mapSizey+10;
      break;
    }
    connonv[i]=random(minConnonSpeed,maxConnonSpeed); //rock speed
    connonxv[i]=connonv[i]*((posX-connonx[i])/sqrt(sq(connonx[i]-posX)+sq(connony[i]-posY))); //x
    connonyv[i]=connonv[i]*((posY-connony[i])/sqrt(sq(connonx[i]-posX)+sq(connony[i]-posY))); // y
    connonw[i]=5;//ball big small
  }
}

void draw() {

  background(imgBG);
  image (img, posX,posY, 30,30);

  if (gamestart) {
    //gameStart();
    update();
    setConnon();
    scoreShow();
  }
  else {

    textSize(40);                        //big small
    fill(255,255,255);                   //colour
    text("PRESS HERE TO START", 30,100); //title
  }
}




void keyPressed()  //keyboard up down left right
{
  switch(keyCode)
  {
    case LEFT:          //<<
      walkAccelx=-0.2;  //speed  
      walkAccelxtmp=0;  //ship start 0 everytime then -0.15
      break;
     
    case RIGHT:          //>>
      walkAccelx=0.2;  
      walkAccelxtmp=0;
      break;
     
    case UP:             //^^
      walkAccely=-0.2;
      walkAccelytmp=0;
      break;
     
    case DOWN:          //↓↓
      walkAccely=0.2;
      walkAccelytmp=0;
      break;
   }
}


void keyReleased() //put out
{
  switch(keyCode)
  {
    case LEFT:                      
      walkAccelxtmp=walkAccelx;      //orginal speed switch
      walkAccelx=0;                  //restar 0
      break;
     
    case RIGHT:
      walkAccelxtmp=walkAccelx;
      walkAccelx=0;
      break;
     
    case UP:
      walkAccelytmp=walkAccely;
      walkAccely=0;
      break;
     
    case DOWN:
      walkAccelytmp=walkAccely;
      walkAccely=0;
      break;
     
    case ' ':                 //space bar
      if (gameover==true)
      {  
         score=0;
         gameover=false;
         frameCount=0;
         walkAccelytmp=0;
         setup();
        //redraw();          
       }
       break;
    }
}

void mouseClicked()  
{
  if (gameover==true)
  {
    score=0;
    gameover=false;
    frameCount=0;
    setup();
    //redraw();
  }
  if (gamestart==false)
  {
    gamestart=true;
  }
}       // see dao zhe bian

void update()
{
  if (posY>=10 && posY<=mapSizey-10)
  {
    posY+=walkSpeedy;
    if (walkAccely!=0)
    {
      if (abs(walkSpeedy)<maxWalkSpeed)
      {
        walkSpeedy+=walkAccely;
      }
      else
      {
        if (walkSpeedy>0)
        {
          walkSpeedy=maxWalkSpeed;
        }
        else
        {
          walkSpeedy=-maxWalkSpeed;
        }
      }
    }
    else
    {
      if (abs(walkSpeedy)>0.2)
      {
        walkSpeedy-=walkAccelytmp;
      }
      else
      {
        walkSpeedy=0;
        walkAccelytmp=0;
      }
    }
  }
  else
  {
    if (posY<10)
    {
      walkSpeedy=0;
      posY=10;
      walkAccely=0;
    }
    if (posY>mapSizey-10)
    {
      walkSpeedy=0;
      posY=mapSizey-10;
      walkAccely=0;
    }
  }
  if (posX>=10&&posX<=mapSizex-10)
  {
    posX+=walkSpeedx;
    if (walkAccelx!=0)
    {
      if (abs(walkSpeedx)<maxWalkSpeed)
      {
        walkSpeedx+=walkAccelx;
      }
      else
      {
        if (walkSpeedx>0)
        {
          walkSpeedx=maxWalkSpeed;
        }
        else
        {
          walkSpeedx=-maxWalkSpeed;
        }
      }
    }
    else
    {
      if (abs(walkSpeedx)>0.2)
      {
        walkSpeedx-=walkAccelxtmp;
      }
      else {
        walkSpeedx=0;
        walkAccelxtmp=0;
      }
    }
  }
  else
  {
    if (posX<10)          //dun give aloplant go outside
    {
      walkSpeedx=0;
      posX=10;
      walkAccelx=0;
    }
    if (posX>mapSizex-10)
    {
      walkSpeedx=0;
      posX=mapSizex-10;
      walkAccelx=0;
    }
  }
  int a=0;
 
  if(myPort.available()>0) a =myPort.read();
  if( (a&0x01)==0x01)posY+=10;///{println("up");}else println("no up");
  if( (a&0x02)==0x02)posY-=10;
  if( (a&0x04)==0x04)posX+=10;
  if( (a&0x08)==0x08)posX-=10;

       
 
  noStroke();
  fill(0,255,0,1);
  ellipse(posX,posY, 10, 10);   //mid xiao dian
}



void setConnon() {

  for (i=1;i<=maxConnon;i++) {

    if (abs(connonx[i]-posX)<connonw[i]&&abs(connony[i]-posY)<connonw[i]) {
      gameover=true;
    }
    else {
      if ((connonx[i]>mapSizex+10)||(connonx[i]<-10)||(connony[i]<-10)||(connony[i]>mapSizey+10)||gameover) {

        switch(floor(random(1, 4.99))) {
        case 1: //左
          connonx[i]=-10;
          connony[i]=random(-10, mapSizey+10);
          break;
        case 2: //上
          connonx[i]=random(-10, mapSizex+10);
          connony[i]=-10;
          break;
        case 3: //右
          connonx[i]=mapSizex+10;
          connony[i]=random(-10, mapSizey+10);
          break;
        case 4: //下
          connonx[i]=random(-10, mapSizex+10);
          connony[i]=mapSizey+10;
          break;
        }
        connonv[i]=random(0.1, 5);
        connonxv[i]=connonv[i]*((posX-connonx[i])/sqrt(sq(connonx[i]-posX)+sq(connony[i]-posY)));
        connonyv[i]=connonv[i]*((posY-connony[i])/sqrt(sq(connonx[i]-posX)+sq(connony[i]-posY)));


        if (!gameover) {
          score+=1;
        }

        if (frameCount>=1000&&frameCount<2000) {
          connonw[i]=floor(random(3, 15));
        }
        if (frameCount>=2000&&frameCount<4000) {
          connonw[i]=floor(random(3, 30));
        }
        if (frameCount>=4000) {
          connonw[i]=floor(random(3, 80));
        }
      }


      else {
        connonx[i]+=connonxv[i];
        connony[i]+=connonyv[i];
        noStroke();
        fill(250, 20, 0);
        ellipse(connonx[i], connony[i], connonw[i], connonw[i]);
      }
    }
  }
}

void scoreShow() //show score
{
  if (gameover)
  {
    textSize(15);
    fill(255, 255, 255);
    text("Game Over\nYour Score: "+score+"\nPress space bar to continue", floor(mapSizex/4), floor(mapSizey/2));
  }
  else
  {
    textSize(10);    
    fill(240, 220, 0);
    text("Your Score: "+score, 10, mapSizey+5); //left botton score
  }
}

arduino:

void setup(){
  Serial.begin(9600);
  pinMode(12, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(8,INPUT_PULLUP);

}
void loop(){
  int a=0;
  if(digitalRead(12)==LOW)a|=0x01;//Serial.println("up  ");
  if(digitalRead(5)==LOW) a|=0x02;//Serial.println("down");
  if(digitalRead(3)==LOW) a|=0x04;//Serial.println("left");
  if(digitalRead(0)==LOW) a|=0x08;//Serial.println("right");

  Serial.write(a);

  delay(20);
}

2015年1月17日 星期六

期末作業 跑跑薑餅人

 http://youtu.be/fNCvBARkWDc

期末作品







遙控器------------------↓

期末作業: 跑跑薑餅人


遊戲:簡單版跑跑薑餅人
玩法:
按下按鈕後,薑餅人即可跳起
吃到一枚硬幣加五分
碰到大便及失敗


processing的程式碼
PImage imgBG, img, img1, img2;
PImage img10;
PImage img11;
PImage img12;
PImage img13;
PImage img14;
PImage img15;
PImage img16;
PImage img17;
PImage img18;
PImage img19;
float centerx=9570;
float myImgX=80;
float myImgY=320;
float mySpeed=25;
int [][] cx=new int[50][50];
int [][] cy=new int[50][50];
int [][] cd=new int[50][50];
int [][] bx=new int[50][50];
int [][] by=new int[50][50];
int [][] bd=new int[50][50];
int csx=150;
int csy=320;
int ry;
int bs;
int i, j;
int jump=0;
int score;
int bt=1;
int n1, n2, n3, n4, n5, nu1, nu2, nu3, nu4, nu5;

import processing.serial.*;
import ddf.minim.*;
Serial myPort;
AudioPlayer player;
AudioPlayer player1;
Minim minim;
void setup() {
 
  myPort=new Serial(this,"COM5",9600);

  size(720, 576);
  img = loadImage("ginger.png");
  img1 = loadImage("coin.png");
  img2 = loadImage("poo.png");
  imgBG = loadImage("back.jpg");
  img10 = loadImage("0.png");
  img11 = loadImage("1.png");
  img12 = loadImage("2.png");
  img13 = loadImage("3.png");
  img14 = loadImage("4.png");
  img15 = loadImage("5.png");
  img16 = loadImage("6.png");
  img17 = loadImage("7.png");
  img18 = loadImage("8.png");
  img19 = loadImage("9.png");
  nu1=10;
  nu2=100;
  nu3=1000;
  nu4=10000;
  nu5=100000;
  n1=0;
  n2=0;
  n3=0;
  n4=0;
  n5=0;

  for (j=0; j<50; j++)
    for (i=0; i<50; i++) {
      bd[j][i]=0;
    bs=int(random(1, 100));
      if (bs>=0&&bs<5)bd[j][i]=1;

      cd[j][i]=1;
      cx[j][i]=csx;
      bx[j][i]=csx;
      by[j][i]=csy;
        ry=int(random(1, 3));
      if (ry==1)cy[j][i]=csy;
      else if (ry==2)cy[j][i]=220;

      csx+=75;
    }

  imageMode(CENTER);
  minim = new Minim(this);
  player = minim.loadFile("coin.mp3", 2048);
  player1 = minim.loadFile("pee.wav",2048);
}
void draw() {
  //-------------------
 
  if(myPort.available()>0)
  {
    int a=myPort.read();
    if(a=='A' && jump==0) jump=1;
  }
 
  //---------------------
 
 
  if (bt==1) {
    image(imgBG, centerx, 288);
    image(img, myImgX, myImgY, 100, 100);
    print(myImgX);
    for (j=0; j<50; j++)
      for (i=0; i<50; i++) {
        if (myImgX>=cx[j][i]-20&&myImgX<=cx[j][i]+20)
          if (myImgY>=cy[j][i]-20&&myImgY<=cy[j][i]+20)
          {
            cd[j][i]=0;
            score += 5;
            player = minim.loadFile("coin.mp3");
           
            player.play();
          }
      }
     
       for (j=0; j<50; j++)
      for (i=0; i<50; i++) {
        if(bd[j][i]==1)
        if (myImgX>=bx[j][i]-20&&myImgX<=bx[j][i]+20)
          if (myImgY>=by[j][i]-20&&myImgY<=by[j][i]+20)
          {

            bt=2;
            player1 = minim.loadFile("pee.wav");
        player1.play();
          }
      }
     

    for (j=0; j<50; j++)
      for (i=0; i<50; i++)
      {
        if (cd[j][i]==1)image(img1, cx[j][i], cy[j][i], 50, 50);
          if (bd[j][i]==1)image(img2, bx[j][i], by[j][i], 50, 50);
      }


    centerx-=10;
    for (j=0; j<50; j++)
      for (i=0; i<50; i++)
      {
        cx[j][i]-=10;
        bx[j][i]-=10;
       
      }

    if (jump>0)
    {
      if (jump<=20)
        myImgY-=10;
      jump++;
      if (jump>20)
        myImgY+=10;
      if (jump==40)jump=0;
    }  
    if (centerx<=-8850)bt=2;
  }

  if (bt==2)
  {
    n1=score%nu1;
    n2=score%nu2/10;
    n3=score%nu3/100;
    n4=score%nu4/1000;
    n5=score%nu5/10000;
    //println(time);
    bt=3;
  }

  if (bt==3)
  {
    if (n1==0)image(img10, 630, 300, 50, 50);
    if (n1==1)image(img11, 630, 300, 50, 50);
    if (n1==2)image(img12, 630, 300, 50, 50);
    if (n1==3)image(img13, 630, 300, 50, 50);
    if (n1==4)image(img14, 630, 300, 50, 50);
    if (n1==5)image(img15, 630, 300, 50, 50);
    if (n1==6)image(img16, 630, 300, 50, 50);
    if (n1==7)image(img17, 630, 300, 50, 50);
    if (n1==8)image(img18, 630, 300, 50, 50);
    if (n1==9)image(img19, 630, 300, 50, 50);


    if (n2==0)image(img10, 580, 300, 50, 50);
    if (n2==1)image(img11, 580, 300, 50, 50);
    if (n2==2)image(img12, 580, 300, 50, 50);
    if (n2==3)image(img13, 580, 300, 50, 50);
    if (n2==4)image(img14, 580, 300, 50, 50);
    if (n2==5)image(img15, 580, 300, 50, 50);
    if (n2==6)image(img16, 580, 300, 50, 50);
    if (n2==7)image(img17, 580, 300, 50, 50);
    if (n2==8)image(img18, 580, 300, 50, 50);
    if (n2==9)image(img19, 580, 300, 50, 50);



    if (n3==0)image(img10, 530, 300, 50, 50);
    if (n3==1)image(img11, 530, 300, 50, 50);
    if (n3==2)image(img12, 530, 300, 50, 50);
    if (n3==3)image(img13, 530, 300, 50, 50);
    if (n3==4)image(img14, 530, 300, 50, 50);
    if (n3==5)image(img15, 530, 300, 50, 50);
    if (n3==6)image(img16, 530, 300, 50, 50);
    if (n3==7)image(img17, 530, 300, 50, 50);
    if (n3==8)image(img18, 530, 300, 50, 50);
    if (n3==9)image(img19, 530, 300, 50, 50);


    if (n4==0)image(img10, 480, 300, 50, 50);
    if (n4==1)image(img11, 480, 300, 50, 50);
    if (n4==2)image(img12, 480, 300, 50, 50);
    if (n4==3)image(img13, 480, 300, 50, 50);
    if (n4==4)image(img14, 480, 300, 50, 50);
    if (n4==5)image(img15, 480, 300, 50, 50);
    if (n4==6)image(img16, 480, 300, 50, 50);
    if (n4==7)image(img17, 480, 300, 50, 50);
    if (n4==8)image(img18, 480, 300, 50, 50);
    if (n4==9)image(img19, 480, 300, 50, 50);



    if (n5==0)image(img10, 430, 300, 50, 50);
    if (n5==1)image(img11, 430, 300, 50, 50);
    if (n5==2)image(img12, 430, 300, 50, 50);
    if (n5==3)image(img13, 430, 300, 50, 50);
    if (n5==4)image(img14, 430, 300, 50, 50);
    if (n5==5)image(img15, 430, 300, 50, 50);
    if (n5==6)image(img16, 430, 300, 50, 50);
    if (n5==7)image(img17, 430, 300, 50, 50);
    if (n5==8)image(img18, 430, 300, 50, 50);
    if (n5==9)image(img19, 430, 300, 50, 50);
  }
}


--------------------------------------------------------------------------------------------------------------------------
arduino
void setup(){
  Serial.begin(9600);
  pinMode(3, INPUT_PULLUP);
}
void loop()
{
 
  if(digitalRead(A3) == LOW )
  {
    digitalWrite(13,LOW);
    Serial.write('A');
 
  }

delay(100);
}

2015年1月5日 星期一

Week17_楊育維_01160093

第19週1/19(一)上午10:00-12:00期末作品展示注意事項
1. 期末作品展示, 大家把成品帶過來介紹展示, 同時大家一起票選成績
2. 期末作品影片 1-2分鐘, 拍攝剪輯好貼在 Blog裡面



目前進度:

8個按鈕



week17

第19週1/19(一)上午10:00-12:00期末作品展示注意事項
1. 期末作品展示, 大家把成品帶過來介紹展示, 同時大家一起票選成績
2. 期末作品影片 1-2分鐘, 拍攝剪輯好貼在 Blog裡面 

Week17_呂季樺_01160306

第19週1/19(一)上午10:00-12:00期末作品展示注意事項
1. 期末作品展示, 大家把成品帶過來介紹展示, 同時大家一起票選成績
2. 期末作品影片 1-2分鐘, 拍攝剪輯好貼在 Blog裡面 
3.

作品材料:以空紙盒以及筷子橡皮筋做成理想的機台

Week 17 葉正聖老師示範, 最後衝刺

第19週1/19(一)上午10:00-12:00期末作品展示注意事項
1. 期末作品展示, 大家把成品帶過來介紹展示, 同時大家一起票選成績
2. 期末作品影片 1-2分鐘, 拍攝剪輯好貼在 Blog裡面 

老師示範 阿貴灌氣球
老師示範 跑跑薑餅人