顯示具有 99160291鄒宛妮 標籤的文章。 顯示所有文章
顯示具有 99160291鄒宛妮 標籤的文章。 顯示所有文章

2013年1月18日 星期五

Week19, Final


這次的期末作品是拿我們的期中作品來改良的,把原本用滑鼠移動的海綿寶寶改用Arduino的按鍵來坐上下左右的移動

Arduino程式碼:
int buttonPin5 = 5;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;

int buttonState5 = 0;  
int buttonState2 = 0;  
int buttonState3 = 0;  
int buttonState4 = 0;  
void setup() {

  pinMode(buttonPin5, INPUT);     
  pinMode(buttonPin2, INPUT);     
  pinMode(buttonPin3, INPUT);      
  pinMode(buttonPin4, INPUT);
  
  Serial.begin(9600);

}
void loop() {
  buttonState5 = digitalRead(buttonPin5);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  
  if (buttonState5 == HIGH) {     
   //tone(8, 131, 300);
   Serial.write('A');
  }  
  else if (buttonState5 == LOW) { 
   //Serial.write('Z');
  }
  
  if (buttonState2== HIGH) {     
   //tone(8, 147 , 300);
   Serial.print('S');
  }
  else if (buttonState2 == LOW) { 
   //Serial.write('X');
  }

  if (buttonState3 == HIGH) {     
   //tone(8, 165 , 300);
   Serial.print('D');
  }
   else if (buttonState3 == LOW) { 
   //Serial.write('C');
  }

  if (buttonState4 == HIGH) {     
   //tone(8, 175 , 300);
   Serial.print('F');
  }
   else if (buttonState4 == LOW) { 
   //Serial.write('V');
  }
  if(buttonState2 == LOW&&buttonState3 == LOW&&buttonState4 == LOW&&buttonState5 == LOW){
  Serial.write('H');
  }
   delay(500);
}







processing程式碼:


import processing.serial.*;
Serial myPort;

int popox=0,popoy=0,popoy1=0,popoy2=0,popoy3=0,popoy4=0,popoy5=0;
int fishx=0,fishy=0;
int score=600;
int lasttime=60;

import ddf.minim.*;
AudioPlayer  player,wate,cheers;
Minim minim;

PImage popo;
//PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
  size(800,600);
  myPort = new Serial(this, "COM3", 9600);
  fish=loadImage("fish.png"); //游動的魚
  bobo=loadImage("bobo.png"); //海綿寶寶
  //finger=loadImage("finger.png"); //手指
  popo=loadImage("popo.png"); //泡泡
  back=loadImage("back.jpeg"); //背景圖
  minim=new Minim(this);
  //wate=minim.loadFile("wate.wav", 2048);
