added death message and username (closes #25)
This commit is contained in:
parent
462668e5cd
commit
db52ff95ae
5 changed files with 26 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"player.name": "Player",
|
||||
|
||||
"input.touchscreen.crosspad.enabled": false,
|
||||
"input.touchscreen.crosspad.overlay": true,
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
{
|
||||
"player": {
|
||||
"name": "Player settings"
|
||||
},
|
||||
"player.name": {
|
||||
"name": "Player name",
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
"input": {
|
||||
"name": "Input settings"
|
||||
},
|
||||
|
|
|
@ -50,6 +50,11 @@ class ConfigEditor extends Popup {
|
|||
}
|
||||
input.value=config.getN(key);
|
||||
input.addEventListener('change', () => config.set(key, input.value));
|
||||
} else if(data.type=='string') {
|
||||
input=document.createElement('input');
|
||||
input.type='text';
|
||||
input.value=config.getS(key);
|
||||
input.addEventListener('change', () => config.set(key, input.value));
|
||||
}
|
||||
|
||||
input.setAttribute('id', id);
|
||||
|
|
|
@ -233,7 +233,8 @@
|
|||
|
||||
// create and configure popup
|
||||
let popup=new Popup("Finished!");
|
||||
popup.addStrong("You died...");
|
||||
popup.addStrong(config.getS('player.name')+' '+snek.death.message);
|
||||
popup.addEm('('+config.getS('player.name')+' '+snek.death.reason+')');
|
||||
popup.addContent({
|
||||
"Time": snek.endPlayTime/1000+'s',
|
||||
"Score": snek.score,
|
||||
|
|
|
@ -405,17 +405,18 @@ class SnekGame {
|
|||
head[0]=(head[0]+this.dimensions[0])%this.dimensions[0];
|
||||
head[1]=(head[1]+this.dimensions[1])%this.dimensions[1];
|
||||
} else {
|
||||
return this.die();
|
||||
return this.die("literally fell out of the world", "exited the grid");
|
||||
}
|
||||
}
|
||||
|
||||
switch(this.world[head[0]][head[1]]) {
|
||||
// you hit, you die
|
||||
case WALL:
|
||||
case FIRE:
|
||||
case WALL: return this.die("thought walls were edible", "hit a wall");
|
||||
case FIRE: return this.die("burned to a crisp", "hit fire");
|
||||
case SNAKE:
|
||||
case HOLE_S:
|
||||
return this.die();
|
||||
case FLAMMABLE_S:
|
||||
return this.die("achieved every dog's dream", "ate their own tail");
|
||||
|
||||
// if either 3 consecutive segments or the whole snake is on a hole, you die
|
||||
case HOLE:
|
||||
|
@ -426,7 +427,7 @@ class SnekGame {
|
|||
this.snake.length>=2 &&
|
||||
this.world[this.snake[0][0]][this.snake[0][1]]==HOLE_S &&
|
||||
this.world[this.snake[1][0]][this.snake[1][1]]==HOLE_S
|
||||
) return this.die();
|
||||
) return this.die("fell harder than their grades", "fell in a hole");
|
||||
break;
|
||||
|
||||
// you eat, you get a massive score boost
|
||||
|
@ -533,7 +534,7 @@ class SnekGame {
|
|||
];
|
||||
return surrounding.some(tile => tile==FIRE);
|
||||
};
|
||||
if(this.getTilesOfType(FLAMMABLE_S).some(touchingFire)) return this.die();
|
||||
if(this.getTilesOfType(FLAMMABLE_S).some(touchingFire)) return this.die("didn't know oil was flammable", "stood on oil when it caught on fire");
|
||||
this.getTilesOfType(FLAMMABLE).filter(touchingFire).forEach(([x, y]) => this.world[x][y]=FIRE);
|
||||
}
|
||||
|
||||
|
@ -567,9 +568,10 @@ class SnekGame {
|
|||
if(this.callback) this.callback('win');
|
||||
}
|
||||
|
||||
die() {
|
||||
die(message='died', reason='died') {
|
||||
this.playing=false;
|
||||
this.endPlayTime=this.playTime;
|
||||
this.death={message, reason};
|
||||
if(this.callback) this.callback('die');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue