顯示具有 97163102謝睿峰 標籤的文章。 顯示所有文章
顯示具有 97163102謝睿峰 標籤的文章。 顯示所有文章

2013年1月14日 星期一

Week 19, Final Project

系統名稱: 傳奇戰役 (Rise of The Argonauts)


目的: 

  能夠單純使用一支手控制、遊玩一個2D橫軸的遊戲,能夠控制英雄在眾多怪獸中生存,依據殺敵數量不同而得到不同的分數。並能夠在排行榜中爭取高分!

遊戲畫面:

開始畫面(按下即可開始)


進入遊戲畫面,怪物一定間格時間會產生一隻,並隨機產生其中一種及方向


攻擊畫面,成功擊殺怪物分數增加


可以跳躍迴避攻擊


受到攻擊時,左上角的血量會減少


成績排行(白色代表你當次遊戲的成績)


遊戲設備介紹及控制方法:

  控制手套(正面)


控制手套(背面)


以下同時為控制介紹:

正面(同時為遊戲初始狀態,靜止不動)


控制人物左移


控制人物右移


紅色按鈕為攻擊



附註:手向上甩,人物跳躍

如何製作:

  環境:

    作業系統:Windows 7
    硬體主機板:Arduino
    軟體撰寫:Processing(Java) + Arduino(C)

  製作重點:
      遊戲分為main、Hero Class以及Monster Class,主要撰寫的部分
    是Class。在那二個Class中分別記錄大小、生命值、座標、方向、
    向上跳躍的向量以及攻擊力及攻擊間隔,再各別撰寫函式去控制
    。

      而Serial傳遞數值的部分全部放在serialControl()函數裡面,以便
    於撰寫及控制。排行部分則是使用reader and writer去讀取以及寫檔
    。

程式碼:

Arduino:

#include <string.h>

int btn_left = 2;
int btn_right = 3;
int btn_atk = 4;
int past_leftState =1;
int past_rightState = 1;
int past_atkState = 1;
void setup() {
  Serial.begin(9600);
  pinMode(btn_left, INPUT_PULLUP);
  pinMode(btn_right, INPUT_PULLUP);
  pinMode(btn_atk, INPUT_PULLUP);
}
void loop(){
  int leftState = digitalRead(btn_left);
  int rightState = digitalRead(btn_right);
  int atkState = digitalRead(btn_atk);
  if(past_leftState != leftState) Serial.print(0);
  if(past_rightState != rightState) Serial.print(1);
  if(past_atkState != atkState && atkState == 0) Serial.print(2);
  past_leftState = leftState ;
  past_rightState = rightState ;
  past_atkState = atkState ;
  delay(10);        // delay in between reads for stability
}
Processing 

main

import processing.serial.*;
import java.io.*;
import java.util.*;
import ddf.minim.*;
import java.util.Arrays;
//define
final static int SIZE = 3;
final static int ATK_TIME = 15;

//file process about (in fact , is about rank )
BufferedReader rank;
PrintWriter rankin;

//Music about
Minim minim;
AudioPlayer groove,p;
//Serial
Serial myPort;
//linked list
List<monsterClass> lt;
//hero class
heroClass hero = new heroClass(50,75);
//control kind of avtivity
boolean[] ctl = new boolean[SIZE] ;
//Number Image
PImage[] num = new PImage[10];
//back ground img
PImage img_bg_game = loadImage(basicPath + "background\\gameBg.png");
PImage img_start = loadImage(basicPath + "background\\start.jpg");
//parameter
int ctlEnd = 0;
int grade=0;
int count;
int monsterNumber=0;
int nowRunFrame=0;
int monsterNewTime=50;
int dtime = 0;
//0:: game , 1:: rank ,  2::start
int type = 2;
void setup()
{
  size(640, 480);
  //load music
  minim = new Minim(this);
  groove = minim.loadFile(basicPath + "sound\\1.mp3", 512);
  p = minim.loadFile(basicPath + "sound\\atk.mp3", 512);
  groove.loop();
  //initialize
  lt = new LinkedList<monsterClass>();
  myPort = new Serial(this,"COM3", 9600);
  for(int i=0;i<SIZE;i++) ctl[i] = false;
  for(int i=0;i<10;i++) num[i] = loadImage(basicPath + "number\\" + i + "b.png");
}

void draw()
{
  if(type == 0){
    ctlEnd = 0 ;
    //contorl monster create time
    if(++nowRunFrame>monsterNewTime){
      monsterNewTime = 50;
      //add to list
      monsterClass m = new monsterClass(50,75,(int)random(0,199.99));
      lt.add(m); 
      monsterNumber++;
      nowRunFrame=0;
    }
    
    image(img_bg_game,0,0);
    fill(255,0,0);
    rect(0,0,hero.getHealth()*2,50);
    //show hero
    hero.showImage();
    //show grade
    showGrade();
    //detector monsters motion and attack
    for(int i=0;i<lt.size();i++){
      lt.get(i).move(hero.getPoint());
      lt.get(i).showImage();
      hero.setHealth(lt.get(i).atkDetector(hero.getPoint()));
      if(hero.getHealth() <=0) type =1;
    }
    //serial control about
    serialControl();
    if(count>0) grade += hero.atk(lt);
    //control attack img show time
    count--;
  }
  else if(type == 2 ){
     serialControl();
     image(img_start,0,0,640,480);
     dtime--;
  }
  else{
    dtime--;
    serialControl();
    background(0);
    rank=createReader(basicPath + "data\\rank.txt");
    int[] rankArr = new int[11];
    for(int i=0;i<10;i++){
      try{
          rankArr[i] = int(rank.readLine());
          println(rankArr[i]);
       } 
       catch (IOException e) {
          e.printStackTrace();
       }  
    }
    rankArr[10] = grade;
    Arrays.sort(rankArr);
    for(int k=1;k<11;k++){
      int temp=rankArr[k]*10;
      fill(255);
      if(grade == rankArr[k]) rect(650-240-k*25-5,100+(9-k)*35,230,35);
      image(num[10-k],650-240-k*30-60,100+(9-k)*35,50,50);
      for(int i=3;i>=0;i--)
         image(num[(temp/=10)%10],650-60*(4-i)-k*25,100+(9-k)*35,40,40);
    }
     if(ctlEnd == 1 && dtime<=0){
       rankin=createWriter(basicPath + "data\\rank.txt");
       for(int i=1;i<11;i++) rankin.println(rankArr[i]);
       rankin.flush();
       rankin.close();
       type = 2;
       for(int i=0;i<lt.size();i++) lt.remove(i--);
       hero.setHealth(100);
       grade = 0;
       dtime = 500;
     }
  }
}
void showGrade()
{
  
   int temp=grade*10;
   for(int i=3;i>=0;i--)
     image(num[(temp/=10)%10],640-60*(4-i),0,60,60);
   
}
void serialControl()
{
  int temp;
  if ( myPort.available() > 0){
    temp =myPort.read();
    //If btn push is attack
    if((temp - 48) == 2){
      if(type == 1 ) ctlEnd = 1;
      else if(type == 2 && dtime <= 0){
        type = 0;
        dtime = 500; 
      }
      else if(type== 0){
        grade += hero.atk(lt);
        count=ATK_TIME; 
        p.play(0);
      }
    }
    else ctl[temp-48] = !ctl[temp-48];
  }
  // if left and right together is jump
  if(ctl[0] == true && ctl[1] == true) hero.setJump(17);
  //left
  else if(ctl[0] == true){
     hero.setPoint(hero.getPoint().x-3,hero.getPoint().y);
     hero.setState(FACE_LEFT);
  }
  //right
  else if(ctl[1] == true){
     hero.setPoint(hero.getPoint().x+3,hero.getPoint().y);
     hero.setState(FACE_RIGHT);
  }
}

//Keyboard use

void keyPressed() {
  if (key == CODED) {
    if (keyCode == RIGHT || ctl[1] == true) {
      hero.setPoint(hero.getPoint().x+3,hero.getPoint().y);
      hero.setState(FACE_RIGHT);
    } 
    else if (keyCode == LEFT ) {
      hero.setPoint(hero.getPoint().x-3,hero.getPoint().y);
      hero.setState(FACE_LEFT);
    }
    else if(keyCode == UP){
      hero.setJump(17);
    }
    else if(keyCode == DOWN){
      grade += hero.atk(lt);
      count=ATK_TIME; 
      p.play(0);
    }
  }
}

class

final static String basicPath = "D:\\修\\學校課業\\大三\\互動技術\\期末作業\\game\\"; 
final static int ATK_DURING = 100;

