-
Notifications
You must be signed in to change notification settings - Fork 0
/
TentenGameWorld.js
133 lines (107 loc) · 3.35 KB
/
TentenGameWorld.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
130
131
132
133
"use strict";
function tentenGameWorld () {
this.grid = new mygrid();
this.figurePanel = new figurePanel();
this.titleScreen = new titleScreen();
// this.settingsScreen = new settingsScreen();
this.restartScreen = new restartScreen();
// this.buttonMenu = new buttonMenu();
this.buttonSound = new buttonSound(new Vector2(50, 50));
this.buttonRestart = new buttonRestart();
this.activeFigure = false;
this.score = 0;
this.highScore = 0;
this.gameOver = false;
this.fontType = 'Quicksand, Courier New';
this.loadHighScore();
};
tentenGameWorld.prototype.loadHighScore = function () {
if (localStorage && localStorage.highScore) {
this.highScore = JSON.parse(localStorage.highScore);
}
};
tentenGameWorld.prototype.writeHighScore = function () {
if (!localStorage)
return;
this.highScore = this.score;
localStorage.highScore = JSON.stringify(this.highScore);
};
tentenGameWorld.prototype.handleInput = function (delta) {
if (!this.gameOver) {
if (this.restartScreen.on) {
this.restartScreen.handleInput(delta);
} else {
this.grid.handleInput(delta);
this.figurePanel.handleInput(delta);
// this.buttonMenu.handleInput(delta);
this.buttonSound.handleInput(delta);
this.buttonRestart.handleInput(delta);
this.titleScreen.handleInput(delta);
// /*this.settingsScreen.handleInput(delta);*/
}
}
else {
if (Touch.isTouchDevice) {
if (Touch.isTouching)
this.reset();
} else {
if (Mouse.left.down)
this.reset();
}
}
};
tentenGameWorld.prototype.update = function (delta) {
this.titleScreen.update(delta);
/*this.settingsScreen.update(delta);*/
this.restartScreen.update(delta);
// this.buttonMenu.update(delta);
this.buttonSound.update(delta);
this.buttonRestart.update(delta);
this.grid.update(delta);
this.figurePanel.update(delta);
if (this.highScore < this.score)
this.writeHighScore();
};
tentenGameWorld.prototype.draw = function () {
Canvas2D.clear();
Canvas2D.drawImage(images.bg, new Vector2(), new Vector2());
Canvas2D.drawText('Highscore: ' + this.highScore,
new Vector2(288, 20), "center", 30, this.fontType)
if (this.score > 0) {
Canvas2D.drawText(this.score, {x : 576 / 2, y : Game.gameWorld.grid.position.y /2},
"center", 50, this.fontType);
}
this.grid.draw();
this.figurePanel.draw();
// this.buttonMenu.draw();
this.buttonSound.draw();
this.buttonRestart.draw();
this.titleScreen.draw();
// /*this.settingsScreen.draw();*/
this.restartScreen.draw();
if (this.gameOver) {
Canvas2D.drawImage(images.gameOver, new Vector2(), new Vector2());
Canvas2D.drawText('Game Over', {x : 576 / 2, y : 442.5},
"center", 80, this.fontType);
}
};
tentenGameWorld.prototype.reset = function () {
this.grid.reset();
this.figurePanel.reset();
this.score = 0;
this.gameOver = false;
};
tentenGameWorld.prototype.addScore = function (object) {
var count = 0;
for (var i = 0; i < object.length; i ++) {
for (var j = 0; j < object[i].length; j ++) {
if (object[i][j] !== 0)
count ++;
}
}
this.score += count;
};
tentenGameWorld.prototype.addBonusScore = function (factor, crossing) {
var cross = typeof crossing !== 'undefined' ? crossing : 1;
this.score += (factor * factor * 10 * cross);
};