int horizon = 500; int score=0; float heroX=500,heroY=450, heroW=50,heroH=100; float sunX=100,sunY=50,sunW=80,sunH=80,sunDX=5; float bombX=sunX,bombY=sunY,bombW=40,bombH=40; float herovX= 3,herovY=2,bombvY=5; float bulletX=-20,bulletY=random(height),bulletW=40,bulletH=30,bulletDX=5; void setup() { size(800,600); smooth(); frameRate(30); } void draw() { scene(); hero(); bomb(); bullet(); theScore(); } void scene(){ background(50,50,200); // SKY fill(0); text(score,45,45); // SCORE fill(0,255,0); rect(0,horizon,800,600); //GRASS fill(200,200,0); ellipse(sunX,sunY,sunW,sunH); // SUN sunX += sunDX; // MOVE SUN X if (sunX > width-sunW/4 || sunX < 0 + sunW/4) { // 'SUN X' WIDTH CONSTRAINTS sunDX= -sunDX; } } void hero(){ if (key=='p'||key=='P') { text( "PAUSED",width/2,height/2); } else { heroX += herovX; heroY += herovY; // MOVE HERO (>) OR (<) WIDTH if (heroX > width-heroW/4 || heroX < 0+heroW/4) { // REVERSE SPEED || +POINTS herovX = -herovX; score += 1; } // MOVE HERO ||(>) OR (<) HEIGHT heroY += herovY; if (heroY > height-heroH/4 || heroY < 0+heroH/4) { // REVERSE SPEED || +POINTS herovY = -herovY; score += 2; } } // DRAW HERO fill(0); rect(heroX,heroY,heroW,heroH); // HERO BODY fill(255); ellipse(heroX,heroY,heroW/2,heroH/2); // HERO EYE ellipse(heroX+20,heroY,heroW/2,heroH/2); // HERO EYE } void keyPressed() { // PRESS "B" TO DROP BOMBS ON EM! if (key == 'b'||key == 'B') { // FALLS FROM Y|X sunX= random(width); bombY=sunY-2; bombX=sunX; } else if (key == 'v'||key == 'V') { // BULLET TIME ON X AXIS bulletX += bulletDX; bulletY=random(height); } else if (key == 'r'||key =='R') { // 'R' = RESET SCORE score=0; } } void bomb() { if (bombY < sunY || bombY>height) {// CHECK FOR BOMB bombY= sunY; // RESET BOMB } else { // BOMB SPEED bombY += bombvY; } // DRAW BOMB fill(80); ellipse(bombX,bombY, 60,60 ); line(bombX,bombY-30,bombX,bombY-40); } void bullet(){ if(bulletX < 0 || bulletX > height) { // CHECK FOR BULLET bulletX = -10; } else { // BULLET SPEED bulletX += bulletDX; } //float // for(int i=0; i<3; i++){ } ////// VOID THE SCORE() \\\\\\ void theScore() { // BOMB HITS HERO || --POINTS if ((dist(bombX, bombY, heroX, heroY) < 40)) { // DETECT COLLISION ^ || +SCORE background(0); score -= 50; heroX = random(width); heroY = random(height); } }