顯示具有 98160762潘瀅玉 標籤的文章。 顯示所有文章
顯示具有 98160762潘瀅玉 標籤的文章。 顯示所有文章

2013年1月14日 星期一

Week19 Final Project



系統名稱:接香菇瑪利歐


圖片:

此圖為遊戲開始畫面

此圖為遊戲進行畫面

此圖為硬體arduino線路接法
 
 
 
 

心得介紹

這次期末作業從單純的processing加上硬體arduino,一開始我們不太會接arduino到後來自己成功的做出自己的期末作品,雖然只是按鈕功能,但還是很有趣。我們的遊戲計分方式分別是紅色的香菇代表得五分,綠色的香菇代表得一分,怪物代表減生命值,金幣可以讓生命值增加一個。我們設計這樣的遊戲計分方面玩遊戲的人可以增加遊戲的刺激度。

影片

這是遊戲失敗的影片



這是遊戲過關的影片




組員分工情況

邱舒曼之負責工作:

1 撰寫部落格
2.寫processing遊戲的計分程式
3.寫arduion連接processing部分的程式

潘瀅玉 之負責工作:

1.拍攝成果的影片
2.寫processing遊戲的兩種香菇、怪物、金幣的掉落方式
3.接arduion的按鈕,負責接硬體




2012年12月25日 星期二

Week15, HW12,

本周進度為成功時做了兩個按鈕,分別控制讓小人不掉落和重新開始遊戲的部分

本周電路板圖片



以下為本周程式碼

processing

import processing.serial.*;
Serial myPort;
int now;
int now2;
int testState=0;
//int testState2=0;
int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;
float dir = 1;  // current direction of the player (gravity vs pushing)
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1; // 遊戲狀態, 1=running, 0=lost, -1=lost and score printed
float cur_space = 450;  // space to play
float factor = 0.5;     // how far the cave can move max in the y axis for one x step
// the cave borders
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];
// the player (snake)遊戲的線
float[] yplayer = new float[cfg_width/2];
PFont myFont;
import ddf.minim.*;
Minim minim;
AudioPlayer player;

void initcave() {

  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;
  body=loadImage("bodyknife.png");

  for (int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for (int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}

void drawframe () {
  drawframe2 ();//我寫的背景變色程式
  // draw cave
  stroke(255, 0, 0);
  for (int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);
  }

  if (mode < 1) {
    stroke(0, 255, 0);
    strokeWeight(5);
    fill(100, 255, 0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
  people();
}
//背景變色程式在這邊~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void drawframe2 () {
  if (score/10<10) {//因為他計分我發現他是score有除以10 所以這邊也要把分數除10才會跟顯示的計分看起來一樣
    background(0, 0, 0);//小於10分
  }
  else if (score/10<=50) {
    background(0, 0, 255);//大於10分小於等於50分
  }
  else  if (score/10<100) {
    background(255, 255, 255);//大於等於50分小於100分
  }
  else  if (score/10>=100) {
    background(255, 255, 255);//大於等於100分
  } 
  //要把所有數值的情況考慮進去,不然畫面會閃一下。例如原本是小於100 和大於100 沒有寫道等於100的情況 那100分的時候遊戲畫面會閃一下
}
void people() {//小人改變大小
  for (int i=1; i<width/2; i++) {  
    if (score/10<50) {
      image(body, i, int(yplayer[i]), 80, 80);
    }
    else if (score/10<=100) {//大於50分 小於等於100分
      image(body, i, int(yplayer[i]), 60, 60);
    }
    else  if (score/10<150) {
      image(body, i, int(yplayer[i]), 30, 30);//大於100分小於150分
    }
    else  if (score/10>=150) {
      image(body, i, int(yplayer[i]), 30, 30);//大於等於150分
    }
  }
}

void setup()
{


  size(cfg_width, cfg_height);
  myPort= new Serial(this, "COM3", 9600);

  initcave();
  frameRate(100);
  minim = new Minim(this); //播音樂
  player = minim.loadFile("Kalimba.mp3");  //播音樂
   player.play();  //播音樂
    myFont = loadFont("SansSerif-12.vlw");
   textFont(myFont);
}

void drawscore()
{
  stroke(0);
  strokeWeight(3);
  fill(0);
  text("最高分紀錄: " + int(maxscore/10) + "  分數: " + int(score/10), 1, 12);//計分都有除10在這
  if (mode == -1) {
    text("Game Over!再玩一次.", 2, 26);
  }
}
void draw()
{

  while (myPort.available ()>0) {
    testState = myPort.read();
    println(testState);
    if (testState==49)
    {
      now = 1;
    }
    if (now==1)
      dir *= 0.997;
    if (testState=='a')
    {
      mode = 1;
      initcave();

    }

  if (mode == 1) {

    for (int i = 1; i < width; i++) {
      ylinetop[i-1] = ylinetop[i];
      ylinebottom[i-1] = ylinebottom[i];
    }
 
    for (int i = 1; i < width/2; i++) {
      yplayer[i-1] = yplayer[i];
    }
 
    ylinetop[width-1] =
      constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
      + ylinetop[width-1]
      , 0, height-int(cur_space+1));
    ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);

 
    dir = pow(cfg_gravity, dir) * dir;
 
    yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);


    if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
      mode = 0;
    }
 
    cur_space *= cfg_space_mod;

    score += 1;

    if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
      factor *= -1;
    }
  }
  else {  // collision detected
    if (mode == 0) {
      // save new max score
      maxscore = maxscore > score ? maxscore : score;
      mode = -1;
    }
  }
  drawframe();
  drawscore();
}

