-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.js
139 lines (124 loc) · 3.52 KB
/
repo.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
134
135
136
137
138
139
'use strict';
function gameover(){
canvas.canvas.style.cursor = 'auto';
}
function load_data(id){
canvas.canvas.style.cursor = 'none';
click_x = -1;
click_y = -1;
score = 0;
randomize_shapes();
}
function randomize_shapes(){
entity_remove_all();
entity_create({
'id': 'target',
'properties': {
'x': core_random_integer({
'max': canvas_properties['width'] - core_storage_data['target-width'],
}),
'y': core_random_integer({
'max': canvas_properties['height'] - core_storage_data['target-height'],
}),
},
});
core_ui_update({
'ids': {
'score': score,
},
});
canvas_draw();
}
function repo_drawlogic(){
canvas_setproperties({
'fillStyle': '#206620',
});
canvas.fillRect(
entity_entities['target']['x'],
entity_entities['target']['y'],
core_storage_data['target-width'],
core_storage_data['target-height']
);
if(click_x >= 0){
canvas_setproperties({
'fillStyle': '#663366',
});
canvas.fillRect(
click_x - core_storage_data['click-width'] / 2,
click_y - core_storage_data['click-height'] / 2,
core_storage_data['click-width'],
core_storage_data['click-height']
);
canvas_setproperties({
'fillStyle': '#000',
});
canvas.fillRect(
click_x - 3,
click_y - 3,
6,
6
);
}
}
function repo_escape(){
if(!core_menu_open){
core_repo_reset();
}else if(canvas_properties['ready']){
gameover();
}
}
function repo_init(){
core_repo_init({
'events': {
'start': {
'onclick': core_repo_reset,
},
},
'globals': {
'click_x': -1,
'click_y': -1,
'score': 0,
},
'info': '<button id=start type=button>Start New Game</button>',
'menu': true,
'mousebinds': {
'mousedown': {
'todo': function(event){
if(canvas.canvas.style.cursor === 'auto'){
return;
}
click_x = core_mouse['down-x'];
click_y = core_mouse['down-y'];
if(click_x <= entity_entities['target']['x']
|| click_x >= entity_entities['target']['x'] + core_storage_data['target-width']
|| click_y <= entity_entities['target']['y']
|| click_y >= entity_entities['target']['y'] + core_storage_data['target-height']){
gameover();
canvas_draw();
}else{
audio_start('boop');
score += 1;
randomize_shapes();
}
},
},
},
'reset': canvas_setmode,
'storage': {
'click-height': 36,
'click-width': 36,
'target-height': 100,
'target-width': 100,
},
'storage-menu': '<table><tr><td><input class=mini id=click-height min=8 step=any type=number><td>Click Height'
+ '<tr><td><input class=mini id=click-width min=8 step=any type=number><td>Click Width'
+ '<tr><td><input class=mini id=target-height min=1 step=any type=number><td>Target Height'
+ '<tr><td><input class=mini id=target-width min=1 step=any type=number><td>Target Width</table>',
'title': 'BlindMouse.htm',
'ui': 'Score: <span id=score></span>',
});
canvas_init({
'interval': false,
});
document.body.onmouseleave = gameover;
}