-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo.js
More file actions
192 lines (173 loc) · 5.01 KB
/
repo.js
File metadata and controls
192 lines (173 loc) · 5.01 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'use strict';
function create_shape(type, id){
const max = core_storage_data[type + '_size_max'];
const bonus = core_storage_data[type + '_size_bonus'];
entity_create({
'id': type + '_' + id,
'properties': {
'color': core_storage_data[type + '_color'],
'height': core_random_integer(max) + bonus,
'width': core_random_integer(max) + bonus,
'x': core_random_integer(canvas_properties.width) - bonus / 2,
'y': core_random_integer(canvas_properties.height - 30) - bonus / 2 + 30,
},
});
}
function decisecond(){
if(time > 0){
time = core_round({
'decimals': 1,
'number': time - .1,
});
core_ui_update({
'ids': {
'time': core_number_format({
'decimals_min': 1,
'number': time,
}),
},
});
}
if(time <= 0){
core_interval_lock('interval');
}
}
function draw_shape(entity){
canvas_setproperties({
'fillStyle': entity.color,
});
canvas.fillRect(
entity.x,
entity.y,
entity.width,
entity.height
);
}
function randomize_shapes(){
entity_remove_all();
for(let i = 0; i < core_storage_data.negative_count; i++){
create_shape('negative', i);
}
for(let i = 0; i < core_storage_data.positive_count; i++){
create_shape('positive', i);
}
canvas_draw();
}
function repo_drawlogic(){
entity_group_modify({
'groups': [
'canvas',
],
'todo': draw_shape,
});
}
function repo_escape(){
audio_state_all(!core_menu_open);
if(!entity_entities.negative_0
&& !entity_entities.positive_0
&& !core_menu_open){
start();
}
}
function repo_init(){
core_repo_init({
'beforeunload': {
'todo': function(event){
if(score !== 0){
core_escape(true);
event.preventDefault();
}
},
},
'events': {
'start': {
'onclick': start,
},
},
'globals': {
'score': 0,
'time': 0,
},
'info': '<button class=medium id=start type=button>Start New Game</button>',
'menu': true,
'pointerbinds': {
'pointerdown': {
'todo': function(){
if(time <= 0){
return;
}
const pixel = canvas.getImageData(
core_pointer.x, core_pointer.y,
1, 1
).data[0];
if(pixel === 0){
return;
}
score += pixel === 102
? core_storage_data.negative_score
: core_storage_data.positive_score;
core_ui_update({
'ids': {
'score': score,
},
});
audio_start('boop');
randomize_shapes();
},
},
},
'storage': {
'negative_color': '#663366',
'negative_count': 10,
'negative_score': -1,
'negative_size_bonus': 42,
'negative_size_max': 200,
'positive_color': '#206620',
'positive_count': 1,
'positive_score': 1,
'positive_size_bonus': 20,
'positive_size_max': 99,
'time_limit': 30,
},
'storage_menu': '<table><tr><td><input class=mini id=time_limit step=any type=number><td>Time Limit'
+ '<tr><td><input id=positive_color type=color><td>Positive Color'
+ '<tr><td><input class=mini id=positive_count min=0 step=1 type=number><td># of Positive'
+ '<tr><td><input class=mini id=positive_score step=any type=number><td>Positive Score'
+ '<tr><td><input class=mini id=positive_size_max min=0 step=any type=number><td>Positive Size Max'
+ '<tr><td><input class=mini id=positive_size_bonus min=0 step=any type=number><td>Positive Size Bonus'
+ '<tr><td><input id=negative_color type=color><td>Negative Color'
+ '<tr><td><input class=mini id=negative_count min=0 step=1 type=number><td># of Negative'
+ '<tr><td><input class=mini id=negative_score step=any type=number><td>Negative Score'
+ '<tr><td><input class=mini id=negative_size_max min=0 step=any type=number><td>Negative Size Max'
+ '<tr><td><input class=mini id=negative_size_bonus min=0 step=any type=number><td>Negative Size Bonus</table>',
'title': 'SpeedShape.htm',
'ui': 'Score: <span id=score></span> | Time: <span id=time></span>',
});
canvas_init({
'cursor': 'pointer',
'interval': false,
});
}
function repo_load(id){
score = 0;
time = core_storage_data.time_limit;
core_ui_update({
'ids': {
'score': score,
'time': time,
},
});
randomize_shapes();
core_interval_modify({
'id': 'interval',
'interval': 100,
'todo': decisecond,
});
}
function start(){
if(score !== 0
&& !globalThis.confirm('Start new game?')){
return;
}
canvas_setmode();
}