顯示具有 05161120_徐譽嘉 標籤的文章。 顯示所有文章
顯示具有 05161120_徐譽嘉 標籤的文章。 顯示所有文章

2019年1月5日 星期六

AHSU interaction week11

原內建的程式碼


changing-melody-with-push-button








AHSU interaction week15

void setup() {
  Serial.begin(9600);
  pinMode(5,INPUT);
  digitalWrite(5,HIGH);
}

byte data[3];
void loop() {
  int valX=analogRead(A0);
  int valY=analogRead(A1);
  data[0]=valX/8;
  data[1]=valY/8;
  if(digitalRead(5)==LOW) data[2]=1;
  else data[2]=0;
  Serial.write(data,3);
  delay(100);
}

AHSU interaction week 16

import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
Serial myPort;
int state=0;
PImage bg, playing, cat87, cat887, ending, end, again;
PImage []rock=new PImage[5];
float catx=300, caty=400, catvx=0, catvy=0;
float []rockx=new float[5];
float []rocky=new float[5];
float []rockvx=new float[5];
float []rockvy=new float[5];
boolean catL=false, catR=false;
int time, score;

void setup() {
  size(600, 800);
  myPort = new Serial(this, "COM3", 9600);
  minim =new Minim(this);
  player=minim.loadFile("Bongo Cat - Nyan Cat.mp3");
  bg=loadImage("title.png");
  playing=loadImage("universe.png");
  cat87=loadImage("nyan-cat.png");
  cat887=loadImage("nyan-cat87.png");
  ending=loadImage("game over.png");
  end=loadImage("god_logo_800.jpg");
  again=loadImage("play-again.png");
  imageMode(CENTER);
  for (int i=0; i<5; i++) {
    rock[i]=loadImage("ball.png");
    rockx[i]=random(50, 550);
    rocky[i]=random(50, 750);
    rockvx[i]=5*random(-1, 1);
    rockvy[i]=5*random(-1, 1);
  }
  player.loop();
}

void draw() {
  frameRate=30;
  getData();
  if (state==0) {
    image(bg, width/2, height/2, width, height);
    if (data[2]==1)
      state=1;
  } else if (state==1) {
    image(playing, width/2, height/2, width, height);
    if (data[0]==64 || data[1]==64) {
      catvx=0;
      catvy=0;
    }
    catvx=(data[0]-64)/5.0;
    catvy=(data[1]-64)/5.0;
    catx+=catvx;
    caty+=catvy;
    if (!(catR) && !(catL)) {
      image(cat87, catx, caty, 133, 100);
    }
    if (catvx<0) {
      image(cat887, catx, caty, 133, 100);
      catL=true;
      catR=false;
    } else if (catvx>0) {
      image(cat87, catx, caty, 133, 100);
      catR=true;
      catL=false;
    } else {
      if (catL) image(cat887, catx, caty, 133, 100);
      else if (catR) image(cat87, catx, caty, 133, 100);
    }

    if (catx<60)  catx=60;
    if (catx>538)  catx=538;
    if (caty<30)  caty=30;
    if (caty>763)  caty=763;

    for (int i=0; i<5; i++) {
      image(rock[i], rockx[i], rocky[i], 75, 73);
      rockx[i]+=rockvx[i];
      rocky[i]+=rockvy[i];
      if (frameCount%30==0) {
        rockvx[i]=rockvx[i]*random(1.0, 1.1);
        rockvy[i]=rockvy[i]*random(1.0, 1.1);
      }
      if (rockx[i]<=30 || rockx[i]>=566)
        rockvx[i] = -rockvx[i];
      if (rocky[i]<=30 || rocky[i]>=763)
        rockvy[i] = -rockvy[i];
      if ((time+29)/30>1 && dist(rockx[i], rocky[i], catx, caty)<(75/2+45/2)) {
        state=2;
        catx=300;
        caty=400;
      }
    }
    time++;
    fill(255);
    textSize(50);
    if ((time+29)/30<10)  text(((time+29)/30), 300-10, 60);
    else  text(((time+29)/30), 300-15-10, 60);
    score=(time+29)/30*10;
  } else if (state==2) {
    image(end, width/2, height/2, width, height);
    image(ending, 300, 400+20, 870/4, 460/4);
    image(again, 300, 650, 200, 100);
    text("your score is "+score, 150-40, 220);
    if (data[0]==64 || data[1]==64) {
      catvx=0;
      catvy=0;
    }
    catvx=(data[0]-64)/5.0;
    catvy=(data[1]-64)/5.0;
    catx+=catvx;
    caty+=catvy;
    if (!(catR) && !(catL)) {
      image(cat87, catx, caty, 133, 100);
    }
    if (catvx<0) {
      image(cat887, catx, caty, 133, 100);
      catL=true;
      catR=false;
    } else if (catvx>0) {
      image(cat87, catx, caty, 133, 100);
      catR=true;
      catL=false;
    } else {
      if (catL) image(cat887, catx, caty, 133, 100);
      else if (catR) image(cat87, catx, caty, 133, 100);
    }

    if (catx<60)  catx=60;
    if (catx>538)  catx=538;
    if (caty<30)  caty=30;
    if (caty>763)  caty=763;

    if (catx>200-50 && catx<400+50 && caty>550-50 && caty<650+50 && data[2]==1) {
      time=0;
      score=0;
      catx=300;
      caty=400;
      for (int i=0; i<5; i++) {
        rockx[i]=random(50, 550);
        rocky[i]=random(50, 750);
        rockvx[i]=5*random(-1, 1);
        rockvy[i]=5*random(-1, 1);
      }
      state=1;
    }
  }
}

