-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode_9_game.ino
336 lines (274 loc) · 10.5 KB
/
mode_9_game.ino
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// ####################################################################################################
// # Flight 3000 written by Mark Sunnucks (Snux) Copyright 2016 #
// # #
// # Based on and expanded from example code supplied with the myPinballs Custom Controller Boardset #
// # #
// # This code will not compile or run on its own. It requires the myPinballs Custom Controller #
// # Boardset hardware and frameworks, which are available here: #
// # http://mypinballs.co.uk/electronics/store.jsp #
// # #
// # Boardset, All Frameworks & Code Structure/Design are Copyright Orange Cloud Software Ltd #
// ####################################################################################################
//
// This file is part of Flight 3000.
//
// Flight 3000 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// Flight 3000 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// ___ _ _ ___ ___ _
// / __|___ _ _| |_ _ _ __ _| | / __|__ _ _ __ ___ / __|___ __| |___
// | (__/ -_) ' \ _| '_/ _` | | | (_ / _` | ' \/ -_) | (__/ _ \/ _` / -_)
// \___\___|_||_\__|_| \__,_|_| \___\__,_|_|_|_\___| \___\___/\__,_\___|
//
//----------------------------------------
//define includes
//----------------------------------------
//----------------------------------------
//----------------------------------------
//define global variables
//----------------------------------------
static long ball_save_current_timer_store;
static long ball_save_reference_timer_store;
//----------------------------------------
//methods
//----------------------------------------
void setup_players()
{
for (int i = 0; i < max_players; i++)
{
player_score[i] = 0;
player_active_flag[i] = false;
}
}
void start_game()
{
Serial.print(F("start_game called with ball in play as "));
Serial.println(String(ball_in_play));
if (credits > 0 or free_play)
{
if (!game_started)
{
//cancel any active lamp effects
lamp_game_over.off();
reset_lamp_effects();
//clear displays
reset_displays();
sound_channel1.play(338); //Prepare for mission
//set the ball save reference
//ball_save_reference_timer_store = millis(); - remove?
trough_switch_handler(); // Initial call to set trough counts.
}
//set flag
game_started = true;
//log
Serial.println(F("Game Started"));
if (num_of_players < max_players && ball_num[active_player_id] <= 1)
{
num_of_players += 1;
player_active_flag[num_of_players - 1] = true;
player_score[num_of_players - 1] = 0; //reset score
left_spinner_lit[num_of_players - 1] = false;
next_left_drop[num_of_players - 1] = 5;
stage_lit[num_of_players - 1] = 0;
multiball_stage[num_of_players - 1] = 0;
bonus_mult[num_of_players - 1] = 1;
clear_blastoff(num_of_players - 1);
blastoff_completed[num_of_players - 1] = false;
//update credits
if (!free_play)
{
subtract_credit();
}
//play sound
sound_channel1.play(2);
//log
Serial.print(F("Player "));
Serial.print(String(num_of_players));
Serial.println(F(" Added"));
}
if (!ball_in_play)
{
start_ball();
}
}
}
void end_game()
{
game_started = false;
Serial.println(F("Game Ended"));
//reset player vars and set high score if required
for (int i = 0; i < num_of_players; i++)
{
ball_num[i] = 0;
player_active_flag[i] = false;
//update high score if needed
if (player_score[i] > high_score);
{
high_score = player_score[i];
EEPROMWritelong(0, high_score);
}
player_score[i] = 0;
}
num_of_players = 0;
active_player_id = 0;
attract_lamps_setup = false;
//run match
match();
//delay 5 secs then enter attract
mhs_delay(5000);
}
void start_ball()
{
// If we're coming here with extra balls to play, then use one up
// since the current player number won't have changed.
// Otherwise the player number will have incremented, so we up the
// ball count for that player.
if (extra_balls > 0)
{
use_extra_ball();
}
else
{
ball_num[active_player_id] += 1;
}
sound_channel1.play(338); // Prepare for mission
/*
switch (active_player_id) {
case 0: sound_channel1.play(342); //Player one stand by
break; //One
case 1: sound_channel1.play(343);
break; //Two
case 2: sound_channel1.play(344);
break; //Three
case 3: sound_channel1.play(345);
break; //Four
}
*/
Serial.print(F("Ball Start 1 : Ball number is "));
Serial.println(ball_num[active_player_id], DEC);
Serial.print(F("Ball Start 1 : Balls per game is "));
Serial.println(balls_per_game, DEC);
Serial.print(F("Ball Start 1 : Extra balls is "));
Serial.println(extra_balls, DEC);
Serial.print(F("Ball Start 1 : Active player id is "));
Serial.println(active_player_id, DEC);
Serial.print(F("Ball Start 1 : Number of players is "));
Serial.println(num_of_players, DEC);
right_drop_target_reset();
// Reset the left bank, using a parm of true will force the bank to reset
left_drop_target_reset(true);
right_spinner_value[active_player_id] = 500;
bonus_count[active_player_id] = 0;
Serial.print(F("Ball started, Player:"));
Serial.print(String(active_player_id));
Serial.print(F(", Ball in play:"));
Serial.println(String(ball_num[active_player_id]));
//start bgnd music
//sound_channel1.play(50);
//reset lamps
reset_lamps();
//update lamps for features
update_blastoff_lamps();
update_spinner_lamps();
update_special_lamps();
update_bonus_mult_lamps(bonus_mult[active_player_id]);
update_bonus_lamps(bonus_count[active_player_id]);
update_apollo_lamps();
//turn on ball in play lamp
lamp_match.on(0);
trough_mech_handler(0); // Start ball
// If this is the last ball for the player, briefly display the high score on all the displays
if (ball_num[active_player_id] == balls_per_game)
{
show_high_scores(high_score);
mhs_delay(2000);
update_display();
}
ball_in_play = true;
//flash current players score
flash_display(active_player_id);
//update bip to display
update_credit_display();
}
void end_ball()
{
Serial.print(F("Ball Ended 1 : Ball number is "));
Serial.println(ball_num[active_player_id], DEC);
Serial.print(F("Ball Ended 1 : Balls per game is "));
Serial.println(balls_per_game, DEC);
Serial.print(F("Ball Ended 1 : Extra balls is "));
Serial.println(extra_balls, DEC);
Serial.print(F("Ball Ended 1 : Active player id is "));
Serial.println(active_player_id, DEC);
Serial.print(F("Ball Ended 1 : Number of players is "));
Serial.println(num_of_players, DEC);
ball_in_play = false; //update flag
//play end of ball music
sound_channel1.play(51);
//turn off ball in play lamp
lamp_match.off();
left_flipper_coil.cancel();
right_flipper_coil.cancel();
//wait
delay(2000);
//run bonus
count_bonus();
//end of ball logic
if (ball_num[active_player_id] == balls_per_game && num_of_players - 1 == active_player_id && extra_balls == 0) //all balls played, time to end game
{
end_game();
}
else //progress game to next ball
{
// Only move to the next player if we're not going to run an extra ball for the same player
if (extra_balls == 0)
{
//update the active player
if (num_of_players - 1 > active_player_id)
{
active_player_id += 1;
}
else if (num_of_players - 1 == active_player_id)
{
active_player_id = 0;
}
}
Serial.print(F("Ball Ended 2 : Ball number is "));
Serial.println(ball_num[active_player_id], DEC);
Serial.print(F("Ball Ended 2 : Balls per game is "));
Serial.println(balls_per_game, DEC);
Serial.print(F("Ball Ended 2 : Extra balls is "));
Serial.println(extra_balls, DEC);
Serial.print(F("Ball Ended 2 : Active player id is "));
Serial.println(active_player_id, DEC);
Serial.print(F("Ball Ended 2 : Number of players is "));
Serial.println(num_of_players, DEC);
start_ball();
}
}
void ball_save_loop()
{
if (ball_save_enabled and player_score[active_player_id] > 0)
{
if (!ball_save_active_flag) //first run , set the flags and lamp
{
ball_save_reference_timer_store = millis();
ball_save_active_flag = true;
lamp_shoot_again.flash(50, 0);
}
ball_save_current_timer_store = millis();
if ((ball_save_current_timer_store - ball_save_reference_timer_store) > ball_save_time * 1000 and ball_save_active_flag) // check for ball save deactivation
{
ball_save_disable();
}
}
}
void ball_save_disable()
{
Serial.println(F("Ball Save : Disabled"));
ball_save_active_flag = false;
ball_save_enabled = false;
lamp_shoot_again.off();
}
//------------------