class Bacteria{
float spawn;
Bacteria(float tempbx, float tempby, float tempbspeed){
bx = tempbx;
by = tempby;
tempbspeed = bspeed;
}
void restart(){
spawn = round(random(0, 1));
if(spawn == 0){
bx = round(random(0, 1)) * width;
by = random(0, height);
}
else {
if(spawn == 1){
by = round(random(0, 1)) * height;
bx = random(0, width);
}
}
}
void update(){
bx += random(-1, 1);
if (bx > width){
bx = width;
bactR += PI;
}
if (bx < 0){
bx = 0;
bactR += PI;
}
by += random(-1, 1);
if (by > height){
by = height;
bactR += PI;
}
if (by < 0){
by = 0;
bactR += PI;
}
bspeed = 1;
//collision
if((dist(cx,cy, bx,by) < diameter/2) && (death == 0)){
eat = true;
}
if(eat == true){
level ++;
bAlpha = 0;
spawn = round(random(0, 1));
if(spawn == 0){
bx = round(random(0, 1)) * width;
by = random(0, height);
}
else {
if(spawn == 1){
by = round(random(0, 1)) * height;
bx = random(0, width);
}
}
eat = false;
}
if(bAlpha < 100){
bAlpha ++;
}
pushMatrix();
bactR += random(-.3, .3);
bx += cos(bactR) * bspeed;
by += sin(bactR) * bspeed;
translate(bx, by);
rotate(bactR);
strokeWeight(3);
stroke(0, bAlpha);
fill(180, 93, 73, bAlpha);
ellipse(0, 0, 10, 10);
popMatrix();
}
}
PFont myfont1;
PFont myfont2;
PFont myfont3;
int death = 300;
float textAlpha;
int level = -1;
int score;
int highscore = 0;
//you
float cx, cy;
float dx, dy, ratio;
float var1;
float targetX, targetY;
float easing = 0.04;
int dash;
float topSpeed = 50;
float diameter;
float mem1;
float membrane;
float memWeight;
float memAlpha = 200;
float cellR;
float cellRx, cellRy;
float cellS;
float cellS2;
float sDist;
float s = 0;
float sMult;
float cAlpha = 30;
float shieldtimer = 0;
boolean shield = false;
//bacteria
float bx = 400;
float by = 200;
float bactR;
float bspeed;
float bAlpha;
boolean eat = false;
//virus
boolean respawn1 = false;
boolean respawn2 = false;
Bacteria bacteria;
Virus virus1;
Virus virus2;
You you;
void setup() {
myfont1 = loadFont("Verdana-12.vlw");
myfont2 = loadFont("SegoeUI-BoldItalic-100.vlw");
myfont3 = loadFont("SegoeUI-BoldItalic-50.vlw");
textFont(myfont1);
frameRate(60);
//size(800, 480);
size(480, 320);
colorMode(HSB, 360, 100, 100, 100);
strokeCap(SQUARE);
smooth();
background(100);
bacteria = new Bacteria(480, 320, 0);
virus1 = new Virus(480, 320, level);
virus2 = new Virus(480, 320, level);
you = new You(width/2, height);
}
//-------------------------------------------------------------------
void draw() {
fill(165, 5, 67, 50);
noStroke();
rect(0, 0, width, height);
if(level == -1){
death = 0;
var1 += .2;
fill(0, 10);
rect(0, 238, width, 45);
fill(300);
textAlign(CENTER);
textFont(myfont2);
text("CELL", width/2, .4 * height);
textFont(myfont1);
text("You", .2 * width, .55 * height + 20);
text("Eat", .5 * width, .55 * height + 20);
text("Avoid", .8 * width, .55 * height + 20);
text("Movement:", .2 * width, .8 * height);
text("Dash:", .5 * width, .8 * height);
text("Pulse Shield:", .8 * width, .8 * height);
fill(50);
text("mouse", .2 * width, .85 * height);
text("click", .5 * width, .85 * height);
text("spacebar", .8 * width, .85 * height);
fill(300);
text("click to play", width/2, .95 * height);
textAlign(LEFT);
text("Instructions", .10 * width, .55 * height - 5);
stroke(70, 100);
strokeWeight(3);
fill(50, 83, 53, 40);
ellipse(.2 * width + 2 * sin(var1/3), .68 * height + 2 * cos(var1), 20, 20);
stroke(40, 100);
fill(180, 93, 73, 100);
ellipse( .5 * width + 2 * -sin(var1+var1), .55 * height + 40 + 2 * -sin(var1), 10, 10);
stroke(0, 100, 100);
pushMatrix();
translate(.8 * width, .55 * height + 40 + 3 * -sin(var1+var1));
line(0, 5, 0, -5);
popMatrix();
if(mousePressed){
level = 0;
death = 0;
you.restart();
virus1.restart();
virus2.restart();
bacteria.restart();
}
} else {
if(death == 0){
textAlign(LEFT);
fill(300);
text("Score: " + level, 10, 17);
}
virus1.update();
virus2.update();
bacteria.update();
you.update();
}
if(death == 1){
score = level;
}
if(death > 50){
if(score > highscore){
highscore = score;
}
fill(300);
textAlign(CENTER);
textFont(myfont3);
text("GAME OVER", width/2, .4 * height);
textAlign(LEFT);
textFont(myfont1);
text("Score: " + score, .2* width, .4 * height + 30);
text("Highscore: " + highscore, .2* width, .4 * height + 50);
}
if(death > 300){
if((mousePressed) || (frameCount == 1)){
level = 0;
death = 0;
shield = false;
shieldtimer = 0;
you.restart();
virus1.restart();
virus2.restart();
bacteria.restart();
}
textAlign(CENTER);
text("click to restart", width/2, .9 * height);
}
}
float targetx, targety;
class Virus {
float var1;
float spawn;
float vx;
float vy;
float vR;
float vR2;
float vR2var;
float vspeed;
boolean alive = true;
float pause = 0;
Virus (float tempvx, float tempvy, float tempvspeed) {
vx = tempvx;
vy = tempvy;
vspeed = tempvspeed;
}
void restart(){
spawn = round(random(0, 1));
if(spawn == 0){
vx = round(random(0, 1)) * width;
vy = random(0, height);
}
else {
if(spawn == 1){
vy = 0;
vx = random(0, width);
}
}
}
void respawn() {
spawn = round(random(0, 1));
if(spawn == 0){
vx = round(random(0, 1)) * width;
vy = random(0, height);
}
else {
if(spawn == 1){
vy = round(random(0, 1)) * height;
vx = random(0, width);
}
}
}
void update() {
if((dist(cx, cy, vx, vy) < .5*diameter + 4) && (death == 0) && (alive == true) && (shield == true)){
alive = false;
vR = atan2(cy - vy, cx - vx) + PI;
}
if((dist(cx, cy, vx, vy) < .5*diameter - 2) && (death == 0) && (alive == true)){
death = 1;
pause = 100;
}
if(alive == true){
//easing
if(vR < atan2(cy - vy, cx - vx)){
vR += random(-.001, .008) * level;
}else{
vR -= random(-.001, .008) * level;
}
vx += random(-.1, .1);
if (vx > width){
vx = width;
vR += PI;
}
if (vx < 0){
vx = 0;
vR += PI;
}
vy += random(-.1, .1);
if (vy > height){
vy = height;
vR += PI;
}
if (vy < 0){
vy = 0;
vR += PI;
}
vspeed = 1 + .05 * level;
if(pause > 0){//if it kills you
pause --;
vR += random(-.3 , .3);
vx += cos(vR) * .1;
vy += sin(vR) * .1;
var1 ++;
strokeWeight(cos(var1)*2 + 2);
} else {//it's normal movement
vR += random(-.2, .2);
vR2 = atan2(mouseY - vy, mouseX - vx);
println(vR2);
vx += cos(vR) * vspeed;
vy += sin(vR) * vspeed;
strokeWeight(1);
}
} else {
vx += cos(vR) * vspeed;
vy += sin(vR) * vspeed;
if ((vx > width + 200) || (vx < -200) || (vy < -200) || (vy > height + 200)){
respawn();
vR = random(0, 2*PI);
alive = true;
}
}
pushMatrix();
translate(vx, vy);
rotate(vR);
stroke(0, 100, 100);
strokeWeight(2);
line(5, 0, -5, 0);
popMatrix();
}
}
class You{
float cHue = 50;
float memWeight = 3;
You(float tempcx, float tempcy){
tempcx = cx;
tempcy = cy;
}
void restart(){
death = 0;
cx = width/2;
cy = height;
cHue = 50;
cAlpha = 30;
memAlpha = 200;
memWeight = 3;
}
void update(){
if(death == 0){//--(alive)
//movement--------------------
if(easing > .04){
easing -= .002;
}
targetX = mouseX;
dx = cos(cellR) * (sDist);
targetY = mouseY;
dy = sin(cellR) * (sDist);
ratio = atan2(dy, dx);
//dash------------------------
if(dash > 0){
dash --;
}
//top speed--------------------
if(dx >= topSpeed){
dx = cos(cellR) * topSpeed;
}
if(dx <= -topSpeed){
dx = cos(cellR) * topSpeed;
}
if(abs(dx) > 1) {
cx += dx * easing;
}
if(dy >= topSpeed){
dy = sin(cellR) * topSpeed;
}
if(dy <= topSpeed){
dy = sin(cellR) * topSpeed;
}
if(abs(dy) > 1) {
cy += dy * easing;
}
//shape--------------------
diameter = 30 + level;
sDist = dist(mouseX, mouseY, cx, cy);
if(sDist > 100){
s += .25;
}
else {
s += map(sDist, 0, 100, .05, .25);
}
var1 += .2;
sMult = map(sDist, 0, 100, 0, .25 * diameter);
if(sMult > .25 * diameter){
sMult = .25 * diameter;
}
cellS = sMult * cos(s);
cellS2 = sMult * (.5 +(cos(s)/2));
//rotation--------------------
cellRx = mouseX - cx;
cellRy = mouseY - cy;
cellR = atan2(cellRy, cellRx);
if((keyPressed) && (death == 0)){
if((key == ' ') && (shieldtimer == 0) && (shield == false)){
shieldtimer ++;
shield = true;
}
}
if (shieldtimer > 0){
shieldtimer ++;
memWeight += 2;
memAlpha -= 20;
if(shieldtimer == 10){
shield = false;
}
if(shieldtimer >= 300){
memWeight = 3;
memAlpha = 0;
shieldtimer = 0;
shield = false;
}
}
if((shieldtimer == 0)){
memWeight = 3;
if(memAlpha < 200){
memAlpha += 2;
memWeight = 3;
}
}
if(cHue < 50){
cHue += .5;
}
if(cx > width){
cx = width;
}
if(cx < 0){
cx = 0;
}
if(cy > height){
cy = height;
}
if(cy < 0){
cy = 0;
}
}
else
//----------------DEAD-----------------
{
death ++;
if (death < 10){
score = level;
}
else {
level = 0;
}
cx += random(-1, 1);
cy += random(-1, 1);
cHue -= .5;
cAlpha -= .2 ;
memAlpha -= 1.5 - memWeight/10;
memWeight += random(-5, 5);
if(memWeight < 0){
memWeight = 1;
}
if(memWeight > 8){
memWeight = 6;
}
} //end dead---------
if(mousePressed){
if((dash == 0) && (death == 0)){
easing = .12;
dash = 70;
cHue = 10;
}
}
if(memWeight < 3){
memWeight ++;
}
//---------------DISPLAY---------------
pushMatrix();
translate(cx + 2*sin(var1), cy + 2*cos(var1));
rotate(cellR);
stroke(80, memAlpha);
strokeWeight(memWeight);
fill(cHue, 83, 53, cAlpha);
ellipse(0, 0, diameter + cellS, diameter - cellS2);
popMatrix();
}
}
arcade game, move with mouse, click to dash, and space to shield,
Tip: shields must be properly timed to work.