//This class use to save site and size ( 2D information )
class Index2D
{
  public int x;
  public int y;
  public Index2D(int x,int y)
  {
    this.x = x;
    this.y = y; 
  }
};

//define :: To make me more easy to know
final static int FACE_RIGHT = 1;
final static int FACE_LEFT = 0;

class heroClass
{
  private Index2D point,size;
  private int health ;
  private int state ;  //Face 0 :: left , 1 :: right
  private PImage img,img_mirro ; 
  private PImage atk,atk_mirro ;
  private int w,h;
  private int vector;
  private boolean lock;
  
  public heroClass(int w,int h)
  {
     img = loadImage(basicPath + "role\\hero.png");
     img_mirro= loadImage(basicPath + "role\\hero_mirro.png");
     atk = loadImage(basicPath + "role\\attack.png");
     atk_mirro= loadImage(basicPath + "role\\attack_mirro.png");
     point = new Index2D(320-w,350-h);
     size = new  Index2D(w,h);
     state = vector = 0;
     lock = false;
     health = 100;
  }
  
  public void setHealth(int x)
  {
    health += x ;
  }
  public int getHealth()
  {
    return health; 
  }
  public PImage getImage()
  {
    return img;
  }
  public Index2D getPoint()
  {
    return point; 
  }
  public Index2D getSize()
  {
    return size; 
  }
  public void showImage()
  {
    point.y -= vector;
    
    //Jump parameter
    if(point.y +size.y!=350){
      vector-=1;
      lock = true;
    }else{
      vector = 0;
      lock = false ; 
    }
    //do not over the window board
    point.x = point.x < 0 ? 0 : point.x;
    point.x = point.x > 640-size.x ? 640-size.x : point.x;
    //control face which site
    if(state == FACE_LEFT ) image(img,point.x,point.y,size.x,size.y);
    else image(img_mirro,point.x,point.y,size.x,size.y);
  }
  public void setPoint(int x , int y)
  {
    point.x = x;
    point.y = y;
  }
  public void setState(int type)
  {
    state = type; 
  }
  public void setJump(int h)
  {
    if(lock == false ) vector = h ;
  }
  public int atk(List<monsterClass> lt)
  {
    //return value is kill number and will add to grade
    int tmp;
    int killNum = 0;
    if(state == FACE_LEFT ) image(atk,point.x-size.x,point.y,size.x,size.y);
    else image(atk_mirro,point.x+size.x,point.y,size.x,size.y);
    
    for(int i=0;i<lt.size();i++){
      //get monster's x site
      tmp =lt.get(i).getPoint().x;
      if(state == FACE_LEFT){
        //if is in range      reduce their life point
         if(tmp >= point.x-size.x && tmp <= point.x){
           lt.get(i).setHealth(-5);
           if( lt.get(i).getHealth()<=0){
             lt.remove(i--);
             killNum++; 
           }
         }
      }
      else{
        if(tmp >= point.x && tmp <= point.x+size.x){
           lt.get(i).setHealth(-50);
           if( lt.get(i).getHealth()<=0){
             lt.remove(i--);
             killNum++;
           }
         }
      }
    }
    return killNum;
  }
 
};

class monsterClass
{
  private Index2D point,size;
  private int health ;
  private int state ;  //Face 0 :: left , 1 :: right
  private PImage img,img_mirro ; 
  private PImage atk;
  private int w,h;
  private int type; 
  private int during,atkPower; //during is how long will attack hero
  private boolean lock ;
  private int count;
  