player=minim.loadFile("file.mp3"); //背景音樂
player.play();
}
int val;
int b_x=400,b_y=300;
int w=5,s=5,a=5,d=5;
void draw()
{
  if(myPort.available()>0){
    val = myPort.read();//第三個重點:如果讀到數字就拿出來用
    println(val);
}

  image(back,0,0);
  //image(bobo,250,100);


  popoy-=3; //泡泡移動量
  image(popo,popox+300,popoy+600,100,100);  //泡泡坐標,大小
 
  if (b_x > popox+300 && b_x< popox+400 && b_y<popoy+700 && b_y>popoy+600) //判斷滑鼠是否點到泡泡的範圍
   {
     popoy=600; //泡泡回到下面再跑一次
   score-=10; //碰到泡泡減十分
   wate=minim.loadFile("wate.wav"); //戳到泡泡時播放音效
   wate.play();
   }
 
   if (b_x > popox+200 && b_x< popox+300 && b_y<popoy1+600 && b_y>popoy1+500)
  {
    popoy1=500;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
  }
   if (b_x > popox+100 && b_x< popox+200 && b_y<popoy2+800 &&  b_y>popoy2+700)
  {
    popoy2=700;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
 }
   if (b_x > popox+500 && b_x< popox+600 && b_y<popoy3+750 && b_y>popoy3+650)
   {
     popoy3=600;
   score-=10;
   wate=minim.loadFile("wate.wav");
   wate.play();
   }
  if (b_x > popox+400 && b_x< popox+500 && b_y<popoy4+950 && b_y>popoy4+850)
  {
    popoy4=600;
  score-=10;
  wate=minim.loadFile("wate.wav");
   wate.play();
  }
    if (b_x > popox+600 && b_x< popox+700 &&  b_y<popoy5+1050 && b_y>popoy5+950)
  {
    popoy5=700;
  score-=10;
  wate=minim.loadFile("wate.wav");
   wate.play();
  }
 
  if(popoy+600<0) //判斷泡泡是否跑出視窗
  {

    popoy=0; //泡泡回到原點再跑一次
  }
   popoy1-=2;
  image(popo,popox+200,popoy1+500,100,100);
   if(popoy1+500<0)
  {

    popoy1=0;
  }
   popoy2-=3;
  image(popo,popox+100,popoy2+700,100,100);
   if(popoy2+700<0)
  {

    popoy2=0;
  }
   popoy3-=5.5;
  image(popo,popox+500,popoy3+650,100,100);
   if(popoy3+650<0)
  {
    popoy3=0;
  }
  popoy4-=2;
  image(popo,popox+400,popoy4+850,100,100);
   if(popoy4+850<0)
  {
    popoy4=0;
  }
  popoy5-=3;
  image(popo,popox+600,popoy5+950,100,100);
   if(popoy5+950<0)
  {
    popoy5=0;
  }

  image(bobo,b_x,b_y,60,60);
  fishx++;
  image(fish,fishx,fishy+200);
  {
    if(fishx>800) //判斷魚是否跑出視窗
    {
    fishx=0;
    fishy=250;
    }
  }
  world();

 if(val=='A'){
    b_x-=4;
  }
 if(val=='S'){
    b_x+=4;
  }
 if(val=='F'){
    b_y-=4;
  }
 if(val=='D'){
    b_y+=4;
  }
  if(val=='H'){
   b_y+=0;
    b_x+=0;
  }
 
  if(b_x<0)
  {
    b_x=0;
  }
 
    if(b_x>745)
  {
    b_x=745;
  }
 
    if(b_y<0)
  {
    b_y=0;
  }

   if(b_y>540)
  {
    b_y=540;
  }
}

  void world()
  {
     textFont(createFont("Georgia", 48));
      fill(255);
  text("score:"+score, 20, 550); //分數
 
  textFont(createFont("Georgia", 48));
      fill(255);
  text("Time:"+lasttime, 250, 550); //計時器
  lasttime=60-millis()/1000;
 
      if(lasttime==0) //當時間=0,秀出得分
      {
      stop();
      textFont(createFont("Georgia", 80));
      background(51,102,51);
      fill(255,255,255);
      text("Game Over",200,300);
      text("Your score:"+score,180,400);
      cheers=minim.loadFile("cheers.wav");
      cheers.play();
      }
  }

心得:
這次的期末作業我們覺得沒有做得很好,Demo到後面的時候有點乾
按鍵道具的部分也是用課堂上的案件,並沒有花心思在其他道具上,但在Arduino的程式上,我們花了不少時間去研究,也學到了不少的東西.

2012年12月6日 星期四

Week13,Hw11

1.程式碼

int inpin1=6;
int inpin2=7;
int inpin3=9;
int inpin4=3;
int inpin5=1;


int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;

void setup() {
 
pinMode(inpin1, INPUT);
pinMode(inpin2, INPUT);
pinMode(inpin3, INPUT);
pinMode(inpin4, INPUT);
pinMode(inpin5, INPUT);


}


void loop() {
  buttonState1 = digitalRead(inpin1);
  buttonState2 = digitalRead(inpin2);
  buttonState3 = digitalRead(inpin3);
  buttonState4 = digitalRead(inpin4);
  buttonState5 = digitalRead(inpin5);

  if (buttonState1 == HIGH)  tone(8, 524,4);
  else if (buttonState2 == HIGH)  tone(8, 588,4);
  else if (buttonState3 == HIGH)  tone(8, 660,4);
  else if (buttonState4 == HIGH)  tone(8, 698,4);
  else if (buttonState5 == HIGH)  tone(8, 784,4);
  else {
  noTone(9);
  }
 
 
 
 
}


