Processing&Arduino小蜜蜂完成版
本帖最后由 MicroMaker 于 2017-5-13 10:50 编辑刚学习了Processing一两年,做了一些游戏,但是只能用键盘来玩,不能像游戏机一样可以用手柄玩,所以,我做了一个可以用Arduino手柄玩的Processing小蜜蜂游戏。
配件:手柄、6个按钮、Arduino Leonardu开发板、Processing小蜜蜂程序(Minim库)。
视频:(必须用高清看)
http://player.youku.com/player.php/sid/XMjcyMzc2MjQ0NA==/v.swf
原理:
由手柄和6个按钮把数字信号发送到Arduino Leonardu开发板上,用Arduino Leonardu开发板模拟鼠标键盘,在Processing里通过判断鼠标键盘状态在游戏里做出各种动作。
玩法说明(括号里是键盘按键):
控制:
手柄:往上(W);往下(S);往左(A);往右(D)分别对应主战舰的上下左右移动。
主战舰: http://www.arduino.cn/forum.php?mod=image&aid=32407&size=300x300&key=dddb5b599659421f&nocache=yes&type=fixnone
按钮:1号:发射子弹(MouseLEFT);2.发射激光(Q);3.发射核弹(E);4.重新开始(R);5.防御盾(MouseMIDDLE);6.选普通难度时用的(N).
子弹: 核弹:
敌方战舰:
小兵: Boss::lol:lol:lol
功能物品:
弹药箱: 主战舰碰到后如果子弹小于300,那么子弹+50;如果激光小于15,那么激光+1;
血瓶:主战舰碰到后如果血量小于5,那么血量+1;
键盘操作:
W:主战舰前进;
A:主战舰左移;
S:主战舰右移;
D:主战舰后退;
Q:发射激光;
E:发射核弹;
R:重新开始;
E:选难度时简单;
N:选难度时普通;
H:选难度时困难;
MouseLEFT:发射子弹;
MouseMIDDLE:启动防护盾;
作弊:
Y:无限血;
U:无限子弹;
I:无限防护盾;
O:无限核弹;
P:无限激光;
;:自杀;
Space:瞬移到黄十字位置;
H:生成一个弹药箱;
Z:生成一个血瓶;
J:生成一个Boss;
其他:
用子弹打死小兵+1分,打死Boss+7分;
撞死小兵+1分,血量-1;撞死Boss+1分,血量-2;
释放核弹后,如果主战舰在屏幕中任何一个位置,百分之百炸掉所有敌舰,并按照灭敌数加分;
释放激光后,按照自己Y坐标发射横的激光,碰到的敌舰炸掉,不加分;
释放防护盾后,敌舰撞上防护盾炸掉,不加分,耐久显示(蓝>绿>绿红>黄>红绿>红),最后消失;
核弹、激光、防护盾都要一定时间蓄力;
Boss的生成是按照分数决定的,每生成一个Boss,分数+1;
游戏内存可能达到1GB,请注意!!!
游戏代码:
//Arduino
#include <Keyboard.h>
#include <Mouse.h>
int wb = 3;//w
int ab = 4;//a
int sb = 5;//s
int db = 6;//d
int rb = 7;//Mleft
int eb = 8;//q
int nb = 9;//e
int hb = 10; //r
int ob = 11; //2
int pb = 12; //n
int w = 3;
int a = 4;
int s = 5;
int d = 6;
int r = 7;
int e = 8;
int n = 9;
int h = 10;
int o = 11;
int p = 12;
/*boolean ww = false;
boolean aa = false;
boolean ss = false;
boolean dd = false;
boolean rr = false;
boolean ee = false;
boolean nn = false;
boolean hh = false;
boolean oo = false;
boolean pp = false;*/
long wdelay;
long adelay;
long sdelay;
long ddelay;
long rdelay;
long edelay;
long ndelay;
long hdelay;
long odelay;
long pdelay;
void setup()
{
Serial.begin(115200);
Keyboard.begin();
Mouse.begin();
pinMode(wb,INPUT_PULLUP);
pinMode(ab,INPUT_PULLUP);
pinMode(sb,INPUT_PULLUP);
pinMode(db,INPUT_PULLUP);
pinMode(rb,INPUT_PULLUP);
pinMode(eb,INPUT_PULLUP);
pinMode(nb,INPUT_PULLUP);
pinMode(hb,INPUT_PULLUP);
pinMode(ob,INPUT_PULLUP);
pinMode(pb,INPUT_PULLUP);
}
void loop()
{
w = digitalRead(wb);
a = digitalRead(ab);
s = digitalRead(sb);
d = digitalRead(db);
r = digitalRead(rb);
e = digitalRead(eb);
n = digitalRead(nb);
h = digitalRead(hb);
o = digitalRead(ob);
p = digitalRead(pb);
if(w == 0)
{
Keyboard.press('w');
wdelay = millis();
}
if(w == 1&&millis()-wdelay>=1)
{
Keyboard.release('w');
}
if(a == 0)
{
Keyboard.press('a');
adelay = millis();
}
if(a == 1&&millis()-adelay>=1)
{
Keyboard.release('a');
}
if(s == 0)
{
Keyboard.press('s');
sdelay = millis();
}
if(s == 1&&millis()-sdelay>=1)
{
Keyboard.release('s');
}
if(d == 0)
{
Keyboard.press('d');
ddelay = millis();
}
if(d == 1&&millis()-ddelay>=1)
{
Keyboard.release('d');
}
//------
if(r == 0)
{
Mouse.press(MOUSE_LEFT);
rdelay = millis();
}
if(r == 1&&millis()-rdelay>=4)
{
Mouse.release(MOUSE_LEFT);
}
if(e == 0&&millis()-edelay>=90)
{
Keyboard.press('q');
edelay = millis();
}
if(e == 1)
{
Keyboard.release('q');
}
if(n == 0&&millis()-ndelay>=90)
{
Keyboard.press('e');
ndelay = millis();
}
if(n == 1)
{
Keyboard.release('e');
}
if(h == 0&&millis()-hdelay>=90)
{
Keyboard.press('r');
hdelay = millis();
}
if(h == 1)
{
Keyboard.release('r');
}
//----------
if(o == 0&&millis()-odelay>=20)
{
Mouse.press(MOUSE_MIDDLE);
odelay = millis();
}
if(o == 1)
{
Mouse.release(MOUSE_MIDDLE);
}
if(p == 0&&millis()-pdelay>=90)
{
Keyboard.press('n');
pdelay = millis();
}
if(p == 1)
{
Keyboard.release('n');
}
}
//Processing
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
int numParticles = 600;
GenParticle[] p = new GenParticle;
Back back;
Main main;
String face = "D:/face/";
int musicmemony = 1024;
//Nucking nukenuke;
Minim minim;
Minim minima;
Minim minimb;
Minim minimc;
AudioPlayer bmusic;
AudioPlayer bbmusic;
AudioPlayer mbmusic;
AudioPlayer dianliumusic;
AudioPlayer bgm;
AudioPlayer bgm1;
AudioPlayer boom;
AudioPlayer bvmusic;
AudioPlayer tpm;
AudioPlayer nuckmusic;
AudioPlayer xuepingmusicll;
AudioPlayer hdmusic;
ArrayList<Bullet> bullet = new ArrayList<Bullet>();
ArrayList<Hudun> hudun = new ArrayList<Hudun>();
ArrayList<BulletBob> bulletbob = new ArrayList<BulletBob>();
ArrayList<Explosion> explosiondisplay = new ArrayList<Explosion>();
ArrayList<Main> mainm = new ArrayList<Main>();
ArrayList<st> sting = new ArrayList<st>();
ArrayList<Nucking> nucking = new ArrayList<Nucking>();
ArrayList<Obstacle> obstacle = new ArrayList<Obstacle>();
float bgmrandom;
int bgmnumber;
int prv = frameCount;
int bobprv = frameCount;
float pprv = frameCount;
int ppppp = frameCount;
int tpprv = frameCount;
int bossprv = frameCount;
int rgbprv = frameCount;
int hudunprv = frameCount;
int hudunprvs = frameCount;
int hudunprvm = frameCount;
int hudunnumber = 5;
float musicsuijishu = 0;
float mx;
float my;
boolean boss = false;
int bv = 50;
int prvbv = frameCount;
boolean eatbv;
float bvx;
float bvy;
float xuepingx;
float xuepingy = 100;
boolean xuepingeat;
int xuepingprv = frameCount;
int score = 1;
int hp = 5;
int stb = 5;
int nuck = 5;
int dianliuprv = frameCount;
PImage xuepingtu;
int difficulty;
boolean right = false;
float armymove;
float bossmove;
float armydan;
float bossdan;
float xuepingdan;
float danyaodan;
float guangbosu;
float mainmove;
float huduntime;
float huduntimes;
int bobshesu;
boolean o = true;
int tptime;
boolean boomm = false;
boolean bexist;
boolean nexist;
boolean sexist;
String cname = "1";
boolean bossspawn = true;
float bbx = 0.0, bby = 0.0;
float r = 255, g = 0, b = 0;
void setup()
{
minim = new Minim(this);
//music
boom = minim.loadFile(face + "mainzhadan.mp3", musicmemony);
tpm = minim.loadFile(face + "dianliu.mp3", musicmemony);
bvmusic = minim.loadFile(face + "bvmusic.mp3", musicmemony);
xuepingmusicll = minim.loadFile(face + "xuepingmusic.mp3", musicmemony);
bmusic = minim.loadFile(face + "bmusic.mp3", musicmemony);
nuckmusic = minim.loadFile(face + "nmusic.mp3", musicmemony);
dianliumusic = minim.loadFile(face + "dianliu.mp3", musicmemony);
hdmusic = minim.loadFile(face + "hudunmp.mp3", musicmemony);
mbmusic = minim.loadFile(face + "mainzhadan.mp3", musicmemony);
bbmusic = minim.loadFile(face + "bmusic.mp3", musicmemony);
hdmusic = minim.loadFile(face + "hudunmp.mp3", musicmemony);
bgm = minim.loadFile(face + "1.0000001.mp3", musicmemony);
bgm1 = minim.loadFile(face + "1.0000002.mp3", musicmemony);
bgmnumber = 1;
//musicEnd
size(1200, 1050);
back = new Back();
main = new Main();
bgm.play();
noStroke();
smooth();
fill(255);
for (int i = 0; i < p.length; i++)
{
float velX = random(-1, 1);
float velY = -i;
p = new GenParticle(100, 100, velX, velY, 5.0, width / 2, height / 2);
}
}
void draw()
{
background(255);
noCursor();
if (right == false)
{
back.display();
mousexy();
textSize(50);
text("Difficuly: ", 100, 300);
textSize(30);
text("EASE key'e'", 300, 400);
text("NORMAL key'n'", 300, 500);
text("HARD key'h'", 300, 600);
if (key == 'e')
{
armymove = 6;
bossmove = 3;
armydan = 0.6;
bossdan = 16;
xuepingdan = 1000;
danyaodan = 1000;
guangbosu = 200;
mainmove = 20;
bobshesu = 50;
tptime = 10;
huduntime = 1000;
huduntimes = 700;
hudunnumber = 5;
right = true;
}
if (key == 'n')
{
armymove = 9;
bossmove = 5;
armydan = 1;
bossdan = 12;
xuepingdan = 2000;
danyaodan = 2500;
guangbosu = 1500;
mainmove = 16;
bobshesu = 40;
tptime = 15;
huduntime = 1250;
huduntimes = 550;
hudunnumber = 5;
right = true;
}
if (key == 'h')
{
armymove = 13;
bossmove = 10;
armydan = 2;
bossdan = 7;
xuepingdan = 2500;
danyaodan = 3100;
guangbosu = 2000;
mainmove = 12;
bobshesu = 30;
tptime = 20;
huduntime = 1500;
huduntimes = 400;
hudunnumber = 5;
right = true;
}
}
if (right == true)
{
if (hp >= 1)
{
back.display();
main.display();
nuckingdisplay();
bulletdisplay();
bobbulletdisplay();
obstacleDisplay();
stdisplay();
mousexy();
hudundisplay();
textSize(20);
if (hp >= 1000000000)
{
text("HP: ∞", 40, 100);
}
if (hp >= 6 && hp <= 999999999)
{
text("HP: " + hp, 40, 100);
}
if (hp <= 5)
{
text("HP:", 40, 100);
if (hp == 5)
{
fill(0, 255, 0);
rect(80, 80, 200, 20);
}
if (hp == 4)
{
fill(125, 255, 0);
rect(80, 80, 160, 20);
}
if (hp == 3)
{
fill(255, 255, 0);
rect(80, 80, 120, 20);
}
if (hp == 2)
{
fill(255, 125, 0);
rect(80, 80, 80, 20);
}
if (hp == 1)
{
fill(255, 0, 0);
rect(80, 80, 40, 20);
}
if (hp <= 0)
{
text("Death", 60, 100);
}
}
fill(255, 0, 0);
text("Score: " + score, 300, 100);
}
else
{
back.display();
main.display();
mousexy();
textSize(45);
text("Game Over!!!", 900, 900);
text("Press'R'!!!", 900, 950);
text("Score: " + score, 100, 150);
textSize(20);
if (key == 'r')
{
right = false;
}
}
if (boomm == true)
{
if (o == true)
{
boom.play();
boom.rewind();
}
boomm = false;
}
}
if (key == 'r')
{
hp = 5;
score = 1;
bv = 50;
stb = 6;
nuck = 6;
}
if (key == ';')
{
hp = -2147483648;
}
if (key == 'y')
{
hp = 2147483647;
}
if (key == 'o')
{
nuck = 2147483647;
}
}
void mousexy()
{
int mousex;
int mousey;
mousex = mouseX;
mousey = mouseY;
textSize(20);
text("MouseX: " + mousex, 1000, 50);
text("MouseY: " + mousey, 1000, 100);
text("MainX: " + mx, 1000, 150);
text("MainY: " + my, 1000, 200);
fill(255, 255, 0);
rect(mousex - 9, mousey, 19, 2);
rect(mousex, mousey - 9, 2, 19);
textSize(20);
fill(255, 0, 0);
}
class Back
{
PImage png;
int x1 = -1200;
Back()
{
png = loadImage(face + "background.jpg");
}
void display()
{
x1--;
if (x1 <= -1994)
{
x1 = 0;
}
image(png, x1, 0);
fill(0, 36);
rect(0, 0, width, height);
fill(255);
for (int i = 0; i < p.length; i++)
{
p.updata();
p.regenerate();
p.display();
}
//BGM.rewind
if(bgmnumber == 1)
{
if(bgm.isPlaying()) {}
else if(bgm.position() == bgm.length() || bgm.isPlaying() == false)
{
bgmrandom = (int)random(10);
if(frameCount % 2 == 0)
{
bgm.rewind();
bgm.play();
bgmnumber = 1;
}
else
{
bgm1.rewind();
bgm1.play();
bgmnumber = 2;
}
}
}
if(bgmnumber == 2)
{
if(bgm1.isPlaying()) {}
else if(bgm1.position() == bgm1.length() || bgm1.isPlaying() == false)
{
bgmrandom = (int)random(10);
if(frameCount % 2 == 0)
{
bgm.rewind();
bgm.play();
bgmnumber = 1;
}
else
{
bgm1.rewind();
bgm1.play();
bgmnumber = 2;
}
}
}
}
}
class Main
{
PImage png;
float x = 500;
float y = 500;
Main()
{
png = loadImage(face + "Main" + cname + ".jpg");
}
void tp()
{
if (keyPressed && key == ' ' && frameCount - tpprv > 10)
{
x = mouseX - 20;
y = mouseY - 40;
if (o == true)
{
tpm.rewind();
tpm.play();
}
tpprv = frameCount;
}
}
void display()
{
tp();
if (keyPressed)
{
if (key == 'w' || key == 'W') y -= mainmove;
if (key == 's' || key == 'S') y += mainmove;
if (key == 'a' || key == 'A') x -= mainmove;
if (key == 'd' || key == 'D') x += mainmove;
if (key == 'u' || key == 'U') bv = 2147483647;
if (key == 'm' || key == 'M') bv = 10;
if (key == 'p' || key == 'P') stb = 2147483647;
if (key == '[' || key == '[')o = true;
if (key == 'i' || key == 'I') hudunnumber = 2147483647;
}
image(png, x, y);
mx = x;
my = y;
if (dist(bvx, bvy, x, y) < 30)
{
if (bv < 300)
{
bv += 50;
}
if (stb < 15)
{
stb += 1;
}
if (o == true)
{
bvmusic.rewind();
bvmusic.play();
}
eatbv = true;
bvx = -10000;
bvy = -10000;
}
//------------------
if (dist(xuepingx, xuepingy, x, y) < 30)
{
if (hp <= 4)
{
hp += 1;
}
if (o == true)
{
xuepingmusicll.rewind();
xuepingmusicll.play();
}
xuepingeat = true;
xuepingx = -10000;
xuepingy = -10000;
}
}
}
class Bullet
{
float x1;
float y1;
PImage png;
boolean exist;
int x2;
int y2;
float random;
Bullet()
{
random = random(0, 10);
if (random > 0 && random <= 7.4)
{
png = loadImage(face + "Bullet2" + cname + ".png");
}
if (random >= 7.4 && random <= 10)
{
if (cname == "1")
{
png = loadImage(face + "Bullet2" + cname + "2" + ".png");
}
}
x1 = mx + 15;
y1 = my;
exist = true;
}
void display()
{
if (exist)
{
y1 -= 26;
image(png, x1, y1);
if (bv <= 999999999)
{
text("BULLET: " + bv, 800, 800);
}
else
{
text("BULLET: ∞ ", 800, 800);
}
}
else
{
}
}
}
void bulletdisplay()
{
if (mousePressed && mouseButton == LEFT && frameCount - prv > 10 && bv >= 1)
{
bullet.add(new Bullet());
if (o == true)
{
bmusic.rewind();
bmusic.play();
}
prv = frameCount;
bv -= 1;
}
if ((frameCount - prvbv > danyaodan && eatbv == true) || key == 'h')
{
prvbv = frameCount;
bvx = random(100, 1000);
bvy = 100;
eatbv = false;
}
if (eatbv == false)
{
fill(255, 0, 0);
if (cname == "0")
{
rect(bvx, bvy, 30, 30);
}
if (cname == "1")
{
PImage danyaoxiangphoto;
danyaoxiangphoto = loadImage(face + "danyaoxiang.png");
image(danyaoxiangphoto, bvx, bvy);
}
bvy += 2;
if (bvy > 1000)
{
eatbv = true;
}
}
///----------------
if (hp >= 1)
{
if (frameCount - xuepingprv > xuepingdan && xuepingeat == true || key == 'z')
{
xuepingprv = frameCount;
xuepingx = random(100, 1000);
xuepingy = 1;
xuepingeat = false;
}
if (xuepingeat == false)
{
xuepingtu = loadImage(face + "xueping" + cname + ".png");
image(xuepingtu, xuepingx, xuepingy);
xuepingy += 2;
if (xuepingy > 1000)
{
xuepingeat = true;
}
}
for (Bullet i : bullet)
{
i.display();
}
}
}
class st
{
//Super star
float x1;
float y1;
boolean exist;
PImage[] photo;
st()
{
x1 = mx + 40;
y1 = my;
exist = true;
}
void display()
{
sexist = exist;
if (exist)
{
y1 -= 10;
if (cname == "0" || cname == "1")
{
fill(255, 0, 0);
rect(x1 - 1000, y1, 2000, 20);
}
if (stb <= 999999999)
{
text("Super laser: " + stb, 800, 900);
}
else
{
text("Super laser: ∞", 800, 900);
}
}
else
{
}
}
}
void stdisplay()
{
if (keyPressed && key == 'q' && frameCount - pprv > guangbosu && stb >= 1)
{
sting.add(new st());
//nmusic= minim.loadFile("bmusic.mp3", 1024);
//bmusic.play();
stb -= 1;
pprv = frameCount;
}
if (stb <= 999999999)
{
text("Super laser: " + stb, 800, 900);
}
else
{
text("Super laser: ∞", 800, 900);
}
for (st i : sting)
{
i.display();
}
}
////--------------------------------
class Nucking
{
float x1;
float y1;
PImage png;
boolean exist;
Nucking()
{
png = loadImage(face + "nuke" + cname + ".png");
x1 = mx + 40;
y1 = my;
exist = true;
}
void display()
{
nexist = exist;
if (exist)
{
y1 -= 1;
image(png, x1, y1);
text("Nuck: " + nuck, 800, 900);
}
else
{
}
}
}
void nuckingdisplay()
{
if (keyPressed && key == 'e' && frameCount - pprv > guangbosu && nuck >= 1)
{
fill(255, 0, 0);
nucking.add(new Nucking());
for (Nucking m : nucking)
{
if (m.exist)
{
if (o == true)
{
nuckmusic.rewind();
nuckmusic.play();
}
nuck -= 1;
}
ppppp = frameCount;
pprv = frameCount;
}
}
if (nuck <= 999999999)
{
text("Nuck: " + nuck, 800, 400);
}
else
{
text("Nuck: ∞", 800, 400);
}
for (Nucking i : nucking)
{
i.display();
}
}
class Obstacle
{
boolean hd = true;
int ppp;
boolean la = false;
boolean lpo = false;
boolean kill = false;;
int ppprv = frameCount;
float x;
int r;
float y;
float bbbx = 0;
float bbby = 0;
PImage photo;
String name;
int blood;
int di1;
int di2;
int state2;
boolean exist;
boolean bossss = false;
boolean ok;
int timer;
boolean bbb;
Explosion temp;
float bossx;
float bossy;
int i = 0;
Obstacle(int state)
{
this.x = random(1200);
this.y = 0;
state2 = state;
exist = true;
bbb = false;
if (state2 == 0)
{
r = 10;
blood = 1;
name = face + "army" + cname + ".png";
di1 = 900;
di2 = 900;
}
if (state2 == 1)
{
r = 50;
blood = 15;
if (random(0, 9) > 1.3)
{
name = face + "boss" + cname + ".png";
bossss = false;
}
else
{
if (cname == "1")
{
name = face + "boss" + cname + "1" + ".png";
bossss = true;
}
else
{
name = face + "boss" + cname + ".png";
bossss = false;
}
}
di1 = 120000;
di2 = 120000;
}
photo = loadImage(name);
}
void bong()
{
if (state2 == 1)
{
bossx = x;
bossy = y;
if (x < 100)
{
bbb = true;
}
if (x > 1000)
{
bbb = false;
}
if (bbb == true)
{
x += bossmove;
}
else
{
x -= bossmove;
}
y = 200;
}
if (state2 == 0)
{
y += armymove;
}
}
void up()
{
for (Bullet i : bullet)
{
if (i.exist && exist && pow(x - i.x1, 2) + pow(y - i.y1, 2) < di1)
{
blood--;
i.exist = false;
if (blood == 0 || kill)
{
if (state2 == 1)
{
bossspawn = true;
la = false;
}
exist = false;
score += 7;
boomm = true;
}
}
if (exist && pow(x - mx, 2) + pow(y - my, 2) < di2)
{
exist = false;
if (state2 == 0)
{
hp -= 1;
}
else
{
hp -= 2;
bossspawn = true;
}
score++;
boomm = true;
}
}
for (st j : sting)
{
if (j.exist && exist && dist(0, y, 0, j.y1) < 40)
{
blood -= 0.25;
if (j.y1 < 0)
{
j.exist = false;
}
else
{
if (frameCount - dianliuprv > 4)
{
for (st l : sting)
{
if (l.exist)
{
if (o == true)
{
dianliumusic.rewind();
dianliumusic.play();
}
dianliuprv = frameCount;
}
}
}
}
if (blood <= 0)
{
kill = true;
if (state2 == 1)
{
score += 1;
la = false;
}
}
// }
}
}
for (Nucking n : nucking)
{
if (n.exist && exist && dist(x, y, n.x1, n.y1) < 1000)
{
blood--;
exist = false;
score += 7;
boomm = true;
if (state2 == 1)
{
la = false;
}
if (frameCount - ppppp > 15)
{
n.exist = false;
}
else
{
ppppp = frameCount;
}
}
}
//..............
for (Hudun mm : hudun)
{
//mm.display();
if (mm.exist && exist && dist(x,y, mx+22,my+50) < 150)
{
blood -= 0.25;
exist = false;
if (o == true && hd == true)
{
hdmusic.rewind();
hdmusic.play();
hd = false;
}
}
else
{
}
}
}
void display()
{
if (state2 == 1)
{
la = true;
}
if (la == true)
{
if (frameCount - bossprv >= 100 && la)
{
if (o == true)
{
bbmusic.rewind();
bbmusic.play();
}
bossprv = frameCount;
bulletbob.add(new BulletBob(bossx, bossy));
for (BulletBob ll : bulletbob)
{
ll.display();
}
}
}
up();
if (exist && kill == false)
{
bong();
bbbx = x;
bbby = y;
if (state2 == 1 && bossss == false)
{
image(photo, x - 190, y - 15);
}
if (state2 == 1 && bossss)
{
image(photo, x - 55, y - 15);
}
if (state2 == 0)
{
image(photo, x + 1, y - 15);
}
}
else
{
if (!ok)
{
temp = new Explosion(x, y);
temp.exist = true;
ok = !ok;
}
if (timer-- == 0)
{
temp.explode();
}
temp.display();
for (Obstacle n : obstacle)
{
n = null;
}
}
}
}
void obstacleDisplay()
{
if (((score % bossdan) == 0 && bossspawn) || key == 'j' && keyPressed)
{
score++;
obstacle.add(new Obstacle(1));
boss = true;
bossspawn = false;
}
else if (random(10) < armydan)
{
boss = false;
obstacle.add(new Obstacle(0));
}
for (Obstacle n : obstacle)
{
n.display();
}
}
class Particle
{
float x, y;
float vx, vy;
float ra;
float g = 0.1;
Particle(int xpos, int ypos, float velx, float vely, float r)
{
x = xpos;
y = ypos;
vx = velx;
vy = vely;
ra = r;
}
void updata()
{
vy += g;
y += vy;
x += vx;
}
void display()
{
fill(255, 0, 0);
ellipse(x, y, 4, 4);
}
}
class GenParticle extends Particle
{
float originX, originY;
GenParticle(int xIn, int yIn, float vxIn, float vyIn, float r, float ox, float oy)
{
super(xIn, yIn, vxIn, vyIn, r);
originX = (int)bbx;
originY = (int)bby;
fill(255, 0, 0);
}
void regenerate()
{
if ((x > width + ra) || (x < -ra) || (y > height + ra) || (y < -ra))
{
x = originX;
y = originY;
vx = random(-1.0, 1.0);
vy = random(-4.0, -2.0);
}
}
}
class Explosion
{
int state;
float x;
float y;
boolean exist;
PImage [] photo;
String name;
Explosion(float x, float y)
{
state = 0;
this.x = x;
this.y = y;
photo = new PImage;
for (int i = 0; i < 6; i++)
{
name = face + "0" + (i + 1) + ".png";
photo = loadImage(name);
}
}
void explode()
{
image(photo, x, y);
state = ++state % 6;
}
void display()
{
if (exist)
{
explode();
if (state == 0)
{
exist = false;
}
}
}
}
class BulletBob
{
int prv = frameCount;
float x1;
boolean hd = true;
float y1;
PImage png;
boolean exist;
int x2;
int y2;
float random;
int di2 = 900;
BulletBob(float x, float y)
{
random = random(0, 10);
if (random > 0 && random <= 7.4)
{
png = loadImage(face + "Bullet2" + cname + ".png");
}
if (random >= 7.4 && random <= 10)
{
if (cname == "1")
{
png = loadImage(face + "Bullet2" + cname + "3" + ".png");
}
}
if (x != -100 && y != -100)
{
for (Obstacle n : obstacle)
{
x1 = n.x;
y1 = n.y;
}
}
else
{
x1 = x;
y1 = y;
}
exist = true;
}
void display()
{
if (exist)
{
y1 += 13;
if (exist && pow(x1 - mx, 2) + pow(y1 - my, 2) < di2)
{
exist = false;
hp -= 1;
if (o == true)
{
mbmusic.rewind();
mbmusic.play();
}
}
for (Nucking n : nucking)
{
if (n.exist && exist && dist(x1, y1, n.x1, n.y1) < 1000)
{
exist = false;
}
}
for (st j : sting)
{
if (j.exist && exist && dist(0, y1, 0, j.y1) < 40)
{
exist = false;
}
}
if (exist != true)
{
}
for (Hudun mm : hudun)
{
if (mm.exist && exist && dist(x1, y1, mm.x1, mm.y1) < 150)
{
exist = false;
if (o == true && hd == true)
{
hdmusic.rewind();
hdmusic.play();
hd = false;
}
}
else
{
}
}
image(png, x1, y1);
}
//H.D.
}
}
void bobbulletdisplay()
{
if (frameCount - bobprv > bobshesu)
{
bulletbob.add(new BulletBob(-100, -100));
for (BulletBob ll : bulletbob)
{
bobprv = ll.prv;
}
}
for (BulletBob ll : bulletbob)
{
ll.display();
}
}
class Hudun
{
float x1;
float y1;
int clour = frameCount;
boolean exist = true;
Hudun()
{
clour = frameCount;
hudunprvs = frameCount;
exist = true;
}
void display()
{
x1 = mx + 22;
y1 = my + 50;
if (exist)
{
strokeWeight(8);
if (frameCount - hudunprvs < huduntimes)
{
if (frameCount - clour >= 350)
{
stroke(255,0,0);
}
if (frameCount - clour >= 236 && frameCount - clour <= 349)
{
stroke(255,125,0);
}
else if (frameCount - clour >= 151 && frameCount - clour <= 235)
{
stroke(111,211,0);
}
else if (frameCount - clour >= 57 && frameCount - clour <= 150)
{
stroke(125,255,0);
}
else if (frameCount - clour >= 1 && frameCount - clour <= 56)
{
stroke(0,255,0);
}
noFill();
ellipse(x1,y1,120,120);
noStroke();
}
if(frameCount - hudunprvs >= huduntimes)
{
exist = false;
}
}
if (exist == false)
{
x1=10000;
y1=10000;
}
}
}
void hudundisplay()
{
if(hudunnumber <=999999999)
{
text("H.D.: " + hudunnumber, 800, 450);
}
else
{
text("H.D.: ∞" , 800, 450);
}
if (mousePressed && mouseButton == CENTER && frameCount - hudunprv > huduntime && hudunnumber >= 1)
{
hudun.add(new Hudun());
for (Hudun mmm : hudun)
{
if(mmm.exist)
{
hudunnumber--;
}
}
hudunprv = frameCount;
}
for (Hudun mmm : hudun)
{
mmm.display();
}
}
游戏文件:
代码:
资源包:https://pan.baidu.com/s/1kVG7lTd
提示:把资源包下好后,把它放在随便哪个目录下,然后把Processing第13行代码的face,赋值为路径(例:资源包(face)在D:/abc/下,face就赋值为D:/abc/face/)
最后,我还要谢谢cholla(微信),是她帮助我解决问题的。
6666666666666666666666666666666666666666666666666666666666666666666666666666 还是耍人好用,有些电脑没1gb内存
页:
[1]