/** PIRATE-GO-ROUND: a game by Lea for Ludum Dare 17 April 25th, 2010 */ Boat blueboat; Boat redboat; boolean gameend = false; boolean gamebeginning = true; boolean explanationon = true; int boatradius = 200; int frame; int frameCountSinceBeginning; //PImage[] backgroundimage; //PImage backgroundwaves; PShape backgroundwaves; PShape backgroundframe; PShape backgroundland; PShape explanation; PShape redimage; PShape blueimage; PShape deadboat; PShape redbar; PShape bluebar; PShape redfill; PShape bluefill; PShape skull; PFont helvetica; PFont helveticasmall; PFont helveticalittlest; color ourred = color(173,48,31); color ourblue = color(39,16,175); color backgroundblue = color(129,201,226); //========================================================== void setup() { size(600,550); smooth(); rectMode(CENTER); textAlign(CENTER, CENTER); helvetica = loadFont("HelveticaNeue-Bold-35.vlw"); helveticasmall = loadFont("HelveticaNeue-Bold-20.vlw"); helveticalittlest = loadFont("HelveticaNeue-Bold-16.vlw"); textFont(helvetica); /* backgroundimage = new PImage[3]; backgroundimage[0] = loadImage("background1.png"); backgroundimage[1] = loadImage("background2.png"); backgroundimage[2] = loadImage("background3.png"); */ backgroundland = loadShape("background-land.svg"); backgroundwaves = loadShape("background-waves.svg"); backgroundframe = loadShape("frame.svg"); bluebar = loadShape("bluebar.svg"); redbar = loadShape("redbar.svg"); bluefill = loadShape("bluefill.svg"); redfill = loadShape("redfill.svg"); skull = loadShape("skull.svg"); explanation = loadShape("explanation.svg"); redimage = loadShape("redimage.svg"); blueimage = loadShape("blueimage.svg"); deadboat = loadShape("deadboat.svg"); blueboat = new Boat(PI, blueimage); redboat = new Boat(0, redimage); gameend = false; gamebeginning = true; frameCountSinceBeginning = 0; } //========================================================== void draw() { // background(backgroundcolor); shape(backgroundland, 0, 0); pushMatrix(); translate(width/2, height/2); scale(wavescale()); shape(backgroundwaves,-300, -275); popMatrix(); shape(backgroundframe,0,0); pushMatrix(); translate(width/2, height/2); blueboat.update(); redboat.update(); if(blueboat.locked) { redboat.drawBoat(); blueboat.drawBoat(); } else { blueboat.drawBoat(); redboat.drawBoat(); } if(!gameend) { updateCannonballs(redboat); updateCannonballs(blueboat); } popMatrix(); if (!gamebeginning) { drawHUD(); frameCountSinceBeginning++; } checkCollisions(); if(!gameend && !gamebeginning) { textFont(helveticalittlest); noStroke(); fill(255,255,255); text("Press SPACE to toggle guide.", width/2, height-15, width, 50); } if(gamebeginning) { drawIntroScreen(); } if (explanationon) { shape(explanation, 0,0); } if(gameend) { drawDeathScreen(); } } //============================================================== float wavescale() { float thisscale = cos(float(frameCount)/35); thisscale = map(thisscale, -1, 1, 0.90, 1); return thisscale; } void drawHUD() { noStroke(); // fill(ourred); for(int i=0; i<27-blueboat.damage; i++) { shape(bluefill,20+(i*4),20); } shape(bluebar,20,20); if(blueboat.damage>=27) { shape(skull, 20, 15); blueboat.drawyes = false; endGame(); } /* text("Ammo="+redboat.ammo.size(), 3*width/4, 30, width/2, 50); text("Damage="+redboat.damage, 3*width/4, 60, width/2, 50); */ // fill(ourblue); for(int i=0; i<27-redboat.damage; i++) { shape(redfill,width-145+(i*4),20); } shape(redbar,width-145,20); if(redboat.damage>=27) { shape(skull,width-145,15); redboat.drawyes = false; endGame(); } /* text("Ammo="+blueboat.ammo.size(), width/4, 30, width/2, 50); text("Damage="+blueboat.damage, width/4, 60, width/2, 50); */ } void drawDeathScreen() { noStroke(); fill(255,255,255); textFont(helvetica); text("GAME OVER", width/2, (height/2)-30, width, height); textFont(helveticasmall); text("Press SPACE to restart", width/2, height/2, width, height); } void drawIntroScreen() { noStroke(); fill(255,255,255); textFont(helvetica); text("WELCOME", width/2, (height/2)-30, width, height); textFont(helveticasmall); text("Press SPACE to start", width/2, height/2, width, height); } //============================================================== void checkCollisions() { if (aboutToHit(redboat, blueboat)) { blueboat.locked = true; blueboat.velocity = 0; redboat.speedup(); redboat.takedamage(); } else blueboat.locked = false; if (aboutToHit(blueboat, redboat)) { redboat.locked = true; redboat.velocity = 0; blueboat.speedup(); blueboat.takedamage(); } else redboat.locked = false; } boolean aboutToHit (Boat aboat, Boat bboat) //returns whether or not bboat is about to hit aboat { float difference = specialMinus(aboat.location, bboat.location); if (difference < PI/10) return true; else return false; } void endGame() { gameend = true; redboat.velocity = 0; blueboat.velocity = 0; } //============================================================== void keyPressed() { if(!gameend && !gamebeginning) { if(key == 'd') blueboat.speedup(); else if(key == 's') blueboat.pause(); else if(key == 'a') blueboat.slowdown(); else if(key == 'q' || key == 'w' || key == 'e' || key == 'r') blueboat.fire(); else if(key == 'l') redboat.speedup(); else if(key == 'k') redboat.pause(); else if(key == 'j') redboat.slowdown(); else if(key == 'u' || key == 'i' || key == 'o' || key == 'p') redboat.fire(); } if (key == ' ') { if(gamebeginning) { gamebeginning = false; } else if(gameend) setup(); else if(!gamebeginning && !gameend) { if (explanationon) explanationon=false; else explanationon = true; } } } //===================================================== boolean within(float firstvalue, float epsilon, float secondvalue) { if(secondvalue-epsilon < firstvalue && firstvalue < secondvalue+epsilon) return true; else return false; } float specialMinus (float specialfirst, float specialsecond) { float difference = specialfirst - specialsecond; if (difference<0) difference = difference +(2*PI); return difference; } float specialPlus(float specialfirst, float specialsecond) { float sum = specialfirst + specialsecond; if (sum>2*PI) sum = sum-(2*PI); return sum; } boolean specialWithin(float firstvalue, float epsilon, float secondvalue) { if(specialMinus(secondvalue, firstvalue)