Danna - Project 2

By Danna Bialik
/////////ZEUS WILL DESTROY!!!!! int score= 0; Characters c1; Characters c2; Characters c3;//declare object Characters c4; Characters c5; Lightning l; PFont font; PImage greekbackground; PImage gameover; PImage lightningbolt; PImage zeus; PImage explosion; PImage chimera; PImage goddess; PImage greekDirections; PImage greekopenpage; PImage nemeonlion; PImage aphrodite; PImage typhon; int numFrames= 5; int frame=0; PImage[] lightningbolts = new PImage [numFrames];//lightning array boolean moveLightning = false; boolean safe = true; //declare page int page=1; void setup () { size (600, 400); smooth(); font= loadFont("LithosPro-Black-28.vlw"); textFont (font, 28); greekopenpage= loadImage ("greekopenpage.png"); greekDirections= loadImage ("greekDirections.png"); gameover= loadImage ("gameover.png"); greekbackground= loadImage ("greekbackground.png"); zeus= loadImage ("zeus.png"); explosion= loadImage("explosion.png"); typhon= loadImage("typhon.png"); chimera= loadImage("Chimera.png"); nemeonlion= loadImage("nemeonlion.png"); goddess= loadImage("goddess.png"); aphrodite= loadImage("Aphrodite.png"); lightningbolts[0]= loadImage("lightningbolt.png"); lightningbolts[1]= loadImage("lightningbolt2.png"); lightningbolts[2]= loadImage("lightningbolt3.png"); lightningbolts[3]= loadImage("lightningbolt4.png"); lightningbolts[4]= loadImage("lightningbolt5.png"); c1= new Characters (600, 250, 3.6, typhon); c2= new Characters (940, 250, 3.6, chimera); l= new Lightning (410, 35, 3, 5); } void draw () { //Open page if (page==1){ image(greekopenpage, 0, 0); } //Directions else if (page==2){ image (greekDirections, 0, 0); } //Game else if (page==3){ image (greekbackground, 0, 0); image (zeus, 220, -25); text("SCORE: " + score,49, 40); frame++; if (frame== numFrames){ frame=0; } c1.move(); c1.display(); c2.move(); c2.display(); l.display(); if (moveLightning == true){ l.move(); if((l.x+30) > c1.x && l.x<(c1.x+150)&& (l.y+100)>c1.y&& l.y<(c1.y+150)){ if (c1.charType<4){ image(explosion, c1.x, c1.y); if (c1.hit == false) { c1.hit=true; score++; } } else{ page=4; c1.reset(); c2.reset(); l.reset(); moveLightning=false; } } if((l.x+30) > c2.x && l.x<(c2.x+150)&& (l.y+100)>c2.y&& l.y<(c2.y+150)){ if (c2.charType<4){ image(explosion, c2.x, c2.y); if (c2.hit == false) { c2.hit=true; score++; } } else{ page=4; c1.reset(); c2.reset(); l.reset(); moveLightning=false; } } } if (page==4){ image (gameover,0,0); score=0; } } } void mousePressed(){ if (page==1){ if ((mouseX>449) && (mouseX<600) && (mouseY>345) && (mouseY<400)){ page=2; } } if (page==2){ if ((mouseX>482) && (mouseX<600) && (mouseY>197) && (mouseY<257)){ page=3; } } if (page==4){ if((mouseX>186) && (mouseX<424) && (mouseY>280) && (mouseY<346)){ page=1; } } } void keyPressed (){ if (key == ' '){ // SpaceBar moveLightning= true; } } //////characters class class Characters { float x; float y; float speed; int direction=-1; boolean hit= false; PImage img; float xinitial; float yinitial; int charType; // from 1 to 5. Characters(float xpos, float ypos, float sp, PImage pimg) { x= xpos; xinitial=xpos; yinitial=ypos; y= ypos; speed= sp; charType= int(random(1,6)); if (charType == 1){ img = typhon; } else if (charType ==2){ img= chimera; } else if (charType ==3){ img= nemeonlion; } else if (charType==4){ img= goddess; } else if (charType==5){ img= aphrodite; } } void move (){ x+= (speed*direction); if (x<-img.width){ hit=false; x=xinitial; charType= int(random(1,5.1)); if (charType == 1){ img = typhon; } else if (charType ==2){ img= chimera; } else if (charType ==3){ img= nemeonlion; } else if (charType==4){ img= goddess; } else if (charType==5){ img= aphrodite; } } } void reset(){ hit=false; x=xinitial; charType= int(random(1,5.1)); if (charType == 1){ img = typhon; } else if (charType ==2){ img= chimera; } else if (charType ==3){ img= nemeonlion; } else if (charType==4){ img= goddess; } else if (charType==5){ img= aphrodite; } } void display () { if (hit==false){ image (img, x, y); } } } ///// lightning class class Lightning { float x, y; float xinitial; float yinitial; float spdX; float spdY; int directionX=-1; int directionY=1; Lightning(float xpos, float ypos, float speedX, float speedY){ x= xpos; y= ypos; xinitial=xpos; yinitial=ypos; spdX = speedX; spdY= speedY; } void move () { y+= (spdY*directionY); x+= (spdX*directionX); if (l.y > height) { l.y=35; l.x=410; moveLightning=false; } } void reset (){ x= xinitial; y= yinitial; } void display (){ image (lightningbolts[frame], x, y); } }

One Comment

  1. Posted November 26, 2008 at 3:19 pm | Permalink

    Because the space bar is your button, it would be simpler to start the game by pressing space bar, instead of clicking the mouse in two different areas.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*