void keyPressed() {

  if (mode == 1 && key == '2') {
    dir *= 0.997;
  }

  if (mode == -1 && (key == '0' )) { //按0重新開始
    mode = 1;
    initcave();
  }
}

ardino

/*
  DigitalReadSerial
 Reads a digital input on pin 2, prints the result to the serial monitor

 This example code is in the public domain.
 */
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
int pushButton2 = 3;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
  pinMode(pushButton2, INPUT);
}
int a=0;
int a2=0;
// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  int buttonState2 = digitalRead(pushButton2);
  // print out the state of the button:
  if (buttonState == HIGH && a==0 ) {  // If switch is ON,
      Serial.print(1);
      a=1;      // send 1 to Processing
  }
  if (buttonState == LOW && a==1) {                               // If the switch is not ON,
    Serial.println(0); 
      a=0;    // send 0 to Processing
  }
  if (buttonState2 == HIGH && a2==0 ) {  // If switch is ON,
    Serial.print('a');
    a2=1;      // send 1 to Processing
  }
  if (buttonState2 == LOW && a2==1) {                               // If the switch is not ON,
    Serial.println('b'); 
     a2=0;    // send 0 to Processing
  }
 // Serial.println(buttonState);
  delay(10);        // delay in between reads for stability
}


以下為我們的電路板




2012年12月19日 星期三

Week15, HW12,




  本周專心於探討將期中的processing作品如何和arduino做結合的部分,我們的期中作品是利用空白鍵控制挖洞穴的小人不一直掉下來得以前進,將原本利用空白鍵來控制的部分改用數字鍵2,希望可將此訊息傳到arduino中,將我們製做好的按鈕可以取代鍵盤來實作。

  日後更希望可以將重新開始遊戲的按鍵也能夠讓我們做的第二顆按鈕取代,而其中困難的部分將是思考如何將processing所傳送的按鍵訊息讓arduino收到並得以實踐。


程式碼



import processing.serial.*;
Serial myPort;

int testState=0;

int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;

float dir = 1;
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1;
float cur_space = 450;
float factor = 0.5;  

// the cave borders
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];

// the player (snake)遊戲的線
float[] yplayer = new float[cfg_width/2];

PFont myFont;

import ddf.minim.*;
Minim minim;
AudioPlayer player;


void initcave() {
 
  // game variables
  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;
 
  body=loadImage("bodyknife.png");
 
 

  for(int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for(int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}


void drawframe () {

    drawframe2 ();//我寫的背景變色程式

   stroke(255,0,0);
 
  for(int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);

  }

  if (mode < 1) {
    stroke(0,255,0);
    strokeWeight(5);
    fill(100,255,0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
     people();
}
//背景變色程式在這邊~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  void drawframe2 () {
  if (score/10<10){//因為他計分我發現他是score有除以10 所以這邊也要把分數除10才會跟顯示的計分看起來一樣
  background(0,0,0);//小於10分
  }
  else if (score/10<=50) {
    background(0,0,255);//大於10分小於等於50分

  }
  else  if (score/10<100){
  background(255,255,255);//大於等於50分小於100分
  }
   else  if (score/10>=100){
  background(255,255,255);//大於等於100分
  }
 //要把所有數值的情況考慮進去,不然畫面會閃一下。例如原本是小於100 和大於100 沒有寫道等於100的情況 那100分的時候遊戲畫面會閃一下
}

void people(){//小人改變大小
  for(int i=1; i<width/2; i++) {  
  if (score/10<50){
     image(body,i, int(yplayer[i]),80,80);
  }
  else if (score/10<=100) {//大於50分 小於等於100分
     image(body,i, int(yplayer[i]),60,60);

  }
  else  if (score/10<150){
     image(body,i, int(yplayer[i]),30,30);//大於100分小於150分
  }
  else  if (score/10>=150){
     image(body,i, int(yplayer[i]),30,30);//大於等於150分
  }

  }

}


void setup()
{
 
 
  size(cfg_width, cfg_height);
  myPort= new Serial(this,"COM3",9600);
  initcave();
  frameRate(100);
 
  minim = new Minim(this); //播音樂
  player = minim.loadFile("Kalimba.mp3");  //播音樂
 // player.play();  //播音樂
//  myFont = loadFont("SansSerif-12.vlw");
 // textFont(myFont);
}



void drawscore()
{
  stroke(0);
  strokeWeight(3);
  fill(0);
  text("最高分紀錄: " + int(maxscore/10) + "  分數: " + int(score/10), 1, 12);//計分都有除10在這~~~~~~~~~~~~~~~~~~~
 
  // when lost tell the player how to restart
  if (mode == -1) {
    text("Game Over!再玩一次.", 2, 26);
  }
}

void draw()
{
  println(testState);
   while(myPort.available()>0){
    testState = myPort.read();
    print(testState);
  }

 if (mode == 1) {

  for(int i = 1; i < width; i++) {
    ylinetop[i-1] = ylinetop[i];
    ylinebottom[i-1] = ylinebottom[i];
  }
 

  for(int i = 1; i < width/2; i++) {
    yplayer[i-1] = yplayer[i];
  }
 

  ylinetop[width-1] =
    constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
                 + ylinetop[width-1]
              , 0, height-int(cur_space+1));
             
  ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);
 
 

  dir = pow(cfg_gravity, dir) * dir;
 

  yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);
 
 

  if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
    mode = 0;
  }

  cur_space *= cfg_space_mod;

  score += 1;

  if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
    factor *= -1;
  }
   
 } else {  // collision detected
   if (mode == 0) {
     // save new max score
     maxscore = maxscore > score ? maxscore : score;
   
     mode = -1;
   }
 }
 
 drawframe();
 drawscore();
 
}


void keyPressed() {
 

  if (mode == 1 && key == '1') {
    dir *= 0.997;
  }


  if (mode == -1 && (keyCode == ENTER || keyCode == RETURN)) {
    mode = 1;
    initcave();
  }
 
}

2012年12月4日 星期二

week13,hw11







程式碼

int buttonPin = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin5 = 5;
int buttonPin6 = 6;
int buttonState = 0; 
int buttonState3 = 0; 
int buttonState4 = 0; 
int buttonState5 = 0; 
int buttonState6 = 0; 
void setup() {
  pinMode(buttonPin, INPUT);    
  pinMode(buttonPin3, INPUT);    
  pinMode(buttonPin4, INPUT);    
  pinMode(buttonPin5, INPUT);    
  pinMode(buttonPin6, INPUT);    
}
void loop() {
  buttonState = digitalRead(buttonPin);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);
 
  if (buttonState == HIGH) {    
   tone(8, 262, 10);
  }


  if (buttonState3== HIGH) {    
   tone(8, 294, 10);
  }


  if (buttonState4 == HIGH) {    
   tone(8, 330, 10);
  
  }


  if (buttonState5 == HIGH) {    
   tone(8, 349, 10);
  }


  if (buttonState6 == HIGH) {    
   tone(8, 392, 10);
  }

}


2012年11月27日 星期二

week11,hw10

影片一 自動發光


影片二手動發光