byte [] data = new byte[3];
void getData() {
  if (myPort.available()>0) {
    myPort.readBytes(data);
  }
}

AHSU interaction week 17作品

成果展示:



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

這次的其中作品我負責出idea, 找資料, 部分程式(得分的部分)以及程式的debug

藍色球拍(左)用wasd控制移動, 紅色球拍(右)用4568控制移動, 以先得3分者或20秒內決定勝負

製作ice hockey的難點在於控制球的反彈

AHSU interaction week14

maker uno的設定方法




2019年1月3日 星期四

week17 互動技術筆記@

期末作品展示

影片連結:https://youtu.be/h7PBZZPgU4w


操作:玩家利用搖桿操控畫面中的貓咪,來躲避隨著時間加快的五顆隕石。一旦被隕石碰到即結束遊戲,結束後會顯示得分(存活秒數*10)以及再玩一次的畫面。

2018年12月6日 星期四

AHSU interaction week13

install ch341ser

確認是com7

processing--範例程式--lib--serial--simpleread
portname改成com7
ardno--工具--開發粄, 埠要改

改ardno程式碼, 他會讀很多0.1的資料







AHSU interaction week12




去hacker space做光劍
差點失敗

2018年11月1日 星期四

week08 互動技術筆記@

Ice Hocket

影片連結:https://www.youtube.com/watch?v=0G64yvSQOGA&feature=youtu.be


操作:這個遊戲有兩個玩家,藍色(左邊)用WASD移動、紅色(右邊)用8456移動。玩家需操控推盤,將中間的黑盤推入畫面左右兩邊黑色部分,得分後可獲得發球權。遊戲時間為20秒,先得到三分或是時間到最高分者為贏家。

2018年10月18日 星期四

AHSU interaction week 6

水果忍者
陣列為20顆水果給予vx,vy,fx,fy值
random 隨機上拋
random(6)-3  --->  -3到3

滑鼠干擾會讓球reborn
掉下也會reborn








2018年10月11日 星期四

AHSU interaction week 5

掉雞蛋範例


加上分數後

程式碼:
float[] eggx=new float[100];
float[] eggy=new float[100]; //雞蛋有100顆
boolean[] eggd=new boolean[100];
void setup(){
   size(800,600);
   for(int i=0;i<100;i++){
      eggx[i]=random(100,700);//隨機x座標
      eggy[i]=-random(2000);//隨機y座標
      eggd[i]=false;
   }
}
int score=0;
void draw(){
   fill(255);
   background(255);
   rect(mouseX-50,mouseY-25,100,50);//雞蛋籃
   for(int i=0;i<100;i++){
     if(eggd[i])continue;
      fill(255);
      ellipse(eggx[i],eggy[i],80,100);//雞蛋
      eggy[i]+=5;//+=5讓雞蛋下落
      if(eggy[i]>700) eggy[i]=-2000+600;//雞蛋到視窗底下就在上方重生
      if(dist(mouseX-50,mouseY-25,eggx[i],eggy[i])<50){
         eggd[i]=true;  score+=100;//接到蛋就消失  分數要+=100text的分數才會加
      }
   }
   fill(255,0,0);
   textSize(80);
   text("Score:"+score,100,100);
}




2018年10月4日 星期四

AHSU interaction week4

文字的應用方法,
textsize(); fill(, ,); text("", , )


射出子彈的應用
boolean bulletflying=true/false;
keypressed時改變true/false


超過100會當掉bulletN;
boolean==>賦予是非



















2018年9月27日 星期四

AHSU interaction week 03

颱風天寫程式:
畫圓形

nofill

老師講解的影片連結:
https://www.facebook.com/jsyeh.org/videos/vb.100000084969969/1310952318917588/

mytriangle:


會動的png(老師範例mario)



加上重力加速度後:













2018年9月20日 星期四

AHSU interaction week02

複習上周的內容
函式 setup() draw() keypressed()
劃線,畫四邊形,小畫家mouseX,mouseY


噁心接龍


噁心變色接龍


用random畫的花
* colorMode(HSB,100);
* fill(H,100,100);


將圖片隨mouse移動
*圖片要拖曳到processing中
* ctrl k可開圖檔位置

先在draw函式設定background()在loadimage就不會有殘影










2018年9月13日 星期四

AHSU interaction week1


size視窗大小,line畫線,rect畫四方形


void setup();void draw()的運用

小畫家:
線不會斷
---------->solution


stroke的用法(粗細,rgb)