Send the score on ENTER

This commit is contained in:
Aaron Mueller 2013-05-16 22:04:05 +02:00
parent bb21ad16e2
commit 9a37a561e9
2 changed files with 18 additions and 3 deletions

View file

@ -71,7 +71,7 @@ ig.module(
name: function() {
var name = '';
for(var i=0; i<this.numberOfChars; i++)
name += this.symbols[this.name[i]];
name += this.symbols[this._name[i]];
return name;
}
});

View file

@ -122,7 +122,8 @@ ig.module(
nameField: null,
init: function() {
ig.input.bind(ig.KEY.ENTER, 'main-menu');
ig.input.bind(ig.KEY.ENTER, 'submit-score');
ig.input.bind(ig.KEY.ESCAPE, 'main-menu');
this.nameField = ig.game.spawnEntity(EntityNameField, 250, 150);
this.loadScores();
},
@ -131,6 +132,14 @@ ig.module(
if (ig.input.pressed('main-menu')) {
ig.system.setGame(StartScreen);
}
if (ig.input.pressed('submit-score')) {
this.nameField.kill();
//TODO: The name field does not kill itself ... this.draw();
this.saveScore(this.nameField.name(), ig.global.score, function(context) {
setTimeout(function() { context.loadScores(); }, 2000);
});
}
this.parent();
},
@ -141,7 +150,13 @@ ig.module(
});
},
saveScore: function(username, score) {
saveScore: function(username, score, cb) {
$.post('https://www.scoreoid.com/api/createScore', {
api_key: this.scoreoid.api_key,
game_id: this.scoreoid.game_id,
score: score,
username: username
}, cb(this));
},
draw: function() {