level 1
托颖训跃伦鹤ba
楼主
int num = 1000;//障碍物数量
int numg = 100;//一次武器的子弹数
int numofg = 3;//武器初始使用次数
//system
int score = 0;//original score(s).
float speed1 = 0.2;//速度最小值
float speed2 = 0.5;//速度最大值
float gr = 100;//武器微粒的影响大小
float gR = 1000;//武器扩散大小
float easing = 0.05;
int ltime = 140;//时间
int gameMode = 1;
int Hscore = 0;//历史分数
int Shuffle(){
int sfu;
sfu = int(random(100)%2);
return sfu;
}
PVector gp[] = new PVector[numg];//向量
PVector gd[] = new PVector[numg];//向量
int numofgorg = numofg;
float gtheta[] = new float[numg];
PVector vm = new PVector(0,0);
int gsht = 0;
int gtime;
float px[] = new float[num];//原始x坐标
float py[] = new float[num];//原始y坐标
PVector v[] = new PVector[num];//速度
int orgpom = 1;//original position mode.1=X,0=Y
void setup(){
size(1000,1000);
background(0);
frameRate(30);//帧速率
GiveKinestate();
for(int i = 0;i<numg-1;i++){
gtheta[i] = random(TWO_PI);
}
}
void draw(){
background(0);
fill(255,150);
textAlign(LEFT,TOP);
text("num of gun = " + numofg ,0,0);
text("score = "+score,0,20);
Render();
Return();
Shoot();
Knock();
Medicine();
score += 1+num/numg*10+speed2*10;
GameOver();
}
void Render(){//重复
for(int i = 0;i<num-1;i++){
px[i]+=v[i].x;
py[i]+=v[i].y;
noStroke();
ellipse(px[i],py[i],10,10);
}
}
void Return(){
for(int i = 0;i<num-1;i++){
if(px[i]>width||px[i]<0||py[i]>height||py[i]<0){
orgpom = Shuffle();
if(orgpom==1){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = 0;
v[i] = new PVector(random(-speed1,speed1),random(speed2,speed2*2));
}
if(orgpom==0){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
}
if(orgpom==0){
orgpom = Shuffle();
if(orgpom==1){
px[i] = 0;
py[i] = random(height);
v[i] = new PVector(random(speed2,speed2*2),random(-speed1,speed1));
}
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
}
void GiveKinestate(){
//给予初始运动状态
for(int i=0;i<num-1;i++){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
if(orgpom==0){
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
void mousePressed(){
if(gameMode == 1){
gsht = 1;
gtime = frameCount;
for(int i = 0;i<numg-1;i++){
gp[i] = new PVector(mouseX,mouseY);
}
if(numofgorg>0){
numofg -=1;
}
}
if(gameMode == 0){
GiveKinestate();
numofg=numofgorg;
score = 0;
loop();//循环
gameMode = 1;
}
}
void Shoot(){
if(numofg<0){
gsht = 0;
}
if(numofgorg>0){
if(numofg>=0){
if(gsht == 1){
for(int i = 0;i<numg-1;i++){
gd[i] = new PVector(mouseX+gR*cos(gtheta[i]),mouseY+gR*sin(gtheta[i]));
gp[i].lerp(gd[i].x,gd[i].y,0,easing);
noStroke();
fill(255,255,0);
rect(gp[i].x,gp[i].y,5,5);
}
if(ltime/3+gtime-frameCount<0){
gsht = 0;
}
}
}
}
}
void Knock(){
if(numofgorg>0){
if(numofg>=0){
if(gsht == 1){
for(int i = 0;i<num-1;i++){
for(int j =0;j<numg-1;j++){
if(i>=j){
float d = dist(px[i],py[i],gp[j].x,gp[j].y);
if(d<=gr){
orgpom = Shuffle();
if(orgpom==1){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = 0;
v[i] = new PVector(random(-speed1,speed1),random(speed2,speed2*2));
}
if(orgpom==0){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
}
if(orgpom==0){
orgpom = Shuffle();
if(orgpom==1){
px[i] = 0;
py[i] = random(height);
v[i] = new PVector(random(speed2,speed2*2),random(-speed1,speed1));
}
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
}
}
}
}
}
if(numofg<0){
numofg = 0;
}
}
int mx;
int my;
int medicineTime = 600;
int medicineExist = 0;
void Medicine(){
if(numofg < numofgorg){
if(frameCount%medicineTime == 0){
mx = round(random(width/10,width*9/10));
my = round(random(height/10,height*9/10));
medicineExist = 1;
}
if(medicineExist == 1){
rectMode(CENTER);
noStroke();
fill(255,255,0);
rect(mx,my,10,10);
if(mouseX>mx-10&&mouseX<mx+10){
if(mouseY>my-10&&mouseY<my+10){
medicineExist = 0;
numofg += 1;
}
}
}
}
}
void GameOver(){
for(int i =0;i<num-1;i++){
if(dist(mouseX,mouseY,px[i],py[i])<1){
noLoop();
score -= (numofgorg-2)*score/10;
score -= (numofgorg-numofg-1)*score/10;
textAlign(CENTER);
fill(25,250,120);
text("GameOver",width/2,height/2);
text("Socre : "+score,width/2,height/2+100);
text("Num of my weapon = "+numofgorg,width/2,height/2+15);
text("Lasted = "+numofg,width/2,height/2
+3
0);
text("All points = "+num,width/2,height/2+45);
text("Num of points in my weapon = "+numg,width/2,height/2+60);
if(Hscore<score){
Hscore = score;
fill(255,100,50);
text("New Score!",width/2,height/2+80);
}
gameMode = 0;
}
}
}
2016年12月10日 15点12分
1
int numg = 100;//一次武器的子弹数
int numofg = 3;//武器初始使用次数
//system
int score = 0;//original score(s).
float speed1 = 0.2;//速度最小值
float speed2 = 0.5;//速度最大值
float gr = 100;//武器微粒的影响大小
float gR = 1000;//武器扩散大小
float easing = 0.05;
int ltime = 140;//时间
int gameMode = 1;
int Hscore = 0;//历史分数
int Shuffle(){
int sfu;
sfu = int(random(100)%2);
return sfu;
}
PVector gp[] = new PVector[numg];//向量
PVector gd[] = new PVector[numg];//向量
int numofgorg = numofg;
float gtheta[] = new float[numg];
PVector vm = new PVector(0,0);
int gsht = 0;
int gtime;
float px[] = new float[num];//原始x坐标
float py[] = new float[num];//原始y坐标
PVector v[] = new PVector[num];//速度
int orgpom = 1;//original position mode.1=X,0=Y
void setup(){
size(1000,1000);
background(0);
frameRate(30);//帧速率
GiveKinestate();
for(int i = 0;i<numg-1;i++){
gtheta[i] = random(TWO_PI);
}
}
void draw(){
background(0);
fill(255,150);
textAlign(LEFT,TOP);
text("num of gun = " + numofg ,0,0);
text("score = "+score,0,20);
Render();
Return();
Shoot();
Knock();
Medicine();
score += 1+num/numg*10+speed2*10;
GameOver();
}
void Render(){//重复
for(int i = 0;i<num-1;i++){
px[i]+=v[i].x;
py[i]+=v[i].y;
noStroke();
ellipse(px[i],py[i],10,10);
}
}
void Return(){
for(int i = 0;i<num-1;i++){
if(px[i]>width||px[i]<0||py[i]>height||py[i]<0){
orgpom = Shuffle();
if(orgpom==1){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = 0;
v[i] = new PVector(random(-speed1,speed1),random(speed2,speed2*2));
}
if(orgpom==0){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
}
if(orgpom==0){
orgpom = Shuffle();
if(orgpom==1){
px[i] = 0;
py[i] = random(height);
v[i] = new PVector(random(speed2,speed2*2),random(-speed1,speed1));
}
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
}
void GiveKinestate(){
//给予初始运动状态
for(int i=0;i<num-1;i++){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
if(orgpom==0){
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
void mousePressed(){
if(gameMode == 1){
gsht = 1;
gtime = frameCount;
for(int i = 0;i<numg-1;i++){
gp[i] = new PVector(mouseX,mouseY);
}
if(numofgorg>0){
numofg -=1;
}
}
if(gameMode == 0){
GiveKinestate();
numofg=numofgorg;
score = 0;
loop();//循环
gameMode = 1;
}
}
void Shoot(){
if(numofg<0){
gsht = 0;
}
if(numofgorg>0){
if(numofg>=0){
if(gsht == 1){
for(int i = 0;i<numg-1;i++){
gd[i] = new PVector(mouseX+gR*cos(gtheta[i]),mouseY+gR*sin(gtheta[i]));
gp[i].lerp(gd[i].x,gd[i].y,0,easing);
noStroke();
fill(255,255,0);
rect(gp[i].x,gp[i].y,5,5);
}
if(ltime/3+gtime-frameCount<0){
gsht = 0;
}
}
}
}
}
void Knock(){
if(numofgorg>0){
if(numofg>=0){
if(gsht == 1){
for(int i = 0;i<num-1;i++){
for(int j =0;j<numg-1;j++){
if(i>=j){
float d = dist(px[i],py[i],gp[j].x,gp[j].y);
if(d<=gr){
orgpom = Shuffle();
if(orgpom==1){
orgpom = Shuffle();
if(orgpom==1){
px[i] = random(width);
py[i] = 0;
v[i] = new PVector(random(-speed1,speed1),random(speed2,speed2*2));
}
if(orgpom==0){
px[i] = random(width);
py[i] = height;
v[i] = new PVector(random(-speed1,speed1),random(-speed2*2,-speed2));
}
}
if(orgpom==0){
orgpom = Shuffle();
if(orgpom==1){
px[i] = 0;
py[i] = random(height);
v[i] = new PVector(random(speed2,speed2*2),random(-speed1,speed1));
}
if(orgpom==0){
px[i] = width;
py[i] = random(height);
v[i] = new PVector(random(-speed2*2,-speed2),random(-speed1,speed1));
}
}
}
}
}
}
}
}
}
if(numofg<0){
numofg = 0;
}
}
int mx;
int my;
int medicineTime = 600;
int medicineExist = 0;
void Medicine(){
if(numofg < numofgorg){
if(frameCount%medicineTime == 0){
mx = round(random(width/10,width*9/10));
my = round(random(height/10,height*9/10));
medicineExist = 1;
}
if(medicineExist == 1){
rectMode(CENTER);
noStroke();
fill(255,255,0);
rect(mx,my,10,10);
if(mouseX>mx-10&&mouseX<mx+10){
if(mouseY>my-10&&mouseY<my+10){
medicineExist = 0;
numofg += 1;
}
}
}
}
}
void GameOver(){
for(int i =0;i<num-1;i++){
if(dist(mouseX,mouseY,px[i],py[i])<1){
noLoop();
score -= (numofgorg-2)*score/10;
score -= (numofgorg-numofg-1)*score/10;
textAlign(CENTER);
fill(25,250,120);
text("GameOver",width/2,height/2);
text("Socre : "+score,width/2,height/2+100);
text("Num of my weapon = "+numofgorg,width/2,height/2+15);
text("Lasted = "+numofg,width/2,height/2
+3
0);
text("All points = "+num,width/2,height/2+45);
text("Num of points in my weapon = "+numg,width/2,height/2+60);
if(Hscore<score){
Hscore = score;
fill(255,100,50);
text("New Score!",width/2,height/2+80);
}
gameMode = 0;
}
}
}