-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuController.ts
More file actions
93 lines (82 loc) · 2.14 KB
/
MenuController.ts
File metadata and controls
93 lines (82 loc) · 2.14 KB
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
/// <reference path="GameLoop.ts" />
module Game{
export class MenuController{
gameloop;
canvas;
width;
height;
model;
menuView;
notEnoughCat;
constructor(gameloop,canvas,width,height,model,menuView){
this.gameloop = gameloop;
this.canvas = canvas;
this.model = model
this.height = height;
this.width = width;
this.menuView = menuView;
this.notEnoughCat = false;
}
takeInput(){
this.mobileClick = <any>this.mobileClick.bind(this);
this.canvas.addEventListener('click', this.mobileClick);
}
mobileClick(e){
var mobileClickY = (event as any).y;
mobileClickY -= this.canvas.offsetTop;
var mobileClickX = (event as any).x;
mobileClickX -= this.canvas.offsetLeft;
if(this.notEnoughCat){
this.catClick(mobileClickX,mobileClickY);
}else{
this.click(mobileClickX,mobileClickY);
}
}
catClick(X,Y){
clearTimeout(this.menuView.animationOne);
this.notEnoughCat = false;
this.menuView.render(this.gameloop.currentGame);
}
click(X,Y){
if(X<183*this.width/375 && X>7*this.width/375){
if(Y<342*this.height/667 && Y>291*this.height/667){
this.switchToGameState();
}
else if(Y<410*this.height/667 && Y>352*this.height/667){
this.switchToCategoriesState();
}
else if(Y<475*this.height/667 && Y>425*this.height/667){
this.gameloop.switchGameModes();
}
else if(Y<540*this.height/667 && Y>483*this.height/667){
this.switchToHelpState();
}
}
}
switchStates(){
clearTimeout(this.menuView.balloonAnimation);
this.canvas.removeEventListener('click', this.mobileClick);
console.log("switching states");
}
switchToGameState(){
if(this.model.gameCanStart()){
var m = this.model;
var s = m.gameView;
//s.inMenu = false;
this.switchStates();
this.gameloop.switchToGameState();
}else{
this.notEnoughCat =true;
this.menuView.renderNotEnoughCategories(-10,1,0);
}
}
switchToCategoriesState(){
this.switchStates();
this.gameloop.switchToCategoriesState();
}
switchToHelpState(){
this.switchStates();
this.gameloop.switchToHelpState();
}
}
}