xxxxxxxxxx
138
new p5();
// noprotect
var barr = [];
var screen = [];
for(var i = 0; i < 10; i++){
screen[i] = [];
for(var j = 0; j < 10; j++){
screen[i][j] = 0;
}
}
var b = [];
var m = createVector(width/2, height/2);
var mcol = [255, 255, 255];
var mr = 12;
var mhp = 255;
var score = 0;
var bg = 0;
var ktog = false;
function setup() {
createCanvas(800, 500);
}
function draw() {
background(bg, 0, 0);
bg *= 0.9;
stroke(255);
strokeWeight(1);
for(var i = b.length-1; i >= 0; i--){
b[i].eval();
if(b[i].r <= 1) b.splice(i,1);
}
if(mhp > 0){
if(ktog && b.length > 0){
if(random(100) < 1){
b[floor(random(b.length))].r = 0;
score-=0.2;
if(mhp < 255) mhp++;
}
}
strokeWeight(2);
if(mhp > 150) stroke(0, mhp, 0);
if(mhp < 150 && mhp > 100) stroke(mhp + 25, mhp + 20, 0);
if(mhp < 100) stroke(mhp + 50, 0, 0);
if(!ktog){
fill(mcol[0],mcol[1],mcol[2], mhp);
m.x = mouseX;
m.y = mouseY;
}else{
fill(0,0,0);
}
if(mouseX > width || mouseX < 0 || mouseY > height || mouseY < 0){
score+=0.1;
m = createVector(width/2,height/2);
}
score+=0.02;
document.getElementById("sco").innerHTML = "Score: " + round(score) + " (HP: " + round(mhp) + "/255)";
ellipse(m.x, m.y, mr*2, mr*2);
if(mhp < 255) mhp+=score/100000;
}else{
m = createVector(-width, -height);
document.getElementById("sco").innerHTML = "Score: " + round(score) + " (Dead)";
}
if(random(100) < score/(random(100,200))) b[b.length] = new ball(width/2, height/2, createVector(random(-6,6), random(6,-6)), random(6,14), [random(255),random(255),random(255)]);
}
class ball{
constructor(x, y, dir, r, col){
this.pos = createVector(x, y);
this.dir = dir;
this.r = r;
this.col = col;
}
render(){
fill(this.col[0]+random(25), this.col[1]+random(25), this.col[2]+random(25));
ellipse(this.pos.x, this.pos.y, this.r*2, this.r*2);
}
tick(){
this.pos.add(this.dir);
if(this.dir.x > 10/this.r) this.dir.x *= 0.9;
if(this.dir.y > 10/this.r) this.dir.y *= 0.9;
}
bouncex(){
let newdir = createVector(this.dir.x*-1,this.dir.y);
this.dir = newdir.copy();
this.dir.mult(1.2);
}
bouncey(){
let newdir = createVector(this.dir.x,this.dir.y*-1);
this.dir = newdir.copy();
this.dir.mult(1.2);
}
bounce(){
this.dir.mult(-2);
}
collide(){
if(dist(this.pos.x, this.pos.y, m.x, m.y) < this.r + mr){
var r = floor(random(3));
mcol[r]-=this.r;
if(mcol[r] < 0) mcol[r] = 255;
mr+=r/10;
mhp-=r;
this.col[r]++;
if(this.col[r] > 255) this.col[r] = 0;
this.bounce();
bg += 100;
this.r-=1;
score++;
}
}
eval(){
if(this.r > 1){
this.render();
this.tick();
this.collide();
if(this.pos.x > width || this.pos.x < 0) this.bouncex();
if(this.pos.y > height || this.pos.y < 0) this.bouncey();
if(random(100) < 0.01){
var vect = createVector(m.x-this.pos.x, m.y-this.pos.y);
vect.setMag(1);
this.dir = vect.copy();
this.r--;
}
}
}
}
function mousePressed(){
if(ktog) ktog = false;
else ktog = true;
return false;
}