Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / Creep.cxx
blob100132ab7a054a880a271e7dc0e2a4cf8e4eae5b
1 /*
2 * Creep.cxx
3 * Daniel Nelson - 8/25/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
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
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
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?
32 #include "Creep.h"
34 #include "Game.h"
35 #include "Grid.h"
36 #include "BlockManager.h"
37 #include "Controller.h"
38 #include "ComboManager.h"
39 #include "Displayer.h"
40 #include "LevelLights.h"
41 #include "LoseBar.h"
44 int Creep::creep;
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;
50 bool Creep::advance;
52 void Creep::gameStart ( )
54 creep = 0;
56 creep_timer_step = GC_CREEP_INITIAL_TIMER_STEP;
57 creep_timer = 0;
59 increase_velocity_alarm = Game::time_step + GC_CREEP_INCREMENT_DELAY;
61 creep_freeze = false;
63 advance = false;
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;
75 else {
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
84 if (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();
92 // check to end it
93 if (!Grid::checkSafeHeightViolation())
94 creep_freeze = false;
97 return;
100 // if we're in a creep freeze
101 if (creep_freeze) {
103 // check to end it
104 if (!Grid::checkSafeHeightViolation())
105 creep_freeze = false;
107 else {
108 // check for game loss
109 if (--loss_alarm == 0)
110 Game::loss();
112 // and don't creep
113 return;
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
119 creep_freeze = true;
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;
127 else
128 creep_timer += creep_timer_step;
129 advance = true;
130 } else
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
138 if (!advance)
139 creep++;
141 // if we're going to creep fast
142 else {
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) {
150 creep = 0;
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
164 } else {
165 creep_timer += GC_CREEP_DELAY;
166 creep = GC_STEPS_PER_GRID - 1;
169 if (advance && !Controller::advanceCommand())
170 advance = false;