From 76788d98e7d00e6a91c6c4b51baa69cb85e6ae6d Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Tue, 15 Dec 2015 08:48:45 -0500 Subject: [PATCH 01/14] i have a raindrop --- raindropGameCode/raindrop_class.pde | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 raindropGameCode/raindrop_class.pde diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde new file mode 100644 index 0000000..2f35d2f --- /dev/null +++ b/raindropGameCode/raindrop_class.pde @@ -0,0 +1,37 @@ +class Raindrop { + PVector loc, vel; + float grav, diam, locx, locy; + + Raindrop(float locx, float locy) { + loc = new PVector(locx, locy); + vel = new PVector(0, 1); + grav = 0.098; + diam = 20; + } + + void display() { + noStroke(); + fill(255, 255, 255, 100); + ellipse(loc.x, loc.y, diam, diam); + triangle(loc.x-diam/2, loc.y, loc.x, loc.y-diam, loc.x+diam/2, loc.y); + } + + void fall() { + loc.add(vel); + vel.y += grav; + } + + void reset() { + loc.x = random(width); + loc.y = 0; + vel.y = 1; + } + + boolean isInContactWith(PVector var) { + if (loc.dist(var) < diam/2) { + return true; + } else { + return false; + } + } +} \ No newline at end of file From d64f0a205dd5ca354679cb13e73889ec53e8410e Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Tue, 15 Dec 2015 09:25:33 -0500 Subject: [PATCH 02/14] ITS RAINING (just not men tho) --- raindropGameCode/raindropGameCode.pde | 31 +++++++++++++++++++++++---- raindropGameCode/raindrop_class.pde | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 944de61..17ba1ca 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,6 +1,7 @@ PVector mouse; //declare a P Raindrop r; //declare a new Raindrop called r - +Raindrop r2; +Raindrop[] muchrain = new Raindrop[50]; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object // You can start out by just using the single Raindrop as you test @@ -9,18 +10,40 @@ Raindrop r; //declare a new Raindrop called r void setup() { size(1200, 800); mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} - r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + r2 = new Raindrop(random(width), 0); + for(int i = 0; i < 50; i++){ + muchrain[i] = new Raindrop(random(width), 0); + } } void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - background(0, 200, 255); + background(50, 50, 60); r.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + r2.fall(); + for(int i = 0; i < 50; i++){ + muchrain[i].fall(); + muchrain[i].display(); + if(muchrain[i].isInContactWith(mouse)) { + muchrain[i].reset(); + } + if(muchrain[i].loc.y > height + muchrain[i].diam/2) { + muchrain[i].reset(); + } + } r.display(); //display the raindrop + r2.display(); if (r.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse r.reset(); //if it is, reset the raindrop } + if (r2.isInContactWith(mouse)) { + r2.reset(); + } if (r.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen r.reset(); //if it does, reset the raindrop } -} + if (r2.loc.y > height + r2.diam/2) { + r2.reset(); + } +} \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde index 2f35d2f..6ab0bff 100644 --- a/raindropGameCode/raindrop_class.pde +++ b/raindropGameCode/raindrop_class.pde @@ -4,7 +4,7 @@ class Raindrop { Raindrop(float locx, float locy) { loc = new PVector(locx, locy); - vel = new PVector(0, 1); + vel = new PVector(0, 2); grav = 0.098; diam = 20; } From ed4319572e296dd5d9fff6bd7d0b9db0f0fa22d9 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Thu, 17 Dec 2015 09:08:14 -0500 Subject: [PATCH 03/14] stuff --- raindropGameCode/bucket_class.pde | 7 +++++++ raindropGameCode/raindropGameCode.pde | 7 ++++--- raindropGameCode/raindrop_class.pde | 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 raindropGameCode/bucket_class.pde diff --git a/raindropGameCode/bucket_class.pde b/raindropGameCode/bucket_class.pde new file mode 100644 index 0000000..74f2aa9 --- /dev/null +++ b/raindropGameCode/bucket_class.pde @@ -0,0 +1,7 @@ +class Bucket{ + PVector loc; + float notdiam; + + Bucket(){ + loc = new PVector(mouseX, mouseY); + notdiam = 50; \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 17ba1ca..3e02891 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,7 +1,8 @@ +int c = 900; PVector mouse; //declare a P Raindrop r; //declare a new Raindrop called r Raindrop r2; -Raindrop[] muchrain = new Raindrop[50]; +Raindrop[] muchrain = new Raindrop[c]; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object // You can start out by just using the single Raindrop as you test @@ -12,7 +13,7 @@ void setup() { mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions r2 = new Raindrop(random(width), 0); - for(int i = 0; i < 50; i++){ + for(int i = 0; i < c; i++){ muchrain[i] = new Raindrop(random(width), 0); } } @@ -22,7 +23,7 @@ void draw() { background(50, 50, 60); r.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity r2.fall(); - for(int i = 0; i < 50; i++){ + for(int i = 0; i < c; i++){ muchrain[i].fall(); muchrain[i].display(); if(muchrain[i].isInContactWith(mouse)) { diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde index 6ab0bff..bdb0bf6 100644 --- a/raindropGameCode/raindrop_class.pde +++ b/raindropGameCode/raindrop_class.pde @@ -4,14 +4,14 @@ class Raindrop { Raindrop(float locx, float locy) { loc = new PVector(locx, locy); - vel = new PVector(0, 2); + vel = new PVector(0, random(1, 3)); grav = 0.098; diam = 20; } void display() { noStroke(); - fill(255, 255, 255, 100); + fill(230, 230, 255, 100); ellipse(loc.x, loc.y, diam, diam); triangle(loc.x-diam/2, loc.y, loc.x, loc.y-diam, loc.x+diam/2, loc.y); } @@ -24,7 +24,7 @@ class Raindrop { void reset() { loc.x = random(width); loc.y = 0; - vel.y = 1; + vel.y = random(1, 3); } boolean isInContactWith(PVector var) { From 671190216011a0e26b63cd3159bb91a30fcb6261 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Tue, 5 Jan 2016 09:25:31 -0500 Subject: [PATCH 04/14] a thing? --- raindropGameCode/bucket_class.pde | 21 ++++++++++++++++----- raindropGameCode/raindropGameCode.pde | 21 ++++++++++++--------- raindropGameCode/raindrop_class.pde | 19 +++++++++---------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/raindropGameCode/bucket_class.pde b/raindropGameCode/bucket_class.pde index 74f2aa9..c0fbb56 100644 --- a/raindropGameCode/bucket_class.pde +++ b/raindropGameCode/bucket_class.pde @@ -1,7 +1,18 @@ -class Bucket{ +class Shield{ PVector loc; - float notdiam; + float notdiam, locx, locy; - Bucket(){ - loc = new PVector(mouseX, mouseY); - notdiam = 50; \ No newline at end of file + Shield(float locx, float locy){ + loc = new PVector(locx, locy); + notdiam = 50; + } + + void show(){ + fill(225,50,10); + loc.set(mouseX, 600); + noFill(); + stroke(200,200,255); + strokeWeight(5); + arc(loc.x,loc.y,500,100, PI+QUARTER_PI, TWO_PI-QUARTER_PI); + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 3e02891..0a9bb65 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,8 +1,9 @@ int c = 900; PVector mouse; //declare a P -Raindrop r; //declare a new Raindrop called r -Raindrop r2; -Raindrop[] muchrain = new Raindrop[c]; +Missile r; //declare a new Raindrop called r +Missile r2; +Missile[] muchrain = new Missile[c]; +Shield b; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object // You can start out by just using the single Raindrop as you test @@ -10,21 +11,22 @@ Raindrop[] muchrain = new Raindrop[c]; void setup() { size(1200, 800); + b = new Shield(mouseX, 600); mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} - r = new Raindrop(random(width), 0); //Initialize r. The parameters used are the initial x and y positions - r2 = new Raindrop(random(width), 0); + r = new Missile(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + r2 = new Missile(random(width), 0); for(int i = 0; i < c; i++){ - muchrain[i] = new Raindrop(random(width), 0); + muchrain[i] = new Missile(random(width), 0); } } void draw() { mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(50, 50, 60); - r.fall(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - r2.fall(); + r.fire(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + r2.fire(); for(int i = 0; i < c; i++){ - muchrain[i].fall(); + muchrain[i].fire(); muchrain[i].display(); if(muchrain[i].isInContactWith(mouse)) { muchrain[i].reset(); @@ -47,4 +49,5 @@ void draw() { if (r2.loc.y > height + r2.diam/2) { r2.reset(); } + b.show(); } \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde index bdb0bf6..a028f29 100644 --- a/raindropGameCode/raindrop_class.pde +++ b/raindropGameCode/raindrop_class.pde @@ -1,30 +1,29 @@ -class Raindrop { +class Missile { PVector loc, vel; - float grav, diam, locx, locy; + float diam, locx, locy; - Raindrop(float locx, float locy) { + Missile(float locx, float locy) { loc = new PVector(locx, locy); - vel = new PVector(0, random(1, 3)); - grav = 0.098; - diam = 20; + vel = new PVector((random(1,3)), random(6, 8)); + diam = 10; } void display() { noStroke(); fill(230, 230, 255, 100); - ellipse(loc.x, loc.y, diam, diam); + ellipse(loc.x, loc.y, 10, 50); triangle(loc.x-diam/2, loc.y, loc.x, loc.y-diam, loc.x+diam/2, loc.y); } - void fall() { + void fire() { loc.add(vel); - vel.y += grav; } void reset() { loc.x = random(width); loc.y = 0; - vel.y = random(1, 3); + vel.y = random(5, 7); + vel.x = (random(-0.5,0.5)); } boolean isInContactWith(PVector var) { From 09d7d6b1688eb4236c8a6823f8eaa61dfb339ed0 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Wed, 6 Jan 2016 11:04:40 -0500 Subject: [PATCH 05/14] more stuff --- raindropGameCode/building.pde | 21 ++++++++ raindropGameCode/missile_class.pde | 48 +++++++++++++++++++ raindropGameCode/raindropGameCode.pde | 34 ++++++++----- raindropGameCode/raindrop_class.pde | 36 -------------- .../{bucket_class.pde => shield_class.pde} | 2 + 5 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 raindropGameCode/building.pde create mode 100644 raindropGameCode/missile_class.pde delete mode 100644 raindropGameCode/raindrop_class.pde rename raindropGameCode/{bucket_class.pde => shield_class.pde} (99%) diff --git a/raindropGameCode/building.pde b/raindropGameCode/building.pde new file mode 100644 index 0000000..7502ebd --- /dev/null +++ b/raindropGameCode/building.pde @@ -0,0 +1,21 @@ +class Building{ + float h, w, x, transp; + + Building(float h, float w, float x){ + h = random(10, 50); + w = random(5, 15); + x = random(width); + transp = 0; + } + + void build(){ + fill(100,200,100, transp); + rectMode(CORNERS); + rect(x, height, x+w, height-h); + } + + void destroyed(){ + transp=255; + } +} + \ No newline at end of file diff --git a/raindropGameCode/missile_class.pde b/raindropGameCode/missile_class.pde new file mode 100644 index 0000000..59a5ce3 --- /dev/null +++ b/raindropGameCode/missile_class.pde @@ -0,0 +1,48 @@ +class Missile { + PVector loc, vel; + float diam, locx, locy, r, g, b; + + Missile(float locx, float locy) { + loc = new PVector(locx, locy); + vel = new PVector((random(-3, 3)), random(6, 8)); + diam = 10; + r = 230; + g = 230; + b = 255; + } + + void display() { + noStroke(); + fill(r, g, b); + ellipse(loc.x, loc.y, diam, diam); + } + + void fire() { + loc.add(vel); + } + + void deflected() { + vel.y = -vel.y; + rotate(PI); + display(); + } + void boom() { + fill(0); + ellipse(loc.x, loc.y, 50, 50); + vel.x = 0; + vel.y = 0; + loc.y = height; + diam = 50; + r = 0; + g = 0; + b = 0; + } + + boolean isInContactWith(PVector var) { + if (loc.dist(var) < diam/2) { + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 0a9bb65..816c2df 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,9 +1,11 @@ -int c = 900; +int c = 20; +int pop = 30; PVector mouse; //declare a P Missile r; //declare a new Raindrop called r Missile r2; Missile[] muchrain = new Missile[c]; Shield b; +Building[] city = new Building[pop]; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object // You can start out by just using the single Raindrop as you test @@ -15,39 +17,47 @@ void setup() { mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} r = new Missile(random(width), 0); //Initialize r. The parameters used are the initial x and y positions r2 = new Missile(random(width), 0); - for(int i = 0; i < c; i++){ + for (int i = 0; i < c; i++) { muchrain[i] = new Missile(random(width), 0); } + for(int i = 0; i < pop; i++){ + city[i] = new Building(random(10,50), random(5,15), random(width)); + } } void draw() { - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY background(50, 50, 60); + mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY r.fire(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity r2.fire(); - for(int i = 0; i < c; i++){ + for (int i = 0; i < c; i++) { muchrain[i].fire(); muchrain[i].display(); - if(muchrain[i].isInContactWith(mouse)) { - muchrain[i].reset(); + if (muchrain[i].isInContactWith(mouse)) { + muchrain[i].deflected(); } - if(muchrain[i].loc.y > height + muchrain[i].diam/2) { - muchrain[i].reset(); + if (muchrain[i].loc.y > height + muchrain[i].diam/2) { + muchrain[i].boom(); } + for(int j = 0; j < pop; j++){ + city[j].build(); + if(muchrain[i].loc.y >= city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)){ + city[j].destroyed(); + } } r.display(); //display the raindrop r2.display(); if (r.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.reset(); //if it is, reset the raindrop + r.deflected(); //if it is, reset the raindrop } if (r2.isInContactWith(mouse)) { - r2.reset(); + r2.deflected(); } if (r.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.reset(); //if it does, reset the raindrop + r.boom(); //if it does, reset the raindrop } if (r2.loc.y > height + r2.diam/2) { - r2.reset(); + r2.boom(); } b.show(); } \ No newline at end of file diff --git a/raindropGameCode/raindrop_class.pde b/raindropGameCode/raindrop_class.pde deleted file mode 100644 index a028f29..0000000 --- a/raindropGameCode/raindrop_class.pde +++ /dev/null @@ -1,36 +0,0 @@ -class Missile { - PVector loc, vel; - float diam, locx, locy; - - Missile(float locx, float locy) { - loc = new PVector(locx, locy); - vel = new PVector((random(1,3)), random(6, 8)); - diam = 10; - } - - void display() { - noStroke(); - fill(230, 230, 255, 100); - ellipse(loc.x, loc.y, 10, 50); - triangle(loc.x-diam/2, loc.y, loc.x, loc.y-diam, loc.x+diam/2, loc.y); - } - - void fire() { - loc.add(vel); - } - - void reset() { - loc.x = random(width); - loc.y = 0; - vel.y = random(5, 7); - vel.x = (random(-0.5,0.5)); - } - - boolean isInContactWith(PVector var) { - if (loc.dist(var) < diam/2) { - return true; - } else { - return false; - } - } -} \ No newline at end of file diff --git a/raindropGameCode/bucket_class.pde b/raindropGameCode/shield_class.pde similarity index 99% rename from raindropGameCode/bucket_class.pde rename to raindropGameCode/shield_class.pde index c0fbb56..7f64820 100644 --- a/raindropGameCode/bucket_class.pde +++ b/raindropGameCode/shield_class.pde @@ -15,4 +15,6 @@ class Shield{ strokeWeight(5); arc(loc.x,loc.y,500,100, PI+QUARTER_PI, TWO_PI-QUARTER_PI); } + +} } \ No newline at end of file From b52b59cab2183910f6377b643231f89f48592f1a Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Wed, 6 Jan 2016 11:48:37 -0500 Subject: [PATCH 06/14] ehh? --- raindropGameCode/building.pde | 28 +++++----- raindropGameCode/missile_class.pde | 6 +++ raindropGameCode/raindropGameCode.pde | 73 ++++++++++++++++----------- raindropGameCode/shield_class.pde | 17 +++---- 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/raindropGameCode/building.pde b/raindropGameCode/building.pde index 7502ebd..745ed38 100644 --- a/raindropGameCode/building.pde +++ b/raindropGameCode/building.pde @@ -1,21 +1,21 @@ -class Building{ +class Building { float h, w, x, transp; - - Building(float h, float w, float x){ - h = random(10, 50); - w = random(5, 15); + + Building() { + h = random(20, 60); + w = random(10, 20); x = random(width); - transp = 0; + transp = 255; } - - void build(){ - fill(100,200,100, transp); + + void build() { + noStroke(); + fill(100, 200, 100, transp); rectMode(CORNERS); rect(x, height, x+w, height-h); } - - void destroyed(){ - transp=255; + + void destroyed() { + transp=0; } -} - \ No newline at end of file +} \ No newline at end of file diff --git a/raindropGameCode/missile_class.pde b/raindropGameCode/missile_class.pde index 59a5ce3..7e204a0 100644 --- a/raindropGameCode/missile_class.pde +++ b/raindropGameCode/missile_class.pde @@ -37,6 +37,12 @@ class Missile { g = 0; b = 0; } + void reset() { + loc.x= 0; + loc.y = 0; + vel.x = random(-3,3); + vel.y = random(6,8); + } boolean isInContactWith(PVector var) { if (loc.dist(var) < diam/2) { diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 816c2df..415773a 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,10 +1,11 @@ int c = 20; -int pop = 30; +int pop = 40; +int b = 0; PVector mouse; //declare a P -Missile r; //declare a new Raindrop called r -Missile r2; +Missile m; //declare a new Raindrop called r +Missile m2; Missile[] muchrain = new Missile[c]; -Shield b; +Shield s; Building[] city = new Building[pop]; // On your own, create an array of Raindrop objects instead of just one // Use the array instead of the single object @@ -13,51 +14,63 @@ Building[] city = new Building[pop]; void setup() { size(1200, 800); - b = new Shield(mouseX, 600); + s = new Shield(mouseX, 600); mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} - r = new Missile(random(width), 0); //Initialize r. The parameters used are the initial x and y positions - r2 = new Missile(random(width), 0); + m = new Missile(random(width), 0); //Initialize r. The parameters used are the initial x and y positions + m2 = new Missile(random(width), 0); for (int i = 0; i < c; i++) { muchrain[i] = new Missile(random(width), 0); } - for(int i = 0; i < pop; i++){ - city[i] = new Building(random(10,50), random(5,15), random(width)); + for (int i = 0; i < pop; i++) { + city[i] = new Building(); } } void draw() { background(50, 50, 60); mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - r.fire(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - r2.fire(); + m.fire(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity + m2.fire(); + for (int i = 0; i < pop; i++) { + city[i].build(); + } for (int i = 0; i < c; i++) { muchrain[i].fire(); muchrain[i].display(); - if (muchrain[i].isInContactWith(mouse)) { + if(muchrain[i].loc.y <=0){ + muchrain[i].reset(); + if (muchrain[i].loc.x >= mouseX-250 && muchrain[i].loc.x <= mouseX+250 && muchrain[i].loc.y >=550 && muchrain[i].loc.y >=600) { muchrain[i].deflected(); } if (muchrain[i].loc.y > height + muchrain[i].diam/2) { - muchrain[i].boom(); + muchrain[i].reset(); } - for(int j = 0; j < pop; j++){ - city[j].build(); - if(muchrain[i].loc.y >= city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)){ + for (int j = 0; j < pop; j++) { + if (muchrain[i].loc.y >= height-city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)) { city[j].destroyed(); + b += 1; } + } + m.display(); //display the raindrop + m2.display(); + if (m.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + m.deflected(); //if it is, reset the raindrop + } + if (m2.isInContactWith(mouse)) { + m2.deflected(); + } + if (m.loc.y > height + m.diam/2) { //check to see if the raindrop goes below the bottom of the screen + m.boom(); //if it does, reset the raindrop + } + if (m2.loc.y > height + m2.diam/2) { + m2.boom(); + } + s.show(); } - r.display(); //display the raindrop - r2.display(); - if (r.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - r.deflected(); //if it is, reset the raindrop - } - if (r2.isInContactWith(mouse)) { - r2.deflected(); - } - if (r.loc.y > height + r.diam/2) { //check to see if the raindrop goes below the bottom of the screen - r.boom(); //if it does, reset the raindrop - } - if (r2.loc.y > height + r2.diam/2) { - r2.boom(); + if(b >= pop){ + background(0); + fill(255,0,0); + textSize(100); + text("game over they ded", 0, height/2); } - b.show(); } \ No newline at end of file diff --git a/raindropGameCode/shield_class.pde b/raindropGameCode/shield_class.pde index 7f64820..a7e859c 100644 --- a/raindropGameCode/shield_class.pde +++ b/raindropGameCode/shield_class.pde @@ -1,20 +1,19 @@ -class Shield{ +class Shield { PVector loc; float notdiam, locx, locy; - - Shield(float locx, float locy){ + + Shield(float locx, float locy) { loc = new PVector(locx, locy); notdiam = 50; } - - void show(){ - fill(225,50,10); + + void show() { + fill(225, 50, 10); loc.set(mouseX, 600); noFill(); - stroke(200,200,255); + stroke(200, 200, 255); strokeWeight(5); - arc(loc.x,loc.y,500,100, PI+QUARTER_PI, TWO_PI-QUARTER_PI); + arc(loc.x, loc.y, 500, 100, PI, TWO_PI); } - } } \ No newline at end of file From 98d3189090a1700d40e7a86ce019d7eab6fc9db3 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Thu, 7 Jan 2016 12:00:25 -0500 Subject: [PATCH 07/14] restart this now --- raindropGameCode/missile_class.pde | 4 +- raindropGameCode/raindropGameCode.pde | 63 ++++++++++++++------------- raindropGameCode/shield_class.pde | 4 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/raindropGameCode/missile_class.pde b/raindropGameCode/missile_class.pde index 7e204a0..45a7187 100644 --- a/raindropGameCode/missile_class.pde +++ b/raindropGameCode/missile_class.pde @@ -40,8 +40,8 @@ class Missile { void reset() { loc.x= 0; loc.y = 0; - vel.x = random(-3,3); - vel.y = random(6,8); + vel.x = random(-3, 3); + vel.y = random(6, 8); } boolean isInContactWith(PVector var) { diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 415773a..2d622a9 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -37,40 +37,41 @@ void draw() { for (int i = 0; i < c; i++) { muchrain[i].fire(); muchrain[i].display(); - if(muchrain[i].loc.y <=0){ + if (muchrain[i].loc.y <=0) { muchrain[i].reset(); - if (muchrain[i].loc.x >= mouseX-250 && muchrain[i].loc.x <= mouseX+250 && muchrain[i].loc.y >=550 && muchrain[i].loc.y >=600) { - muchrain[i].deflected(); - } - if (muchrain[i].loc.y > height + muchrain[i].diam/2) { - muchrain[i].reset(); - } - for (int j = 0; j < pop; j++) { - if (muchrain[i].loc.y >= height-city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)) { - city[j].destroyed(); - b += 1; + if (muchrain[i].loc.x >= mouseX-250 && muchrain[i].loc.x <= mouseX+250 && muchrain[i].loc.y >=550 && muchrain[i].loc.y >=600) { + muchrain[i].deflected(); } + if (muchrain[i].loc.y > height + muchrain[i].diam/2) { + muchrain[i].reset(); + } + for (int j = 0; j < pop; j++) { + if (muchrain[i].loc.y >= height-city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)) { + city[j].destroyed(); + b += 1; + } + } + m.display(); //display the raindrop + m2.display(); + if (m.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse + m.deflected(); //if it is, reset the raindrop + } + if (m2.isInContactWith(mouse)) { + m2.deflected(); + } + if (m.loc.y > height + m.diam/2) { //check to see if the raindrop goes below the bottom of the screen + m.boom(); //if it does, reset the raindrop + } + if (m2.loc.y > height + m2.diam/2) { + m2.boom(); + } + s.show(); } - m.display(); //display the raindrop - m2.display(); - if (m.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - m.deflected(); //if it is, reset the raindrop - } - if (m2.isInContactWith(mouse)) { - m2.deflected(); - } - if (m.loc.y > height + m.diam/2) { //check to see if the raindrop goes below the bottom of the screen - m.boom(); //if it does, reset the raindrop - } - if (m2.loc.y > height + m2.diam/2) { - m2.boom(); + if (b >= pop) { + background(0); + fill(255, 0, 0); + textSize(100); + text("game over they ded", 0, height/2); } - s.show(); - } - if(b >= pop){ - background(0); - fill(255,0,0); - textSize(100); - text("game over they ded", 0, height/2); } } \ No newline at end of file diff --git a/raindropGameCode/shield_class.pde b/raindropGameCode/shield_class.pde index a7e859c..47c6938 100644 --- a/raindropGameCode/shield_class.pde +++ b/raindropGameCode/shield_class.pde @@ -8,12 +8,10 @@ class Shield { } void show() { - fill(225, 50, 10); + fill(0); loc.set(mouseX, 600); - noFill(); stroke(200, 200, 255); strokeWeight(5); arc(loc.x, loc.y, 500, 100, PI, TWO_PI); } -} } \ No newline at end of file From 786ccfc95538d3920d7ee29671d868211c4106da Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Mon, 11 Jan 2016 21:24:21 -0500 Subject: [PATCH 08/14] still not working but at least i have array lists kinda --- raindropGameCode/missile_class.pde | 3 +- raindropGameCode/raindropGameCode.pde | 89 +++++++-------------------- 2 files changed, 23 insertions(+), 69 deletions(-) diff --git a/raindropGameCode/missile_class.pde b/raindropGameCode/missile_class.pde index 45a7187..ac330c5 100644 --- a/raindropGameCode/missile_class.pde +++ b/raindropGameCode/missile_class.pde @@ -23,7 +23,6 @@ class Missile { void deflected() { vel.y = -vel.y; - rotate(PI); display(); } void boom() { @@ -38,7 +37,7 @@ class Missile { b = 0; } void reset() { - loc.x= 0; + loc.x= random(width); loc.y = 0; vel.x = random(-3, 3); vel.y = random(6, 8); diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 2d622a9..626013a 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,77 +1,32 @@ -int c = 20; -int pop = 40; -int b = 0; -PVector mouse; //declare a P -Missile m; //declare a new Raindrop called r -Missile m2; -Missile[] muchrain = new Missile[c]; -Shield s; -Building[] city = new Building[pop]; -// On your own, create an array of Raindrop objects instead of just one -// Use the array instead of the single object -// You can start out by just using the single Raindrop as you test - +ArrayList m = new ArrayList(); +ArrayList city = new ArrayList(); +Shield s = new Shield(mouseX, 600); void setup() { - size(1200, 800); - s = new Shield(mouseX, 600); - mouse = new PVector(); //initialize mouse PVector. value is irrelevant since it will be set at the start of void draw(){} - m = new Missile(random(width), 0); //Initialize r. The parameters used are the initial x and y positions - m2 = new Missile(random(width), 0); - for (int i = 0; i < c; i++) { - muchrain[i] = new Missile(random(width), 0); - } - for (int i = 0; i < pop; i++) { - city[i] = new Building(); - } + size(1600, 800); + m.add(new Missile(random(width), 0)); + city.add(new Building()); } void draw() { - background(50, 50, 60); - mouse.set(mouseX, mouseY); //set value of mouse as mouseX,mouseY - m.fire(); //make the raindrop fall. It should accelerate as if pulled towards the ground by earth's gravity - m2.fire(); - for (int i = 0; i < pop; i++) { - city[i].build(); - } - for (int i = 0; i < c; i++) { - muchrain[i].fire(); - muchrain[i].display(); - if (muchrain[i].loc.y <=0) { - muchrain[i].reset(); - if (muchrain[i].loc.x >= mouseX-250 && muchrain[i].loc.x <= mouseX+250 && muchrain[i].loc.y >=550 && muchrain[i].loc.y >=600) { - muchrain[i].deflected(); - } - if (muchrain[i].loc.y > height + muchrain[i].diam/2) { - muchrain[i].reset(); + println(m.size()); + println(city.size()); + background(0); + s.show(); + m.add(new Missile(random(width), 0)); + for (int j = city.size()-1; j>= 0; j--) { + Building b = city.get(j); + b.build(); + for (int i = m.size()-1; i >= 0; i--) { + Missile miss = m.get(i); + miss.display(); + miss.fire(); + if (miss.loc.x >= s.loc.x-250 && miss.loc.x <= s.loc.x+250 && miss.loc.y >= 550 && miss.loc.y <= 600) { + miss.deflected(); } - for (int j = 0; j < pop; j++) { - if (muchrain[i].loc.y >= height-city[j].h && muchrain[i].loc.x >= city[j].x && muchrain[i].loc.x <= (city[j].x+city[j].w)) { - city[j].destroyed(); - b += 1; - } + if (miss.loc.y < 0 || miss.loc.y >=height) { + m.remove(i); } - m.display(); //display the raindrop - m2.display(); - if (m.isInContactWith(mouse)) { //check to see if the raindrop is in contact with the point represented by the PVector called mouse - m.deflected(); //if it is, reset the raindrop - } - if (m2.isInContactWith(mouse)) { - m2.deflected(); - } - if (m.loc.y > height + m.diam/2) { //check to see if the raindrop goes below the bottom of the screen - m.boom(); //if it does, reset the raindrop - } - if (m2.loc.y > height + m2.diam/2) { - m2.boom(); - } - s.show(); - } - if (b >= pop) { - background(0); - fill(255, 0, 0); - textSize(100); - text("game over they ded", 0, height/2); } } } \ No newline at end of file From a711358697e7d180342c3fc47f74549ab3603e1b Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Tue, 12 Jan 2016 17:15:39 -0500 Subject: [PATCH 09/14] now the shield flashes red when you hit it. and also the missiles aren't endless --- raindropGameCode/building.pde | 2 +- raindropGameCode/raindropGameCode.pde | 7 +++++-- raindropGameCode/shield_class.pde | 10 +++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/raindropGameCode/building.pde b/raindropGameCode/building.pde index 745ed38..ffd4f1b 100644 --- a/raindropGameCode/building.pde +++ b/raindropGameCode/building.pde @@ -2,7 +2,7 @@ class Building { float h, w, x, transp; Building() { - h = random(20, 60); + h = random(40, 120); w = random(10, 20); x = random(width); transp = 255; diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 626013a..605432e 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -13,16 +13,19 @@ void draw() { println(city.size()); background(0); s.show(); - m.add(new Missile(random(width), 0)); for (int j = city.size()-1; j>= 0; j--) { Building b = city.get(j); b.build(); for (int i = m.size()-1; i >= 0; i--) { Missile miss = m.get(i); + if(m.size() <=20){ + m.add(new Missile(random(width), 0)); + } miss.display(); miss.fire(); - if (miss.loc.x >= s.loc.x-250 && miss.loc.x <= s.loc.x+250 && miss.loc.y >= 550 && miss.loc.y <= 600) { + if (miss.loc.x > s.loc.x-200 && miss.loc.x < s.loc.x+200 && miss.loc.y > 550 && miss.loc.y < 600) { miss.deflected(); + s.isHit(); } if (miss.loc.y < 0 || miss.loc.y >=height) { m.remove(i); diff --git a/raindropGameCode/shield_class.pde b/raindropGameCode/shield_class.pde index 47c6938..f10b724 100644 --- a/raindropGameCode/shield_class.pde +++ b/raindropGameCode/shield_class.pde @@ -12,6 +12,14 @@ class Shield { loc.set(mouseX, 600); stroke(200, 200, 255); strokeWeight(5); - arc(loc.x, loc.y, 500, 100, PI, TWO_PI); + arc(loc.x, loc.y, 400, 100, PI, TWO_PI); + } + + void isHit(){ + fill(0); + loc.set(mouseX, 600); + stroke(255, 0, 0); + strokeWeight(5); + arc(loc.x, loc.y, 400, 100, PI, TWO_PI); } } \ No newline at end of file From 6ba4d42af3c81e3b845688771c08e68d2bd5b269 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Sat, 16 Jan 2016 16:17:46 -0500 Subject: [PATCH 10/14] i finally got the buildings to work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit but now i’m stuck on getting the missiles to actually recognize the buildings --- raindropGameCode/raindropGameCode.pde | 18 ++++++++++++------ raindropGameCode/shield_class.pde | 8 ++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 605432e..525dbc2 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,9 +1,9 @@ ArrayList m = new ArrayList(); ArrayList city = new ArrayList(); -Shield s = new Shield(mouseX, 600); +Shield s = new Shield(mouseX, 400); void setup() { - size(1600, 800); + size(1200, 600); m.add(new Missile(random(width), 0)); city.add(new Building()); } @@ -13,17 +13,21 @@ void draw() { println(city.size()); background(0); s.show(); + if(city.size() <= 20){ + city.add(new Building()); + } for (int j = city.size()-1; j>= 0; j--) { Building b = city.get(j); b.build(); - for (int i = m.size()-1; i >= 0; i--) { + } + for (int i = m.size()-1; i >= 0; i--) { Missile miss = m.get(i); - if(m.size() <=20){ + if(m.size() <=10){ m.add(new Missile(random(width), 0)); } miss.display(); miss.fire(); - if (miss.loc.x > s.loc.x-200 && miss.loc.x < s.loc.x+200 && miss.loc.y > 550 && miss.loc.y < 600) { + if (miss.loc.x > s.loc.x-100 && miss.loc.x < s.loc.x+100 && miss.loc.y > 350 && miss.loc.y < 400) { miss.deflected(); s.isHit(); } @@ -31,5 +35,7 @@ void draw() { m.remove(i); } } - } + if(m.loc.y >= city.loc.y && m.loc.x >= city.loc.x && m.loc.x <= city.loc.x+city.w){ + city.destroyed(); + } } \ No newline at end of file diff --git a/raindropGameCode/shield_class.pde b/raindropGameCode/shield_class.pde index f10b724..a1da3f0 100644 --- a/raindropGameCode/shield_class.pde +++ b/raindropGameCode/shield_class.pde @@ -9,17 +9,17 @@ class Shield { void show() { fill(0); - loc.set(mouseX, 600); + loc.set(mouseX, 400); stroke(200, 200, 255); strokeWeight(5); - arc(loc.x, loc.y, 400, 100, PI, TWO_PI); + arc(loc.x, loc.y, 200, 100, PI, TWO_PI); } void isHit(){ fill(0); - loc.set(mouseX, 600); + loc.set(mouseX, 400); stroke(255, 0, 0); strokeWeight(5); - arc(loc.x, loc.y, 400, 100, PI, TWO_PI); + arc(loc.x, loc.y, 200, 100, PI, TWO_PI); } } \ No newline at end of file From e1dd94b023fa00e80c742bd6b018b93dec6e059d Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Wed, 20 Jan 2016 19:51:54 -0500 Subject: [PATCH 11/14] now i broke it it crashes whenever it runs. not sure what i did --- raindropGameCode/raindropGameCode.pde | 44 +++++++++++++-------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 525dbc2..4a14501 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -5,7 +5,9 @@ Shield s = new Shield(mouseX, 400); void setup() { size(1200, 600); m.add(new Missile(random(width), 0)); - city.add(new Building()); + if (city.size() <= 20) { + city.add(new Building()); + } } void draw() { @@ -13,29 +15,25 @@ void draw() { println(city.size()); background(0); s.show(); - if(city.size() <= 20){ - city.add(new Building()); - } - for (int j = city.size()-1; j>= 0; j--) { - Building b = city.get(j); - b.build(); - } for (int i = m.size()-1; i >= 0; i--) { - Missile miss = m.get(i); - if(m.size() <=10){ - m.add(new Missile(random(width), 0)); - } - miss.display(); - miss.fire(); - if (miss.loc.x > s.loc.x-100 && miss.loc.x < s.loc.x+100 && miss.loc.y > 350 && miss.loc.y < 400) { - miss.deflected(); - s.isHit(); - } - if (miss.loc.y < 0 || miss.loc.y >=height) { - m.remove(i); - } + Missile miss = m.get(i); + if (m.size() <=10) { + m.add(new Missile(random(width), 0)); + } + miss.display(); + miss.fire(); + if (miss.loc.x > s.loc.x-100 && miss.loc.x < s.loc.x+100 && miss.loc.y > 350 && miss.loc.y < 400) { + miss.deflected(); + s.isHit(); } - if(m.loc.y >= city.loc.y && m.loc.x >= city.loc.x && m.loc.x <= city.loc.x+city.w){ - city.destroyed(); + if (miss.loc.y < 0 || miss.loc.y >=height) { + m.remove(i); } + for (int j = city.size(); j >= 0; j--) { + Building target = city.get(j); + if (miss.loc.y >= height-target.h && miss.loc.x >= target.x && miss.loc.x <= target.x+target.w) { + target.destroyed(); + } + } + } } \ No newline at end of file From 01f9df45d1a11f3590578c0729795b9d522a632b Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Thu, 21 Jan 2016 09:28:46 -0500 Subject: [PATCH 12/14] it's working!!!1!! the 1 was intentional. now i just need to put in score and comment it and game over and a start screen and all that fancy stuff --- raindropGameCode/raindropGameCode.pde | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 4a14501..a42279a 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -5,16 +5,19 @@ Shield s = new Shield(mouseX, 400); void setup() { size(1200, 600); m.add(new Missile(random(width), 0)); - if (city.size() <= 20) { + while (city.size() <= 20) { city.add(new Building()); } } void draw() { - println(m.size()); println(city.size()); background(0); s.show(); + for (int i = 0; i = 0; i--) { Missile miss = m.get(i); if (m.size() <=10) { @@ -29,7 +32,7 @@ void draw() { if (miss.loc.y < 0 || miss.loc.y >=height) { m.remove(i); } - for (int j = city.size(); j >= 0; j--) { + for (int j = city.size()-1; j >= 0; j--) { Building target = city.get(j); if (miss.loc.y >= height-target.h && miss.loc.x >= target.x && miss.loc.x <= target.x+target.w) { target.destroyed(); From fe714ccaf987992936144ddfdf1edfa193a75873 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Fri, 22 Jan 2016 11:35:48 -0500 Subject: [PATCH 13/14] score? --- raindropGameCode/raindropGameCode.pde | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index a42279a..129d18c 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,18 +1,31 @@ ArrayList m = new ArrayList(); ArrayList city = new ArrayList(); Shield s = new Shield(mouseX, 400); +float runtime; +float reset; +float score; void setup() { size(1200, 600); m.add(new Missile(random(width), 0)); + score = 0; + runtime = 0; while (city.size() <= 20) { city.add(new Building()); } } void draw() { - println(city.size()); + //if (ded < 21) { background(0); + runtime += frameRate; + score = runtime; + fill(255); + textSize(20); + text("Surviving Buildings:",0,25); + text(city.size(), 0, 50); + text("Score:",width-100,25); + text(score,width-100,50); s.show(); for (int i = 0; i = 0; j--) { Building target = city.get(j); if (miss.loc.y >= height-target.h && miss.loc.x >= target.x && miss.loc.x <= target.x+target.w) { - target.destroyed(); + city.remove(j); + score -= 500000/millis(); + //ded += 1; + } + } + } + //} + if (city.size() == 0) { + background(0); + fill(255, 0, 0); + textSize(50); + text("game over they ded", width/2, height/2); + textSize(10); + text("press 'r' key to restart", width/2, height-100); + text("Final score:",0,25); + text(score,0,50); + score +=0; + score=0; + if (keyPressed && key == 'r') { + while (city.size() <= 20) { + city.add(new Building()); + reset = runtime; + runtime -= reset; } } } From 8186229c71bdc570aa34e5f5a18ef42f68f48845 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Sat, 23 Jan 2016 20:58:42 -0500 Subject: [PATCH 14/14] done!!!!! waaaaaay late but done --- raindropGameCode/building.pde | 21 +++--- raindropGameCode/missile_class.pde | 50 ++++---------- raindropGameCode/raindropGameCode.pde | 94 ++++++++++++++------------- raindropGameCode/shield_class.pde | 31 ++++----- 4 files changed, 84 insertions(+), 112 deletions(-) diff --git a/raindropGameCode/building.pde b/raindropGameCode/building.pde index ffd4f1b..8aa1a7d 100644 --- a/raindropGameCode/building.pde +++ b/raindropGameCode/building.pde @@ -1,21 +1,16 @@ class Building { - float h, w, x, transp; + float h, w, x; //height, width, x coordinate Building() { - h = random(40, 120); - w = random(10, 20); - x = random(width); - transp = 255; + h = random(40, 120); //height varies between 40 and 120 + w = random(10, 20); //width varies betweeen 10 and 20 + x = random(width); //building can have any x coordinate on the canvas } void build() { - noStroke(); - fill(100, 200, 100, transp); - rectMode(CORNERS); - rect(x, height, x+w, height-h); - } - - void destroyed() { - transp=0; + noStroke(); //no stroke + fill(100, 200, 100); //greenish fill + rectMode(CORNERS); //draw from bottom left corner + rect(x, height, x+w, height-h); //building with specified h/w/x on the bottom of canvas } } \ No newline at end of file diff --git a/raindropGameCode/missile_class.pde b/raindropGameCode/missile_class.pde index ac330c5..648a51b 100644 --- a/raindropGameCode/missile_class.pde +++ b/raindropGameCode/missile_class.pde @@ -1,53 +1,25 @@ class Missile { - PVector loc, vel; - float diam, locx, locy, r, g, b; + PVector loc, vel; //location and velocity + float diam, locx, locy; //diameter, x, y - Missile(float locx, float locy) { - loc = new PVector(locx, locy); - vel = new PVector((random(-3, 3)), random(6, 8)); - diam = 10; - r = 230; - g = 230; - b = 255; + Missile(float locx, float locy) { //x & y coordinates are parameters + loc = new PVector(locx, locy); //pvector at locx, locy + vel = new PVector((random(-3, 3)), random(6, 8)); //velocity is random and has a greater y magnitude than x magnitude + diam = 10; //diameter of 10 } void display() { - noStroke(); - fill(r, g, b); - ellipse(loc.x, loc.y, diam, diam); + noStroke(); //no stroke + fill(230, 230, 255); //light blue + ellipse(loc.x, loc.y, diam, diam); //missiles are little circles } void fire() { - loc.add(vel); + loc.add(vel); //move at vel } void deflected() { - vel.y = -vel.y; + vel.y = -vel.y; //missile bounces display(); } - void boom() { - fill(0); - ellipse(loc.x, loc.y, 50, 50); - vel.x = 0; - vel.y = 0; - loc.y = height; - diam = 50; - r = 0; - g = 0; - b = 0; - } - void reset() { - loc.x= random(width); - loc.y = 0; - vel.x = random(-3, 3); - vel.y = random(6, 8); - } - - boolean isInContactWith(PVector var) { - if (loc.dist(var) < diam/2) { - return true; - } else { - return false; - } - } } \ No newline at end of file diff --git a/raindropGameCode/raindropGameCode.pde b/raindropGameCode/raindropGameCode.pde index 129d18c..d3677fb 100644 --- a/raindropGameCode/raindropGameCode.pde +++ b/raindropGameCode/raindropGameCode.pde @@ -1,76 +1,80 @@ -ArrayList m = new ArrayList(); -ArrayList city = new ArrayList(); -Shield s = new Shield(mouseX, 400); -float runtime; -float reset; +ArrayList m = new ArrayList(); //creates array list of missiles +ArrayList city = new ArrayList(); //creates array list of buildings +Shield s = new Shield(mouseX, 400); //creates shield +float runtime; //these two variables deal with the score float score; void setup() { - size(1200, 600); + size(1200, 600); //canvas 1200 by 600 m.add(new Missile(random(width), 0)); - score = 0; + score = 0; //these two lines ensure score starts at zero runtime = 0; - while (city.size() <= 20) { + while (city.size() <= 20) { //start game with 20 buildings city.add(new Building()); } } void draw() { - //if (ded < 21) { - background(0); - runtime += frameRate; - score = runtime; - fill(255); - textSize(20); - text("Surviving Buildings:",0,25); + background(0); //black background + runtime += frameRate/1000; //score is based on frame rate and will increase consistent with time + score += runtime; + fill(255); //white fill + textSize(20); //size 20 text + text("Surviving Buildings:", 0, 25); //displays how many buildings remain text(city.size(), 0, 50); - text("Score:",width-100,25); - text(score,width-100,50); - s.show(); + text("Score:", width-100, 25); //displays score + text(score, width-100, 50); + s.show(); //draws shield for (int i = 0; i = 0; i--) { Missile miss = m.get(i); if (m.size() <=10) { - m.add(new Missile(random(width), 0)); + m.add(new Missile(random(width), 0)); //ensures there are always 10 missiles on screen } - miss.display(); - miss.fire(); - if (miss.loc.x > s.loc.x-100 && miss.loc.x < s.loc.x+100 && miss.loc.y > 350 && miss.loc.y < 400) { - miss.deflected(); - s.isHit(); + miss.display(); //draw missile + miss.fire(); //fire (move) missile + if (miss.loc.x > s.loc.x-s.notdiam/2 && miss.loc.x < s.loc.x+s.notdiam/2 && miss.loc.y > s.loc.y-s.notdiam1/2 && miss.loc.y < 400) { + miss.deflected(); //missile bounces off shield if it hits it + s.isHit(); //shield flashes red when hit } if (miss.loc.y < 0 || miss.loc.y >=height) { - m.remove(i); + m.remove(i); //if the missile gets to the bottom, it's removed } for (int j = city.size()-1; j >= 0; j--) { Building target = city.get(j); if (miss.loc.y >= height-target.h && miss.loc.x >= target.x && miss.loc.x <= target.x+target.w) { - city.remove(j); - score -= 500000/millis(); - //ded += 1; + city.remove(j); //building is destroyed if it gets hit by a missile + score -= 500000/millis(); //penalty for losing a building } } } - //} - if (city.size() == 0) { - background(0); - fill(255, 0, 0); - textSize(50); - text("game over they ded", width/2, height/2); - textSize(10); - text("press 'r' key to restart", width/2, height-100); - text("Final score:",0,25); - text(score,0,50); - score +=0; - score=0; - if (keyPressed && key == 'r') { - while (city.size() <= 20) { + if (city.size() <= 5 && city.size() > 1) { //shield shrinks once only 5 buildings remain + s.notdiam = 75; + s.notdiam1 = 50; + } + if (city.size() == 1) { //with one building left, it gets way harder + s.notdiam = 50; + s.notdiam1 = 25; + } + if (city.size() == 0) { //if all the buildings have been hit + runtime*=0; //score should stop increasing (not sure why it still does???) + background(0); //black background + fill(255, 0, 0); //red fill + textSize(50); //size 50 text + text("game over they ded", width/2, height/2); //helpfully inform the player that the entire city has died a horrible death + textSize(10); //size 10 text + text("press 'r' key to restart", width/2, height-100); //tell player to restart + textSize(20); //size 20 text + text("Final score:", 0, 25); //show the player their score + text(score, 0, 50); + if (keyPressed && key == 'r') { //if the player wants to embark on this quixotic mission again + score = 0; //score resets to 0 + runtime = 0; + while (city.size() <= 20) { //city is built again city.add(new Building()); - reset = runtime; - runtime -= reset; } } } diff --git a/raindropGameCode/shield_class.pde b/raindropGameCode/shield_class.pde index a1da3f0..83e304f 100644 --- a/raindropGameCode/shield_class.pde +++ b/raindropGameCode/shield_class.pde @@ -1,25 +1,26 @@ class Shield { - PVector loc; - float notdiam, locx, locy; + PVector loc; //location vector + float notdiam, notdiam1, locx, locy; //diameters and coordinates - Shield(float locx, float locy) { - loc = new PVector(locx, locy); - notdiam = 50; + Shield(float locx, float locy) { //x & y coordinates are parameters + loc = new PVector(locx, locy); //location is at locx, locy + notdiam = 200; //horizontal diameter is 200 + notdiam1 = 100; //vertical diameter is 100 } void show() { - fill(0); - loc.set(mouseX, 400); - stroke(200, 200, 255); - strokeWeight(5); - arc(loc.x, loc.y, 200, 100, PI, TWO_PI); + fill(0); //shield is just an arc + loc.set(mouseX, 400); //location is always at mouse x and y of 400 + stroke(200, 200, 255); //light blue + strokeWeight(5); //stroke weight of 5 + arc(loc.x, loc.y, notdiam, notdiam1, PI, TWO_PI); //180 degree arc } void isHit(){ - fill(0); - loc.set(mouseX, 400); - stroke(255, 0, 0); - strokeWeight(5); - arc(loc.x, loc.y, 200, 100, PI, TWO_PI); + fill(0); //shield is still just an arc + loc.set(mouseX, 400); //location does not change + stroke(255, 0, 0); //shield flashes bright red + strokeWeight(5); //stroke weight does not change + arc(loc.x, loc.y, notdiam, notdiam1, PI, TWO_PI); //shape does not change } } \ No newline at end of file