Created
March 16, 2013 17:02
-
-
Save rixtox/5177312 to your computer and use it in GitHub Desktop.
A initial plan for how the engine should be formed.
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
var marathon_playfield = new voka.playfield({ | |
width: 10, | |
height: 20, | |
event_handlers: { | |
lines_cleared: function(event) { | |
var current_level = event.game.level, | |
lines_cleared = event.lines_cleared.length; | |
var addition = { | |
1: current_level * 100, | |
2: current_level * 300, | |
3: current_level * 500, | |
4: current_level * 700 | |
}[lines_cleared]; | |
event.game.score += addition; | |
event.game.total_lines_cleared += lines_cleared; | |
event.game.renderer.popup_lines_cleared(lines_cleared); | |
event.game.update_level(); | |
}, | |
piece_placed: function(event) { | |
if (event.placing_manner === 'spin' && | |
event.placed_piece.type === 't') { | |
event.game.score += current_level * 400; | |
event.game.renderer.popup_tspin(); | |
} | |
}, | |
soft_drop: function(event) { | |
event.game.score += 2; | |
}, | |
hard_drop: function(event) { | |
event.game.score += 20; | |
}, | |
updated: function(event) { | |
/* event = { | |
previous_matrix: new voka.block_matrix(), | |
current_matrix: new voka.block_matrix(), | |
type: 'line_cleared', | |
lines_cleared: [5,6] | |
}*/ | |
event.game.renderer.render_playfield(this); | |
}, | |
timer: function(event) { | |
switch (event.timer_id) { | |
case 'gravity_timer': | |
event.playfield.fall(); | |
break; | |
default: | |
console.log('unhandled timer.') | |
} | |
} | |
}, | |
piece_queue: new voka.piece_queue(new voka.standard_tetrinimo_set()) | |
}); | |
marathon_playfield.register_timer({ | |
id: 'gravity_timer', | |
interval: 1000 | |
}); | |
var marathon = new voka.game({ | |
playfield: marathon_playfield | |
}); | |
marathon.level = 1; | |
marathon.total_lines_cleared = 0; | |
marathon.update_level = function() { | |
if (this.level == 1 && marathon.total_lines_cleared >= 10 || | |
this.level == 2 && marathon.total_lines_cleared >= 30 || | |
this.level == 3 && marathon.total_lines_cleared >= 60 /* ... */) { | |
marathon.level += 1; | |
this.playfield.update_timer({id: 'gravity_timer', | |
interval: (this.level / 1000) }) | |
this.renderer.popup_levelup(this.level); | |
} | |
} | |
function marathon_renderer() { | |
// ... | |
} | |
marathon.set_renderer(mararthon_renderer); | |
marathon.start_game(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment