Created
July 13, 2011 11:53
-
-
Save Sephi-Chan/1080170 to your computer and use it in GitHub Desktop.
Impact game
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 | |
currentState: null | |
currentLevel: null | |
STATE: | |
MAIN_MENU: 0 | |
PLAYING: 1 | |
init: -> | |
@currentState = @STATE.MAIN_MENU | |
@cursorWidth = @font.widthForString(">>") | |
# 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.MAIN_MENU | |
1 | |
when @STATE.PLAYING | |
@currentLevel = LevelTest | |
@loadLevel(@currentLevel) | |
# 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 | |
@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: -> | |
# @currentState = @STATE.PLAYING | |
console.log "Start game..." | |
showCredits: -> | |
console.log "Show credits..." | |
showOptions: -> | |
console.log "Show options..." | |
showHelp: -> | |
console.log "Show help..." | |
fps = 20 | |
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