-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.js
181 lines (169 loc) · 5.81 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
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
'use strict';
function load_data(id){
randomize_shapes();
score = 0;
time = core_storage_data['time-limit'];
}
function randomize_shapes(){
entity_remove_all();
if(core_storage_data['negative-count'] > 0){
let loop_counter = Math.floor(core_storage_data['negative-count']) - 1;
do{
entity_create({
'id': 'negative-' + loop_counter,
'properties': {
'color': '#663366',
'height': core_random_integer({
'max': core_storage_data['negative-size-max'],
}) + core_storage_data['negative-size-bonus'],
'width': core_random_integer({
'max': core_storage_data['negative-size-max'],
}) + core_storage_data['negative-size-bonus'],
'x': core_random_integer({
'max': canvas_properties['width'],
}) - core_storage_data['negative-size-bonus'] / 2,
'y': core_random_integer({
'max': canvas_properties['height'],
}) - core_storage_data['negative-size-bonus'] / 2,
},
});
}while(loop_counter--);
}
if(core_storage_data['positive-count'] > 0){
let loop_counter = Math.floor(core_storage_data['positive-count']) - 1;
do{
entity_create({
'id': 'positive-' + loop_counter,
'properties': {
'color': '#206620',
'height': core_random_integer({
'max': core_storage_data['positive-size-max'],
}) + core_storage_data['positive-size-bonus'],
'width': core_random_integer({
'max': core_storage_data['positive-size-max'],
}) + core_storage_data['positive-size-bonus'],
'x': core_random_integer({
'max': canvas_properties['width'],
}) - core_storage_data['positive-size-bonus'] / 2,
'y': core_random_integer({
'max': canvas_properties['height'],
}) - core_storage_data['positive-size-bonus'] / 2,
},
});
}while(loop_counter--);
}
canvas_draw();
}
function repo_drawlogic(){
entity_group_modify({
'groups': [
'canvas',
],
'todo': function(entity){
canvas_setproperties({
'fillStyle': entity_entities[entity]['color'],
});
canvas.fillRect(
entity_entities[entity]['x'],
entity_entities[entity]['y'],
entity_entities[entity]['width'],
entity_entities[entity]['height']
);
},
});
}
function repo_escape(){
if(!entity_entities['negative-0']
&& !entity_entities['positive-0']
&& !core_menu_open){
core_repo_reset();
}
}
function repo_init(){
core_repo_init({
'events': {
'start': {
'onclick': core_repo_reset,
},
},
'globals': {
'score': 0,
'time': 0,
},
'info': '<button id=start type=button>Start New Game</button>',
'menu': true,
'mousebinds': {
'mousedown': {
'preventDefault': true,
'todo': function(){
if(time <= 0){
return;
}
const pixel = canvas.getImageData(
core_mouse['x'], core_mouse['y'],
1, 1
).data[0];
if(pixel === 0){
return;
}
score += pixel === 102
? core_storage_data['negative-score']
: core_storage_data['positive-score'];
audio_start('boop');
randomize_shapes();
},
},
},
'reset': canvas_setmode,
'storage': {
'negative-count': 10,
'negative-score': -1,
'negative-size-bonus': 42,
'negative-size-max': 200,
'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=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-bonus step=any type=number><td>Negative Size Bonus'
+ '<tr><td><input class=mini id=negative-size-max step=any type=number><td>Negative Size Max'
+ '<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-bonus step=any type=number><td>Positive Size Bonus'
+ '<tr><td><input class=mini id=positive-size-max step=any type=number><td>Positive Size Max'
+ '<tr><td><input class=mini id=time-limit step=any type=number><td>Time Limit</table>',
'title': 'SpeedShape.htm',
'ui': 'Score: <span id=score></span><br>Time: <span id=time></span>',
});
canvas_init({
'cursor': 'pointer',
'interval': false,
});
core_interval_modify({
'id': 'interval',
'interval': 100,
'todo': function(){
if(time <= 0){
core_interval_pause_all();
return;
}
time = time - .1;
const time_display = core_number_format({
'decimals-min': 1,
'number': core_round({
'decimals': 1,
'number': time,
}),
});
core_ui_update({
'ids': {
'score': score,
'time': time_display + '/' + core_storage_data['time-limit'],
},
});
},
});
}