PFont smallFont; int gamestate; int TITLE = 1; int PRELUDE = 2; int PLAYING = 3; int POSTLUDE = 4; int GAMEOVER = 5; int ending; //int int deadInvaderCount; import ddf.minim.*; Minim minim; AudioSample kick; HashSet invadersAttacking;// = new HashSet(); HashSet invadersToKill = new HashSet(); HashSet bricks;// = new HashSet(); HashSet bricksToKill = new HashSet(); HashSet tanks;// = new HashSet(); HashSet tanksToKill = new HashSet(); HashSetparticles; HashSetparticlesToKill = new HashSet(); HashSetparticlesToAdd = new HashSet(); color GREEN = color(102,204,0); color WHITE = color(255); PImage imgArrowLeft; PImage imgArrowRight; Fleet f; void sendInFleet(){ f = new Fleet(); hidePreludeText = true; tanks = new HashSet(); for(int i = 0; i < 1; i++) { tanks.add(new Tank(i)); } } void startGame() { gamestate = PLAYING; invadersAttacking = new HashSet(); deadInvaderCount = 0; playBg(); } void clearWorld(){ bricksToKill.addAll(bricks); particlesToKill.addAll(particles); } void setup() { loadProps(); particles = new HashSet(); bricks = new HashSet(); invadersAttacking = new HashSet(); gamestate=TITLE; smallFont = loadFont("pixelmix-24.vlw"); imgArrowLeft = loadImage("arrow-left.png"); imgArrowRight = loadImage("arrow-right.png"); minim = new Minim(this); startupFX(); startupMusic(); playOpen(); size(480,432); } void draw() { background(0); if(gamestate == TITLE){ showTitle(); } if(gamestate == PLAYING){ if(f.invaders.size() == 0 && invadersAttacking.size() == 0){ startPostlude(); } if(f.landed()){ startPostlude(); } } if(gamestate == GAMEOVER){ showResults(); } if(gamestate == PRELUDE || gamestate == PLAYING || gamestate == POSTLUDE){ drawHorizon(); } if(gamestate == PRELUDE){ showPrelude(); if(f != null){ f.march(); f.draw(); if(f.onDeck){ startGame(); } } if(tanks != null){ for(Tank t:tanks){ t.move(); t.draw(); } } } for(Brick b : bricks){ b.draw(); } if(gamestate == POSTLUDE){ showPostlude(); f.draw(); } if(gamestate == PLAYING){ if(f.needToTouch == LEFT){ //might need to not be when hit bottom showArrows(LEFT); } else { showArrows(RIGHT); } f.move(); f.draw(); for(Tank t:tanks){ t.move(); t.draw(); t.doBullet(); } for(Invader i : invadersAttacking){ i.move(); i.checkHitTank(); i.draw(); } } for(Particle p : particles){ p.move(); p.draw(); } // print(f.invaders.size()+":"); if(f != null) f.removeAll(invadersToKill); invadersAttacking.removeAll(invadersToKill); deadInvaderCount += invadersToKill.size(); invadersToKill.clear(); bricks.removeAll(bricksToKill); bricksToKill.clear(); if(tanks != null){ tanks.removeAll(tanksToKill); tanksToKill.clear(); } particles.removeAll(particlesToKill); particlesToKill.clear(); particles.addAll(particlesToAdd); particlesToAdd.clear(); } void mousePressed(){ if(true) return; if(f == null) return; gamestate = POSTLUDE; for(Invader i : f.invaders){ if(i.hit(mouseX,mouseY)){ if(DEBUG==1){ invadersToKill.add(i); //f.launchInvader(i); } } } } void stop(){ // always close Minim audio classes when you are done with them :-) shutdownFX(); shutdownMusic(); minim.stop(); super.stop(); } void drawHorizon(){ strokeWeight(2); stroke(GREEN); int incr = 1; for(float hor = HORIZON; hor < height; hor += incr) { line(0,hor,width,hor); incr += 1; } } int arrowcounter; void showArrows(int dir){ arrowcounter++; if(arrowcounter >= 60){ arrowcounter = 0; } if(arrowcounter > 30){ return; } if(dir == RIGHT){ for(float y = 10; y < height*3/4 - 40; y += 60){ image(imgArrowRight, width - 15,y+20); } } if(dir == LEFT){ for(float y = 10; y < height*3/4 - 40; y += 60){ image(imgArrowLeft, 0,y+20); } } }