• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrrunner.cpp
Go to the documentation of this file.
1 #include "kgrdebug.h"
2 
3 /****************************************************************************
4  * Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18  ****************************************************************************/
19 
20 #include "kgrrunner.h"
21 #include "kgrlevelgrid.h"
22 #include "kgrrulebook.h"
23 #include "kgrlevelplayer.h"
24 
25 #include <KDebug>
26 
27 KGrRunner::KGrRunner (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
28  int i, int j, const int pSpriteId,
29  KGrRuleBook * pRules, const int startDelay)
30  :
31  QObject (pLevelPlayer), // Destroy runner when level is destroyed.
32  levelPlayer (pLevelPlayer),
33  grid (pGrid),
34  rules (pRules),
35  spriteId (pSpriteId),
36  gridI (i),
37  gridJ (j),
38  deltaX (0),
39  deltaY (0),
40  pointCtr (0),
41  falling (false),
42 
43  currDirection (STAND),
44  currAnimation (FALL_L),
45 
46  // The start delay is zero for the hero and 50 msec for the enemies. This
47  // gives the hero about one grid-point advantage. Without this lead, some
48  // levels become impossible, notably Challenge, 4, "Quick Off The Mark" and
49  // Curse of the Mummy, 20, "The Parting of the Red Sea".
50  timeLeft (TickTime + startDelay),
51 
52  leftRightSearch (true)
53 {
54  getRules();
55 
56  gridX = i * pointsPerCell;
57  gridY = j * pointsPerCell;
58 
59  // As soon as the initial timeLeft has expired (i.e. at the first tick in
60  // the hero's case and after a short delay in the enemies' case), the
61  // pointCtr will reach its maximum, the EndCell situation will occur and
62  // each runner will look for a new direction and head that way if he can.
63  pointCtr = pointsPerCell - 1;
64 
65  dbgLevel = 0;
66 }
67 
68 KGrRunner::~KGrRunner()
69 {
70 }
71 
72 void KGrRunner::getRules()
73 {
74  pointsPerCell = rules->pointsPerCell();
75  turnAnywhere = rules->turnAnywhere();
76  if (spriteId < 1) {
77  kDebug() << "pointsPerCell" << pointsPerCell
78  << "turnAnywhere" << turnAnywhere;
79  }
80 }
81 
82 Situation KGrRunner::situation (const int scaledTime)
83 {
84  timeLeft -= scaledTime;
85  if (timeLeft >= scaledTime) {
86  dbe3 "%d sprite %02d scaled %02d timeLeft %03d - Not Time Yet\n",
87  pointCtr, spriteId, scaledTime, timeLeft);
88  return NotTimeYet;
89  }
90 
91  if (grid->cellType (gridI, gridJ) == BRICK) {
92  dbe2 "%d sprite %02d scaled %02d timeLeft %03d - Caught in brick\n",
93  pointCtr, spriteId, scaledTime, timeLeft);
94  return CaughtInBrick;
95  }
96 
97  gridX += deltaX;
98  gridY += deltaY;
99  pointCtr++;
100 
101  if (pointCtr < pointsPerCell) {
102  timeLeft += interval;
103  dbe2 "%d sprite %02d scaled %02d timeLeft %03d - Mid Cell\n",
104  pointCtr, spriteId, scaledTime, timeLeft);
105  return MidCell;
106  }
107 
108  dbe2 "%d sprite %02d scaled %02d timeLeft %03d - END Cell\n",
109  pointCtr, spriteId, scaledTime, timeLeft);
110  return EndCell;
111 }
112 
113 char KGrRunner::nextCell()
114 {
115  pointCtr = 0;
116  gridI = gridX / pointsPerCell;
117  gridJ = gridY / pointsPerCell;
118  return grid->cellType (gridI, gridJ);
119 }
120 
121 bool KGrRunner::setNextMovement (const char spriteType, const char cellType,
122  Direction & dir,
123  AnimationType & anim, int & interval)
124 {
125  bool fallingState = false;
126 
127  Flags OK = 0;
128  if (spriteType == HERO) {
129  dir = levelPlayer->getDirection (gridI, gridJ);
130  OK = grid->heroMoves (gridI, gridJ);
131  }
132  else {
133  dir = levelPlayer->getEnemyDirection (gridI, gridJ, leftRightSearch);
134  OK = grid->enemyMoves (gridI, gridJ);
135  }
136  if ((dir >= nDirections) || (dir < 0)) {
137  dir = STAND; // Make sure indices stay within range.
138  }
139 
140  if (dir == STAND) {
141  anim = currAnimation;
142  }
143  else {
144  anim = aType [dir];
145  }
146  if (((anim == RUN_R) || (anim == RUN_L)) && (cellType == BAR)) {
147  anim = (dir == RIGHT) ? CLIMB_R : CLIMB_L;
148  }
149 
150  interval = runTime;
151 
152  KGrEnemy * onEnemy = levelPlayer->standOnEnemy (spriteId, gridX, gridY);
153  bool canStand = (OK & dFlag [STAND]) || (OK == 0) || onEnemy;
154  if ((dir == DOWN) && (cellType == BAR)) {
155  canStand = false;
156  }
157  bool cannotMoveAsRequired = (! (OK & dFlag [dir]));
158 
159  // TODO - Check that the trap time is the same as in KGr 3.0.
160  // TODO - We seem to be early getting into/out of the hole, but
161  // the captive time is now OK. Total t down by ~100 in 4400.
162  if ((spriteType == ENEMY) && (cellType == USEDHOLE)) {
163  // The enemy is in a hole.
164  if (currDirection == DOWN) {
165  // The enemy is at the bottom of the hole: start the captive-timer.
166  dir = STAND;
167  anim = currAnimation;
168  interval = trapTime;
169  dbe1 "T %05d id %02d Captive at [%02d,%02d]\n",
170  t.elapsed(), spriteId, gridI, gridJ);
171  }
172  else {
173  // The enemy can start climbing out after a cycle of captive-times.
174  dir = UP;
175  anim = CLIMB_U;
176  dbe1 "T %05d id %02d Start climb out at [%02d,%02d]\n",
177  t.elapsed(), spriteId, gridI, gridJ);
178  }
179  }
180  else if ((! canStand) ||
181  (onEnemy && (onEnemy->isFalling()) && cannotMoveAsRequired)) {
182  // Must fall: cannot even walk left or right off an enemy's head here.
183  fallingState = true;
184  interval = onEnemy ? enemyFallTime : fallTime;
185  dir = DOWN;
186  anim = (falling) ? currAnimation :
187  ((currDirection == RIGHT) ? FALL_R : FALL_L);
188  }
189  else if (cannotMoveAsRequired) {
190  // Sprite cannot move, but the animation shows the desired direction.
191  dir = STAND;
192  }
193 
194  return fallingState;
195 }
196 
197 
198 KGrHero::KGrHero (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
199  int i, int j, int pSpriteId, KGrRuleBook * pRules)
200  :
201  KGrRunner (pLevelPlayer, pGrid, i, j, pSpriteId, pRules, 0),
202  nuggets (0) // KGrLevelPlayer object will call hero->setNuggets().
203 {
204  kDebug() << "THE HERO IS BORN at" << i << j << "sprite ID" << pSpriteId;
205  rules->getHeroTimes (runTime, fallTime, enemyFallTime, trapTime);
206  kDebug() << "Hero run time" << runTime << "fall time" << fallTime;
207  interval = runTime;
208 }
209 
210 KGrHero::~KGrHero()
211 {
212 }
213 
214 HeroStatus KGrHero::run (const int scaledTime)
215 {
216  Situation s = situation (scaledTime);
217  if (s == NotTimeYet) {
218  return NORMAL;
219  }
220 
221  // Die if a brick has closed over us.
222  if (s == CaughtInBrick) {
223  return DEAD;
224  }
225 
226  // If standing on top row and all nuggets gone, go up a level.
227  if ((gridJ == 1) && (nuggets <= 0) &&
228  (grid->heroMoves (gridI, gridJ) & dFlag [STAND])) {
229  return WON_LEVEL;
230  }
231 
232  // Check if we have fallen onto an enemy. If so, continue at enemy-speed.
233  if (falling && (interval != enemyFallTime)) {
234  if (levelPlayer->standOnEnemy (spriteId, gridX, gridY)) {
235  interval = enemyFallTime;
236  // If MidCell, hero-speed animation overshoots, but looks OK.
237  }
238  }
239 
240  // We need to check collision with enemies on every grid-point.
241  if (levelPlayer->heroCaught (gridX, gridY)) {
242  return DEAD;
243  }
244 
245  // Emit StepSound once per cell or ClimbSound twice per cell.
246  if (((s == EndCell) || (pointCtr == (pointsPerCell/2))) &&
247  (currDirection != STAND) && (! falling)) {
248  int step = ((currAnimation == RUN_R) || (currAnimation == RUN_L)) ?
249  StepSound : ClimbSound;
250  if ((s == EndCell) || (step == ClimbSound)) {
251  emit soundSignal (step);
252  }
253  }
254 
255  if (s == MidCell) {
256  return NORMAL;
257  }
258 
259  // Continue to the next cell.
260  char cellType = nextCell();
261 
262  if (cellType == NUGGET) {
263  nuggets = levelPlayer->runnerGotGold (spriteId, gridI, gridJ, true);
264  emit incScore (250); // Add to the human player's score.
265  if (nuggets > 0) {
266  emit soundSignal (GoldSound);
267  }
268  else {
269  emit soundSignal (LadderSound);
270  }
271  }
272 
273  Direction nextDirection;
274  AnimationType nextAnimation;
275  bool newFallingState = setNextMovement (HERO, cellType, nextDirection,
276  nextAnimation, interval);
277  if (newFallingState != falling) {
278  emit soundSignal (FallSound, newFallingState); // Start/stop falling.
279  falling = newFallingState;
280  }
281  timeLeft += interval;
282  dbe2 "%d sprite %02d [%02d,%02d] timeLeft %03d currDir %d nextDir %d "
283  "currAnim %d nextAnim %d\n",
284  pointCtr, spriteId, gridI, gridJ, timeLeft, currDirection, nextDirection,
285  currAnimation, nextAnimation);
286 
287  if ((nextDirection == currDirection) && (nextAnimation == currAnimation)) {
288  if (nextDirection == STAND) {
289  return NORMAL;
290  }
291  }
292 
293  deltaX = movement [nextDirection][X];
294  deltaY = movement [nextDirection][Y];
295 
296  // Start the running animation (repeating).
297  emit startAnimation (spriteId, true, gridI, gridJ,
298  (interval * pointsPerCell * TickTime) / scaledTime,
299  nextDirection, nextAnimation);
300  currAnimation = nextAnimation;
301  currDirection = nextDirection;
302  return NORMAL;
303 }
304 
305 bool KGrHero::dig (const Direction diggingDirection, int & i, int & j)
306 {
307  QString text = (diggingDirection == DIG_LEFT) ? "LEFT" : "RIGHT";
308  // kDebug() << "Start digging" << text;
309 
310  Flags moves = grid->heroMoves (gridI, gridJ);
311  bool result = false;
312 
313  // If currDirection is UP, DOWN or STAND, dig next cell left or right.
314  int relativeI = (diggingDirection == DIG_LEFT) ? -1 : +1;
315 
316  if ((currDirection == LEFT) && (moves & dFlag [LEFT])) {
317  // Running LEFT, so stop at -1: dig LEFT at -2 or dig RIGHT right here.
318  relativeI = (diggingDirection == DIG_LEFT) ? -2 : 0;
319  }
320  else if ((currDirection == RIGHT) && (moves & dFlag [RIGHT])) {
321  // Running RIGHT, so stop at +1: dig LEFT right here or dig RIGHT at -2.
322  relativeI = (diggingDirection == DIG_LEFT) ? 0 : +2;
323  }
324 
325  // The place to dig must be clear and there must be a brick under it.
326  char aboveBrick = grid->cellType (gridI + relativeI, gridJ);
327  // kDebug() << "aboveBrick =" << aboveBrick;
328  if ((grid->cellType (gridI + relativeI, gridJ + 1) == BRICK) &&
329  ((aboveBrick == FREE) || (aboveBrick == HOLE))) {
330 
331  // You can dig under an enemy, empty space or hidden ladder, but not a
332  // trapped enemy, ladder, gold, bar, brick, concrete or false brick.
333  i = gridI + relativeI;
334  j = gridJ + 1;
335  result = true;
336  }
337  if (result) {
338  emit soundSignal (DigSound);
339  }
340 
341  return result; // Tell the levelPlayer whether & where to open a hole.
342 }
343 
344 void KGrHero::showState()
345 {
346  fprintf (stderr, "(%02d,%02d) %02d Hero ", gridI, gridJ, spriteId);
347  fprintf (stderr, " gold %02d dir %d ctr %d",
348  nuggets, currDirection, pointCtr);
349  fprintf (stderr, " X %3d Y %3d anim %d dt %03d\n",
350  gridX, gridY, currAnimation, interval);
351 }
352 
353 
354 KGrEnemy::KGrEnemy (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
355  int i, int j, int pSpriteId, KGrRuleBook * pRules)
356  :
357  KGrRunner (pLevelPlayer, pGrid, i, j, pSpriteId, pRules, 50),
358  nuggets (0),
359  birthI (i),
360  birthJ (j),
361  prevInCell (-1)
362 {
363  rulesType = rules->getEnemyTimes (runTime, fallTime, trapTime);
364  enemyFallTime = fallTime;
365  interval = runTime;
366  kDebug() << "ENEMY" << pSpriteId << "IS BORN at" << i << j;
367  if (pSpriteId < 2) {
368  kDebug() << "Enemy run time " << runTime << "fall time" << fallTime;
369  kDebug() << "Enemy trap time" << trapTime << "Rules type" << rulesType;
370  }
371  t.start(); // IDW
372 }
373 
374 KGrEnemy::~KGrEnemy()
375 {
376 }
377 
378 void KGrEnemy::run (const int scaledTime)
379 {
380  Situation s = situation (scaledTime);
381  if (s == NotTimeYet) {
382  return;
383  }
384 
385  // Die if a brick has closed over us.
386  if (s == CaughtInBrick) {
387  releaseCell (gridI + deltaX, gridJ + deltaY);
388  emit incScore (75); // Killed: add to the player's score.
389  dbe1 "T %05d id %02d Died in brick at [%02d,%02d]\n",
390  t.elapsed(), spriteId, gridI, gridJ);
391  dieAndReappear(); // Move to a new (gridI, gridJ).
392  reserveCell (gridI, gridJ);
393  // Go to next cell, with s = CaughtInBrick, thus forcing re-animation.
394  }
395 
396  else if ((pointCtr == 1) && (currDirection == DOWN) &&
397  (grid->cellType (gridI, gridJ + 1) == HOLE)) {
398  // Enemy is starting to fall into a hole.
399  dbe1 "T %05d id %02d Mark hole [%02d,%02d] as used\n",
400  t.elapsed(), spriteId, gridI, gridJ+1);
401  grid->changeCellAt (gridI, gridJ + 1, USEDHOLE);
402  dropGold();
403  emit incScore (75); // Trapped: add to the player's score.
404  return;
405  }
406 
407  // Wait till end of cell.
408  else if (s == MidCell) {
409  if (grid->cellType (gridI, gridJ) == USEDHOLE) {
410  dbe1 "T %05d id %02d Stay captive at [%02d,%02d] count %d\n",
411  t.elapsed(), spriteId, gridI, gridJ, pointCtr);
412  }
413  return;
414  }
415 
416  // Continue to the next cell.
417  char cellType = nextCell();
418 
419  // Try to pick up or drop gold in the new cell.
420  if (currDirection != STAND) {
421  checkForGold();
422  }
423 
424  // Find the next move that could lead to the hero.
425  Direction nextDirection;
426  AnimationType nextAnimation;
427  bool fallingState = setNextMovement (ENEMY, cellType, nextDirection,
428  nextAnimation, interval);
429  dbe3 "\n");
430 
431  // If the enemy just left a hole, change it to empty. Must execute this
432  // code AFTER finding the next direction and valid moves, otherwise the
433  // enemy will just fall back into the hole again.
434  if ((currDirection == UP) &&
435  (grid->cellType (gridI, gridJ + 1) == USEDHOLE)) {
436  dbk3 << spriteId << "Hole emptied at" << gridI << (gridJ + 1);
437  // Empty the hole, provided it had not somehow caught two enemies.
438  if (grid->enemyOccupied (gridI, gridJ + 1) < 0) {
439  grid->changeCellAt (gridI, gridJ + 1, HOLE);
440  }
441  }
442 
443  dbe2 "%d sprite %02d [%02d,%02d] timeLeft %03d currDir %d nextDir %d "
444  "currAnim %d nextAnim %d\n",
445  pointCtr, spriteId, gridI, gridJ, timeLeft,
446  currDirection, nextDirection, currAnimation, nextAnimation);
447 
448  if (fallingState != falling) {
449  falling = fallingState;
450  if (falling) {
451  t.restart();
452  dbe1 "T %05d id %02d Start falling\n", t.elapsed(), spriteId);
453  }
454  }
455 
456  // Check for a possible collision with another enemy.
457  if (levelPlayer->bumpingFriend (spriteId, nextDirection, gridI, gridJ)) {
458  nextDirection = STAND; // Wait for one timer interval.
459  pointCtr = pointsPerCell - 1; // Try again after the interval.
460  }
461 
462  if ((rulesType == KGoldrunnerRules) && (nextDirection == STAND) &&
463  (cellType != USEDHOLE)) {
464  // In KGoldrunner rules, if unable to move, switch the search direction.
465  leftRightSearch = (leftRightSearch) ? false : true;
466  pointCtr = pointsPerCell - 1;
467  }
468 
469  timeLeft += interval;
470  deltaX = movement [nextDirection][X];
471  deltaY = movement [nextDirection][Y];
472 
473  // If moving, occupy the next cell in the enemy's path and release this one.
474  if (nextDirection != STAND) {
475  // If multiple enemies move into a cell, they stack. Each enemy uses
476  // nextInCell to remember the ID of the enemy beneath it (or -1). The
477  // top enemy is remembered by grid->setEnemyOccupied().
478  //
479  // NOTE: In Scavenger rules, multiple enemies can fall or climb into a
480  // a cell, but should keep to one per cell if moving horizontally. In
481  // Traditional or KGoldrunner rules, it should not be possible for
482  // multiple enemies to enter a cell, but anomalies can happen, so a
483  // stack is used to record them temporarily and split them up again.
484 
485  releaseCell (gridI, gridJ);
486 
487  int nextI = gridI + deltaX;
488  int nextJ = gridJ + deltaY;
489  reserveCell (nextI, nextJ);
490  }
491 
492  if ((nextDirection == currDirection) && (nextAnimation == currAnimation)) {
493  if ((nextDirection == STAND) && (s != CaughtInBrick)) {
494  // In the CaughtInBrick situation, enemy sprites must not be shown
495  // standing in the bricks where they died: we must re-animate them.
496  return;
497  }
498  }
499 
500  // Start the running animation (repeating).
501  emit startAnimation (spriteId, true, gridI, gridJ,
502  (interval * pointsPerCell * TickTime) / scaledTime,
503  nextDirection, nextAnimation);
504  currAnimation = nextAnimation;
505  currDirection = nextDirection;
506 }
507 
508 void KGrEnemy::dropGold()
509 {
510  if (nuggets > 0) {
511  // If enemy is trapped when carrying gold, he must give it up.
512  nuggets = 0;
513  // Can drop in an empty cell, otherwise it is lost (no score for hero).
514  bool lost = (grid->cellType (gridI, gridJ) != FREE);
515  levelPlayer->runnerGotGold (spriteId, gridI, gridJ, false, lost);
516  }
517 }
518 
519 void KGrEnemy::checkForGold()
520 {
521  char cell = grid->cellType (gridI, gridJ);
522  uchar random;
523  if ((nuggets == 0) && (cell == NUGGET)) {
524  bool collect = rules->alwaysCollectNugget();
525  if (! collect) {
526  random = levelPlayer->randomByte ((uchar) 100);
527  dbk3 << "Random" << random << "at NUGGET" << gridI << gridJ;
528  collect = (random >= 80);
529  }
530  if (collect) {
531  levelPlayer->runnerGotGold (spriteId, gridI, gridJ, true);
532  dbk1 << "Enemy" << spriteId << "at" << gridI << gridJ
533  << "COLLECTS gold";
534  nuggets = 1;
535  }
536  }
537  else if ((nuggets > 0) && (cell == FREE)) {
538  // Dropping gold is a random choice, but do not drop in thin air.
539  char below = grid->cellType (gridI, gridJ + 1);
540  if ((below != FREE) && (below != NUGGET) && (below != BAR)) {
541  random = levelPlayer->randomByte ((uchar) 100);
542  dbk3 << "Random" << random << "for DROP " << gridI << gridJ;
543  if (random >= 93) {
544  levelPlayer->runnerGotGold (spriteId, gridI, gridJ, false);
545  dbk1 << "Enemy" << spriteId << "at" << gridI << gridJ
546  <<"DROPS gold";
547  nuggets = 0;
548  }
549  }
550  }
551 }
552 
553 void KGrEnemy::dieAndReappear()
554 {
555  if (nuggets > 0) {
556  // Enemy died and could not drop nugget. Gold is LOST - no score.
557  nuggets = 0; // Set lost-flag in runnerGotGold().
558  levelPlayer->runnerGotGold (spriteId, gridI, gridJ, false, true);
559  }
560 
561  if (rules->reappearAtTop()) {
562  // Traditional or Scavenger rules.
563  dbk3 << spriteId << "REAPPEAR AT TOP";
564  levelPlayer->enemyReappear (gridI, gridJ);
565  }
566  else {
567  // KGoldrunner rules.
568  dbk3 << spriteId << "REAPPEAR AT BIRTHPLACE";
569  gridI = birthI;
570  gridJ = birthJ;
571  }
572 
573  // Set up the enemy's state so as to be ready for moving to the next cell.
574 
575  // There is no time-delay and no special animation here, though there was
576  // in the Apple II game and there is in Scavenger. KGoldrunner has never
577  // had a time-delay here, which makes KGoldrunner more difficult sometimes.
578  gridX = gridI * pointsPerCell;
579  gridY = gridJ * pointsPerCell;
580  deltaX = 0;
581  deltaY = 0;
582  pointCtr = pointsPerCell;
583  falling = false;
584  interval = runTime;
585  timeLeft = TickTime;
586  currDirection = STAND;
587  currAnimation = FALL_L;
588 }
589 
590 void KGrEnemy::reserveCell (const int i, const int j)
591 {
592  // Push down a previous enemy or -1 if the cell was empty.
593  prevInCell = grid->enemyOccupied (i, j);
594  grid->setEnemyOccupied (i, j, spriteId);
595  dbe3 "%02d Entering [%02d,%02d] pushes %02d\n", spriteId, i, j, prevInCell);
596 }
597 
598 void KGrEnemy::releaseCell (const int i, const int j)
599 {
600  // Pop up a previous enemy or -1 if the cell was empty.
601  if (spriteId == grid->enemyOccupied (i, j)) {
602  grid->setEnemyOccupied (i, j, prevInCell);
603  }
604  else {
605  levelPlayer->unstackEnemy (spriteId, i, j, prevInCell);
606  }
607  dbe3 "%02d Leaves [%02d,%02d] to %02d\n", spriteId, i, j, prevInCell);
608 }
609 
610 void KGrEnemy::showState()
611 {
612  fprintf (stderr, "(%02d,%02d) %02d Enemy", gridI, gridJ, spriteId);
613  fprintf (stderr, " gold %02d dir %d ctr %d",
614  nuggets, currDirection, pointCtr);
615  fprintf (stderr, " X %3d Y %3d anim %d dt %03d prev %d\n",
616  gridX, gridY, currAnimation, interval, prevInCell);
617 }
618 
619 #include "kgrrunner.moc"
KGrHero::KGrHero
KGrHero(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, int pSpriteId, KGrRuleBook *pRules)
The constructor of the KGrHero class.
Definition: kgrrunner.cpp:198
KGrLevelPlayer::unstackEnemy
void unstackEnemy(const int spriteId, const int gridI, const int gridJ, const int prevEnemy)
Helper function to remove an enemy from among several stacked in a cell.
Definition: kgrlevelplayer.cpp:728
HeroStatus
HeroStatus
Definition: kgrglobals.h:219
KGrRunner::turnAnywhere
bool turnAnywhere
Definition: kgrrunner.h:111
KGrLevelPlayer::heroCaught
bool heroCaught(const int heroX, const int heroY)
Helper function to determine whether the hero has collided with an enemy and must lose a life (unless...
Definition: kgrlevelplayer.cpp:632
KGrLevelPlayer::enemyReappear
void enemyReappear(int &gridI, int &gridJ)
Helper function to determine where an enemy should reappear after being trapped in a brick...
Definition: kgrlevelplayer.cpp:880
dbe1
#define dbe1
Definition: kgrdebug.h:34
KGrRunner::t
QTime t
Definition: kgrrunner.h:137
kgrdebug.h
KGrLevelGrid::enemyOccupied
int enemyOccupied(int i, int j)
Definition: kgrlevelgrid.h:50
KGrLevelGrid::heroMoves
Flags heroMoves(int i, int j)
Definition: kgrlevelgrid.h:38
BAR
const char BAR
Definition: kgrglobals.h:39
KGrRunner::trapTime
int trapTime
Definition: kgrrunner.h:129
FALL_L
Definition: kgrglobals.h:207
KGrLevelGrid::cellType
char cellType(int i, int j)
Definition: kgrlevelgrid.h:34
KGrRunner::getRules
void getRules()
Definition: kgrrunner.cpp:72
dbk3
#define dbk3
Definition: kgrdebug.h:26
KGrHero::soundSignal
void soundSignal(const int n, const bool onOff=true)
KGrLevelPlayer
Class to play, record and play back a level of a game.
Definition: kgrlevelplayer.h:65
KGrLevelGrid
Definition: kgrlevelgrid.h:27
kgrlevelgrid.h
TickTime
const int TickTime
Definition: kgrglobals.h:217
Situation
Situation
Definition: kgrrunner.h:30
KGrRunner::pointCtr
int pointCtr
Definition: kgrrunner.h:109
RUN_L
Definition: kgrglobals.h:204
HERO
const char HERO
Definition: kgrglobals.h:31
KGrRuleBook::alwaysCollectNugget
bool alwaysCollectNugget() const
Definition: kgrrulebook.h:38
KGrEnemy::KGrEnemy
KGrEnemy(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, int pSpriteId, KGrRuleBook *pRules)
The constructor of the KGrEnemy class.
Definition: kgrrunner.cpp:354
KGrLevelPlayer::runnerGotGold
int runnerGotGold(const int spriteId, const int i, const int j, const bool hasGold, const bool lost=false)
Helper function for an enemy to pick up or drop gold or the hero to collect gold. ...
Definition: kgrlevelplayer.cpp:820
NORMAL
Definition: kgrglobals.h:220
KGrRuleBook::getHeroTimes
void getHeroTimes(int &runTime, int &fallTime, int &enemyFallTime, int &trapTime)
Definition: kgrrulebook.h:48
KGrEnemy::isFalling
bool isFalling()
Returns true if the enemy is falling.
Definition: kgrrunner.h:292
kgrrulebook.h
DIG_LEFT
Definition: kgrglobals.h:175
WON_LEVEL
Definition: kgrglobals.h:220
KGrRunner::enemyFallTime
int enemyFallTime
Definition: kgrrunner.h:128
CLIMB_U
Definition: kgrglobals.h:206
dbe2
#define dbe2
Definition: kgrdebug.h:35
KGrRunner::pointsPerCell
int pointsPerCell
Definition: kgrrunner.h:110
KGrLevelGrid::enemyMoves
Flags enemyMoves(int i, int j)
Definition: kgrlevelgrid.h:42
RUN_R
Definition: kgrglobals.h:204
dbgLevel
static int dbgLevel
Definition: kgrdebug.h:21
KGrRunner::runTime
int runTime
Definition: kgrrunner.h:126
KGrRunner::gridI
int gridI
Definition: kgrrunner.h:102
KGrLevelPlayer::bumpingFriend
bool bumpingFriend(const int spriteId, const Direction dirn, const int gridI, const int gridJ)
Helper function to determine whether an enemy is colliding with another enemy.
Definition: kgrlevelplayer.cpp:672
USEDHOLE
const char USEDHOLE
Definition: kgrglobals.h:41
KGrRunner::grid
KGrLevelGrid * grid
Definition: kgrrunner.h:97
CLIMB_R
Definition: kgrglobals.h:205
kgrlevelplayer.h
KGrLevelGrid::changeCellAt
void changeCellAt(const int i, const int j, const char type)
Definition: kgrlevelgrid.cpp:113
Direction
Direction
Definition: kgrglobals.h:174
LEFT
Definition: kgrglobals.h:174
X
Definition: kgrglobals.h:187
QTime::elapsed
int elapsed() const
KGrLevelGrid::setEnemyOccupied
void setEnemyOccupied(int i, int j, const int spriteId)
Definition: kgrlevelgrid.h:54
MidCell
Definition: kgrrunner.h:30
StepSound
Definition: kgrglobals.h:70
CaughtInBrick
Definition: kgrrunner.h:30
NUGGET
const char NUGGET
Definition: kgrglobals.h:37
KGrRuleBook::reappearAtTop
bool reappearAtTop() const
Definition: kgrrulebook.h:40
kgrrunner.h
KGrRunner::~KGrRunner
virtual ~KGrRunner()
Definition: kgrrunner.cpp:68
KGrRuleBook
Definition: kgrrulebook.h:30
QObject
KGrRunner::situation
Situation situation(const int scaledTime)
Definition: kgrrunner.cpp:82
KGrHero::run
HeroStatus run(const int scaledTime)
Makes the hero run, under control of a pointer or the keyboard and guided by the layout of the grid...
Definition: kgrrunner.cpp:214
KGrRunner::gridY
int gridY
Definition: kgrrunner.h:105
movement
const int movement[EndDirection][nAxes]
Definition: kgrglobals.h:189
FallSound
Definition: kgrglobals.h:70
KGrRunner::startAnimation
void startAnimation(const int spriteId, const bool repeating, const int i, const int j, const int time, const Direction dirn, const AnimationType type)
Requests the view-object to display an animation of a runner at a particular cell, cancelling and superseding any current animation.
KGrRunner::deltaX
int deltaX
Definition: kgrrunner.h:106
LadderSound
Definition: kgrglobals.h:70
QTime::restart
int restart()
FALL_R
Definition: kgrglobals.h:207
KGrRunner::currDirection
Direction currDirection
Definition: kgrrunner.h:123
Y
Definition: kgrglobals.h:187
QString
KGrRunner::fallTime
int fallTime
Definition: kgrrunner.h:127
KGrLevelPlayer::randomByte
uchar randomByte(const uchar limit)
Helper function to provide enemies with random numbers for reappearing and deciding whether to pick u...
Definition: kgrlevelplayer.cpp:925
KGrRunner::gridX
int gridX
Definition: kgrrunner.h:104
KGrLevelPlayer::getDirection
Direction getDirection(int heroI, int heroJ)
Helper function for the hero to find his next direction when using mouse or touchpad control...
Definition: kgrlevelplayer.cpp:480
nDirections
Definition: kgrglobals.h:174
KGrHero::showState
void showState()
Implements the author's debugging aid that shows the hero's state.
Definition: kgrrunner.cpp:344
KGrRunner::falling
bool falling
Definition: kgrrunner.h:122
dbe3
#define dbe3
Definition: kgrdebug.h:36
ENEMY
const char ENEMY
Definition: kgrglobals.h:29
KGrRunner::KGrRunner
KGrRunner(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, const int pSpriteId, KGrRuleBook *pRules, const int startDelay)
The constructor of the KGrRunner virtual class.
Definition: kgrrunner.cpp:27
KGoldrunnerRules
const char KGoldrunnerRules
Definition: kgrglobals.h:66
BRICK
const char BRICK
Definition: kgrglobals.h:33
KGrRunner
This class provides the shared features of all runners (hero and enemies).
Definition: kgrrunner.h:35
KGrRuleBook::turnAnywhere
bool turnAnywhere() const
Definition: kgrrulebook.h:43
KGrRunner::timeLeft
int timeLeft
Definition: kgrrunner.h:133
UP
Definition: kgrglobals.h:174
EndCell
Definition: kgrrunner.h:30
GoldSound
Definition: kgrglobals.h:70
KGrEnemy::~KGrEnemy
~KGrEnemy()
Definition: kgrrunner.cpp:374
KGrRunner::incScore
void incScore(const int n)
Requests the KGoldrunner game to add to the human player's score.
KGrHero::dig
bool dig(const Direction dirn, int &digI, int &digJ)
Decides whether the hero can dig as is required by pressing a key or a mouse-button.
Definition: kgrrunner.cpp:305
HOLE
const char HOLE
Definition: kgrglobals.h:40
KGrRunner::nextCell
char nextCell()
Definition: kgrrunner.cpp:113
KGrRuleBook::getEnemyTimes
char getEnemyTimes(int &runTime, int &fallTime, int &trapTime)
Definition: kgrrulebook.h:53
KGrRunner::setNextMovement
bool setNextMovement(const char spriteType, const char cellType, Direction &dir, AnimationType &anim, int &interval)
Definition: kgrrunner.cpp:121
DigSound
Definition: kgrglobals.h:70
CLIMB_L
Definition: kgrglobals.h:205
RIGHT
Definition: kgrglobals.h:174
DEAD
Definition: kgrglobals.h:220
QTime::start
void start()
KGrHero::~KGrHero
~KGrHero()
Definition: kgrrunner.cpp:210
NotTimeYet
Definition: kgrrunner.h:30
KGrEnemy::showState
void showState()
Implements the author's debugging aid that shows the enemy's state.
Definition: kgrrunner.cpp:610
OK
Definition: kgrgameio.h:29
dbk1
#define dbk1
Definition: kgrdebug.h:24
Flags
char Flags
Definition: kgrglobals.h:172
KGrEnemy::run
void run(const int scaledTime)
Makes an enemy run, guided by the position of the hero and the layout of the grid.
Definition: kgrrunner.cpp:378
KGrRunner::leftRightSearch
bool leftRightSearch
Definition: kgrrunner.h:135
KGrRunner::rules
KGrRuleBook * rules
Definition: kgrrunner.h:98
KGrLevelPlayer::getEnemyDirection
Direction getEnemyDirection(int enemyI, int enemyJ, bool leftRightSearch)
Helper function for an enemy to find his next direction, based on where the hero is and the search al...
Definition: kgrlevelplayer.cpp:621
KGrRunner::gridJ
int gridJ
Definition: kgrrunner.h:103
KGrRunner::spriteId
int spriteId
Definition: kgrrunner.h:100
KGrRunner::levelPlayer
KGrLevelPlayer * levelPlayer
Definition: kgrrunner.h:96
ClimbSound
Definition: kgrglobals.h:70
STAND
Definition: kgrglobals.h:174
AnimationType
AnimationType
Definition: kgrglobals.h:203
aType
const AnimationType aType[nDirections]
Definition: kgrglobals.h:210
KGrEnemy
This class models the behaviour of an enemy.
Definition: kgrrunner.h:229
DOWN
Definition: kgrglobals.h:174
FREE
const char FREE
Definition: kgrglobals.h:28
KGrRuleBook::pointsPerCell
int pointsPerCell() const
Definition: kgrrulebook.h:42
KGrRunner::deltaY
int deltaY
Definition: kgrrunner.h:107
KGrRunner::interval
int interval
Definition: kgrrunner.h:132
dFlag
const DirectionFlag dFlag[nDirections]
Definition: kgrglobals.h:178
KGrRunner::currAnimation
AnimationType currAnimation
Definition: kgrrunner.h:124
KGrLevelPlayer::standOnEnemy
KGrEnemy * standOnEnemy(const int spriteId, const int x, const int y)
Helper function to determine whether the hero or an enemy is standing on an enemy's head...
Definition: kgrlevelplayer.cpp:652
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal