顯示具有 99161030傅建國 標籤的文章。 顯示所有文章
顯示具有 99161030傅建國 標籤的文章。 顯示所有文章

2013年1月15日 星期二

Week19, Final Project


Processing程式碼:

import processing.serial.*;
Serial port;
int word;
PImage img;
int rx=28,ry=5;
boolean move = true;
int a=0,b=0,c=0,d=0;
void setup() {
  size(400, 400);
  img = loadImage("maze.jpg");
  port = new Serial(this, "COM3", 9600);
}
void draw() {
 
  if(port.available()>0){
    word = port.read();
    }
 
  image(img, 0, 0);
  loadPixels();
 
  fill(225, 0, 0);//點點
  ellipse(rx, ry, 10, 10);
 
  if (move==true) {
    if(word=='W')ry=ry-1;
    if(word=='S')ry=ry+1;
    if(word=='A')rx=rx-1;
    if(word=='D')rx=rx+1;
  }
  color now_color = pixels[ry*400+rx];
 
  if (rx>398){
    rx=398;
    fill(0, 0, 0);
    rect(0, 0, 400, 400);
    textSize(50);
    fill(255, 255, 0);
    text("Congratulation", 20, 220);
  }
 
  if (red(now_color)<100){
    move = false;
    fill(0, 0, 0);
    rect(0, 0, 400, 400);
    textSize(50);
    fill(255, 255, 0);
    text("GAME OVER", 60, 220);
  }
 
  else move = true;

}

----------------------------------------------------------------------------

Arduino程式碼:

int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 6;

int buttonState1 = 0;  
int buttonState2 = 0;  
int buttonState3 = 0;  
int buttonState4 = 0;  
 
void setup() {
  
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT);     
  pinMode(buttonPin2, INPUT);     
  pinMode(buttonPin3, INPUT);     
  pinMode(buttonPin4, INPUT);     
  
}

void loop() {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  
  if (buttonState1 == HIGH) {     
   Serial.write('W');
  }  
  if (buttonState2 == HIGH) {     
   Serial.print('S');
  }
  if (buttonState3 == HIGH) {     
   tone(8, 165 , 300);
   Serial.print('A');
  }
  if (buttonState4 == HIGH) {     
   tone(8, 175 , 300);
   Serial.print('D');
  }
  delay(100);
}

2012年12月18日 星期二

2012年12月4日 星期二

Week13,HW11

(1)Demo影片


(2)程式碼
int buttonPin = 2;
int buttonPin1 = 3;
int buttonPin2 = 4;
int buttonPin3 = 5;
int buttonPin4 = 6;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

void setup() {
  pinMode(buttonPin, INPUT); 
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
}

void loop(){
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
 
  if (buttonState == HIGH) {    
    tone(9,261,100); 
  }
  if (buttonState1 == HIGH) {
    tone(9,294,100);
  }
  if (buttonState2 == HIGH) {
    tone(9,329,100);
  }
  if (buttonState3 == HIGH) {
    tone(9,349,100);
  }
  if (buttonState4 == HIGH) {
    tone(9,392,100);
  }
 
}

2012年11月27日 星期二

Week12,HW10

(1)Arduino練習:霹靂燈



(2)程式碼
int sensorPin = A0;
int ledPin = 13;    
int sensorValue = 0; 
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT); 
  pinMode(11, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);   
}
void loop() {
  sensorValue = analogRead(sensorPin); 
  Serial.println(sensorValue); 
 
  for (int i=13; i>=7; i--) {
    digitalWrite(i, HIGH);
    delay(sensorValue/10);
  }
   for (int i=13; i>=7; i--) {
    digitalWrite(i, LOW);
    delay(sensorValue/10);
  }
}

2012年11月20日 星期二

Week11,HW09

(1) 利用Arduino的Blink範例使LED燈閃爍

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}
// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

(2) Arduino的應用   將賽車遊戲與現實中的儀表板作結合

2012年11月13日 星期二

Week09,Midtern


int jx=30;//470
int jy=420;
int jz=3;//速度
PImage img;
PImage img2;
int state=1;
int jump=0;
int savetime;
int score;
int rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11 ;
int run=70;
int rectx1, rectx2, rectx3, recty1=100, recty2=0, recty3=-100;
int speed = 1;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
void setup() {
  size(750, 500);
  img = loadImage("10.png");
  img2 = loadImage("20.png");
  savetime = millis();
  minim = new Minim(this); 
  //  player = minim.loadFile("dam.mp3");
  //  player.play();
  randomRect();
}
void draw() {
  background(0, 0, 0);
  fill(185, 122, 87);
  rect(10, 70, 530, 420);
  fill(128, 0, 0);
  rect(30, 70, 490, 400);
  fill(0, 255, 255);
  textSize(20);
  text("SCORE", 120, 30);
  fill(128, 255, 128);
  textSize(50);
  text("F", 420, 55);
  fill(255, 255, 0);
  textSize(55);
  text("JUMPER", 550, 45);
  textSize(20);
  text("99161030", 640, 70);
  textSize(20);
  text("99160574", 640, 90);
  textSize(30);
  text("RECORD:", 550, 200);
  fill(128, 255, 128);
  textSize(50);
  text("F", 700, 280);
  fill(0, 255, 255);
  textSize(50);
  text("PAUSE", 570, 400);
  if  (mousePressed && 570<mouseX && mouseX<720 && 360<mouseY && mouseY<400) {
    state*=-1;
  }

  if (state==1) {
    jx+=jz;
    if (jx>=470 || jx<=30) {
      jz*=-1;
    }
  }
  if (jz==3) image(img, jx, jy);
  if (jz==-3) image(img2, jx, jy);

//  if (millis()%1000<30) {  
//    rect1=int(random(1, 12));
//    rect2=int(random(1, 12));
//    rect3=int(random(1, 12));
//    rect4=int(random(1, 12));
//    rect5=int(random(1, 12));
//    rect6=int(random(1, 12));
//    rect7=int(random(1, 12));
//    rect8=int(random(1, 12));
//    rect9=int(random(1, 12));
//    rect10=int(random(1, 12));
//  }
  fill(185, 122, 87); 
 
  recty1 += 1;
  recty2 += 1;
  recty3 += 1;
//  recty4 += 1;
//  recty5 += 1;
//  recty6 += 1;
//  recty7 += 1;
//  recty3 += 1;
//  recty3 += 1;
  rect(rectx1, recty1, 100, 10);
  rect(rectx2, recty2, 100, 10);
  rect(rectx3, recty3, 100, 10);
//   if(rect1==1){  rect(30,run++, 100, 10);  } 
//   if(rect1==2){  rect(70,run++, 100, 10);  } 
//   if(rect1==3){  rect(110,run++, 100, 10);  } 
//   if(rect1==4){  rect(150,run++, 100, 10);  } 
//   if(rect1==5){  rect(190,run++, 100, 10);  } 
//   if(rect1==6){  rect(230,run++, 100, 10);  }
//   if(rect1==7){  rect(270,run++, 100, 10);  }
//   if(rect1==8){  rect(310,run++, 100, 10);  }
//   if(rect1==9){  rect(350,run++, 100, 10);  } 
//   if(rect1==10){  rect(390,run++, 100, 10);  }   
//   if(rect1==11){  rect(420,run++, 100, 10);  }
  textSize(24);
  text(+score, 120, 60);
  int passtime = millis() - savetime;
  int gametime = 20-passtime/1000;
  textSize(24);
  text("TIME: "+gametime, 590, 140);
  if ( gametime <= 0 ) {
    background(0, 0, 0);
    fill(255, 0, 0);
    textSize(40);
    text(" Time's up !! ", 260, 180);
    text(" SCORE : "+score, 240, 330);
  }
  if (jy-30<recty1 && jx>rectx1)  jy=recty1-30;
  if (jy>=420) jy=420;
  println(mouseY);
}
void randomRect() {
  rectx1 = int(random(30, 420));
  rectx2 = int(random(30, 420));
  rectx3 = int(random(30, 420));
}
void keyPressed()
{
  if (key==' ') {
    jy-=80;
    score=score+=10;
  }
}


還需要改進的部分有: (1)一開始長方體為固定人物漸漸往上跳,鏡頭也可以漸漸帶上去,接連下來有隨機的長方體 (2)每爬上一定的距離FLOOR就會慢慢增加並顯示出來 (3)會留下最高紀錄

2012年10月30日 星期二

Week08,HW08

1. 期中作品報告:

1.1. 之前完成的部分:

  之前已完成遊戲背景底色與其他區域的配色,以及所有的固定文字及

數字的擺設,還有將洛克人去背剩人物本身,有向左、向右跑動以及向左

跳和向又跳的動作圖示。

1.2. 今天計畫的部分:

  今天計劃的部分是將洛克人能成功在限定的範圍內左右跑動,以及向

左和向右的方向正確,在來就是能使遊戲中途暫停及再度開始,

1.3. 可能會遇到的問題,及可能的解決方法

  之後可能遇到的問題是,當人物漸漸向上移動時,上方的長方形也會

慢慢出現,但要如何讓洛克人成功的站在每條方塊上,以及移動和跳動。

2. 目前期中作品的進度圖





2012年10月23日 星期二

Week07,HW07

Week06,HW06

(1)
  我覺得程柔淇那組的熊接蘑菇遊戲感覺很新穎,很不錯,最後蘑菇掉落的速度依序加快的話那就更刺激了,還有楊子儀那組的太鼓達人,感覺也很好,如果再搭配最近最夯的江南Style玩的話,就會更好玩了。

(2)
  (a)素材:我們做的彈跳人,背景音樂想要用瑪莉歐的遊戲音樂,人物、背景、樓梯,我們想要以MAYA來做出來
  (b)流程:一開始進遊戲會有三個選項(1)開始遊戲(選擇人物)(2)高分排行(3)設定(可控制音效和配樂),一進入比賽螢幕向上的速度會由慢漸漸加快,玩家可用一個按鍵按著集氣,按越久則跳躍高,到後面樓層數也會漸漸變少,難度增加。

         (c)範例圖:

2012年10月9日 星期二

Week05,HW05

(1)執行圖:



(2)程式碼:

void setup(){
  size(600,600);
}
float around=0.01;
void draw(){
   background(0,255,0);
  translate(mouseX,mouseY);
 
  rotate(around);
  around+=0.01;
 
  fill(255,255,0);
  for(int i=0;i<18;i++){
  rotate(PI/9);
  ellipse(100,0,100,30);
  }
  fill(185,122,87);
  ellipse(0,0,160,160);
}

(3)
組員:傅建國、范振湟
主題:彈跳人
概述:以自製的一個按鍵,使遊戲中人物一層層向上彈跳。
範例圖:

2012年10月4日 星期四

Week04,HW04

在課堂上製作屬於自己的小畫家,我的小畫家具有變換顏色和變換粗細的功能,這樣大家上課就能玩圈圈叉叉囉!

執行圖:


程式碼:


void setup(){
  size(600,600);
  fill(255,0,0);
  rect(0,0,50,50);//紅按鈕
  fill(0,255,0);
  rect(0,50,50,50);//綠按鈕
  fill(0,0,255);
  rect(0,100,50,50);//藍按鈕
  fill(0,0,0);
  rect(0,150,50,50);//黑按鈕
  fill(255,255,255);
  rect(550,0,50,50);//粗按鈕
  rect(550,50,50,50);//細按鈕
  fill(0,0,0);
  ellipse(575,25,40,40);//粗圓
  ellipse(575,75,10,10);//細圓
}
int lines=2;
void draw(){
  if     (mousePressed && mouseX<50 && mouseY<50)  stroke(255,0,0);
  else if(mousePressed && mouseX<50 && mouseY<100) stroke(0,255,0);
  else if(mousePressed && mouseX<50 && mouseY<150) stroke(0,0,255);
  else if(mousePressed && mouseX<50 && mouseY<200) stroke(0,0,0);
 
  else if(mousePressed && mouseX>550 && mouseY<50){
    strokeWeight(++lines);
  }
  else if(mousePressed && mouseX>550 && mouseY<100){
    strokeWeight(--lines);
    if(lines<2)lines=2;
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);
}

2012年9月25日 星期二

Week03,HW03

作業一 : 圖跟著滑鼠移動

程式碼:

void setup(){
  size(600,600);
}

void draw(){
  fill(128,128,255);
  rect(mouseX,mouseY,60,60,20);
}

執行圖:



作業二:圖追著滑鼠移動

程式碼:

void setup(){
  size(600,600);
  //frameRate(1);
}
float x=100,y=100;
void draw(){
  background(128,128,255);

  fill(255,0,0);
  rect(mouseX-35,mouseY-35,70,70,20);

  fill(random(255),random(255),random(255));
  ellipse(x,y,50,50);

  x=x*0.99 + mouseX*0.01;
  y=y*0.99 + mouseY*0.01;
}

執行圖:




2012年9月18日 星期二

Week2,HW02

1.迴圈長方體


2.彩色馬賽克


3.圓形迴圈



課堂心得:

  除了學會圓形、正方形的打法,還會利用for迴圈做更多變化。

 




2012年9月11日 星期二

Week01 HW01

Processing的作品分享:




 Hollow Kitty練習題:

size(190,190);
PImage kitty;
kitty = loadImage("http://www.e-informacije.com/wp-content/uploads/2009/06/hello-kitty-3-150x150.jpg");
image(kitty,20,20);


課堂心得:

原本從完全不了解這堂課的課程,到學會Processing的基本使用方法,還有Processing的功用,目前來說並不困難。



Processing作品: