/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://cisc1600.sketchpad.cc/sp/pad/view/ro.quN3qiNPO2O/rev.2
*
* authors:
* Michael Mandel
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
//-----------------------------------------------------------------------
int bomblocation() { //need this to be a function so it can be called for randomness rather than setting bombX to it
return int(random(500)); //would just create a set spawn point otherwise if recycled
}
int[] bombX = { //made into an array to create more bombs
bomblocation(),bomblocation(),bomblocation(),bomblocation(),bomblocation()
};
int[] bombY = { //same must be done with Y axis to create individualization
0,5,10,20,30
};
int bombsize = 15; //radius of bomb
int gameState = 0;
int cloudlocation() {
return int(random(500));
}
int[] cloudX = { cloudlocation(),cloudlocation(),cloudlocation() };
int[] cloudY = { 0,290,360 };
int cSpd = 2; //cloud speed
//-----------------------------------------------------------------------
void setup() {
size(500,620);
}
void draw() {
if (gameState == 0) {
titlescreen();
}
if (gameState == 1) {
background(#3399ff);
fill(#cccccc);
stroke(#cccccc);
triangle(mouseX-8, 590, mouseX+8, 590, mouseX, 575); //spaceship start
ellipse(mouseX,590,14,10);
line(mouseX-14,590,mouseX+14,590);
triangle(mouseX-17,591,mouseX-11,591,mouseX-14,585);
triangle(mouseX+17,591,mouseX+11,591,mouseX+14,585); //spaceship end
bombfall();
laser();
}
if (gameState == 2) {
gameOver();
}
}
void titlescreen() {
textSize(18);
background(#cccccc);
fill(#000000);
textAlign(CENTER);
text("Welcome to BOMB CRISIS!",250,150);
text("Control the ship with your mouse and click to fire your laser.",250,200);
text("Try not to let the bombs get past you!",250,250);
fill(0,255,0);
rect(200,400, 100,50);
fill(255,0,0);
text("Start Game",250,430);
if(mousePressed && (mouseX >= 200 && mouseX <= 300 && mouseY >= 400 && mouseY <= 450)) {
gameState = 1; //if mouse is clicked inside above box, then start game
}
}
void gameOver() {
background(#000000);
textAlign(CENTER);
fill(#ffffff);
text("Game Over",250,250);
fill(#333399);
rect(200,400, 100,50);
fill(#ffffff);
text("Retry",250,430);
if(mousePressed && (mouseX >= 200 && mouseX <= 300 && mouseY >= 400 && mouseY <= 450)) {
gameState = 1; //if mouse is clicked inside above box, then start game
}
}
void bombfall() { //bomb falling simulation
fill(255,0,0);
for(int i=0;i<5;i++) {
ellipse(bombX[i],bombY[i]++,bombsize,bombsize);
if(bombY[i] > 615) { //if a bomb reaches bottom, evoke game over screen
gameState = 2;
for(int r=0;r<5;r++) {
bombY[r] = r*10;
}
}
}
for(int i=0;i<3;i++) { //CLOUDS
fill(#cccccc);
ellipse(cloudX[i],cloudY[i],bombsize*2,bombsize*2);
ellipse(cloudX[i]-20,cloudY[i],bombsize*2,bombsize*2);
ellipse(cloudX[i]-13,cloudY[i]+20,bombsize*2,bombsize*2);
ellipse(cloudX[i]+10,cloudY[i]+25,bombsize*2,bombsize*2);
ellipse(cloudX[i]+20,cloudY[i]+10,bombsize*2,bombsize*2);
stroke(#000000);
line(cloudX[i]-3,cloudY[i],cloudX[i]-3,cloudY[i]+6); //smiley face for the cloud =)
line(cloudX[i]+5,cloudY[i],cloudX[i]+5,cloudY[i]+6);
curve(cloudX[i]-30,cloudY[i]-50, cloudX[i]-6,cloudY[i]+12,cloudX[i]+7,cloudY[i]+12, cloudX[i],cloudY[i]); //trial and error
stroke(#cccccc);
cloudY[i] = cloudY[i] + 2;
if (cloudY[i] > 650) {
cloudY[i] = 0;
}
}
}
void laser() { //drawing the laser shot
stroke(#660099);
if(mousePressed) {
line(mouseX,574,mouseX,0);
for(int i=0;i<5;i++) {
if((mouseX <= (bombX[i] + bombsize/2)) && (mouseX >= (bombX[i] - bombsize/2))) { //hit registry checker
bombX[i] = bomblocation();
bombY[i] = 0;
}
else {
line(mouseX,574,mouseX,0);
}
}
}
}