3 * Daniel Nelson - 8/25/0
5 * Copyright (C) 2000 Daniel Nelson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
25 * Handles the upward creepiness of the game.
27 * How to we do a creep roll over? Right now we do a big copy up. We could use
28 * a rolling data structure, but the question is, would the time saved here be
29 * worth the extra dereference we'd have to do each time we access the grid?
35 #include "BlockManager.h"
36 #include "Controller.h"
37 #include "ComboManager.h"
38 #include "Displayer.h"
39 #include "LevelLights.h"
45 int Creep::creep_timer_step
;
46 int Creep::creep_timer
;
47 int Creep::increase_velocity_alarm
;
48 int Creep::loss_alarm
;
49 bool Creep::creep_freeze
;
52 void Creep::gameStart ( )
56 creep_timer_step
= GC_CREEP_INITIAL_TIMER_STEP
;
59 increase_velocity_alarm
= Game::time_step
+ GC_CREEP_INCREMENT_DELAY
;
65 BlockManager::newCreepRow();
68 void Creep::timeStep ( )
70 // if it's time to increase the creep speed
71 if (increase_velocity_alarm
== Game::time_step
) {
73 if (creep_timer_step
== GC_CREEP_MAX_TIMER_STEP
)
74 increase_velocity_alarm
= 0;
76 increase_velocity_alarm
= Game::time_step
+ GC_CREEP_INCREMENT_DELAY
;
77 creep_timer_step
+= GC_CREEP_TIMER_STEP_INCREMENT
;
81 // no creeping when awaking or dying; not a true creep freeze
82 if (Game::awaking_count
!= 0 || Game::dying_count
!= 0) {
83 // if we're in a creep freeze
86 // you can't lose within a certain delay of your last elimination
87 if (loss_alarm
< GC_LOSS_DELAY_ELIMINATION
) {
88 loss_alarm
= GC_LOSS_DELAY_ELIMINATION
;
89 LoseBar::highAlertReset();
93 if (!Grid::checkSafeHeightViolation())
100 // if we're in a creep freeze
104 if (!Grid::checkSafeHeightViolation())
105 creep_freeze
= false;
108 // check for game loss
109 if (--loss_alarm
== 0)
116 // check to see if we're pushing against GC_SAFE_HEIGHT
117 } else if (Grid::checkSafeHeightViolation()) {
118 // freeze the creep for one creap cycle
120 loss_alarm
= GC_LOSS_DELAY
;
121 LevelLights::notifySafeHeightViolation();
124 if (advance
|| Controller::advanceCommand()) {
125 if (creep_timer_step
< GC_CREEP_ADVANCE_TIMER_STEP
)
126 creep_timer
+= GC_CREEP_ADVANCE_TIMER_STEP
;
128 creep_timer
+= creep_timer_step
;
131 creep_timer
+= creep_timer_step
;
133 // if it's time to creep
134 while (creep_timer
>= GC_CREEP_DELAY
) {
135 creep_timer
-= GC_CREEP_DELAY
;
137 // otherwise, creep as normal
141 // if we're going to creep fast
143 creep
+= GC_CREEP_ADVANCE_VELOCITY
;
144 if (creep
> GC_STEPS_PER_GRID
)
145 creep
= GC_STEPS_PER_GRID
;
148 // if we've completed a grid of creeping
149 if (creep
== GC_STEPS_PER_GRID
) {
152 // shift everything up one grid
153 if (Grid::shiftGridUp()) {
155 // create a new bottom row
156 BlockManager::newCreepRow();
158 // link the elimination requests
159 ComboTabulator
&combo
= ComboManager::newComboTabulator();
160 for (int x
= GC_PLAY_WIDTH
; x
--; )
161 Grid::requestEliminationCheck(Grid::blockAt(x
, 1), &combo
);
163 // if we can't shift up, don't; but try again next time
165 creep_timer
+= GC_CREEP_DELAY
;
166 creep
= GC_STEPS_PER_GRID
- 1;
169 if (advance
&& !Controller::advanceCommand())