//Val Jeudy //Project 1 //September 26,2014 //global variables float heroX, heroY; float evilX = 50, evilY = 400; float sunX = 100, sunY = 100; float goldX, goldY; float horizon; int score=1000; // score is set. float skyColor = 50; float skyX = 10; float skyY = 200; void setup() { //setup size(800, 600); horizon = height/4; } void draw() { //if the player lose if (score<=0){ textSize(35); } else { // next frame scene(); hero(); evil(); gold(); score(); } } void scene() { //grass background (0, 153, 51); //blue sky fill(skyColor-50, skyColor+154, skyColor+205); rectMode(CORNER); rect(skyX-9, skyY-199, 1200, 200); //sun fill(255, 255, 0); ellipse(sunX-60,sunY-45,60,60); sunX= sunX + 1.2; if(sunX>=width){ sunX = 0; sunY = sunY; } //title stroke(0); textSize(20); text( "Hero vs. Evil", width-450, horizon*1/4 ); textSize(15); text( "Valondine Jeudy", 20, height-20 ); } void hero() { //Head fill(255); ellipse( heroX, heroY-47, 35, 35); //Body fill(255, 0, 0); rectMode(CENTER); rect( heroX, heroY, 20, 65); //Arms fill(1, 255, 0); rect(heroX, heroY-5, 70, 20); //Name textSize(14); fill(1, 1, 255); text("Hero", heroX-15, heroY-1); //moves with the mouse heroX= heroX + (mouseX-heroX)/50; heroY= heroY + (mouseY-heroY)/50; //if the hero toches the gold. they will get 50 pts. if (dist(heroX, heroY, goldX, goldY) <50) { score+=25; //gold will move to a random place. goldX = random(evilX,width-500); goldY = random(evilY,horizon); } } void evil() { //head fill(255); rectMode(CENTER); rect(evilX, evilY+50, 35, 35); //body fill(255, 1, 25); rectMode(CENTER); rect(evilX, evilY+92, 20, 50); //legs //line (evilX +90 ,evilY+60,95,45); //name fill(25, 25, 255); textSize(14); text("Evil", evilX-10, evilY+55); //movement evilX= evilX + (heroX - evilX)/55; evilY= evilY + (heroY - evilY)/55; //if monster it 50 feet if (dist(heroX, heroY, evilX, evilY) <=30) { eat(); } } void eat() { //if the hero touches evil. it will lose 100 pts. score-= 100; heroX= width/2; heroY= height/2; evilX=width/4; evilY=height/4; } void gold() { //treasure fill(255, 255, 51); ellipse(goldX, goldY, 10, 10); ellipse(goldX+10, goldY+10, 10, 10); ellipse(goldX+20, goldY +20, 10, 10); ellipse(goldX+30, goldY+30, 10, 10); ellipse(goldX+40, goldY+35, 10,10); } void reset (){ //original places. heroX = width/4; heroY = height/4; evilX = width/2; evilY = height/2; goldX = random(30 - X); goldY = random(30 + Y); } void score() { //score box textSize(15); text("Score:", width-100, 95); text( score, width-50, 95); } void mousePressed() { //// gold goes to mouse; hero goes left. heroX = 50; heroY = random(horizon, height-50);; score -= 50; goldX = 200-mouseX; goldY = 200-mouseY; reset(); }