自動發光程式碼

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);


 digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(12, HIGH);
  delay(200);
   digitalWrite(11, HIGH);
 delay(200);
   digitalWrite(10, HIGH);
  delay(200);
   digitalWrite(9, HIGH);
  delay(200);
   digitalWrite(8, HIGH);
  delay(200);
   digitalWrite(7, HIGH);
  delay(200);

  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(12, LOW);
  delay(200);
   digitalWrite(11, LOW);
  delay(200);
   digitalWrite(10, LOW);
  delay(200);
   digitalWrite(9, LOW);
  delay(200);
   digitalWrite(8, LOW);
  delay(200);
   digitalWrite(7, LOW);
  delay(200);

  delay(50);                 
}

手動發光程式碼
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);

  if(sensorValue>=0) digitalWrite(13, HIGH);
  if(sensorValue>100 ) digitalWrite(12, HIGH);
  if(sensorValue<100) digitalWrite(12, LOW);
  if(sensorValue>200)   digitalWrite(11, HIGH);
  if(sensorValue<200)  digitalWrite(11, LOW);
  if(sensorValue>300)  digitalWrite(10, HIGH);
  if(sensorValue<300) digitalWrite(10, LOW);
  if(sensorValue>400)  digitalWrite(9, HIGH);
  if(sensorValue<400)  digitalWrite(9, LOW);
  if(sensorValue>500)  digitalWrite(8, HIGH);
  if(sensorValue<500)  digitalWrite(8, LOW);
  if(sensorValue>600) digitalWrite(7, HIGH);
  if(sensorValue<600) digitalWrite(7, LOW);
  delay(50);                 
}

課堂心得

今天上課內容很好玩,因為接電路板用arduion執行出結果,
LED燈可以發光,我們首先試著條件判斷,讓LED燈用手動
方式亮。再來,我們用delay指令,讓LED燈自動的發光,
好妙唷!!

2012年11月20日 星期二

HW09 Week11

1.有processing+arduion可以做甚麼?

可以小朋友上樓梯,每上一格就發出一個聲音,上樓梯的部分用processing寫,然後結合arduion,用手控制 上樓的方式,假設有五種樓梯的圖案,每一種樓梯分別又各自的按鈕控制,(紅色樓梯就按第一個按鈕來上樓,綠 色樓梯就按第二個按鈕來上樓,依此類推)。



2.arduion應用之影片


玩西洋棋時,每動一步就會有聲音出現!


2012年11月12日 星期一

期中作品



我們的期中作品是小朋友挖隧道的遊戲,我們將玩法改變成小人會不斷的挖隧道前進要離開山洞,利用按空白鍵的方式來讓小人不要碰到山壁,但隨著山洞的路越來越窄小人需要得到高分才可以變小,最後順利離開山洞!
當得分達50分之後便會縮小身體,得到100分之後便成功破關順利離開山洞。

期中作品程式碼


int cfg_width =500;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body,mn,e;
int now=1;


float dir = 1;
long score = 0;
long maxscore = 0;
int push = 0;
int mode = 1;
float cur_space = 450;
float factor = 0.5;  


int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];


float[] yplayer = new float[cfg_width/2];

PFont myFont;

import ddf.minim.*;
Minim minim;
AudioPlayer player;


