/
stats.js
129 lines (101 loc) · 3.72 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
ig.module(
'bootstrap.demos.resident-raver.plugins.stats'
)
.requires(
'impact.font',
'bootstrap.demos.demo-harness',
'bootstrap.plugins.impact.menu',
'plugins.impact-storage.impact-storage',
'bootstrap.entities.base-monster',
'bootstrap.demos.resident-raver.entities.door',
'bootstrap.demos.resident-raver.entities.player'
)
.defines(function ()
{
/* Empty module to require all bootstrap plugins */
MyGame.inject({
onShowPauseMenu: function()
{
if(this.showStats)
this.showMenu(new StatMenu("Pause"));
else
this.parent();
}
})
StatMenu = Menu.extend({
invalidate: true,
collection: {},
collectionKey: [],
draw: function()
{
this.drawModal();
//TODO this should be moved into the utils
var x = ig.system.width * .5;
var y = ig.system.height * .5;
this.menuFont.draw(this.title, x, y - 30, ig.Font.ALIGN.CENTER);
// Show quit message
//if(!ig.game.isGameOver)
this.menuFont.draw("~ Press 'Q' To Quit At Any Time ~", x, y - 45, ig.Font.ALIGN.CENTER); //TODO need to have this support touch controls and customization
//TODO calculate score
var stats = ig.game.stats;
if(stats)
{
var i;
var total;
var displayStats = ["time","kills","doors","score"];
total = displayStats.length;
for (i = 0 ; i < total; i++)
{
var name = displayStats[i];
//TODO need to come up with a better way to handle the score but this is a good hack for now
var points = stats[displayStats[i]];//totalItems * this.collectionKeys[i].value * (i+1);
this.menuFont.draw(name.capitalize()+": "+ points, x, y+(10 * (i+1))+10, ig.Font.ALIGN.CENTER);
}
//this.menuFont.draw("Score : ", x, y+(10 * (i+2))+10, ig.Font.ALIGN.CENTER);
}
}
})
MyGame.inject({
stats: null,
storage: new ig.Storage(),
loadLevel:function (data) {
this.stats = {time:0, kills:0, deaths:0, doors:0, ammo:0};
this.parent(data);
},
onPause: function (value)
{
// Update level time before displaying pause screen
this.updateStats();
this.parent(value);
},
updateStats: function()
{
this.stats.time = Math.round(this.levelTimer.delta());
this.stats.score = (this.stats.doors * 50) + (this.stats.kills * 5);
},
onPlayerDeath: function()
{
this.updateStats();
this.parent();
}
})
EntityBaseMonster.inject({
receiveDamage: function(value, from)
{
this.parent(value, from);
if(this.health <= 0 && from instanceof EntityBaseWeapons)
{
ig.game.stats.kills ++;
console.log("Add to kills", ig.game.stats.kills)
}
}
})
EntityDoor.inject({
close: function()
{
ig.game.stats.doors ++;
//console.log("Add to doors", ig.game.stats.doors)
this.parent();
}
})
});