  public monsterClass(int w,int h,int t)
  {
    count = 0;
    lock = false;
    //t use to decide which kind monster will appear and their parameter
     if( t < 10){
       img = loadImage(basicPath + "role\\monster.png");
       img_mirro= loadImage(basicPath + "role\\monster_mirro.png");
       atk = loadImage(basicPath + "role\\matk.png");
       health = (int)random(200,1000.99);
       during = 40;
       atkPower = -25;
       type = 0;
     }
     else{
       img = loadImage(basicPath + "role\\monster2.png");
       img_mirro= loadImage(basicPath + "role\\monster2_mirro.png");
       atk = loadImage(basicPath + "role\\matk.png");
       health = 50;
       during = 30;
       atkPower = -5;
       type = 1;
     }
     //decide which site will appear
     if(t%2 == 1) state = FACE_LEFT;
     else state = FACE_RIGHT;
     if(state == FACE_LEFT) point = new Index2D(640,350-h);
     else point = new Index2D(0-w,350-h);
     //if is a stronge monster will become bigger;
     if(type == 0){
       size = new Index2D(w*2,h*2);
       point.x -= w;
       point.y -= h; 
     }
     else size = new Index2D(w,h);
  }
  public void setHealth(int x)
  {
    health+=x;  
  }
  public int getHealth()
  {
     return health; 
  }
  public Index2D getPoint()
  {
    return point; 
  }
  public void move(Index2D hero)
  {
    if(lock == false){
      if (point.x < hero.x ) state = FACE_RIGHT ;
      else state = FACE_LEFT ;
      
      if(state == FACE_LEFT ){
        if(type == 0) point.x -= 1;
        else point.x-=2; 
      }
      else{
         if(type == 0) point.x += 1;
        else point.x+=2; 
      }
    }
    
  }
  public int atkDetector(Index2D hero)
  {
    //detector is hero in the attack range 
    //if yes !!  will increase the during time
    //when is over the threshold will attack and do not miss!! XD
    if(hero.y >= point.y-5){
      if(state == FACE_LEFT) {
         if(hero.x > point.x - size.x && hero.x < point.x){
            during++;
            lock = true;
         }
         else lock = false;
      } 
      else{
         if(hero.x < point.x+size.x && hero.x > point.x){
            during++;
            lock = true;
         } 
         else lock = false;
      }
      if(during > ATK_DURING){
         during = 0;
         count = 12;
         return atkPower; 
      }
      else return 0;
    }
    else return 0;
  }
  public void showImage()
  {
    if(state == FACE_LEFT ) image(img,point.x,point.y,size.x,size.y);
    else image(img_mirro,point.x,point.y,size.x,size.y);
    if(count-->0) atk();
  }
  public void atk()
  {
    if(state == FACE_LEFT ) image(atk,point.x-size.x,point.y,size.x,size.y);
    else image(atk,point.x+size.x,point.y,size.x,size.y);
  }
};

小組分工:

Processing、Arduino、硬體部分:徐修謙
購買硬體:謝睿峰

心得:

在這次的作業當中,深深的體會到接駁硬體的困難。不過在製作的過程中,雖然困難但是是非常有趣的,將一段段的線路銜接,最後所製作而成的作品出現,這是非常有成就感的。而程式部分,由於沒有直接使用期中作業去更改,在最後的製作過程其實並不輕鬆。每一個怪物以及英雄所寫成的class,其實也耗費的不少的力氣。雖然以後不太會用到它,不過這個class其實寫出來有不錯的後續延伸性,如果未來我有需要用到相關的功能也可以直接套用就好,不過這好像短期內不太可能。總而言之、言而總之,在這次作業讓我對java更加熟悉,而且也了解到硬體以及電腦軟體之間的通訊,是甚麼一回事,有很大的收穫,也很開心。

2012年12月4日 星期二



/*
  keyboard

 Plays a pitch that changes based on a changing analog input

 circuit:
 * 3 force-sensing resistors from +5V to analog in 0 through 5
 * 3 10K resistors from analog in 0 through 5 to ground
 * 8-ohm speaker on digital pin 8

 created 21 Jan 2010
 modified 9 Apr 2012
 by Tom Igoe
This example code is in the public domain.

 http://arduino.cc/en/Tutorial/Tone3

 */
#include "pitches.h"
const int threshold = 10;    // minimum reading of the sensors that generates a note
// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_A4, NOTE_B4,NOTE_C3 };
void setup() {
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
Serial.begin(9600);
}
void loop() {
  for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
    // get a sensor reading:
    int sensorReading = analogRead(thisSensor);
    // if the sensor is pressed hard enough:
    if (sensorReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[thisSensor], 20);
      Serial.println(DEC);
    }
  }
}

2012年11月27日 星期二

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().

 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground

 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.


 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/AnalogInput

 */
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;// select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int s=7;
void setup() {
  // declare the ledPin as an OUTPUT:
  for(int i=13;i>=7;i--)
  {
  pinMode(i, OUTPUT); 
  }
  Serial.begin(9600);
}
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
   
    Serial.println("00");
    for(int i=13;i>=7;i--)
    {
      if (s==i||s==i+1)
      {
      digitalWrite(i, HIGH);
      }
      else digitalWrite(i, LOW);
     
    }
  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);         
  // turn the ledPin off:       
  digitalWrite(ledPin, LOW);  
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
  s++;
  if(s>=14)s=7;
}

