Commit b57e1fad authored by Ian Wadham's avatar Ian Wadham

Complete the handling of enemy-to-enemy collisions. Complete the handling of...

Complete the handling of enemy-to-enemy collisions.  Complete the handling of gold by enemies, including the lost-gold case.  Add some more API documentation.  Test and debug Traditional rules over about 100 levels.

svn path=/branches/work/kgoldrunner/; revision=938850
parent 4078d305
......@@ -74,9 +74,9 @@ KGoldrunner::KGoldrunner()
}
// This message is to help diagnose distribution or installation problems.
printf
("The games data and handbook should be in the following locations:\n");
printf ("System games: %s\nUser data: %s\nHandbook: %s\n",
fprintf (stderr,
"The games data and handbook should be in the following locations:\n");
fprintf (stderr, "System games: %s\nUser data: %s\nHandbook: %s\n",
systemDataDir.myStr(), userDataDir.myStr(), systemHTMLDir.myStr());
/******************************************************************************/
......@@ -531,7 +531,7 @@ void KGoldrunner::setupActions()
keyControl ("show_positions", i18n ("Show Positions"), Qt::Key_D, S_POSNS);
keyControl ("logging", i18n ("Start Logging"), Qt::Key_G, LOGGING);
keyControl ("show_hero", i18n ("Show Hero"), Qt::Key_R, S_HERO);
keyControl ("show_obj", i18n ("Show Object"), Qt::Key_Question, S_OBJ);
keyControl ("show_obj", i18n ("Show Object"), Qt::Key_Slash, S_OBJ);
keyControl ("show_enemy_0", i18n ("Show Enemy") + '0', Qt::Key_0, ENEMY_0);
keyControl ("show_enemy_1", i18n ("Show Enemy") + '1', Qt::Key_1, ENEMY_1);
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<gui version="8" name="kgoldrunner" >
<gui version="9" name="kgoldrunner" >
<MenuBar>
<Menu name="game" >
<Action append="save_merge" name="save_edits" />
......@@ -61,16 +61,10 @@
</ToolBar>
<ActionProperties>
<Action shortcut="P; Escape" name="game_pause" />
<Action shortcut="P; Escape" name="game_pause" />
<Action shortcut="S" name="game_save" />
<Action shortcut="Ctrl+S" name="save_edits" />
<Action shortcut="Shift+G" name="kgoldrunner" />
<Action shortcut="Shift+A" name="apple_2" />
<Action shortcut="Shift+I" name="ice_cave" />
<Action shortcut="Shift+M" name="midnight" />
<Action shortcut="Shift+K" name="kde_kool" />
<Action shortcut="Up; I" name="move_up" />
<Action shortcut="Right; L" name="move_right" />
<Action shortcut="Down; K" name="move_down" />
......
......@@ -639,12 +639,14 @@ void KGrCanvas::resynchAnimation (const int id, const int i, const int j,
}
void KGrCanvas::gotGold (const int spriteId, const int i, const int j,
const bool spriteHasGold)
const bool spriteHasGold, const bool lost)
{
// Hide collected gold or show dropped gold.
paintCell (i, j, (spriteHasGold) ? FREE : NUGGET);
// Hide collected gold or show dropped gold, but not if the gold was lost.
if (! lost) {
paintCell (i, j, (spriteHasGold) ? FREE : NUGGET);
}
// If the rules allow, show if an enemy sprite is carrying some gold.
// If the rules allow, show whether or not an enemy sprite is carrying gold.
if (enemiesShowGold && (sprites->at(spriteId)->spriteType() == ENEMY)) {
sprites->at(spriteId)->setFrameOffset (spriteHasGold ? goldEnemy : 0);
}
......
......@@ -85,7 +85,7 @@ public slots:
void resynchAnimation (const int id, const int i, const int j,
const bool stop);
void gotGold (const int spriteId, const int i, const int j,
const bool spriteHasGold);
const bool spriteHasGold, const bool lost = false);
void showHiddenLadders (const QList<int> & ladders, const int width);
void deleteSprite (const int id);
void deleteAllSprites ();
......
#ifndef KGRDEBUG_H
#define KGRDEBUG_H
static int dbgLevel = 0; // Local to file where kgrdebug.h is included.
#define dbk kDebug()
#define dbk1 if(dbgLevel>=1)kDebug()
#define dbk2 if(dbgLevel>=2)kDebug()
#define dbk3 if(dbgLevel>=3)kDebug()
#define dbo printf(
#define dbo1 if(dbgLevel>=1)printf(
#define dbo2 if(dbgLevel>=2)printf(
#define dbo3 if(dbgLevel>=3)printf(
#define dbe fprintf(stderr,
#define dbe1 if(dbgLevel>=1)fprintf(stderr,
#define dbe2 if(dbgLevel>=2)fprintf(stderr,
#define dbe3 if(dbgLevel>=3)fprintf(stderr,
#endif
#include "kgrdebug.h"
/****************************************************************************
* Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
* *
......@@ -155,6 +157,7 @@ void KGrLevelPlayer::init (KGrCanvas * view, const Control mode,
targetJ = j;
heroId = emit makeSprite (HERO, i, j);
hero = new KGrHero (this, grid, i, j, heroId, rules);
hero->setNuggets (nuggets);
// TODO - Iff mouse mode, setMousePos();
emit setMousePos (targetI, targetJ);
grid->changeCellAt (i, j, FREE); // Hero now a sprite.
......@@ -179,8 +182,8 @@ void KGrLevelPlayer::init (KGrCanvas * view, const Control mode,
}
// Connect the hero's and enemies' efforts to the graphics.
connect (this, SIGNAL (gotGold (int, int, int, bool)),
view, SLOT (gotGold (int, int, int, bool)));
connect (this, SIGNAL (gotGold (int, int, int, bool, bool)),
view, SLOT (gotGold (int, int, int, bool, bool)));
// Connect mouse-clicks from KGrCanvas to digging slot.
connect (view, SIGNAL (mouseClick (int)), SLOT (doDig (int)));
......@@ -283,7 +286,6 @@ void KGrLevelPlayer::processDugBricks (const int scaledTime)
}
// TODO - Hero gets hidden by dug-brick in the Egyptian theme.
// TODO - Why do we get so many MISSED ticks when we dig?
// TODO - Hero falls through floor when caught in a closing brick.
// TODO - Implement speed-variation as a parameter of tick().
}
}
......@@ -414,13 +416,13 @@ bool KGrLevelPlayer::heroCaught (const int heroX, const int heroY)
if (enemies.count() == 0) {
return false;
}
int enemyX, enemyY, ppc1;
int enemyX, enemyY, pointsPerCell_1;
foreach (KGrEnemy * enemy, enemies) {
ppc1 = enemy->whereAreYou (enemyX, enemyY) - 1;
if (((heroX < enemyX) ? ((heroX + ppc1) >= enemyX) :
(heroX <= (enemyX + ppc1))) &&
((heroY < enemyY) ? ((heroY + ppc1) >= enemyY) :
(heroY <= (enemyY + ppc1)))) {
pointsPerCell_1 = enemy->whereAreYou (enemyX, enemyY) - 1;
if (((heroX < enemyX) ? ((heroX + pointsPerCell_1) >= enemyX) :
(heroX <= (enemyX + pointsPerCell_1))) &&
((heroY < enemyY) ? ((heroY + pointsPerCell_1) >= enemyY) :
(heroY <= (enemyY + pointsPerCell_1)))) {
return true;
}
}
......@@ -433,11 +435,13 @@ bool KGrLevelPlayer::standOnEnemy (const int spriteId, const int x, const int y)
if (enemies.count() < minEnemies) {
return false;
}
int enemyX, enemyY, ppc;
int enemyX, enemyY, pointsPerCell;
foreach (KGrEnemy * enemy, enemies) {
ppc = enemy->whereAreYou (enemyX, enemyY);
if (((enemyY == (y + ppc)) || (enemyY == (y + ppc - 1))) &&
(enemyX > (x - ppc)) && (enemyX < (x + ppc))) {
pointsPerCell = enemy->whereAreYou (enemyX, enemyY);
if (((enemyY == (y + pointsPerCell)) ||
(enemyY == (y + pointsPerCell - 1))) &&
(enemyX > (x - pointsPerCell)) &&
(enemyX < (x + pointsPerCell))) {
return true;
}
}
......@@ -447,13 +451,6 @@ bool KGrLevelPlayer::standOnEnemy (const int spriteId, const int x, const int y)
bool KGrLevelPlayer::bumpingFriend (const int spriteId, const Direction dirn,
const int gridI, const int gridJ)
{
// TODO - Write this.
// if (spriteId != grid->enemyOccupied (gridI, gridJ)) {
// kDebug() << spriteId << "CANNOT MOVE FROM" << gridI << gridJ
// << grid->enemyOccupied (gridI, gridJ) << "MUST GO FIRST";
// return true;
// }
int dI = 0;
int dJ = 0;
switch (dirn) {
......@@ -476,11 +473,11 @@ bool KGrLevelPlayer::bumpingFriend (const int spriteId, const Direction dirn,
int otherEnemy;
if (dI != 0) {
otherEnemy = grid->enemyOccupied (gridI + dI, gridJ);
kDebug() << otherEnemy << "at" << (gridI + dI) << gridJ
<< "dirn" << ((otherEnemy > 0) ?
(enemies.at (otherEnemy - 1)->direction()) : 0)
<< "me" << spriteId << "dirn" << dirn;
if (otherEnemy > 0) {
kDebug() << otherEnemy << "at" << (gridI + dI) << gridJ
<< "dirn" << ((otherEnemy > 0) ?
(enemies.at (otherEnemy - 1)->direction()) : 0)
<< "me" << spriteId << "dirn" << dirn;
if (enemies.at (otherEnemy - 1)->direction() != dirn) {
kDebug() << spriteId << "wants" << dirn << ":" << otherEnemy
<< "at" << (gridI + dI) << gridJ << "wants"
......@@ -491,11 +488,11 @@ bool KGrLevelPlayer::bumpingFriend (const int spriteId, const Direction dirn,
}
if (dJ != 0) {
otherEnemy = grid->enemyOccupied (gridI, gridJ + dJ);
kDebug() << otherEnemy << "at" << gridI << (gridJ + dJ)
<< "dirn" << ((otherEnemy > 0) ?
(enemies.at (otherEnemy - 1)->direction()) : 0)
<< "me" << spriteId << "dirn" << dirn;
if (otherEnemy > 0) {
kDebug() << otherEnemy << "at" << gridI << (gridJ + dJ)
<< "dirn" << ((otherEnemy > 0) ?
(enemies.at (otherEnemy - 1)->direction()) : 0)
<< "me" << spriteId << "dirn" << dirn;
if (enemies.at (otherEnemy - 1)->direction() != dirn) {
kDebug() << spriteId << "wants" << dirn << ":" << otherEnemy
<< "at" << gridI << (gridJ + dJ) << "wants"
......@@ -507,6 +504,26 @@ bool KGrLevelPlayer::bumpingFriend (const int spriteId, const Direction dirn,
return false;
}
void KGrLevelPlayer::unstackEnemy (const int spriteId,
const int gridI, const int gridJ,
const int prevEnemy)
{
dbe "KGrLevelPlayer::unstackEnemy (%02d at [%02d,%02d] prevEnemy %02d)\n",
spriteId, gridI, gridJ, prevEnemy);
int nextId = grid->enemyOccupied (gridI, gridJ);
int prevId;
while (nextId > 0) {
prevId = enemies.at (nextId - 1)->getPrevInCell();
dbe "Next %02d prev %02d\n", nextId, prevId);
if (prevId == spriteId) {
dbe " SET IDs - id %02d prev %02d\n", nextId, prevEnemy);
enemies.at (nextId - 1)->setPrevInCell (prevEnemy);
// break;
}
nextId = prevId;
}
}
void KGrLevelPlayer::tick (bool missed, int scaledTime)
{
if (playState != Playing) {
......@@ -535,24 +552,32 @@ void KGrLevelPlayer::tick (bool missed, int scaledTime)
}
int KGrLevelPlayer::runnerGotGold (const int spriteId,
const int i, const int j,
const bool hasGold)
const int i, const int j,
const bool hasGold, const bool lost)
{
if (hasGold) {
kDebug() << "GOLD COLLECTED BY" << spriteId << "AT" << i << j;
}
else if (lost) {
kDebug() << "GOLD LOST BY" << spriteId << "AT" << i << j;
}
else {
kDebug() << "GOLD DROPPED BY" << spriteId << "AT" << i << j;
}
grid->gotGold (i, j, hasGold); // Record pickup/drop on grid.
emit gotGold (spriteId, i, j, hasGold); // Erase/show gold on screen.
if (! lost) {
grid->gotGold (i, j, hasGold); // Record pickup/drop on grid.
}
emit gotGold (spriteId, i, j, hasGold, lost); // Erase/show gold on screen.
// If hero got gold, score, maybe show hidden ladders, maybe end the level.
if (spriteId == heroId) {
if ((spriteId == heroId) || lost) {
if (--nuggets <= 0) {
grid->placeHiddenLadders();
grid->placeHiddenLadders(); // All gold picked up or lost.
}
}
if (lost) {
hero->setNuggets (nuggets); // Update hero re lost gold.
}
return nuggets;
}
......@@ -714,16 +739,16 @@ void KGrLevelPlayer::bugFix()
{
// Toggle a bug fix on/off dynamically.
KGrGame::bugFix = (KGrGame::bugFix) ? false : true;
printf ("%s", (KGrGame::bugFix) ? "\n" : "");
printf (">>> Bug fix is %s\n", (KGrGame::bugFix) ? "ON" : "OFF\n");
fprintf (stderr, "%s", (KGrGame::bugFix) ? "\n" : "");
fprintf (stderr, ">> Bug fix is %s\n", (KGrGame::bugFix) ? "ON" : "OFF\n");
}
void KGrLevelPlayer::startLogging()
{
// Toggle logging on/off dynamically.
KGrGame::logging = (KGrGame::logging) ? false : true;
printf ("%s", (KGrGame::logging) ? "\n" : "");
printf (">>> Logging is %s\n", (KGrGame::logging) ? "ON" : "OFF\n");
fprintf (stderr, "%s", (KGrGame::logging) ? "\n" : "");
fprintf (stderr, ">> Logging is %s\n", (KGrGame::logging) ? "ON" : "OFF\n");
}
void KGrLevelPlayer::showFigurePositions()
......
......@@ -160,7 +160,7 @@ public:
* @return The number of pieces of gold remaining in this level.
*/
int runnerGotGold (const int spriteId, const int i, const int j,
const bool hasGold);
const bool hasGold, const bool lost = false);
/**
* Helper function to determine whether the hero has collided with an enemy
......@@ -200,6 +200,17 @@ public:
bool bumpingFriend (const int spriteId, const Direction dirn,
const int gridI, const int gridJ);
/**
* Helper function to remove an enemy from among several stacked in a cell.
*
* @param spriteId The identifier of the enemy.
* @param gridI The column-position of the enemy.
* @param gridJ The row-position of the enemy.
* @param prevEnemy The previously stacked enemy in the same cell (or -1).
*/
void unstackEnemy (const int spriteId,
const int gridI, const int gridJ,
const int prevEnemy);
/**
* Helper function to determine where an enemy should reappear after being
* trapped in a brick. This applies with Traditional and Scavenger rules
......@@ -249,7 +260,7 @@ signals:
const Direction dirn, const AnimationType type);
void deleteSprite (const int spriteId);
void gotGold (const int spriteId, const int i, const int j,
const bool hasGold);
const bool hasGold, const bool lost);
private slots:
void tick (bool missed, int scaledTime);
......
#include "kgrdebug.h"
/****************************************************************************
* Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
* *
......@@ -89,10 +91,14 @@ Direction KGrTraditionalRules::findBestWay (const int eI, const int eJ,
// TODO - Add !standOnEnemy() && as a condition here.
// TODO - And maybe !((*playfield)[x][y+1]->whatIam() == HOLE)) not just out of hole,
bool canStand = (grid->enemyMoves (eI, eJ) & dFlag [STAND]);
bool canStand = (grid->enemyMoves (eI, eJ) & dFlag [STAND]) ||
(grid->enemyOccupied (eI, eJ + 1) > 0);
if (! canStand) {
dbk2 << "can stand" << (grid->enemyMoves (eI, eJ) & dFlag [STAND])
<< "occ-below" << grid->enemyOccupied (eI, eJ + 1);
return DOWN;
}
dbk2 << "not DOWN yet";
// Traditional search strategy.
Direction dirn = STAND;
......@@ -108,6 +114,7 @@ Direction KGrTraditionalRules::findBestWay (const int eI, const int eJ,
}
else { // Hero below enemy.
dirn = searchDown (eI, eJ, hJ); // Find way that leads down.
dbk2 << "searchDown1" << eI << eJ << hJ << "ret" << dirn;
if (dirn == STAND) {
dirn = searchUp (eI, eJ, hJ); // No go: try going up first.
}
......@@ -115,6 +122,7 @@ Direction KGrTraditionalRules::findBestWay (const int eI, const int eJ,
if (dirn == STAND) { // When all else fails, look for
dirn = searchDown (eI, eJ, eJ - 1); // a way below the hero.
dbk2 << "searchDown2" << eI << eJ << (eJ - 1) << "ret" << dirn;
}
return dirn;
......@@ -368,6 +376,11 @@ int KGrTraditionalRules::distanceDown (int x, int y, int deltah)
// if ((x*16==enemy->getx()) && (y*16+16==enemy->gety()))
// rungs = 0; // Pit is blocked. Find another way.
// }
if (grid->enemyOccupied (x, y + 1) > 0) {
dbk2 << "Pit block =" << grid->enemyOccupied (x, y + 1)
<< "at" << x << (y + 1);
rungs = 0; // Pit is blocked. Find another way.
}
}
if (rungs <= 0)
return 0; // There is no way down.
......@@ -425,7 +438,7 @@ bool KGrTraditionalRules::willNotFall (int x, int y)
}
// Check the floor.
switch (grid->cellType (x, y+1)) {
switch (grid->cellType (x, y + 1)) {
// Cases where the enemy knows he will fall.
case FREE:
......@@ -443,6 +456,11 @@ bool KGrTraditionalRules::willNotFall (int x, int y)
// TODO - Maybe the presence of another enemy below could be a bool
// TODO - parameter for findBestWay() ... NO, that won't work, we
// TODO - need to know if there is an enemy ANYWHERE under a LR path.
if (grid->enemyOccupied (x, y + 1) > 0) {
dbk2 << "Occupied =" << grid->enemyOccupied (x, y + 1)
<< "at" << x << (y + 1);
return true;
}
// cmax = enemies->count();
// for (c = 0; c < cmax; c++) {
// enemy = enemies->at (c);
......@@ -485,7 +503,7 @@ Direction KGrKGoldrunnerRules::findBestWay (const int eI, const int eJ,
KGrLevelGrid * pGrid)
// TODO - Should be const ... const KGrLevelGrid * pGrid)
{
kDebug() << eI << eJ << hI << hJ;
dbk2 << eI << eJ << hI << hJ;
grid = pGrid;
return RIGHT;
}
......@@ -517,7 +535,7 @@ Direction KGrScavengerRules::findBestWay (const int eI, const int eJ,
KGrLevelGrid * pGrid)
// TODO - Should be const ... const KGrLevelGrid * pGrid)
{
kDebug() << eI << eJ << hI << hJ;
dbk2 << eI << eJ << hI << hJ;
grid = pGrid;
return RIGHT;
}
......
#include "kgrdebug.h"
/****************************************************************************
* Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
* *
......@@ -59,12 +61,15 @@ void KGrRunner::getRules()
kDebug() << "pointsPerCell" << pointsPerCell << "turnAnywhere" << turnAnywhere;
}
bool KGrRunner::notTimeYet (const int scaledTime)
Situation KGrRunner::situation (const int scaledTime)
{
timeLeft -= scaledTime;
if (timeLeft >= scaledTime) {
// kDebug() << "1: Hero interval is:" << interval << "time left:" << timeLeft;
return true;
return NotTimeYet;
}
if (grid->cellType (gridI, gridJ) == BRICK) {
return CaughtInBrick;
}
gridX += deltaX;
......@@ -73,11 +78,11 @@ bool KGrRunner::notTimeYet (const int scaledTime)
// TODO - Count one extra tick when turning to L or R from another dirn.
if (pointCtr < pointsPerCell) {
// kDebug() << "2: Hero interval is:" << interval << "time left:" << timeLeft;
timeLeft += interval;
return true;
return MidCell;
}
return false;
return EndCell;
}
......@@ -85,8 +90,7 @@ KGrHero::KGrHero (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
int i, int j, int pSpriteId, KGrRuleBook * pRules)
:
KGrRunner (pLevelPlayer, pGrid, i, j, pSpriteId, pRules),
nuggets (1000) // TODO - This won't work in the Count, Zero level.
// Implement KGrRunner::setNuggets (int n); and nuggets as a runner value.
nuggets (0) // KGrLevelPlayer object will call hero->setNuggets().
{
kDebug() << "THE HERO IS BORN at" << i << j << "sprite ID" << pSpriteId;
rules->getHeroTimes (runTime, fallTime);
......@@ -104,12 +108,13 @@ int KGrHero::fallTime = 0;
HeroStatus KGrHero::run (const int scaledTime)
{
if (notTimeYet (scaledTime)) {
Situation s = situation (scaledTime);
if (s == NotTimeYet) {
return NORMAL;
}
// Die if a brick has closed over us.
if (grid->cellType (gridI, gridJ) == BRICK) {
if (s == CaughtInBrick) {
return DEAD;
}
......@@ -118,7 +123,9 @@ HeroStatus KGrHero::run (const int scaledTime)
return WON_LEVEL;
}
// TODO - Use nextDirection here, and set currDirection (at end?).
if (s == MidCell) {
return NORMAL;
}
pointCtr = 0;
gridI = gridX / pointsPerCell;
......@@ -138,6 +145,8 @@ HeroStatus KGrHero::run (const int scaledTime)
// kDebug() << "Direction" << nextDirection << "Flags" << OK
// << "at" << gridI << gridJ
// << "on Enemy" << onEnemy;
// TODO - Do a better, smoother job of falling while standing on enemy.
// TODO - Interface fall start and end with sound.
AnimationType nextAnimation = aType [nextDirection];
if (! canStand) {
......@@ -149,30 +158,12 @@ HeroStatus KGrHero::run (const int scaledTime)
nextDirection = STAND;
}
// TODO - Remove this if above code is OK.
// if (OK & dFlag [nextDirection]) {
// if ((nextDirection == DOWN) && (! canStand)) {
// nextAnimation = (currDirection == RIGHT) ? FALL_R : FALL_L;
// interval = fallTime;
// }
// }
// else if ((canStand) || (OK == 0)) {
// nextDirection = STAND;
// }
// else {
// nextDirection = DOWN;
// nextAnimation = (currDirection == RIGHT) ? FALL_R : FALL_L;
// interval = fallTime;
// }
if (nextDirection == STAND) {
nextAnimation = currAnimation;
}
timeLeft += interval;
// kDebug() << "3: Hero interval is:" << interval << "time left:" << timeLeft;
// TODO - Check for collision with an enemy somewhere around here.
if ((! onEnemy) && levelPlayer->heroCaught (gridX, gridY)) {
return DEAD;
}
......@@ -238,21 +229,21 @@ bool KGrHero::dig (const Direction diggingDirection, int & i, int & j)
void KGrHero::showState (char option)
{
printf ("(%02d,%02d) - Hero ", gridI, gridJ);
fprintf (stderr, "(%02d,%02d) - Hero ", gridI, gridJ);
switch (option) {
case 'p': printf ("\n"); break;
case 's': printf (" STATE\n");
case 'p': fprintf (stderr, "\n"); break;
case 's': fprintf (stderr, " STATE\n");
// TODO - Print the hero's state.
// printf (" nuggets %02d status %d walk-ctr %d ",
// fprintf (stderr, " nuggets %02d status %d walk-ctr %d ",
// nuggets, status, walkCounter);
// printf ("dirn %d next dirn %d\n", direction, nextDir);
// printf (" rel (%02d,%02d) abs (%03d,%03d)",
// fprintf (stderr, "dirn %d next dirn %d\n", direction, nextDir);
// fprintf (stderr, " rel (%02d,%02d) abs (%03d,%03d)",
// relx, rely, absx, absy);
// printf (" pix %02d", actualPixmap);
// printf (" mem %d %d %d %d", mem_x, mem_y, mem_relx, mem_rely);
// if (walkFrozen) printf (" wBlock");
// if (fallFrozen) printf (" fBlock");
// printf ("\n");
// fprintf (stderr, " pix %02d", actualPixmap);
// fprintf (stderr, " mem %d %d %d %d", mem_x, mem_y, mem_relx, mem_rely);
// if (walkFrozen) fprintf (stderr, " wBlock");
// if (fallFrozen) fprintf (stderr, " fBlock");
// fprintf (stderr, "\n");
break;
}
}
......@@ -285,74 +276,50 @@ int KGrEnemy::trapTime = 0;
void KGrEnemy::run (const int scaledTime)
{
bool newCell = false;
if (notTimeYet (scaledTime)) {
if ((pointCtr == 1) && (currDirection == DOWN) &&
(grid->cellType (gridI, gridJ + 1) == HOLE)) {
// Enemy is starting to fall into a hole.
kDebug() << spriteId
<< "Falling into hole at:" << gridI << (gridJ + 1);
grid->changeCellAt (gridI, gridJ + 1, USEDHOLE);
dropGold();
}
Situation s = situation (scaledTime);
if (s == NotTimeYet) {
return;
}
// Die and reappear if a brick has closed over us.
if (grid->cellType (gridI, gridJ) == BRICK) {
// Die if a brick has closed over us.
if (s == CaughtInBrick) {
// TODO - What time-delay (if any) is involved here?
// TODO - How should pointCtr, interval and timeLeft be affected?
// TODO - What if >1 enemy has occupied a cell somehow?
// TODO - Effect on CPU time of more frequent BRICK checks ...
releaseCell (gridI + deltaX, gridJ + deltaY);
dieAndReappear(); // Move to a new (gridI, gridJ).
reserveCell (gridI, gridJ);
// No return: treat situation as EndCell.
}
else if ((pointCtr == 1) && (currDirection == DOWN) &&
(grid->cellType (gridI, gridJ + 1) == HOLE)) {
// Enemy is starting to fall into a hole.
kDebug() << spriteId
<< "Falling into hole at:" << gridI << (gridJ + 1);
grid->changeCellAt (gridI, gridJ + 1, USEDHOLE);
dropGold();
return;
}
// Pop up a previous enemy or -1 if the cell was empty.
grid->setEnemyOccupied (gridI, gridJ, prevInCell);
kDebug() << spriteId << "Leaves" << gridI << gridJ
<< "to" << prevInCell;
dieAndReappear();