I want to figure out how to deduct 1 health point if a moving triangle collides with any moving point, and make that one particular point that has the triangle collided with disappear (if that’s possible). Just to note that the moving circles are not ellipses, they’re points with various different stroke weights to them. Once the health score hits -1, my plan is to try and program another screen to pop up and display the amount of time you lasted for.
flake[] flake = new flake[30];
float speed = 10;
int b;
color b1 = color(0, 0, 0);
color b2 = color(141, 84, 216);
int Y_AXIS = 1;
int s = 0;
int m = 0;
int health = 3;
void setup(){
size(1000,800);
for(int i = 0; i < flake.length; i++){
flake[i] = new flake();
}
}
void draw(){
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
b = mouseY;
for(int i = 0; i < flake.length; i++){
flake[i].show();
flake[i].update();
}
display();
timer();
healthScore();
}
void display() {
fill(243, 142, 255);
noStroke();
triangle(917, b, 950, b-15, 950, b+15);
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {
float deltaR = red(c2)-red(c1);
float deltaG = green(c2)-green(c1);
float deltaB = blue(c2)-blue(c1);
if (axis == Y_AXIS) {
for (int i=x; i<=(x+w); i++) {
// row
for (int j = y; j<=(y+h); j++) {
color c = color(
(red(c1)+(j-y)*(deltaR/h)),
(green(c1)+(j-y)*(deltaG/h)),
(blue(c1)+(j-y)*(deltaB/h)));
set(i, j, c);
}
}
}
}
void timer(){
textAlign(100,100);
textSize(30);
if(s<=59){
text(m+":"+s,100,100);
s=s+1;
}
else{
m=m+1;
s=0;
text(m+":"+s,100,100);
}
}
void healthScore(){
textSize(32);
text("Health: "+health, 100, 50);
}
Moving circles class:
class flake{
float y=random(height);
float x=random(-width);
float z = random(20, 100);
float size=map(z, 1, 30, 3, 20);
float speed=map(z, 1, 30, 0.1, 1);
void show(){
stroke(248, 188, 255);
strokeWeight(size);
point(x,y);
}
void update() {
x+=speed;
if(x>width) reset();
}
void reset(){
y = random(height);
x = random(-width,0);
z = random(20,100);
size=map(z,1,29,3,30);
speed=map(z,1,29,0.1,1);
}
}