/* This game was created by Benjamin Nelson in 2006 and 2007 You are free to post it on your website and or play it and or make modifications, just always credit me for my work and let me know if you do anything cool with it. My email is bmnelson@gmail.com Let me know what you think. Benjie */ int startingLevel=0; //////////////////////starting Level! // define constants for all monsters in the game int HERO_RADIUS=30; int WINGMAN_DISTANCE=70; int BUNGER = 0; int BIPPY = 1; int SNAKE = 2; int LAZOR =3; int SUCKER=4; int OCTOPUS=5; int BUBBLE=6; int BUBBLESLUG=7; int SPACEBALL=8; int GEKKO=9; int CHICKEN=10; int CEGG=11; int STARFISH=12; int LASERBALL=13; int CRAWCANNON=14; int SHIELD=15; int BIPPO=16; int TELLY=17; int POPPER=18; int SPACEBLOB=19; int SPACEBLOBDOT=20; int FINAL=21; int maxMonsterTypes=35; //global variable of the player Hero h; ArrayList monsters=new ArrayList(); ArrayList levels; ArrayList DebrisArray=new ArrayList(); int DEBRIS_COUNT = 15; int currentLevelNumber=startingLevel; Level currentLevel; PFont font; boolean invincible=false;//Cheating is bad! void setup(){ size(1000,600);//size of game font = loadFont("SWGothi-37.vlw"); textMode(MODEL); framerate(30); smooth();//I find that I have to call this many times, especially after text. Processing bug? h = new Hero((float)width/2,(float)height/2); ellipseMode(CENTER); colorMode(HSB); levels=makeLevels();//Make all the monsters currentLevel=(Level)levels.get(startingLevel);//and load first level } void draw(){ if(frameCount%15==0){ // println(framerate); } background(0); h.update(); if(currentLevel.update()&&monsters.size()==0){//calling update on currentl level return a true if the level is empty // and also adds random monsters to the arraylist monsters if there are monsters left in the level que currentLevelNumber++;//Level complete! On to the next! currentLevel=(Level)levels.get(currentLevelNumber); } updateMonsters(); //////PLAYER IS DEAD://///////////// if(h.dead){ textFont(font, 48); fill(255); text("Click to try Again", width/2-250, height/2); smooth(); for(int i =0; i.5){ if(random(1)>.5){ v.setXY(-10,random(0,height)); } else{ v.setXY(width+10,random(0,height)); } } else{ if(random(1)>.5){ v.setXY(random(0,width),-10); } else{ v.setXY(random(0,width),height+10); } } return v; } //This runs each monster though one timestep void updateMonsters(){ for(int i=0; ilifespan){ DebrisArray.remove(this); } if(frameCount%1==0){ Vector3D p = pos.copy(); p.x+=random(-10,10); p.y+=random(-10,10); Smoke s= new Smoke(p); DebrisArray.add(s); } } } class Smoke extends Ship{ int counter =0; float growth=5.0; int maxSize=60; Smoke(Vector3D p){ pos=p.copy(); } void update(){ counter+=growth; if(counter>maxSize){ DebrisArray.remove(this); } noStroke(); if(random(0,1)<.7){ fill(255,0,255,255-255*counter/maxSize); } else{ fill(random(5,25),255,255,255-255*counter/maxSize); } ellipse(pos.x,pos.y,counter,counter); } } //Class definition and behavior for all monsters and the player in SpaceGame: class Popper extends Goon{////////////////////////////// Popper ////////////// int popperForce = 25000000; Vector3D destination; float moveK=.95; int counter=0; int repelCounter=0; int popTime=(int)random(50,200); int popRadius=350; float attackAngle=random(0,TWO_PI); Popper(Vector3D p){ pos= p.copy(); acc=new Vector3D(); vel=new Vector3D(); rad=17; type = POPPER; destination=new Vector3D(random(30,width-30),random(30,height-30)); } void unique(){ counter++; if(abs(pos.x-destination.x)<1&&abs(pos.y-destination.y)<1){ if(counter>popTime){ repelCounter++; //if(pos.distanceSquared2D(pos,h.pos)17){ repelCounter=0; counter=0; destination.setXY(random(30,width-30),random(30,height-30)); attackAngle=random(0,TWO_PI); } } } } void drawCircles(int radius){ int num=radius*radius/600; float deg=TWO_PI/num; float circleDiam=TWO_PI*radius/num; pushMatrix(); translate(pos.x,pos.y); rotate(attackAngle); fill(10,255,10000/radius); ellipse(radius,0,circleDiam*3,circleDiam/2); ellipse(-radius,0,circleDiam*3,circleDiam/2); ellipse(0,radius,circleDiam/2,circleDiam*3); ellipse(0,-radius,circleDiam/2,circleDiam*3); for(int i=0; iwarmTime){ pos.x+=jumpDist*cos(angle); pos.y+=jumpDist*sin(angle); attackAngle=random(0,TWO_PI); if(pos.x<80||pos.x>width-80||pos.y<80||pos.y>height-80){ Vector3D v=h.position(); v.sub(pos); attackAngle=v.heading2D(); } warmup=0; } } void movement(){ angle=angle*.8+attackAngle*.2; } void render(){ pushMatrix(); noStroke(); translate(pos.x,pos.y); rotate(angle); fill(90,200,155); beginShape(); vertex(rad/2,0); //curveVertex(0,0); vertex(-rad/2,-rad/2); vertex(0,0); vertex(-rad/2,rad/2); //curveVertex(0,0); // vertex(0,rad/2); endShape(); fill(25,255,200); ellipse(-rad/2,0,rad/2,rad/2); fill(15,255,200); ellipse(-.85*rad,0,rad/4,rad/4); popMatrix(); } } class Bippo extends Goon{////////////////////////////// BIPPO /////////////// int ACC=5; Bippo(Vector3D p){ inBoss=false; pos= p.copy(); acc=new Vector3D(); vel=new Vector3D(); rad=20; type = BIPPO; } // void checkWalls(){ // if(pos.x<0||pos.x>width||pos.y<0||pos.y>height){ //vel.setXYZ(0,0,0); // } // } void unique(){ Vector3D heroP=h.position(); heroP.sub(pos); heroP.normalize(); heroP.mult(.4); Vector3D damp=vel.copy(); damp.mult(.01); heroP.sub(damp); acc=heroP; } void render(){ pushMatrix(); noStroke(); translate(pos.x,pos.y); rotate(angle); fill(40,255,255); if(inBoss){ fill(40,255,90); } ellipse(0,0,rad,rad); fill(15,255,200); if(inBoss){ fill(15,255,80); } ellipse(-6,0,13,13); fill(0,255,255); if(inBoss){ fill(0,255,80); } ellipse(-20,0,6,6); popMatrix(); } } class Starfish extends Goon{ ///////////////////////////////// STARFISH ////////////////////////////////////////////////////////////// float speed=3; int arms=2; int growTime=95; int armLength=40; int maxArms=5; int counter=0; float spin=.05; Starfish(Vector3D p){ pos= p.copy(); acc=new Vector3D(); vel=new Vector3D(speed,random(0,TWO_PI),true); rad=30; type = STARFISH; if(random(0,1)<.5){ spin*=1; } } Starfish(Vector3D p, float a){ pos= p.copy(); acc=new Vector3D(); vel=new Vector3D(speed,a,true); angle=a; rad=30; type = STARFISH; } void movement(){ vel.add(acc); pos.add(vel); angle+=spin; } void unique(){ counter++; if(counter==growTime){ counter=0; arms++; } if(arms>maxArms){ for(int i=0; imaxAge){ alive=false; monsters.remove(this); } rad=15.0-age*15.0/maxAge+5; } void render(){ pushMatrix(); translate(pos.x,pos.y); fill(130+age*125/maxAge,255,255-age); if(!alive){ fill(255); } ellipse(0,0,rad,rad); popMatrix(); } } /******************************************************LAZOR**********************************************************/ class Lazor extends Goon{ Lazor partner; boolean ready; String uniqueName; int state; int ACC = 0; int DECC = 1; int SPINNING = 2; int SHOOTING = 3; int topSpeed=10; int ShootingTimer=0; int ShootingMaxTime=4; float changeProbabilityToSpin=.02; float changeProbabilityToMove=.1; float thrust=.3; float angleChange = .06; boolean partnered; int numberToCheck=10; Lazor(Vector3D p){ uniqueName="bob"+random(1); //eveyone is named bob! How unique! state = 2; type = LAZOR; pos= p.copy(); vel=new Vector3D(); acc=new Vector3D(thrust,radians(45),true); angle=45; partnered=false; rad=25; ready=false; } void checkCollision(){ if(h.hitWingMan(pos,rad)){ monsters.remove(this); alive = false; if(partnered){ partner.goodbye(); } } } void unique(){ if(!partnered){ switch(state){ case 0: if(random(1)topSpeed){ acc.setRTheta(thrust,angle+PI); state++; } break; case 1://currently accellerating float speed = vel.magnitude(); // pos.setXY(70,70); if(speed>topSpeed){//if going too fast, slow down! This is hacky. I should get more elegant... acc.setRTheta(thrust,angle+PI); } if(speed<.1){//if slowed down enough, start spinning or shooting acc.setXY(0,0); vel.setRTheta(.2,angle); state++; if(pos.x>0+30&&pos.y>0+30&&pos.xShootingMaxTime){ ready=false; partnered=false; partner.goodbye(); ShootingTimer=0; } ShootingTimer++; } //wait for partner to get ready } else{//turn the correct direction vel.setRTheta(.01,angle-angleChange); } } else{//if going too fast acc.setRTheta(thrust,angle+PI); } } } boolean ready(){ return ready; } void goodbye(){ ready=false; partnered=false; } boolean hello(Lazor l, String name){ boolean b= (name!=uniqueName&&pos.x>0+30&&pos.y>0+30&&pos.x12){ checkAlongLine(p1,pm,distance/2);///recursion w00t! checkAlongLine(pm,p2,distance/2); } } void checkWalls(){ if(pos.x<0){ vel.x=abs(vel.x); if(state==1){ acc.setRTheta(thrust,vel.heading2D()+PI); } else{ acc.setRTheta(thrust,vel.heading2D()); } } if(pos.x>width){ vel.x=-abs(vel.x); if(state==1){ acc.setRTheta(thrust,vel.heading2D()); } else{ acc.setRTheta(thrust,vel.heading2D()+PI); } } if(pos.y<0){ vel.y=abs(vel.y); if(state==1){ acc.setRTheta(thrust,vel.heading2D()+PI); } else{ acc.setRTheta(thrust,vel.heading2D()); } } if(pos.y>height){ vel.y=-abs(vel.y); if(state==1){ acc.setRTheta(thrust,vel.heading2D()); } else{ acc.setRTheta(thrust,vel.heading2D()+PI); } } } void render(){ pushMatrix(); noStroke(); fill(150); translate(pos.x,pos.y); rotate(angle); ellipse(0,0,rad,rad); fill(0,255,150); if(partnered){ fill(80,255,255); stroke(80,255,255); line(20,0,75,0); } noStroke(); ellipse(-6,0,8,8); ellipse(2,0,6,6); ellipse(10,0,4,4); fill(0,255,255); ellipse(17,0,2,2); fill(0); pushMatrix(); rotate(-.3); rect(-5,6,12,2); rotate(.6); rect(-5,-8,12,2); popMatrix(); popMatrix(); } } class Snake extends Goon{ /////////////////////////////////////////////// SNAKE ///////////////////////////////////// int startingSize =5; float speed = 5; float changeProbability=.04; float angleChange=.05; int turnDirection =1; float spacing = .85; ArrayList followers; Vector3D fPos; float eyeAngle=0; boolean started=false; Snake(Vector3D p){ type = SNAKE; pos= p.copy(); vel=new Vector3D(speed,random(0,TWO_PI),true); acc=new Vector3D(); rad=40; followers = new ArrayList(); } void unique(){ if(!started){ for(int i= 0;i=0; i--){ Goon g = (Goon) monsters.get(i); fPos=g.getPosition(); float biteSize=2; if (g.type()==BUNGER&&fPos.x>pos.x-rad*biteSize&&fPos.xpos.y-rad*biteSize&&fPos.y0){ followLeader(0,pos); } } void followLeader(int i, Vector3D target){ Goon g = (Goon)followers.get(i); fPos=g.getPosition(); fPos.setXY((fPos.x*spacing+target.x*(1-spacing)),(fPos.y*spacing+target.y*(1-spacing))); if(!g.alive()){ followers.remove(g); } i++; // g.update(); if(i