2.影片
 

2012年11月27日 星期二

Week12,HW10

1.程式碼


/*
  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

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(1, OUTPUT);

}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
  // turn the ledPin on
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(1, HIGH);

  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);        
  // turn the ledPin off:      
  digitalWrite(13, LOW);  
  digitalWrite(12, LOW);
  digitalWrite(10, LOW);
  digitalWrite(7, LOW);
  digitalWrite(3, LOW);
  digitalWrite(6, LOW);
  digitalWrite(1, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                
}

2.影片

2012年11月13日 星期二

Week06 , Hw06

 我覺得傅建國的小朋友上樓梯讓我比較期待
因為之前比較常玩小朋友下樓梯,而且在我印象當中都是用手機的方式玩


還有
詹中豪那組的俄羅斯方塊也很勾起我小時的後回憶
感覺他會研發更另類的玩法



我們想做的是“海綿寶寶戳泡泡”

需要
1.海綿寶寶圖案
2.泡泡圖案
3.海底世界背景圖
4.計時,計分器

今天有把基本的架構都做出來,泡泡會動了

Midterm

1 影片


  
2.遊戲方法&截圖
遊戲開始後,下方會開始冒泡泡出來,要用滑鼠去點泡泡,泡泡會消失並且分數會加五分,如果沒有戳到泡泡而讓泡泡跑出視窗,分數會扣五分,為時一分鐘


一分鐘結束後,會秀出所得的分數


3.程式碼

int popox=0,popoy=0,popoy1=0,popoy2=0,popoy3=0,popoy4=0,popoy5=0;
int fishx=0,fishy=0;
int score=0;
int lasttime=60;

import ddf.minim.*;
AudioPlayer  player,wate,cheers;
Minim minim;

PImage popo;
PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
  size(800,600);
  fish=loadImage("fish.png"); //游動的魚
  bobo=loadImage("bobo.png"); //海綿寶寶
  finger=loadImage("finger.png"); //手指
  popo=loadImage("popo.png"); //泡泡
  back=loadImage("back.jpeg"); //背景圖
  minim=new Minim(this);
player=minim.loadFile("file.mp3", 2048); //背景音樂
player.play();
}

void draw()
{

  image(back,0,0);
  image(bobo,250,100);


  popoy-=3; //泡泡移動量
  image(popo,popox+300,popoy+600,100,100);  //泡泡坐標,大小
  if(popoy+600<0) //判斷泡泡是否跑出視窗
  { 
    score-=5; //跑出視窗後扣五分
    popoy=0; //泡泡回到原點再跑一次
  }
   popoy1-=2;
  image(popo,popox+200,popoy1+500,100,100);
   if(popoy1+500<0)
  {
    score-=5;
    popoy1=0;
  }
   popoy2-=3;
  image(popo,popox+100,popoy2+700,100,100);
   if(popoy2+700<0)
  {
    score-=5;
    popoy2=0;
  }
   popoy3-=5.5;
  image(popo,popox+500,popoy3+650,100,100);
   if(popoy3+650<0)
  {
    score-=5;
    popoy3=0;
  }
  popoy4-=2;
  image(popo,popox+400,popoy4+850,100,100);
   if(popoy4+850<0)
  {
    score-=5;
    popoy4=0;
  }
  popoy5-=3;
  image(popo,popox+600,popoy5+950,100,100);
   if(popoy5+950<0)
  {
    score-=5;
    popoy5=0;
  }

  image(finger,mouseX-30,mouseY-30,60,60);
  
  fishx++;
  image(fish,fishx,fishy+200);
  {
    if(fishx>800) //判斷魚是否跑出視窗
    {
    fishx=0; 
    fishy=250;
    }
  }
  world();

  
}

void mousePressed()
  {
  
  if (mouseX > popox+300 && mouseX< popox+400 && mouseY<popoy+700 && mouseY>popoy+600) //判斷滑鼠是否點到泡泡的範圍
   {
     popoy=600; //泡泡回到下面再跑一次
   score+=5; //戳到泡泡加五分
   wate=minim.loadFile("wate.wav", 2048); //戳到泡泡時播放音效
   wate.play();
   }
   if (mouseX > popox+200 && mouseX< popox+300 && mouseY<popoy1+600 && mouseY>popoy1+500)
  {
    popoy1=500;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
   if (mouseX > popox+100 && mouseX< popox+200 && mouseY<popoy2+800 && mouseY>popoy2+700)
  {
    popoy2=700;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
 }
   if (mouseX > popox+500 && mouseX< popox+600 && mouseY<popoy3+750 && mouseY>popoy3+650)
   {
     popoy3=600;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
   }
  if (mouseX > popox+400 && mouseX< popox+500 && mouseY<popoy4+950 && mouseY>popoy4+850)
  {
    popoy4=600;
  score+=5;
  wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
    if (mouseX > popox+600 && mouseX< popox+700 && mouseY<popoy5+1050 && mouseY>popoy5+950)
  {
    popoy5=700;
  score+=5;
  wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
  }
  
  void world()
  {
     textFont(createFont("Georgia", 48)); 
      fill(255);
  text("score:"+score, 50, 550); //分數
  
  textFont(createFont("Georgia", 48));
      fill(255);
  text("Time:"+lasttime, 250, 550); //計時器
  lasttime=60-millis()/1000; 
  
      if(lasttime==0) //當時間=0,秀出得分
      {
      stop();
      textFont(createFont("Georgia", 80));
      background(51,102,51);
      fill(255,255,255);
      text("Game Over",200,300);
      text("Your score:"+score,180,400);
      cheers=minim.loadFile("cheers.wav");
      cheers.play();
      }
  }


   
   

2012年10月30日 星期二

Week08,Hw08

1.1加上手指可以戳泡泡及會游動的魚
1.2加上背景音樂及戳到泡泡時的音效
1.3如何讓泡泡一直不停出現...用回圈寫寫看能不能讓泡泡一直出現

2.1
int popox=0,popoy=0;
int fishx=0,fishy=0;

PImage popo;
PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
  size(800,600);
  fish=loadImage("fish.png");
  bobo=loadImage("bobo.png");
  finger=loadImage("finger.png");
  popo=loadImage("popo.png");
  back=loadImage("back.jpeg");
}

void draw()
{
// background(255,255,255);

  
 image(back,0,0);
  image(bobo,250,100);
  popoy-=0.05;
  image(popo,popox+300,popoy+600,100,100);
  popoy-=0.05;
  image(popo,popox+200,popoy+500,100,100);
   popoy-=0.05;
  image(popo,popox+100,popoy+700,100,100);
  popoy-=0.05;
  image(popo,popox+500,popoy+600,100,100);
  
    popoy-=0.05;
  image(popo,popox+300,popoy+1500,100,100);
  popoy-=0.05;
  image(popo,popox+200,popoy+1400,100,100);
   popoy-=0.05;
  image(popo,popox+100,popoy+1300,100,100);
  popoy-=0.05;
  image(popo,popox+500,popoy+1200,100,100);
  
    popoy-=0.05;
  image(popo,popox+300,popoy+1600,100,100);
  popoy-=0.05;
  image(popo,popox+200,popoy+1500,100,100);
   popoy-=0.05;
  image(popo,popox+100,popoy+1700,100,100);
  popoy-=0.05;
  image(popo,popox+500,popoy+1600,100,100);
  
  popoy--;
  image(popo,popox+300,popoy+800,100,100);
  popoy--;
  image(popo,popox+200,popoy+1000,100,100);
   popoy--;
  image(popo,popox+100,popoy+700,100,100);
  popoy--;
  image(popo,popox+500,popoy+1200,100,100);
  
      popoy-=0.05;
  image(popo,popox+300,popoy+2200,100,100);
  popoy-=0.05;
  image(popo,popox+200,popoy+1900,100,100);
   popoy-=0.05;
  image(popo,popox+100,popoy+2000,100,100);
  popoy-=0.05;
  image(popo,popox+500,popoy+1000,100,100);
  
      popoy-=0.05;
  image(popo,popox+400,popoy+2000,100,100);
  popoy-=0.05;
  image(popo,popox+600,popoy+2300,100,100);
   popoy-=0.05;
  image(popo,popox+500,popoy+2400,100,100);
  popoy-=0.05;
  image(popo,popox+500,popoy+2600,100,100);
  
        popoy-=0.05;
  image(popo,popox+100,popoy+2000,100,100);
  popoy-=0.05;
  image(popo,popox+300,popoy+2300,100,100);
   popoy-=0.05;
  image(popo,popox+200,popoy+2400,100,100);
  popoy-=0.05;
  image(popo,popox+100,popoy+2600,100,100);
  
  image(finger,mouseX-30,mouseY-30,60,60);
  
  fishx++;
  image(fish,fishx,fishy+200);
  
}

2.2

2012年10月9日 星期二

Week05,HW05

void setup(){
  size(600,600);
  background(255,255,255);
}
float rrr=0.01;
void draw(){
  translate(300,200);
  rotate(rrr);rrr+=0.02;
  fill(200,191,231);
  for(int i=0;i<18;i++){
    rotate( PI/9);
    ellipse(100,0,100,50);
  }
  fill(255,255,128);
  ellipse(0,0,100,100);
}

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

}
float rrr=0.01;
void draw(){
   background(255,255,255);
  translate(mouseX,mouseY);
 
  rotate(rrr);rrr+=0.02;
  fill(200,191,231);
  for(int i=0;i<18;i++){
    rotate( PI/9);
    ellipse(100,0,100,50);
  }
  fill(255,255,128);
  ellipse(0,0,100,100);
}
 

 

2012年10月2日 星期二

week04,wh4

void setup(){
size(500,400);
}
void draw(){
if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
 
 
 
void setup(){
size(500,400);
fill(255,0,0);
rect(0,0,50,50);
fill(0,255,0);
rect(0,50,50,50);
fill(255,255,0);
rect(0,100,50,50);
fill(255,255,255);
rect(0,150,50,50);
fill(0,0,0);
rect(0,200,50,50);
fill(255,255,255);
rect(0,250,50,50);
fill(255,255,255);
rect(0,300,50,50);
fill(255,255,255);
rect(450,0,50,50);
fill(255,255,255);
rect(450,50,50,50);
}
int w=5;
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(255,255,0);
else if(mousePressed && mouseX<50 && mouseY<200) stroke(255,255,255);
else if(mousePressed && mouseX<50 && mouseY<250) stroke(0,0,0);
else if(mousePressed && mouseX<50 && mouseY<300) save("bbb.png");
else if(mousePressed && mouseX<50 && mouseY<350){
PImage file=loadImage("bbb.png");
image(file,0,0,500,400);
}
else if(mousePressed && mouseX>450 && mouseY<50){
strokeWeight(++w);
}
else if(mousePressed && mouseX>450 && mouseY<1000){
strokeWeight(--w);
if(w<2)w=2;
}
else if(mousePressed) line(mouseX, mouseY, pmouseX, pmouseY);
}
 
 
 
 

2012年9月25日 星期二

week03,hw03

void setup(){
  size(600,600);
}
float x=100,y=100;
void draw(){
  background(0,0,0);

  fill(255,255,255);
  ellipse(mouseX,mouseY,100,100);

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

  x=x*0.8 + mouseX*0.2;
  y=y*0.8 + mouseY*0.2;
}



2012年9月18日 星期二

week02,hw02

1. 用random畫出50個方格 


size(500,500);
for(int i=0;i<50;i++)
{
  fill( random(255), random(255), random(255));
  rect(random(300),random(300),random(300),random(300));
}

2.

size(400,300);
for(int i=0;i<40;i++){
  for(int k=0;k<30;k++){
    fill(i*255/20,random(255),100);
    rect(i*10,k*10,  10,10);
  }
}



3.size(400,300);
for(int i=0;i<4;i++){
  for(int k=0;k<3;k++){
    fill(i*255/1,random(255),300);
    ellipse(i*50+100,k*50+100,  40,40);
  }
}