顯示具有 04160515_廖葆棠 標籤的文章。 顯示所有文章
顯示具有 04160515_廖葆棠 標籤的文章。 顯示所有文章

2019年1月3日 星期四

Week 17


今天大家都展示了各自的期末作品,非常的精彩,看到了好多厲害的作品。

這是我們製作的遊戲搖桿,分為1P、2P
 

這是我們的期末作品影片:
https://www.youtube.com/watch?v=wA72eiQiiok&feature=youtu.be

非常可惜的是我們搞錯呈現方式了,沒有照到我們怎麼玩,只有螢幕錄影,原本想要重拍,但是東西都拆掉了,只好作罷。

2018年12月27日 星期四

Week16

一開始我們是使用ASCII碼設範圍,結果發現我們的兩個人物跟不上我們搖桿操作的速度,會當當的,後來老師告訴我們有一個更好的方法可以改善這個問題,就是使用Data處理。

讀入data
myPort.readBytes(data); //1P
    mariovX = data[0]/20.0;//-100...+100
    mariovY = data[1]/20.0;//-100...+100

myPort2.readBytes(data); //2P
    mario2vX = data[0]/20.0;//-100...+100
    mario2vY = data[1]/20.0;//-100...+100

2018年12月13日 星期四

Week14



(可用於控制滑鼠的鼠標位置)

int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}

2018年12月6日 星期四

week13

 int switchPin = 4;                       // Switch connected to pin 4

void setup() {
 // pinMode(switchPin, INPUT);             // Set pin 0 as an input
  pinMode(2,INPUT_PULLUP);
  Serial.begin(9600);                    // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(2) == HIGH) {  // If switch is ON,
    Serial.write(1);               // send 1 to Processing
  } else {                               // If the switch is not ON,
    Serial.write(0);               // send 0 to Processing
  }
  delay(100);                            // Wait 100 milliseconds
}


pinMode(2, INPUT_PULLUP); 按鈕是在pin2
pin2按了時processing方塊為黑色
pin2沒按時processing方塊為灰色

2018年11月29日 星期四

week12 戶外教學


一早就起床去搭捷運,便利商店隨便買個吃的就前往目的地,雖然很累,手還折LED燈泡折到有點痛,但真的是一個有趣的經驗,謝謝老師帶我們來這裡,謝謝學長的幫助,讓我們能及時趕上畢業拍,光劍成品太帥啦!!

2018年11月22日 星期四

week11

瀏覽電腦上的驅動程式

前往此網址下載驅動程式:

https://makeruno.com.my/getting-started/

更改工具列的序列埠(COM7)



複製此網頁中的程式碼:

https://makeruno.com.my/playing-melody-using-only-maker-uno/?fbclid=IwAR0tZ_KdYKtJw9aii5Foj-eNHvXMWCRF7SSoir2nivJAez7VqyK8293UdHo

此程式會使用蜂鳴器來播放小星星


int piezoPin = 8;

int length = 15;

char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";      // a space represents a rest

int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };

int tempo = 300;


void playTone(int tone, int duration) 

{

  for (long i = 0; i < duration * 1000L; i += tone * 2) 

  {

    digitalWrite(piezoPin, HIGH);

    delayMicroseconds(tone);

    digitalWrite(piezoPin, LOW);

    delayMicroseconds(tone);

  }

}


void playNote(char note, int duration) 

{

  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };

  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  for (int i = 0; i < 8; i++) 

  {

    if (names[i] == note) 

    {

      playTone(tones[i], duration);

    }

  }

}


void setup() 

{

  pinMode(piezoPin, OUTPUT);

}


void loop() 

{

  for (int i = 0; i < length; i++) 

  {

    if (notes[i] == ' ') 

    {

      delay(beats[i] * tempo);

    } else 

      playNote(notes[i], beats[i] * tempo);

    delay(tempo / 2); 

  }



}


2018年11月15日 星期四

Week10



認識MAKER UNO


前往下列網址:
https://makeruno.com.my/getting-started/?fbclid=IwAR2eFAh0fqWqNJjFLbzTYBV9VI42uael8ZatyZLvERZHnb7MYFMk5pmiSxY

下載Arduino IDE Software
並安裝CH341 Driver for Windows

之後檢查連接埠查看是否更改,檢查是否安裝成功

2018年11月1日 星期四

Week 8

期中作品

組員:廖葆棠、林俐妏

