Add some score mechanism
If the AI or the human player looses 10 games, the game is over and goes back into the main screen. A score is displayed on top of the game for each side.
This commit is contained in:
parent
a4d01fefdd
commit
60b6af8e63
5 changed files with 22 additions and 18 deletions
|
@ -5,11 +5,8 @@ ig.module(
|
|||
'impact.entity'
|
||||
)
|
||||
.defines(function(){
|
||||
|
||||
EntityGoal = ig.Entity.extend({
|
||||
|
||||
height: 90,
|
||||
|
||||
size: {x:48, y:48},
|
||||
checkAgainst: ig.Entity.TYPE.B,
|
||||
|
||||
|
@ -19,9 +16,10 @@ EntityGoal = ig.Entity.extend({
|
|||
|
||||
check: function(other) {
|
||||
if (other.name == 'ball') {
|
||||
ig.game.score[this.owner] -= 1;
|
||||
other.reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ ig.module(
|
|||
EntityPaddle = ig.Entity.extend({
|
||||
|
||||
name: 'paddle',
|
||||
scores: 0,
|
||||
|
||||
size: {x: 30, y: 96},
|
||||
collides: ig.Entity.COLLIDES.FIXED,
|
||||
|
|
2
dev/lib/game/levels/level1.js
Normal file → Executable file
2
dev/lib/game/levels/level1.js
Normal file → Executable file
|
@ -1,6 +1,6 @@
|
|||
ig.module( 'game.levels.level1' )
|
||||
.requires( 'impact.image','game.entities.paddle-enemy','game.entities.paddle-player','game.entities.ball','game.entities.goal' )
|
||||
.defines(function(){
|
||||
LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":56,"y":148},{"type":"EntityPaddlePlayer","x":536,"y":148},{"type":"EntityBall","x":300,"y":184},{"type":"EntityGoal","x":600,"y":48,"settings":{"size":{"x":24,"y":288}}},{"type":"EntityGoal","x":0,"y":48,"settings":{"size":{"x":24,"y":288}}}],"layer":[{"name":"bg","width":3,"height":2,"linkWithCollision":false,"visible":1,"tilesetName":"media/bg.png","repeat":false,"preRender":false,"distance":"1","tilesize":250,"foreground":false,"data":[[1,1,1],[1,1,1]]},{"name":"board","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/tileset.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,2,1,1,1,2,1,1,1,2,2,1,1],[7,4,0,0,0,0,0,0,0,0,0,4,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,3,0,0,0,0,0,0,0,0,0,3,6],[2,1,1,2,1,1,1,1,2,2,2,2,1]]},{"name":"collision","width":13,"height":8,"linkWithCollision":false,"visible":0,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/;
|
||||
LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":56,"y":148},{"type":"EntityPaddlePlayer","x":536,"y":148},{"type":"EntityBall","x":300,"y":184},{"type":"EntityGoal","x":600,"y":48,"settings":{"size":{"x":24,"y":288},"owner":"human"}},{"type":"EntityGoal","x":0,"y":48,"settings":{"size":{"x":24,"y":288},"owner":"ai"}}],"layer":[{"name":"bg","width":3,"height":2,"linkWithCollision":false,"visible":1,"tilesetName":"media/bg.png","repeat":false,"preRender":false,"distance":"1","tilesize":250,"foreground":false,"data":[[1,1,1],[1,1,1]]},{"name":"board","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/tileset.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,2,1,1,1,8,9,10,1,2,2,1,1],[7,4,0,0,0,0,0,0,0,0,0,4,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,5,0,0,0,0,0,0,0,0,0,5,6],[7,3,0,0,0,0,0,0,0,0,0,3,6],[2,1,1,2,1,1,1,1,2,2,2,2,1]]},{"name":"collision","width":13,"height":8,"linkWithCollision":false,"visible":0,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/;
|
||||
LevelLevel1Resources=[new ig.Image('media/bg.png'), new ig.Image('media/tileset.png')];
|
||||
});
|
|
@ -2,6 +2,7 @@ ig.module(
|
|||
'game.main'
|
||||
)
|
||||
.requires(
|
||||
'impact.debug.menu',
|
||||
'impact.game',
|
||||
'impact.font',
|
||||
|
||||
|
@ -14,6 +15,7 @@ ig.module(
|
|||
.defines(function(){
|
||||
RunningGame = ig.Game.extend({
|
||||
font: new ig.Font( 'media/04b03.font.png' ),
|
||||
score: {'ai': 10, 'human': 10},
|
||||
|
||||
init: function() {
|
||||
ig.input.bind(ig.KEY.ESC, 'mainmenu');
|
||||
|
@ -28,12 +30,15 @@ ig.module(
|
|||
},
|
||||
|
||||
update: function() {
|
||||
if (ig.input.pressed('mainmenu')) ig.system.setGame(StartScreen);
|
||||
if (this.score.ai == 0 || this.score.human == 0 || ig.input.pressed('mainmenu'))
|
||||
ig.system.setGame(StartScreen);
|
||||
this.parent(); // Update entries and background
|
||||
},
|
||||
|
||||
draw: function() {
|
||||
this.parent(); // Draw entries and background
|
||||
this.font.draw(this.score.ai, 270, 25, ig.Font.ALIGN.CENTER);
|
||||
this.font.draw(this.score.human, 350, 25, ig.Font.ALIGN.CENTER);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 50 KiB |
Loading…
Reference in a new issue