電路板搭配程式跑出來的效果很好
一開始的程式可以透過小視窗來看輸出訊息也很有電腦跟使用者溝通的感覺

2012年11月20日 星期二

1.看了老師放的那些影片後 我覺得一些有趣的點子可以改變人們的習慣

  手扶梯跟鋼琴樓梯可以讓人們因為被琴聲吸引而多走樓梯的健康習慣

  如果在許多大樓樓梯或是道路上增設一些琴聲 我相信可以讓更多人習慣步行

  打地鼠可以將九宮格設定好 讓打地鼠真的有打地鼠的感覺

2.Arduino作品http://www.youtube.com/watch?v=GUcX41pokZY&feature=related

2012年11月12日 星期一




int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0;
int SPEED = 20;
long grade=0;
int rtime;
int q;
int[] lag,site;
float z;
PImage y;
PFont myFont;

void setup()
{
  myFont = createFont("FFScala", 32);
  textFont(myFont);

  size(600,700);
  background(255,255,255);

  //宣告
  lag=new int[10];
  site = new int[10];

  y=loadImage("Mouse.jpg");

}

void draw()
{
  if(millis()>30000){
    delay(3000);
    exit();
  }
  if((millis()/1000)>=20) SPEED = 10;
  q++;
  background(255);
  fill(255,0,255);
  text("Grade : " + grade, 400, 600);
  text("剩餘時間 : " + (30-(millis()/1000)), 400, 650);
  if(lag[0]!=0){
    lag[0]--;
    image(y, 70,60);
  }else image(y, 70,80);

  if(lag[1]!=0){
    lag[1]--;
    image(y, 220,60);
  }else image(y, 220,80);

  if(lag[2]!=0){
    lag[2]--;
    image(y, 370,60);
  }else image(y, 370,80);

  if(lag[3]!=0){
    lag[3]--;
    image(y, 70,210);
  }else image(y, 70,230);

  if(lag[4]!=0){
    lag[4]--;
    image(y, 220,210);
  }else image(y, 220,230);

  if(lag[5]!=0){
    lag[5]--;
    image(y, 370,210);
  }else image(y, 370,230);

  if(lag[6]!=0){
    lag[6]--;
    image(y, 70,360);
  }else image(y, 70,380);

  if(lag[7]!=0){
    lag[7]--;
    image(y, 220,360);
  }else image(y, 220,380);

  if(lag[8]!=0){
    lag[8]--;
    image(y, 370,360);
  }else image(y, 370,380);


  rtime=(int)random(0,9.99);
  if((q%SPEED)==0)
    switch(rtime)
    {
     case 0: image(y, 70,60);lag[0]=150;  break;
     case 1: image(y, 220,60);lag[1]=150; break;
     case 2: image(y, 370,60);lag[2]=150;  break;
     case 3: image(y, 70,210);lag[3]=150;  break;
     case 4: image(y, 220,210);lag[4]=150;  break;
     case 5: image(y, 370,210);lag[5]=150;  break;
     case 6: image(y, 70,360);lag[6]=150;  break;
     case 7: image(y, 220,360);lag[7]=150;  break;
     case 8: image(y, 370,360);lag[8]=150;  break;
   
    }
 
 
    if(lag[0] == 0) image(y, 70,80);
    if(lag[1] == 0) image(y, 220,80);
    if(lag[2] == 0) image(y, 370,80);
    if(lag[3] == 0) image(y, 70,230);
    if(lag[4] == 0) image(y, 220,230);
    if(lag[5] == 0) image(y, 370,230);
    if(lag[6] == 0) image(y, 70,380);
    if(lag[7] == 0) image(y, 220,380);
    if(lag[8] == 0) image(y, 370,380);

  if(a==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(100,150,100,100);

  if(b==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(250,150,100,100);

  if(c==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(400,150,100,100);

  if(d==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(100,300,100,100);

  if(e==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(250,300,100,100);

  if(f==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(400,300,100,100);

  if(g==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(100,450,100,100);

  if(h==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(250,450,100,100);

  if(i==1)
  {
    fill(255,0,0);
  }
  else
  {
    fill(0,255,0);
  }
  ellipse(400,450,100,100);  
}

void keyPressed(){
  if(key=='1')
  {
    g=1;
    if(lag[6]!=0){
      lag[6]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='2')
  {
    h=1;
    if(lag[7]!=0){
      lag[7]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='3')
  {
    i=1;
    if(lag[8]!=0){
      lag[8]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='4')
  {
    d=1;
    if(lag[3]!=0){
      lag[3]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='5')
  {
    e=1;
    if(lag[4]!=0){
      lag[4]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='6')
  {
    f=1;
    if(lag[5]!=0){
      lag[5]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='7')
  {
    a=1;
    if(lag[0]!=0){
      lag[0]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }  
  else if(key=='8')
  {
    b=1;
    if(lag[1]!=0){
      lag[1]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
  else if(key=='9')
  {
    c=1;
    if(lag[2]!=0){
      lag[2]=0;
      grade++;
      println("Grade : " + grade ) ;
    }
  }
}

void keyReleased(){
  if(key=='1')
  {
    g=0;
  }
  else if(key=='2')
  {
    h=0;
  }
  else if(key=='3')
  {
    i=0;
  }
  else if(key=='4')
  {
    d=0;
  }
  else if(key=='5')
  {
    e=0;
  }  
  else if(key=='6')
  {
    f=0;
  }  
  else if(key=='7')
  {
    a=0;
  }  
  else if(key=='8')
  {
    b=0;
  }  
  else if(key=='9')
  {
    c=0;
  }    
}


size(600,600);
for(int i=0;i<50;i++)
{
fill(random(250),random(255),random(215));
rect(random(150),random(255),random(300),random(205));
}


size(500,500);
for(int i=0;i<50;i++)
{  
    for(int k=0;k<50;k++)
    {    
        fill(i*220/12,k*200/8,i*200/21);
        rect(i*10,k*10,  50,30);
    }
}



size(500,500);
for(int i=0;i<5;i++){
  for(int k=0;k<5;k++){
    fill(i*255/8,k*255/8,50);
    ellipse(i*100+50,k*100+50,  10,100);
    fill(255,255,255);
    ellipse(i*100+50,k*100+50,  30,50);
    fill(0,0,0);
    ellipse(i*100+50,k*100+50,  10,50);
  }
}


這也是補交的作業 
Processing作品 http://www.youtube.com/watch?v=hm-us4XrXaM

老師的KITTY貓
size(500,500);

PImage kitty;
kitty = loadImage("http://buytheway.buyble.com.tw/wp-content/uploads/2011/01/hello-kitty-fredscorner1.jpg");
image(kitty, 20,20);



size(150,300);
background(200,0,200);
fill(0,0,0);
rect(20,90,45,10);
fill(0,0,0);
rect(20,50,10,40);
fill(0,0,0);
rect(38,50,10,40);
fill(0,0,0);
rect(55,50,10,40);

fill(0,0,0);
rect(80,90,45,10);
fill(0,0,0);
rect(80,50,10,40);
fill(0,0,0);
rect(98,50,10,40);
fill(0,0,0);
rect(115,50,10,40);

fill(0,0,0);
rect(38,100,10,40);
fill(0,0,0);
rect(98,100,10,40);

fill(0,0,0);
rect(15,140,120,120);

第三周才加選進這門課 前面的作業太晚補 抱歉  這是補交的作業




2012年10月30日 星期二



之前我將所有素材找到而且將位置規劃放好

今天我完成了老鼠的出現時間以及分數跟時間的設定

有想法想放音樂以及音效還有如果想要背景會動的話應該怎麼做

2012年10月23日 星期二



已經確定老鼠跟數字的素材 今天的作品先將位置固定 這不是一般拿鎚子的打地鼠 而是利用點擊讓框框填滿來判定攻擊到老鼠

心得:今天看到老師寫的範例讓我把鎚子的構想換成這個 剛剛把程式打完也將圖擺好 還挺開心的

2012年10月16日 星期二

同學作品建議

廖子萱
小狗雷克斯誤入了繪畫世界
這個遊戲很有創意而且小巧可愛又因為要動腦劃線所以不會乏味

紀詠心
製作章魚燒
可以新增一個特別章魚燒增加變數以及減少時間讓玩起來更加手忙腳亂

鍾孟志
騎單車撞飛人
可以增加比較強烈的背景音樂還有人飛走的哀號讓玩起更活潑

邱垂傑
射擊遊戲
可以增加魔王讓難度變高以及武器可以更多元

程柔淇
接蘋果
這個架構很完善 而且玩起來不用新增東西就可以手忙腳亂了

詹中豪&王靚暄
俄羅斯方塊
這個點子聽起來非常困難 很期待作品呈現

期中作品的素材要花點時間來做 包括老鼠和背景還有音樂音效而流程方面是在九個空格裡面出現老鼠然後槌子打老鼠來得分

心得:今天看了老師做了兩個同學的雛型真的很厲害 要花點時間回家做了


2012年10月9日 星期二


void setup()
{
  size(600,600);
}
float rrr=-0.5;
void draw()
{
  background(200,255,0);
  rotate(rrr);rrr+=0.001;
  translate(300,300);
  rotate(rrr);rrr+=0.001;
  for(int i=0;i<16;i++)
  {
    fill(i*15,0,255);
    rotate(PI/8);
    ellipse(0,0,100,20);
  }
  fill(mouseX*1/2,255,255);
  ellipse(0,0,30,30);
}
自轉

void setup()
{
  size(600,600);
}
float rrr=-0.5;
void draw()
{
  background(200,255,0);
 
  translate(mouseX,mouseY);
  rotate(rrr);rrr+=0.1;
  for(int i=0;i<16;i++)
  {
    fill(i*15,0,255);
    rotate(PI/8);
    ellipse(0,0,100,20);
  }
  fill(mouseX*1/2,255,255);
  ellipse(0,0,30,30);
}
邊轉邊跟著滑鼠

期中想做打老鼠

心得:這個禮拜開始要做心目中的目標的 也是最後期中期末的作品 多點創意多點細心

2012年10月2日 星期二


void setup()
{
size(500,400);
background(255,255,255);
fill(255,0,0);
rect(0,0,50,50);
fill(255,100,0);
rect(0,50,50,50);
fill(255,255,0);
rect(0,100,50,50);
fill(0,255,0);
rect(0,150,50,50);
fill(0,0,255);
rect(0,200,50,50);
fill(255,0,255);
rect(0,250,50,50);
fill(255,255,255);
rect(450,0,50,50);
fill(255,255,255);
ellipse(475, 25, 2,2);
fill(255);
rect(450,50,50,50);
ellipse(475, 75, 6, 6);
stroke(255,0,0);
strokeWeight(1);
}

int ray=5;
void draw()
{
  if(mouseX < 50 && mouseY<50 && mousePressed)
  {
  stroke(255,0,0);
  }
  else if(mouseX < 50 && mouseY<100 && mousePressed)
  {
  stroke(255,100,0);
  }
  else if(mouseX < 50 && mouseY<150 && mousePressed)
  {
  stroke(255,255,0);
  }
  else if(mouseX < 50 && mouseY<200 && mousePressed)
  {
  stroke(0,255,0);
  }
  else if(mouseX < 50 && mouseY<250 && mousePressed)
  {
  stroke(0,0,255);
  }
  else if(mouseX < 50 && mouseY<300 && mousePressed)
  {
  stroke(255,0,255);
  }
   else if(mousePressed && mouseX>450 && mouseY<50)
  {
    strokeWeight(++ray);
  }
  else if(mousePressed && mouseX>450 && mouseY<1000)
  {
    strokeWeight(--ray);
    if(ray<2)ray=2;
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);
}

好玩自製的小畫家,不需要太艱難的程式碼就可以有成就感。

2012年9月25日 星期二

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

//float x=100.0,y=100.0;
void draw()
{
background(0,0,0);

fill(255,255,0);
ellipse(100,100,100,60);

fill(255,0,255);
ellipse(mouseX,mouseY,50,100);
fill(255,0,255);
ellipse(mouseX,mouseY,80,60);

//x=x*0.9+mouseX*0.1;
//y=y*0.9+mouseY*0.1;
}

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

float x=100.0,y=100.0;
void draw()
{
background(0,0,0);

fill(255,255,0);
ellipse(x,y,100,60);

fill(255,0,255);
ellipse(mouseX,mouseY,50,100);
fill(255,0,255);
ellipse(mouseX,mouseY,80,60);

x=x*0.9+mouseX*0.1;
y=y*0.9+mouseY*0.1;
}


第一次上課吸收太多,要消化一下,不過跟Open gl有點像。