2012年11月13日 星期二
Midtern
1.其中作品程式碼
import ddf.minim.*;
Minim minim;
AudioPlayer song;
AudioPlayer song2;
AudioPlayer song3;
float x;
float y;
float easing = 0.05;
int r =8 ;
int gameCase = 1;
int startTime;
int glose=1;
int gwin=1;
float[] bugx = new float [60];
float[] bugy = new float [60];
int[] bugr = new int [60];
float[] speedx = new float [40];
float[] speedy = new float [40];
float a = 0.05;
void setup() {
size (800, 800);
startTime=millis();
smooth();
minim = new Minim(this);
song = minim.loadFile("music.mp3");
song.play();
rectMode (CENTER);
for (int i=0; i<60; i++) {
bugx[i] = random (0, width);
bugy[i] = random (0, height);
bugr[i] = int (random (0, 30));
}
x = random (0, width);
y = random (0, height);
}
void draw() {
background (100, 232, 138);
noStroke();
fill (100,100,100);
startTime=0+millis()/1000;
textSize(45);
text("Time:"+startTime, 80,80);
fill (0);
for (int i=0; i<40; i++) {
rect (bugx[i], bugy[i], bugr[i]*2, bugr[i]*2);
}
fill (255, 0,0 );
rect (x, y, r*2, r*2);
for (int i=0; i<40; i++) {
float z=(bugx[i]-x)*(bugx[i]-x)+(bugy[i]-y)*(bugy[i]-y)-(bugr[i]+r)*(bugr[i]+r);
if (z<0 && bugr[i]>r) {
gameCase = 0;
}
}
if (gameCase == 0) {
gameover();
} else {
float targetX = mouseX;
float targetY = mouseY;
x += (targetX - x) * easing;
y += (targetY - y) * easing;
for (int i=0; i<40; i++) {
move (i);
}
}
for (int i=0; i<40; i++) {
if ((bugx[i]-x)*(bugx[i]-x)+(bugy[i]-y)*(bugy[i]-y)-(bugr[i]+r)*(bugr[i]+r)<0 && bugr[i]<r) {
r = int (sqrt (r*r + bugr[i]*bugr[i]));
bugr[i] = 0;
}
}
int sum = 100;
for (int i=0; i<40; i++) {
sum += bugr[i];
}
if (sum == 100) {
win();
}
}
void move(int i) {
speedx[i] += random (-a, a);
speedy[i] += random (-a, a);
bugx[i] += speedx[i];
bugy[i] += speedy[i];
if (bugx[i]<-10) {
bugx[i] += width;
}
if (bugx[i] > width+10) {
bugx[i] -= width;
}
if (bugy[i] < -10) {
bugy[i] += height;
}
if (bugy[i] > height+10) {
bugy[i] -= height;
}
}
void gameover() {
background (0, 0, 0);
rect(800,800,0,0);
fill (255,255,255);
if(glose==1)
{
song.close();
minim.stop();
stop();
noLoop();
minim = new Minim(this);
song2 = minim.loadFile("music2.mp3");
song2.play();
}
textSize (60);
textAlign(CENTER);
text ("You Lose!", width/2, height/2);
textAlign(LEFT);
text("YourTime:"+startTime, 230,330);
}
void win() {
background (0, 0, 0);
rect(800,800,0,0);
fill (255,255,255);
if(gwin==1)
{
song.close();
minim.stop();
stop();
noLoop();
minim = new Minim(this);
song3 = minim.loadFile("music3.mp3");
song3.play();
}
textSize (60);
textAlign(CENTER);
text ("You Win!", width/2, height/2);
textAlign(LEFT);
text("YourTime:"+startTime, 230,330);
}
遊戲是紅色小方塊要吃黑色小方塊,只能是面積比自己小的,看玩家能在多久的時間將所有的小方塊吃完。
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言