void DrasculaEngine::startWalking() { characterMoved = 1; stepX = STEP_X; stepY = STEP_Y; if (currentChapter == 2) { if ((roomX < curX) && (roomY <= (curY + curHeight))) quadrant_1(); else if ((roomX < curX) && (roomY > (curY + curHeight))) quadrant_3(); else if ((roomX > curX + curWidth) && (roomY <= (curY + curHeight))) quadrant_2(); else if ((roomX > curX + curWidth) && (roomY > (curY + curHeight))) quadrant_4(); else if (roomY < curY + curHeight) walkUp(); else if (roomY > curY + curHeight) walkDown(); else characterMoved = 0; } else { if ((roomX < curX + curWidth / 2 ) && (roomY <= (curY + curHeight))) quadrant_1(); else if ((roomX < curX + curWidth / 2) && (roomY > (curY + curHeight))) quadrant_3(); else if ((roomX > curX + curWidth / 2) && (roomY <= (curY + curHeight))) quadrant_2(); else if ((roomX > curX + curWidth / 2) && (roomY > (curY + curHeight))) quadrant_4(); else characterMoved = 0; } _startTime = getTime(); }
void KGrEnemy::walkTimeDone () { if (KGrObject::frozen) {walkFrozen = TRUE; return; } // Check we are alive BEFORE checking for friends being in the way. // Maybe a friend overhead is blocking our escape from a brick. if ((*playfield)[x][y]->whatIam()==BRICK) { // sollte er aber in einem Brick dieAndReappear(); // sein, dann stirbt er wohl return; // Must leave "walkTimeDone" when an enemy dies. } if (! bumpingFriend()) { switch (direction) { case UP: walkUp (WALKDELAY); if ((rely == 0) && ((*playfield)[x][y+1]->whatIam() == USEDHOLE)) // Enemy kletterte grad aus einem Loch hinaus // -> gib es frei! ((KGrBrick *)(*playfield)[x][y+1])->unUseHole(); break; case DOWN: walkDown (WALKDELAY, FALLDELAY); break; case RIGHT: walkRight (WALKDELAY, FALLDELAY); break; case LEFT: walkLeft (WALKDELAY, FALLDELAY); break; default: // Switch search direction in KGoldrunner search (only). searchStatus = (searchStatus==VERTIKAL) ? HORIZONTAL : VERTIKAL; // In KGoldrunner rules, if a hole opens under an enemy // who is standing and waiting to move, he should fall. if (!(canStand()||hangAtPole())) { initFall (actualPixmap, FALLDELAY); } else { status = STANDING; } break; } // wenn die Figur genau ein Feld gelaufen ist if (status == STANDING) { // dann suche den Helden direction = searchbestway(x,y,herox,heroy); // und if (walkCounter >= 4) { if (! nuggets) collectNugget(); else dropNugget(); } status = WALKING; // initialisiere die Zählervariablen und walkCounter = 1; // den Timer um den Held weiter walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE); // zu jagen startWalk (); } } else { // A friend is in the way. Try a new direction, but not if leaving a hole. Direction dirn; // In KGoldrunner rules, change the search strategy, // to avoid enemy-enemy deadlock. searchStatus = (searchStatus==VERTIKAL) ? HORIZONTAL : VERTIKAL; dirn = searchbestway (x, y, herox, heroy); if ((dirn != direction) && ((*playfield)[x][y]->whatIam() != USEDHOLE)) { direction = dirn; status = WALKING; walkCounter = 1; relx = 0; absx = 16 * x; rely = 0; absy = 16 * y; startWalk (); } walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE); } showFigure(); }
void KGrHero::walkTimeDone () { if (! started) return; // Ignore signals from earlier play. if (KGrObject::frozen) {walkFrozen = TRUE; return; } if ((*playfield)[x][y]->whatIam() == BRICK) { emit caughtHero(); // Brick closed over hero. return; } if ((y==1)&&(nuggets<=0)) { // If on top row and all nuggets collected, emit leaveLevel(); // the hero has won and can go to next level. return; } if (status == STANDING) setNextDir(); if ((status == STANDING) && (nextDir != STAND)) { if ((standOnEnemy()) && (nextDir == DOWN)) { emit caughtHero(); // Hero is going to step down into an enemy. return; } startWalk(); } if (status != STANDING) { switch (direction) { case UP: walkUp (WALKDELAY); break; case DOWN: walkDown (WALKDELAY, FALLDELAY); break; case RIGHT: walkRight (WALKDELAY, FALLDELAY); break; case LEFT: walkLeft (WALKDELAY, FALLDELAY); break; default : // The following code is strange. It makes the hero fall off a pole. // It works because of other strange code in "startWalk(), case DOWN:". if (!canStand()||hangAtPole()) // falling initFall(FALL1, FALLDELAY); else status = STANDING; break; } herox=x;heroy=y; // Koordinatenvariablen neu // wenn Held genau ein Feld weitergelaufen ist, if ((relx==0)&&(rely==0)) // dann setzte statische { collectNugget(); // und nehme evtl. Nugget } showFigure(); // Is this REDUNDANT now? See showFigure() below. ////////////////////////////////////////////////// } if (status == STANDING) if (!canStand()&&!hangAtPole()) initFall(FALL1, FALLDELAY); else walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE); // This additional showFigure() is to update the hero position after it is // altered by the hero-enemy deadlock fix in standOnEnemy(). Messy, but ... //////////////////////////////////////////////////////////////////////////// showFigure(); if(isInEnemy()) { walkTimer->stop(); emit caughtHero(); } }