我們做了一個馬力歐的2P射擊遊戲,
左邊的玩家使用WASD可以操控上下左右,
右邊的玩家則是使用↑↓←→控制;
射擊的鍵分別為空白鍵及Enter鍵。



2018年10月25日 星期四

Week07

血條的製作
//float fruitX, fruitY, fruitVX, fruitVY;
float [] fruitX=new float[20];
int life=10;
boolean gameOver=false;
void setup(){
  size(500,500);
}
void draw(){
  background(0,0,205);
  fill(255); rect(50,50, 100,20);
  fill(255,0,0); rect(50,50, life*10,20);
  if(gameOver){
    textSize(40);
    text("Game Over",150,150);
  }
}
void mousePressed(){
  life--;
  if(life<=0) gameOver=true;
}


開始畫面
 遊戲畫面
GameOver畫面
int state=0;
int remainTime=0;
void setup(){
  size(800,600);
}
void draw(){
  if(state==0){
    drawOP();
    if(key=='1'){
      state=1;
      remainTime=5*60;
    }
  }else if(state==1){
    drawPlayer();
  }else if(state==2){
    drawED();
  }
}
void drawED(){
  background(0);
  fill(#F0D90C);
  textSize(30);text("Game Over",100,100);
}
void drawPlayer(){
  background(#F0D90C);
  fill(#161FF2);
  textSize(30);text("Playing.. You can press 2 to End",10,100);
  text("remail: "+remainTime,10,200);
  remainTime--;
  if(remainTime<=0) state=2;
}
void drawOP(){
  background(0);
  fill(#F5DE07);
  textSize(30);text("Opening.. You can press 1 to play",10,100);
}

2018年10月18日 星期四

Week06



水果忍者


float fruitX, fruitY, fruitVX, fruitVY;
void setup(){
  size(800,600);
   fruitX=30;  fruitVX=3;
  fruitY=700;  fruitVY=-35;
 }
void draw(){
  background(0);
 ellipse(fruitX,fruitY,100,100);
  fruitX+=fruitVX;
  fruitY+=fruitVY;
  fruitVY+=0.98;
}



一次丟很多水果出來


float [] fruitX=new float[20];
float [] fruitY=new float[20];
float [] fruitVX=new float[20];
float [] fruitVY=new float[20];
void setup(){
  size(800,600);
  for(int i=0;i<20;i++){
  fruitX[i]=random(800);  fruitVX[i]=3;
  fruitY[i]=700;  fruitVY[i]=-35;
  }
}
void draw(){
  background(0);
  for(int i=0;i<20;i++){
  ellipse(fruitX[i],fruitY[i],100,100);
  fruitX[i]+=fruitVX[i];
  fruitY[i]+=fruitVY[i];
  fruitVY[i]+=0.98;
  }
}

開始切水果了!


float [] fruitX=new float[20];
float [] fruitY=new float[20];
float [] fruitVX=new float[20];
float [] fruitVY=new float[20];
void reborn(int i){                                         
  fruitX[i]=random(800);  fruitVX[i]=(6)-3;
  fruitY[i]=700;  fruitVY[i]=-35;
}
void setup(){
  size(800,600);
  for(int i=0;i<20;i++){
    reborn(i);
  }
}
void draw(){
  background(0);
  for(int i=0;i<20;i++){
    if( dist(mouseX, mouseY, fruitX[i],fruitY[i])<=50){
      reborn(i); continue;
    }
    ellipse(fruitX[i],fruitY[i], 100,100);
    fruitX[i]+=fruitVX[i];
    fruitY[i]+=fruitVY[i];
    fruitVY[i]+=0.98;
    if(fruitY[i]>700) reborn(i);
  }
}

2018年10月11日 星期四

Week 05

讓許多雞蛋落下


float[] eggX=new float[100];
float[] eggY=new float[100];
void setup(){
  size(800,600);
  for(int i=0;i<100;i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
  }
}
void draw(){
  background(255);
  for(int i=0;i<100;i++){
    ellipse(eggX[i], eggY[i],80,100);
    eggY[i]+=5;
  }
}



開始接雞蛋


float[] eggX=new float[100];float[] eggY=new float[100];                          
boolean[] eggDie=new boolean[100];
void setup(){  size(800,600);  
for(int i=0;i<100;i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
               eggDie[i]=false;  }
}
void draw(){
  background(255);
  rect(mouseX-50, mouseY-25,100,50);
  for(int i=0;i<100;i++){//for all eggs
    if(eggDie[i])continue;//continue to for loop
    ellipse(eggX[i], eggY[i],80,100);
    eggY[i]+=5; 
   if(eggY[i]>700) eggY[i]=-2000+600;
    if(dist(mouseX-50,mouseY-25,eggX[i],eggY[i])<50){
                        eggDie[i]=true;  }
}
}


水果忍者


PImage img;//讀圖檔
float bananaX=0, bananaY=700;//lower-left
float bananaVX=6,bananaVY=-40;//to right-top
void setup(){
  size(800,600);
  img=loadImage("banana.png");
}
void draw(){
  background(255);
  image(img,bananaX,bananaY,100,150);
  bananaX +=bananaVX;
  bananaY +=bananaVY;
  bananaVY+=0.98;//gravity of earth
}

加上刀子


PImage img;//讀圖檔
float bananaX=0, bananaY=700;//lower-left
float bananaVX=6,bananaVY=-40;//to right-top
void setup(){
  size(800,600);
  img=loadImage("banana.png");
  for(int i=0;i<10;i++) sword[i]=new PVector();
}
PVector [] sword= new PVector[10];

void draw(){
  
  background(255);
  image(img,bananaX,bananaY,100,150);
  bananaX +=bananaVX;
  bananaY +=bananaVY;
  bananaVY+=0.98;//gravity of earth
 for(int i=9; i>0;i--){
   sword[i].x=sword[i-1].x; sword[i].y=sword[i-1].y;
 }
 sword[0].x=mouseX; sword[0].y=mouseY;//Update sword[0] to newest mouse
 for(int i=1;i<10;i++){
   line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
 }
}

一次出現很多香蕉!!


PImage []img=new PImage[8];
float []bananaX=new float[8];
float []bananaY=new float[8];
float []bananaVX=new float[8];
float []bananaVY=new float[8];

void bananaReborn(int i){
   bananaX[i]=random(800);
   bananaY[i]=700;
   bananaVX[i]=random(8)-4;
   bananaVY[i]=-40;
}
void setup(){
  size(800,600);
  for(int i=0;i<8;i++) img[i]=loadImage("banana.png");
  for(int i=0;i<8;i++) bananaReborn(i);
  for(int i=0;i<10;i++) sword[i]=new PVector();
}
PVector [] sword= new PVector[10];
void draw(){
  background(255);
  for(int i=0;i<8;i++){
  image(img[i],bananaX[i],bananaY[i],100,150);
  bananaX[i] +=bananaVX[i];
  bananaY[i] +=bananaVY[i];
  bananaVY[i]+=0.98;//gravity of earth
 }
 for(int i=9; i>0;i--){
   sword[i].x=sword[i-1].x; sword[i].y=sword[i-1].y;
 }
 sword[0].x=mouseX; sword[0].y=mouseY;//Update sword[0] to newest mouse
 for(int i=1;i<10;i++){
   line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
 }

2018年10月4日 星期四

week04



void setup(){
size(800,600); } void draw(){ background(255); fill(255,0,0);rect(100,100,100,100); for(int i=0;i<bulletn;i++){ if(bulletflying[i]){ ellipse(bulletx[i],bullety[i],50,50); bulletx[i]+=3; } } } float []bulletx=new float[100]; float []bullety=new float[100]; int bulletn=0; boolean []bulletflying=new boolean[100]; void keyPressed(){ bulletflying[bulletn]=true; bulletx[bulletn]=100; bullety[bulletn]=100; bulletn++; }



PImage imb; void setup(){ size(800,600); imb=loadImage("images.png"); } void draw(){ background(255); image(imb,mouseX,mouseY,100,100); for(int i=0;i<bulletn;i++){ if(bulletflying[i]){ // ellipse(bulletx[i],bullety[i],50,50); // bulletx[i]+=3; image(imb,bulletx[i],bullety[i],50,50); } } } float []bulletx=new float[100]; float []bullety=new float[100]; int bulletn=0; boolean []bulletflying=new boolean[100]; void mousePressed(){ bulletflying[bulletn]=true; bulletx[bulletn]=mouseX; bullety[bulletn]=mouseY; bulletn++; }



PImage imb; void setup(){ size(800,600); imb=loadImage("images.png"); } void draw(){ background(255); ellipse(mouseX,mouseY,50,50); //image(imb,mouseX,mouseY,100,100); for(int i=0;i<bulletn;i++){ if(bulletflying[i]){ ellipse(bulletx[i],bullety[i],50,50); //bulletx[i]+=3; //image(imb,bulletx[i],bullety[i],50,50); bullety[i]+=bulletvy[i]; bulletvy[i]+=0.98; } } } float []bulletx=new float[100]; float []bullety=new float[100]; float []bulletvy=new float[100]; int bulletn=0; boolean []bulletflying=new boolean[100]; void mousePressed(){ bulletflying[bulletn]=true; bulletx[bulletn]=mouseX; bullety[bulletn]=mouseY; bulletvy[bulletn]=-20; bulletn++; }

2018年9月27日 星期四

week03



void setup(){ size (500,500); } void draw(){ ellipse(250,250,480,480); for(float angle=0; angle<PI*2; angle+=PI/3){ for(int r=0;r<=240;r+=20){ noFill(); triangle(250,250,250+r*cos(angle),250+r*sin(angle), 250+r*cos(angle+PI/3),250+r*sin(angle+PI/3)); } } }



void setup(){ size (800,400); } void mtriangle(int cx, int cy){ float a=-PI/2; for(int r=15;r>0;r-=5){ triangle(cx+r*cos(a),cy+r*sin(a), cx+r*cos(a+2*PI/3),cy+r*sin(a+2*PI/3), cx+r*cos(a-2*PI/3),cy+r*sin(a-2*PI/3)); } } void draw(){ background(255); for(int cx=20;cx<800;cx+=40){ for(int cy=20;cy<400;cy+=40){ mtriangle(cx,cy); } } }


PImage imgmario; float marioX=0,marioY=0,marioVX=0.5,marioVY=0,marioAX=0,marioAY=0.1; void setup(){ size (400,600); imgmario=loadImage("mario.png"); } void draw(){ background(255); image (imgmario,marioX,marioY,100,150); marioX+=marioVX; marioVX+=marioAX; marioY+=marioVY; marioVY+=marioAY; } void keyPressed(){ if(keyCode==UP){marioY-=5;} if(keyCode==DOWN){marioY+=5;} if(keyCode==LEFT){marioX-=5;} if(keyCode==RIGHT){marioX+=5;} }



PImage imgmario; float marioX=0,marioY=0,marioVX=0.5,marioVY=0,marioAX=0,marioAY=0.1; void setup(){ size (400,600); imgmario=loadImage("mario.png"); } void draw(){ background(255); image (imgmario,marioX,marioY,100,150); marioX+=marioVX; marioVX+=marioAX; marioY+=marioVY; marioVY+=marioAY; if(marioY>600-150)marioVY*=-0.9; if(marioX>400-100)marioVX*=-1; if(marioY<0)marioVY*=-0.9; if(marioY<0)marioVX*=-1; if(marioX<300)marioVX=-marioVX; if(marioX>0)marioVX=-marioVX; } void keyPressed(){ if(keyCode==UP){marioY-=5;} if(keyCode==DOWN){marioY+=5;} if(keyCode==LEFT){marioX-=5;} if(keyCode==RIGHT){marioX+=5;} }

2018年9月20日 星期四

Week 02

噁心的接龍

void setup(){
 size(400,400); 
}
int R=30;  //設一變數30
void draw(){
 ellipse(mouseX,mouseY,R,R); //ellipse為橢圓形
 R-=3;
 if(R<0) R=30;//如果R<0,R=30
}

將噁心的接龍上色,變漂亮了!

void setup(){
 size(400,400); 
 colorMode(HSB,100); //這邊選擇HSB,H為色相、S為飽和度、B為亮度
}
int R=30,H=0;
void draw(){
  fill(H,100,100); //fill為填滿
 ellipse(mouseX,mouseY,R,R); 
 R-=3;
 if(R<0) R=30;
 H++;
 if(H>=100) H=0;//如果H>=100,H=0
}

2018年9月13日 星期四

week 01



畫線跟正方形



加入void draw()繪畫函式
更改背景的顏色(按下滑鼠時為紅色,其他時間為藍色):

void setup(){
  size(800,600);
}
void draw(){
  if(mousePressed) background(255,0,0);
  else background (0,0,255);
}

滑鼠一到舞台就一直畫畫不能停下來

mouseX,mouseY 為新的滑鼠座標
pmouseX,pmouseY  為原始的滑鼠座標

滑鼠按下在開始畫畫 放下就停止
加入mousePressed