Created
July 13, 2011 13:06
-
-
Save Sephi-Chan/1080259 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
ig | |
.module('game.main') | |
.requires( | |
'impact.game' | |
'impact.font' | |
'game.menu' | |
'game.levels.test' | |
'game.entities.player' | |
'game.entities.levelchange' | |
'game.entities.trigger' | |
) | |
.defines -> | |
SFH = ig.Game.extend | |
# Load a font. | |
font: new ig.Font 'media/04b03.font.png' | |
gravity: 400 | |
previousState: null | |
currentState: null | |
currentLevel: null | |
STATE: | |
MAIN_MENU: 0 | |
START_PLAYING: 1 | |
PLAYING: 2 | |
init: -> | |
@previousState = @STATE.MAIN_MENU | |
@currentState = @previousState | |
# Initialize your game here bind keys etc. | |
ig.input.bind ig.KEY.LEFT_ARROW, 'left' | |
ig.input.bind ig.KEY.RIGHT_ARROW, 'right' | |
ig.input.bind ig.KEY.UP_ARROW, 'up' | |
ig.input.bind ig.KEY.DOWN_ARROW, 'down' | |
ig.input.bind ig.KEY.X, 'jump' | |
ig.input.bind ig.KEY.SPACE, 'interact' | |
@menu = new Menu @font, [ | |
new MenuItem "Start", => @startGame() | |
new MenuItem "Options", => @showOptions() | |
new MenuItem "Help", => @showHelp() | |
new MenuItem "Credits", => @showCredits() | |
] | |
update: -> | |
switch @currentState | |
when @STATE.START_PLAYING | |
console.log "I load the level, etc." | |
@currentLevel = LevelTest | |
@loadLevel(@currentLevel) | |
@currentState = @STATE.PLAYING | |
@timer = new ig.Timer(2) | |
when @STATE.PLAYING | |
# Screen follows the player | |
player = this.getEntitiesByType(EntityPlayer)[0] | |
if player | |
@screen.x = player.pos.x - ig.system.width/2 | |
@screen.y = player.pos.y - ig.system.height/2 | |
# 2 sec Timer to show the problem. | |
# http://img809.imageshack.us/img809/7581/capturedcran20110713144.png | |
if 0 < @timer.delta() | |
@timer.reset() | |
console.log new Date | |
ig.game.currentState = ig.game.STATE.MAIN_MENU | |
@parent() | |
draw: -> | |
@parent() | |
switch @currentState | |
when @STATE.MAIN_MENU | |
baseX = ig.system.width / 2 | |
text = "Startups from Hell" | |
@font.draw(text, baseX, 12, ig.Font.ALIGN.CENTER) | |
@menu.draw(baseX, 50) | |
text = "Make a choice with UP and DOWN then hit SPACE to confirm." | |
@font.draw(text, baseX, 140, ig.Font.ALIGN.CENTER) | |
startGame: -> | |
console.log "Start game..." | |
@currentState = @STATE.START_PLAYING | |
showCredits: -> | |
console.log "Show credits..." | |
showOptions: -> | |
console.log "Show options..." | |
showHelp: -> | |
console.log "Show help..." | |
fps = 30 | |
width = 320 | |
height = 240 | |
ratio = 1 | |
ig.main '#canvas', SFH, fps, width, height, ratio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment