Processing程式碼:
PImage bg,blue,orange,green,blue1,orange1;
PImage imgPub;
PImage imgMusic;
PImage imgPop;
import processing.serial.*;
Serial myPort;
int N=6;
int count = 9700;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
import ddf.minim.*;
Minim m;
AudioPlayer player;
void setup(){
myPort = new Serial(this, "COM4", 9600);
imgPub=loadImage("Pub.jpg");
imgMusic=loadImage("Music.jpg");
imgPop=loadImage("Pop.jpg");
image(imgPop,400,600);
image(imgMusic,400,600);
image(imgPub,400,600);
bg = loadImage("background.jpg");
blue = loadImage("blue.jpg");
orange = loadImage("orange.gif");
green = loadImage("green.jpg");
blue1 = loadImage("blue1.gif");
orange1 = loadImage("orange1.jpg");
m = new Minim(this);
player = m.loadFile("DNA.mp3");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
player.play();
val = myPort.read();
image(imgPop,0,0,400,600);
if(keyPressed)
textSize(40);
text("Start!!", 250, 300);
if(key=='s')
image(imgMusic,0,0,400,600);
if(countDown>0){
//background(255,0,255);
countDown--;
text("Time: "+countDown/50,170,300);
return;
}
image(bg,0,0, 400,600);
image(blue,0,575,80,40);
image(orange,80,575,80,40);
image(green,160,575,80,40);
image(blue1,240,575,80,40);
image(orange1,320,575,80,40);
for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblue(i);
//if (keyPressed)
//if(key=='d'|| key=='D')
println(val);
if(525<thingY[i] && thingY[i]<700 && val==50)
{
thingY[i] = 650; grade+=100; //println(grade);
fill(#0046FF,90);
rect(0,575,80,-600);
}
}
else if(thingType[i]==2)
{
draworange(i);
//if (keyPressed)
{
//if(key=='f'|| key=='F')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==51)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(80,575,80,-600);
}
}
}
else if(thingType[i]==3)
{
drawgreen(i);
//if (keyPressed)
{
//if(key=='b'|| key=='B')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==52)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#10FF00,90);
rect(160,575,80,-600);
}
}
}
else if(thingType[i]==4)
{
drawblue1(i);
//if (keyPressed)
{
//if(key=='k'|| key=='K')
//println(val);
if(525<thingY[i] && thingY[i]<600 && val==49)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#0046FF,90);
rect(240,575,80,-600);
}
}
}
else if(thingType[i]==5)
{
draworange1(i);
//if (keyPressed)
{
//if(key=='j'|| key=='J')
println(val);
if (525<thingY[i] && thingY[i]<600 && val==53)
{
thingY[i] = 650; grade+=100; println(grade);
fill(#FF7D00,90);
rect(320,575,80,-600);
}
}
}
thingY[i]+=3;
if(thingY[i]>600) newThing(i);
}
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
//background(#FF0015);
//background(imgMusic,400,600);
image(imgMusic,0,0,400,600);
fill(255,0,0);
text("Score: "+grade,122,300);
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblue(int i){
thingX[i]=int(random(0,0));
image(blue,thingX[i],thingY[i],80,22);
}
void draworange(int i){
thingX[i]=int(random(80,80));
image(orange,thingX[i],thingY[i],80,22);
}
void drawgreen(int i){
thingX[i]=int(random(160,160));
image(green,thingX[i],thingY[i],80,22);
}
void drawblue1(int i){
thingX[i]=int(random(240,240));
image(blue1,thingX[i],thingY[i],80,22);
}
void draworange1(int i){
thingX[i]=int(random(320,320));
image(orange1,thingX[i],thingY[i],80,22);
}
2014年1月12日 星期日
2014年1月11日 星期六
99163116鄭祥斌硬體程式碼
期末作品硬體程式碼:
int switchPin1 = 2;
int switchPin2 = 3;
int switchPin3 = 4;
int switchPin4 = 5;
int switchPin5 = 6;
boolean oldStage1 = false;
boolean oldStage2 = false;
boolean oldStage3 = false;
boolean oldStage4 = false;
boolean oldStage5 = false;
void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(switchPin1) == LOW)
{
if(oldStage1)
{
Serial.print(0,DEC);
}
oldStage1 = false;
}
else
{
if(!oldStage1)
{
Serial.print(1,DEC);
}
oldStage1 = true;
}
if (digitalRead(switchPin2) == LOW)
{
if(oldStage2)
{
Serial.print(2,DEC);
}
oldStage2 = false;
}
else
{
if(!oldStage2)
{
Serial.print(3,DEC);
}
oldStage2 = true;
}
if (digitalRead(switchPin3) == LOW)
{
if(oldStage3)
{
Serial.print(4,DEC);
}
oldStage3 = false;
}
else
{
if(!oldStage3)
{
Serial.print(5,DEC);
}
oldStage3 = true;
}
if (digitalRead(switchPin4) == LOW)
{
if(oldStage4)
{
Serial.print(6,DEC);
}
oldStage4 = false;
}
else
{
if(!oldStage4)
{
Serial.print(7,DEC);
}
oldStage4 = true;
}
if (digitalRead(switchPin5) == LOW)
{
if(oldStage5)
{
Serial.print(8,DEC);
}
oldStage5 = false;
}
else
{
if(!oldStage5)
{
Serial.print(9,DEC);
}
oldStage5 = true;
}
}
2013年12月16日 星期一
Week15 葉玉婷
今日上課進度:
寫出期末作品Processing (打磚塊)
磚塊是豬的圖案
橫槓是金箍棒的圖案
第一關只有一排豬
全打完會進入下一關
每進入新的關卡增加一排豬
若球掉了則Game over
遊戲影片:
譚庚倫的15周作業
小朋友下樓梯之破壞樓梯
程式碼:
import ddf.minim.*;
//import processing .serial.*;
int t=0;
//Serial serial
int s=0;
int time=0;
int score=0;
String text="score:";
String text1="get score:";
int []sequence=new int[1000];
int []thingx = new int[100];
int []thingy = new int[100];
PImage floor, bg, man, over, man2,pupu;
int pux;
float puy;
int manx=213;
float many=0;
Minim m;
AudioPlayer player, player1, player2,player3;
void setup() {
m=new Minim(this);
// serial= new Serial(this,"COM3",9600);
for (int i =0;i<10;i++) {
}
player=m.loadFile("down.wav");
player1=m.loadFile("die.wav");
player2=m.loadFile("back.mp3");
player3=m.loadFile("bom.wav");
man2=loadImage("man2.png");
size(426, 311);
pupu=loadImage("pupu.png");
over=loadImage("gameover.jpg");
floor=loadImage("floor.jpg");
man=loadImage("man.png");
bg=loadImage("bg.jpg");
for (int i=0;i<10;i++) {
sequence[i] = int(random(3));
}
for (int i=0;i<10;i++) {
thingx[i] = int(random(426));
thingy[i] = int(random(1000));
}
}
int now=0;
int x=0;
void draw() {
background(bg);
image(man, manx, many, 50, 50);
//if(serial.availabe()>0)
//{
// char c=serial.read();
// print(C);
// }
//player2.play();
if(key=='a' && keyPressed==true){
t=1;
pux=manx;
puy=many;
}
if(t==1)
{
puy=puy+3;
image(pupu,pux, puy, 20, 20);
}
for (int i=0;i<10;i++) {
if(s==0)
{
image(floor, thingx[i], thingy[i]);
thingy[i]-=1;
if (thingy[i]==0)
{
thingy[i]=311;
}
if(dist(thingx[i]+48.5,thingy[i]+10,pux,puy)<=40)
{
//player3.play();
thingy[i]=330;
pux=312;
puy=312;
}
// float dis=dist(thingx[i],thingy[i],manx,many);
if (dist(thingx[i]+48.5, thingy[i]+10, manx, many)<=67.5) {
image(man2, manx, many, 50, 50);
//image(man2,manx,many,50,50);
many=thingy[i]-42;
}
else {
many+=0.1;
}
}
if (many>311)
{
s=1;
image(over, 100, 105.5, 250, 100);
many+=10;
//player.play();
}
if (many<0)
{
s=1;
image(over, 100, 105.5, 250, 100);
}
}
if(s==0){
if(time%50==0)
{
score+=10;
print(score);
}
textSize(32);
fill(200);
text(text,40,40);
textSize(32);
fill(200);
text(score,130,40);
}
else
{
textSize(32);
fill(200);
text(text1,60,250);
textSize(32);
fill(200);
text(score,250,250);
}
time++;
}
void keyPressed() {
//if(keyCode==DOWN)many+=2;
if (keyCode==LEFT)manx-=10;
if (keyCode==RIGHT)manx+=10;
}
Week 15
PImage bg,life1,life2,life3,life4,life5,blu,white,yellow,blu1,white1,yellow1;
void setup(){
bg = loadImage("bg.jpg");
life1 = loadImage("life.jpg");
life2 = loadImage("life.jpg");
life3 = loadImage("life.jpg");
life4 = loadImage("life.jpg");
life5 = loadImage("life.jpg");
blu = loadImage("blu.jpg");
white = loadImage("white.jpg");
yellow = loadImage("yellow.jpg");
blu1 = loadImage("blu1.jpg");
white1 = loadImage("white1.jpg");
yellow1 = loadImage("yellow1.jpg");
size(400,600);
}
void draw(){
image(bg,0,0, 400,600);
image(life1,368,5,28,66);
image(life2,368,76,28,66);
image(life3,368,147,28,66);
image(life4,368,218,28,66);
image(life5,368,289,28,66);
image(blu,13,475,60,15);
image(white,73,475,66,15);
image(yellow,139,475,88,15);
image(blu,227,475,66,15);
image(white,293,475,64,15);
}
第15週作業
float X[],Y[];
PImage plane;
PImage moster;
void setup()
{
background(255,255,255);
size(600,400);
plane=loadImage("plane.gif");
moster=loadImage("moster.jpg");
}
int now=0;
int no=0;
void draw()
{
background(255);
image(moster,300+no,200+now,50,80);
image(plane,0,0,600,400);
}
void keyPressed(){
if(keyCode==UP) now+=10;
if(keyCode==DOWN) now-=10;
if(keyCode==LEFT) no+=10;
if(keyCode==RIGHT) no-=10;
for(int i=0;i<5;i++){
if(moster<300 && moster>200 && moster>300 && moster<200) {
if(keyCode==32) now-=20;
image(moster,X[i], Y[i], 60, 60);
}
}
}
PImage plane;
PImage moster;
void setup()
{
background(255,255,255);
size(600,400);
plane=loadImage("plane.gif");
moster=loadImage("moster.jpg");
}
int now=0;
int no=0;
void draw()
{
background(255);
image(moster,300+no,200+now,50,80);
image(plane,0,0,600,400);
}
void keyPressed(){
if(keyCode==UP) now+=10;
if(keyCode==DOWN) now-=10;
if(keyCode==LEFT) no+=10;
if(keyCode==RIGHT) no-=10;
for(int i=0;i<5;i++){
if(moster<300 && moster>200 && moster>300 && moster<200) {
if(keyCode==32) now-=20;
image(moster,X[i], Y[i], 60, 60);
}
}
}
week15
int switchStateRed = 0;
int switchStateBlue = 0;
void setup(){
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
}
int a=0,b=0;
void loop(){
switchStateRed = digitalRead(2);
switchStateBlue = digitalRead(3);
if(switchStateRed == LOW) a=0;
if(switchStateRed ==HIGH&& a==0) {Serial.write('a'); a=1;}
if(switchStateBlue ==LOW) b=0;
if(switchStateBlue==HIGH&& b==0) {Serial.write('b'); b=1;}
}
下周預備套用在鼓的上面~~
Week15 期末作品企劃
第1 2節
探討如何接arduino 的路線控制鈕
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
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);
}
探討如何接arduino 的路線控制鈕
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
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);
}
2013年12月15日 星期日
Week 15
PImage Aircraft;
int Px=500;
int Py=625;
PImage boom;
void setup()
{
frameRate(30);
size (1300, 800);
bg = loadImage("sky.jpg");
Aircraft = loadImage("1.jpg");
Random();
}
float [] x= new float [8];
float y;
void draw()
{
background(bg);
image(Aircraft, Px, Py);
boom=loadImage("boom.jpg");
for (int i=0;i<8;i++)
image(boom, x[i], y++);
if (y>625)
{
Random();
y=0;
}
}
void Random()
{
for (int i=0;i<8;i++)
x[i]=random(1300);
}
void keyPressed()
{
if (keyCode==RIGHT)
Px+=10;
else if (keyCode==LEFT)
Px-=10;
}
訂閱:
文章 (Atom)