void initcave() {
 

  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;



   body=loadImage("bodyknife.png");

  for(int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for(int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}

void drawframe () {

    drawframe2 ();



  if( score/10==98 ||score/10==99 ||score/10==100)
  {  background(90,90,90);
     e=loadImage("end.jpg");

    image(e,220,80);
 
  }
 if(score/10==101)
  {
    size(500,450);
    mn=loadImage("mn.jpg");
    image(mn,0,0);
  }
  else{

  for(int i=1; i<width; i++) {
    stroke(255,0,0);
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);
  }
  }

 

  if (mode < 1) {
    stroke(0,255,0);
    strokeWeight(5);
    fill(100,255,0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
     people();
}

  void drawframe2 () {
  if (score/10<25){
   background(20);
  }
  else if (score/10<=50) {
    background(40,40,40);

  }
  else  if (score/10<100){
  background(90,90,90);

  }


}

void people(){
  for(int i=1; i<width/2; i++) {
  if (score/10<50){
     image(body,i, int(yplayer[i]),90,90);
  }
  else if (score/10<=100) {//大於50分 小於等於100分
     image(body,i, int(yplayer[i]),60,60);

  }


  }

}
                                 
void drawscore()
{
  if(mode==1 && score/10<=100)
  {
  stroke(0,255,0);
  strokeWeight(3);
  fill(0,255,0);
  textSize(18);


  text("The High Score: " + int(maxscore/10) +
 "   &  Score: " + int(score/10), 2, 20);
  }

 if (mode == -1) {
     fill(0,255,0);
    text("Game Over!\n Try Again.", 2, 20);
  }
}



void setup()
{

  size(cfg_width, cfg_height);

   initcave();

    frameRate(100);
     minim = new Minim(this); //播音樂
  player = minim.loadFile("Kalimba.mp3");  //播音樂
  player.play();  //播音樂


  }

void draw()
{

 if (mode == 1 && score/10<=100) {
   for(int i = 1; i < width; i++) {

    ylinetop[i-1] = ylinetop[i];
    ylinebottom[i-1] = ylinebottom[i];
 
  }

  for(int i = 1; i < width/2; i++) {
    yplayer[i-1] = yplayer[i];
  }


  ylinetop[width-1] =
    constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
                 + ylinetop[width-1]
              , 0, height-int(cur_space+1));
             
  ylinebottom[width-1] = ylinetop[width-1] + int(cur_space); 
  dir = pow(cfg_gravity, dir) * dir; 
  yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);
 
  if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
    mode = 0;
  }

  cur_space *= cfg_space_mod;
 
  score += 1;
 

  if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
    factor *= -1;
  }

   
 }

 else {
   if (mode == 0) {
 
     maxscore = maxscore > score ? maxscore : score;
 
     mode = -1;
   }
 }

 drawframe();
 drawscore();
 
}

void keyPressed() {
 
  if (mode == 1 && key == ' ') {
    dir *= 0.997;
  }


  if (mode == -1 && (keyCode == ENTER || keyCode == RETURN)) {
    mode = 1;
    initcave();
  }

}

期中作品截圖遊戲畫面

開始遊戲畫面

                                                                         失敗畫面
遊戲終點


過關畫面














2012年10月30日 星期二

week08,hw08

1本周進度

這禮拜完成了計分和小人移動的部分,洞穴會越來越窄,而小人會不斷的往下掉,不管他會觸碰到洞穴邊緣死掉,所以我們要一直按空白健讓小人往上移動,不要碰到洞穴邊緣。每次玩遊戲結束或是game over之後可以按Enter重玩一遍.遊戲的最高分數會記錄於左上角。


遊戲失敗畫面



遊戲畫面




2本週程式碼



int cfg_width =450;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;
PImage body;
float dir = 1; 
long score = 0; //分數
long maxscore = 0; //最高分紀錄
int push = 0; //按空白鍵增加
int mode = 1; // 遊戲狀態
float cur_space = 450; 
float factor = 0.5;   

//穴邊
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];

float[] yplayer = new float[cfg_width/2];

PFont myFont;


