arduino
import processing.serial.*;
Serial myPort;
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
size(800, 600);
noStroke();
bang = loadImage("bang.png");
bang1 = loadImage("bang1.png");
mouse=loadImage("mouse1.jpg");
mouse2=loadImage("mouse2.png");
savetime = millis();
minim = new Minim(this);
player = minim.loadFile("123.mp3");
player.play();
size(200, 200);
String portName = Serial.list()[0];
myPort = new Serial(this, "COM1", 9600);
}
void draw(){
if ( myPort.available() > 0) {
val = myPort.read();
}
background(255);
if (val == 0) {
fill(0);
}
else {
fill(204);
}
rect(50, 50, 100, 100);
}
void draw() {
image(mouse, 0, 0);
float targetX = mouseX;
if (mousePressed) {
image(bang1, mouseX-60, mouseY-60);
}
else {
image(bang, mouseX-60, mouseY-60);
}
if(millis()%1000<30){
hole=int(random(1,10));
}
fill(255,0,0);
if(hole==1){ image(mouse2, 80, 25); }
if(hole==2){ image(mouse2, 340, 25); }
if(hole==3){ image(mouse2, 600,25); }
if(hole==4){ image(mouse2, 50,190); }
if(hole==5){ image(mouse2, 350,190); }
if(hole==6){ image(mouse2, 620,190);}
if(hole==7){ image(mouse2, 40,370); }
if(hole==8){ image(mouse2, 350,370); }
if(hole==9){ image(mouse2,645,370); }
fill(255,255,255);
fill(255,255,255);
textSize(24);
text("S C O R E : "+score, 100, 550);
int passtime = millis() - savetime;
int gametime = 15-passtime/1000;
textSize(24);
text("T I M E : "+gametime,500,550);
if( gametime <= 0 ){
background(255,255,0);
fill(255,0,0);
textSize(30);
text(" T I M E IS UP ",200,200);
text(" Y O U R S C O R E : "+score, 200,300);
}
}
void keyPressed(){
if(key=='1' && hole==7){
score=score+=100;
}
if(key=='2' && hole==8){
score=score+=100;
}
if(key=='3' && hole==9){
score=score+=100;
}
if(key=='4' && hole==4){
score=score+=100;
}
if(key=='5' && hole==5){
score=score+=100;
}
if(key=='6' && hole==6){
score=score+=100;
}
if(key=='7' && hole==1){
score=score+=100;
}
if(key=='8' && hole==2){
score=score+=100;
}
if(key=='9' && hole==3){
score=score+=100;
}
minim=new Minim(this);
bm=minim.loadFile("kk.wav", 2048);
bm.play();
}
processing
import processing.serial.*;
Serial myPort;
int val;
float x;
float y;
float easing = 0.05;
int score;
int savetime;
PImage bang, bang1, mouse,mouse2,mouse3;
int hole=0;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
AudioPlayer bm;
void setup() {
size(800, 600);
noStroke();
bang = loadImage("bang.png");
bang1 = loadImage("bang1.png");
mouse=loadImage("mouse1.jpg");
mouse2=loadImage("mouse2.png");
savetime = millis();
minim = new Minim(this);
player = minim.loadFile("123.mp3");
player.play();
size(200, 200);
String portName = Serial.list()[0];
myPort = new Serial(this, "COM1", 9600);
}
void draw(){
if ( myPort.available() > 0) {
val = myPort.read();
}
background(255);
if (val == 0) {
fill(0);
}
else {
fill(204);
}
rect(50, 50, 100, 100);
}
void draw() {
image(mouse, 0, 0);
float targetX = mouseX;
if (mousePressed) {
image(bang1, mouseX-60, mouseY-60);
}
else {
image(bang, mouseX-60, mouseY-60);
}
if(millis()%1000<30){
hole=int(random(1,10));
}
fill(255,0,0);
if(hole==1){ image(mouse2, 80, 25); }
if(hole==2){ image(mouse2, 340, 25); }
if(hole==3){ image(mouse2, 600,25); }
if(hole==4){ image(mouse2, 50,190); }
if(hole==5){ image(mouse2, 350,190); }
if(hole==6){ image(mouse2, 620,190);}
if(hole==7){ image(mouse2, 40,370); }
if(hole==8){ image(mouse2, 350,370); }
if(hole==9){ image(mouse2,645,370); }
fill(255,255,255);
fill(255,255,255);
textSize(24);
text("S C O R E : "+score, 100, 550);
int passtime = millis() - savetime;
int gametime = 15-passtime/1000;
textSize(24);
text("T I M E : "+gametime,500,550);
if( gametime <= 0 ){
background(255,255,0);
fill(255,0,0);
textSize(30);
text(" T I M E IS UP ",200,200);
text(" Y O U R S C O R E : "+score, 200,300);
}
}
void keyPressed(){
if(key=='1' && hole==7){
score=score+=100;
}
if(key=='2' && hole==8){
score=score+=100;
}
if(key=='3' && hole==9){
score=score+=100;
}
if(key=='4' && hole==4){
score=score+=100;
}
if(key=='5' && hole==5){
score=score+=100;
}
if(key=='6' && hole==6){
score=score+=100;
}
if(key=='7' && hole==1){
score=score+=100;
}
if(key=='8' && hole==2){
score=score+=100;
}
if(key=='9' && hole==3){
score=score+=100;
}
minim=new Minim(this);
bm=minim.loadFile("kk.wav", 2048);
bm.play();
}
沒有留言:
張貼留言