Created
February 11, 2015 13:47
-
-
Save foliea/db29357e1748f3611f54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (game.mode == "intro") { | |
if (game.panTo(700)) { | |
game.mode = "load-next-hero"; | |
} | |
} | |
if (game.mode == "wait-for-firing") { | |
if (mouse.dragging) { | |
if (game.mouseOnCurrentHero()){ | |
game.mode = "firing"; | |
} else { | |
game.panTo(mouse.x + game.offsetLeft); | |
} | |
} else { | |
game.panTo(game.slingshotX); | |
} | |
} | |
if(game.mode == "firing"){ | |
if (mouse.down){ | |
game.panTo(game.slingshotX); | |
game.currentHero.SetPosition({x:(mouse.x+game.offsetLeft)/box2d.scale, y:mouse.y/box2d.scale}); | |
} else { | |
game.mode = "fired"; | |
game.slingshotReleasedSound.play(); | |
var impulseScaleFactor = 0.75; | |
var slingshotCenterX = game.slingshotX + 35; | |
var slingshotCenterY = game.slingshotY + 25; | |
var impulse = new b2Vec2((slingshotCenterX - mouse.x - game.offsetLeft) * impulseScaleFactor, (slingshotCenterY - mouse.y)*impulseScaleFactor); | |
game.currentHero.ApplyImpulse(impulse, game.currentHero.GetWorldCenter()); | |
} | |
} | |
if (game.mode == "fired"){ | |
// Pan to wherever the hero currently is | |
var heroX = game.currentHero.GetPosition().x*box2d.scale; | |
game.panTo(heroX); | |
// and wait till he stops moving or is out of bounds | |
if (!game.currentHero.IsAwake() || heroX < 0 || heroX > game.currentLevel.foregroundImage.width){ | |
//then delete old hero | |
box2d.world.DestroyBody(game.currentHero); | |
game.currentHero = undefined; | |
//and load next hero | |
game.mode = "load-next-hero"; | |
} | |
} | |
if (game.mode == "load-next-hero"){ | |
game.countHeroesAndVillains(); | |
// Check if any villains are alive, if not, end the level (success) | |
if (game.villains.length == 0){ | |
game.mode = "level-success"; | |
return; | |
} | |
// Check if there are any more heroes left to load, if not, end the level (failure) | |
if (game.heroes.length == 0){ | |
game.mode = "level-failure"; | |
return; | |
} | |
// Load the hero and set mode to wait-for-firing | |
if (!game.currentHero){ | |
game.currentHero = game.heroes[game.heroes.length-1]; | |
game.currentHero.SetPosition({x:180/box2d.scale, y:200/box2d.scale}); | |
game.currentHero.SetLinearVelocity({x:0, y:0}); | |
game.currentHero.SetAngularVelocity(0); | |
game.currentHero.SetAwake(true); | |
} else { | |
// Wait for hero to stop bouncing and fall asleep and then switch to wait-for-firing | |
game.panTo(game.slingshotX); | |
if(!game.currentHero.IsAwake()){ | |
game.mode = "wait-for-firing"; | |
} | |
} | |
} | |
if (game.mode == "level-success" || game.mode == "level-failure"){ | |
if (game.panTo(0)){ | |
game.ended = true; | |
game.showEndingScreen(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment