/* * Patrick Gillen Project 3 */ float heroX, heroY; float heroDX, heroDY; float bombX, bombY; float bombDY; float score; void setup() //setup window size and run initialize sub-routine { size ( 640, 480 ); initialize(); smooth(); } void initialize() // set intial variable values { heroX = width / 2; heroY = height / 2; heroDX = 2; heroDY = 3; bombDY = 14; bombY = -10; score = 0; } void draw() { doScene(); doBichula(); doBomb(); checkContact(); } void keyPressed() // drops bombs from the sky if the b key is hit, upper or lower case { if (key == 'b' || key == 'B') { bombY = 1; bombX= random ( width ); } } void mousePressed() // moves bichula to locate of the mouse { heroX = mouseX; heroY = mouseY; } void doScene() // draws sky, sun and grass { // makes sky blue background(50, 50, 255); // draws yellow sun stroke(0); strokeWeight(2); fill(255,255,0); ellipse(width/1.5, height/4, 75,75); // draws grass rectMode(CORNERS); fill(50,255,50); rect(0,height/1.5,width,height); } void doBichula() // draws bichula, the hero of the game { //draw bichulas ears //left ear fill(0); triangle(heroX-45, heroY-45, heroX-35,heroY,heroX+35,heroY); //right ear triangle(heroX+45, heroY-45, heroX+35,heroY,heroX-35,heroY); // draws bichulas head, over the ears fill(255,250,250); ellipse(heroX,heroY, 80,80); // draw bichulas eyes //left eye ellipse(heroX-15,heroY-15,23,23); ellipse(heroX-15,heroY-15,1,1); //right eye ellipse(heroX+15,heroY-15,23,23); ellipse(heroX+15,heroY-15,1,1); //draws score on bichula fill(0); text(score, heroX,heroY + 10); //moves hero along the x axis heroX += heroDX; // bounces hero of ither wall if (heroX > width - 40 || heroX < 40) { heroDX = -heroDX; } //moves hero along the y axis heroY += heroDY; // bounces hero of ither wall if (heroY > height - 40 || heroY < 40) { heroDY = -heroDY; } } void doBomb() { // exits function if bomb hasn't been released yet or is of screen if (bombY < 0 || bombY > height) { return; } // bomb acceleration bombY += bombDY; // draw bomb ellipse( bombX, bombY, 25, 90 ); } void checkContact() { // checks if bomb makes contact with bichula and adds points to score if (abs(bombX-heroX) < 45 && abs(bombY-heroY) < 45) { score += 100; heroX = 50; heroY = 50; } }