void initcave() {
  
  score = 0;
  dir = 1;
  push = 0;
  cur_space = 400;
 
  body=loadImage("body.png");
  
  
  
  for(int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  for(int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}

void drawframe () {
  background(0,0,0);
   
   stroke(255,0,0);
 
  for(int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);
  }

 
  for(int i=1; i<width/2; i++) {  
  
   image(body,i, int(yplayer[i]),80,80);
   if ( ylinetop[i]==10 & ylinebottom[i]==100){
     background(255);
   }
 
  }

  if (mode < 1) {
    stroke(0,255,0);
    strokeWeight(5);
    fill(100,255,0);
    ellipse(width/2, yplayer[width/2 - 1], 150, 150);
  }
  
}

void setup()
{
  size(cfg_width, cfg_height);
  initcave();
  frameRate(100);
}


void drawscore()
{
  stroke(0);
  strokeWeight(3);
  fill(0);
  text("最高分紀錄: " + int(maxscore/10) + "  分數: " + int(score/10), 1, 12);
  if (mode == -1) {
    text("Game Over!再玩一次.", 2, 26);
  }
}

void draw()
{
 
 if (mode == 1) {
   
  for(int i = 1; i < width; i++) {
    ylinetop[i-1] = ylinetop[i];
    ylinebottom[i-1] = ylinebottom[i];
  }
  
  for(int i = 1; i < width/2; i++) {
    yplayer[i-1] = yplayer[i];
  }
 
  ylinetop[width-1] =
    constrain( int( random(-cfg_maxchange, cfg_maxchange) + factor)
                 + ylinetop[width-1]
              , 0, height-int(cur_space+1));
              
  ylinebottom[width-1] = ylinetop[width-1] + int(cur_space);
  
  
  dir = pow(cfg_gravity, dir) * dir;
  
  yplayer[width/2-1] = constrain(yplayer[width/2- 2] * dir, 1, height-2);
  
  
  if (yplayer[width/2-1] < ylinetop[width/2] ||
      yplayer[width/2-1] > ylinebottom[width/2]) {
    mode = 0;
  }

  cur_space *= cfg_space_mod;
  
  score += 1;
  
 
  if (ylinetop[width-1] < 2 || ylinebottom[width-1] > height-2) {
    factor *= -1;
  }
    
 } else { 
   if (mode == 0) {
     maxscore = maxscore > score ? maxscore : score;
   
     mode = -1;
   }
 }
 
 drawframe();
 drawscore();
  
}

void keyPressed() {
  

  if (mode == 1 && key == ' ') {
    dir *= 0.997;
  }


  if (mode == -1 && (keyCode == ENTER || keyCode == RETURN)) {
    mode = 1;
    initcave();
  }

}
3尚未完成吃金幣的功能

4本周心得

這禮拜將小人用貼圖方式放進遊戲中,讓它可以順利執行,很開心
今天老師又說明了音樂怎麼進程式中,這樣一來我們也考慮放背景音樂至遊戲裡。
















2012年10月23日 星期二

week07 hw07


期中作品



/*配置變數                                    */
int cfg_width = 940;
int cfg_height = 450;
int cfg_maxchange = 5;
float cfg_space_mod = 0.9994;
int cfg_playersize = 5;
float cfg_gravity = 1.0002;

/* 遊戲變數                                  */
float dir = 1; 
int push = 0;
int mode = 1; // 遊戲狀態
float cur_space = 450; 
 

// 隧道邊
int[] ylinetop = new int[cfg_width];
int[] ylinebottom = new int[cfg_width];

// 遊戲的線
float[] yplayer = new float[cfg_width/2];

PFont myFont;


void initcave() {
  
  // 遊戲變數
  dir = 1;
  push = 0;
  cur_space = 400;
  
  // 隧道
  for(int i = 0; i < width; i++) {
    ylinetop[i] = height/2-int(cur_space)/2;
    ylinebottom[i] = ylinetop[i]+int(cur_space);
  }

  // 玩家
  for(int i = 0; i < width/2; i++) {
    yplayer[i] = height/2;
  }
}

// 畫背景
void drawframe () {
  background(51);
   
  // 畫隧道
  stroke(200);
  for(int i=1; i<width; i++) {  
    line(i, 0, i, ylinetop[i]);
    line(i, ylinebottom[i], i, height);
  }
  
  // 玩家
  stroke(255);
  for(int i=1; i<width/2; i++) {  
    line(i-1, int(yplayer[i-1]), i, int(yplayer[i]) );
  }
  
 
  if (mode < 1) {
    stroke(255,0,0);
    fill(255,0,0);
    ellipse(width/2, yplayer[width/2 - 1], 50, 50);
  }
  
}

void setup()
{

  size(cfg_width, cfg_height);
  initcave();
  frameRate(80);
}

void draw()
{
 
 drawframe();
}





視訊






心得:


   今天透過processing開啟視訊感覺很特別,或許之後可以藉由視訊功能做出更多的互動遊戲。希望之後arduino的學習也可以很有趣,並可以讓我們做更多的結合。




2012年10月16日 星期二

Week6 HW6

作品建議

黃培恩-------踩地雷小遊戲

我覺得可以再踩到地雷的時候出現整片白白的效果,

或是踩到地雷的時候出現腳印的圖案。

他們說在遊戲中搭配音樂還滿不錯的,可以增加遊戲的刺激度。


我們的期中作業進度與流程

1. 素材:小人、金幣、背景(山洞與天空)的圖案

2.在我們的遊戲中背景要隨小人前進而移動,最後背景從暗暗的山洞變成亮亮的天空。

    (所以我們目前初步想到怎麼用程式去表示)

3.吃金幣的後(小人)變小的效果

4.小人碰撞到山壁時,會game over

5. 用code試看背景與小人是否可行


本週上課心得

自己做一個小遊戲不容易,因為要把步驟與流程想過一次,

目前我們已初步的想出背景與小人怎麼同時移動了。

2012年10月9日 星期二

Week05 HW05

1.
程式碼
void setup(){
  background(0,0,0);
  size(500,500);
}
float r1=0.5;
float r2=0.1;
void draw(){
 
    background(0,0,0);
   
    translate(180,150);
    scale(0.8);
    rotate(r1);  r1+=0.05;
    fill(0,255,0); 
    for(int i=0;i<24;i++){
    rotate(PI/10);
    noStroke();
    ellipse(80,0,110,20);
    }
    fill(255,0,0);
    noStroke();
    ellipse(2,0,60,60);

    translate(100,150);
    scale(0.4);
    rotate(r2);  r2+=0.01;
    fill(0,0,255); 
    for(int j=0;j<24;j++){
    rotate(PI/10);
    noStroke();
   
    ellipse(80,0,110,20);
    }
    fill(255,242,0);
    noStroke(); 
    ellipse(2,0,60,60);

}

圖片




















2.
程式碼
void setup(){
  background(0,0,0);
  size(500,500);
}
float r1=0.5;
float r2=0.1;
void circle(){
    //translate(100,150);
    //scale(0.4);
    rotate(r2);  r2+=0.01;
    fill(0,0,255); 
    for(int j=0;j<24;j++){
    rotate(PI/10);
    noStroke();
   
    ellipse(80,0,110,20);
    }
    fill(255,242,0);
    noStroke(); 
    ellipse(2,0,60,60);
 }  
  
void draw(){
 
    background(0,0,0);
   
    translate(mouseX,mouseY);
    scale(0.8);
    rotate(r1);  r1+=0.05;
    fill(255,0,0); 
    for(int i=0;i<24;i++){
    rotate(PI/10);
    noStroke();
    ellipse(80,0,110,20);
    }
    fill(0,100,0);
    noStroke();
    ellipse(2,0,60,60);
   
    translate(100,150);
    scale(0.4);
    circle();
   
   translate(120,130);
    scale(0.6);
    circle();
    
    translate(250,160);
    scale(0.8);
    circle();

}


圖片



















3.
期中作品構想

  在電視節目上看到的遊戲,電流急急棒!在電腦遊戲或是遊戲機上也有看到,我們覺得 很有趣,所以想做一個類似的遊戲。
  我們預設一個小人想要離開山洞,隨著山洞越來越窄越不好走,一碰到山洞的牆壁就會死掉!所以他一路上需要去吃神奇的金幣,讓自己的身體縮小,可以順利逃離山洞。

 
 
第一張圖是小人在山洞時的大小,等小人吃了金幣後,身體變小(如下圖),就可以順利通過
山洞的後段地方,重見光明。













2012年10月2日 星期二

Week04 HW04

程式碼
void setup(){

  size(500,400);
  background(241,224,131);
 
  fill(255,255,255);   //save
  rect(0,250,50,50);
  fill(0,0,0);
  text("Save",10,280);
 
  fill(255,255,255);   //load
  rect(0,300,50,50);
  fill(0,0,0);
  text("Load",10,330);
 
  fill(192,192,192);  //粗
  rect(450,0,50,50);
  fill(255,0,0);
  text("粗筆",463,30);
  
  fill(192,192,192);   //細
  rect(450,50,50,50);
  fill(255,0,0);
  text("細筆",463,80);

  noStroke();
  fill(255,0,0); //red
  rect(0,0,50,50);
 
  fill(233,33,183); //pink
  rect(0,50,50,50);
 
 
  fill(255,255,0);//yellow
  rect(0,100,50,50);

  fill(0,255,0);   //green
  rect(0,150,50,50);
 

  fill(0,0,255);   //blue
 
  rect(0,200,50,50);
 
 
 
}
int s=5;
void draw(){
  if(mousePressed && mouseX<50 && mouseY<50) stroke(255,0,0);
 
  else if(mousePressed && mouseX<50 && mouseY<100) stroke(233,33,183);
 
  else if(mousePressed && mouseX<50 && mouseY<150) stroke(255,255,0);
 
  else if(mousePressed && mouseX<50 && mouseY<200) stroke(0,255,0);
 
  else if(mousePressed && mouseX<50 && mouseY<250) stroke(0,0,255);
 
 
  else if(mousePressed && mouseX<50 && mouseY<300) save("pic.png");
  else if(mousePressed && mouseX<50 && mouseY<350){
    PImage file = loadImage("pic.png");
    image(file, 0,0,500,400);
 
  }else if(mousePressed && mouseX>450 && mouseY<50){
    strokeWeight(++s);
  }
  else if(mousePressed && mouseX>450 && mouseY<1000){
    strokeWeight(--s);
    if(s<3)s=3;
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);
}



圖片




















課堂心得
自己做小畫家好酷,可以調整顏色筆的粗細,很特別。

2012年9月25日 星期二

Week03 HW03

Week03,HW03第一個作業:

程式碼


void setup(){  //固定大小
    size(600,600);
   background(0);
}
void draw(){   //畫,會改變的數值


fill(0,255,100);
noStroke();
//rect(100,100,100,100);

fill(random(255),random(255),random(255));


ellipse(mouseX,mouseY,random(80)/10,random(80)/10);//座標點改成滑鼠座標點,所以滑鼠到哪圖就畫到哪
}

圖片




Week03,HW03第二個作業:

程式碼
void setup(){  //固定大小
    size(600,600);
  
   
 }
float x=100,y=100;
void draw(){   //畫,會改變的數值
noStroke();  
background(0); 





fill(255,0,100);
ellipse(mouseX,mouseY,100,50);//座標點改成滑鼠座標點,所以滑鼠到哪圖就畫到哪
ellipse(mouseX-50,mouseY,20,40);
ellipse(mouseX+50,mouseY,20,40);

fill(0,0,0);
translate(x,y);
scale(0.5,0.5);
mygr();

x=(x+mouseX)/2;
y=(y+mouseY)/2;


}


void mygr()
{
fill(255,150,10);
rect(x,y,80,150);

fill(255,150,10);
rect(x+30,y+150,140,120);


fill(255,150,10);
rect(x+50,y+270,30,150);

fill(255,150,10);
rect(x+120,y+270,30,150);

fill(255,150,10);
ellipse(x+80,y,50,50);

fill(255,150,10);
ellipse(x,y,50,50);

fill(0,255,255);
ellipse(x+9,y,30,30);

fill(0,255,255);
ellipse(x+69,y,30,30);

}


圖片



課堂心得:

這週的課程跟前兩禮拜學的畫圖可以做結合,把第一個禮拜畫的圖使用void,

可以讓變大變小,不用一直調整數值。

寫起程式起來也更簡單,不會很冗長。






2012年9月18日 星期二

week02,HW02

1.HW02_1

程式碼:

size(600,600);
for (int i=0;i<50;i++){
    fill(random(255),random(255),random(255));
    rect(random(400),random(400),random(200),random(200));
}

圖片:



2.HW02_2


程式碼:

size(500,400);
noStroke();
for (int i=0;i<50;i++){
  for(int j=0;j<40;j++){
    fill(i*255/50+100,j*200/40+10,180);
    ellipse(i*30,j*20,40,20);
 
  }
}


圖片:


3.HW02_3


程式碼:


size(400,300);
noStroke();
for (int i=0;i<4;i++){
  for(int j=0;j<3;j++){
    fill(i*255/4,j*255/3,90);
    ellipse(i*100+50,j*100+50,100,90);
    fill(252,255,255);
    ellipse(i*100+50,j*100+50,100,30);
    fill(i*255/10,j*250/10,0);
    ellipse(i*100+50,j*100+50,30,30);
  }
}


圖片:




4.課堂心得:

這禮拜的課堂中,練習顏色的調整,很有趣,

原來顏色的參數可以使用random指令,好酷!




2012年9月11日 星期二

Week 01 HW01

1.processing影片






2.
size(550,450);
PImage amon;
amon = loadImage
("http://i.15fun.com/upload/201009/927_1.jpg");
image(amon,20,20);












 






3.
原始版








 
小畫家

processing版
 

4.心得

第一次上這門課,很新鮮,因為processing真神奇,幾個指令就可以畫出我所要的圖案,
只是在畫圖的過程中,我覺得座標需要花些時間算,還有利用reference找指令,頗有趣的好像在挖寶,會突然找到一些超好用的指令。