예제 #1
0
void monstersMoveChecker(){
    if (monsterToken == 1) {
        moveMonster();      // moves ghost1
    }
    if (monster1Token == 1){
        moveMonster1();     // moves ghost2
    }
}
예제 #2
0
// Display game interface to be able to play
t_game    showGame(t_game game, int tempsActuel, int tempsPrecedent)
{
    if (game.Gevenements.type == SDL_KEYDOWN)
    {
        game.Gplayer1 = movePlayer(game);
        if (game.Gevenements.key.keysym.sym == SDLK_SPACE && game.Gplayer1.nbr_bullet < 2)
        {
            Mix_PlayChannel(-1, game.Gplayer1.bulletGo_sound, 0);
            game.Gplayer1.bullet[game.Gplayer1.nbr_bullet].bullet = loadBullet(game);
            game.Gplayer1.bullet[game.Gplayer1.nbr_bullet].position = init_bulletPos(game.Gplayer1);
            game.Gplayer1.nbr_bullet++;
        }
    }
    // Si 15 ms se sont écoulées depuis le dernier tour de boucle
    if (tempsActuel - tempsPrecedent > 15) {
        game = launch_bullet(game);
        game = launch_bulletMonster(game);
        game = moveMonster(game);
    }
    
    renderAll(game);
    return (game);
}
예제 #3
0
void HelloWorld::moveCallback(float dt)
{
	auto fac = Factory::getInstance();
	fac->moveMonster(player->getPosition(),1);
	hitByMonster(float(1));
}
예제 #4
0
PC_action turnDoPC(dungeon_t* dungeonPtr) {
    PC_action returnValue = actionMovement;
    int userChar;
    int validChar = 0;
    int dstX;
    int dstY;
    turn_t* turnPtr;
    turnPtr = (turn_t *) heap_remove_min(dungeonPtr->turnsHeapPtr);
    dstX = monsterGetX(turnPtr->monsterPtr);
    dstY = monsterGetY(turnPtr->monsterPtr);

    do {
        userChar = getch();
        screenClearRow(0);
        switch (userChar) {
            case '7': //Num Lock on
            case KEY_HOME: //Num Lock off
            case 'y':
                mvprintw(0, 0, "User entered up-left");
                dstX--;
                dstY--;
                validChar = 1;
                break;
            case '8': //Num Lock on
            case KEY_UP: //Num Lock off
            case 'k':
                mvprintw(0, 0, "User entered up");
                dstY--;
                validChar = 1;
                break;
            case '9': //Num Lock on
            case KEY_PPAGE: //Num Lock off
            case 'u':
                mvprintw(0, 0, "User entered up-right");
                dstX++;
                dstY--;
                validChar = 1;
                break;
            case '4': //Num Lock on
            case KEY_LEFT: //Num Lock off
            case 'h':
            case 'a':
                mvprintw(0, 0, "User entered left");
                dstX--;
                validChar = 1;
                break;
            case '6': //Num Lock on
            case KEY_RIGHT: //Num Lock off
            case 'l':
                mvprintw(0, 0, "User entered right");
                dstX++;
                validChar = 1;
                break;
            case '1': //Num Lock on
            case KEY_END: //Num Lock off
            case 'b':
                mvprintw(0, 0, "User entered down-left");
                dstX--;
                dstY++;
                validChar = 1;
                break;
            case '2': //Num Lock on
            case KEY_DOWN: //Num Lock off
            case 'j':
                mvprintw(0, 0, "User entered down");
                dstY++;
                validChar = 1;
                break;
            case '3': //Num Lock on
            case KEY_NPAGE: //Num Lock off
            case 'n':
                mvprintw(0, 0, "User entered down-right");
                dstX++;
                dstY++;
                validChar = 1;
                break;
            case ' ':
            case '5': //Num Lock on
            case 350: //Num Lock off (from testing, I can't find a #define)
                //do nothing
                validChar = 1;
                break;
            case '>':
                if (dungeonPtr->grid[dstY][dstX].material == stairsDn) {
                    returnValue = actionStairsDn;
                    mvprintw(0, 0, "Going down the stairs.");
                    refresh();
                    validChar = 1;
                } else {
                    mvprintw(0, 0, "I can't dig a hole through the floor. Please find me some stairs to use.");
                }
                break;
            case '<':
                if (dungeonPtr->grid[dstY][dstX].material == stairsUp) {
                    returnValue = actionStairsUp;
                    mvprintw(0, 0, "Going up the stairs.");
                    refresh();
                    validChar = 1;
                } else {
                    mvprintw(0, 0, "I can't reach the ceiling from here. Please find me some stairs to use.");
                }
                break;
            case 'm':
                returnValue = actionListMonsters;
                validChar = 1;
                break;
            case 's':
                returnValue = actionSave;
                validChar = 1;
                break;
            default:
                mvprintw(0, 0, "You can't do that! (%d)", userChar);
        }
    } while (!validChar);

    if (returnValue == actionMovement) {
        moveMonster(dungeonPtr, turnPtr->monsterPtr, dstX, dstY);
        pathTunneling(dungeonPtr);
        pathNontunneling(dungeonPtr);
        turnPtr->nextTurn += 100 / monsterSpeed(turnPtr->monsterPtr);
    }
    heap_insert(dungeonPtr->turnsHeapPtr, (void *) turnPtr);
    return returnValue;
}
예제 #5
0
void moveMonsterLogic(dungeon_t* dungeonPtr, monster* monsterPtr) {
    if (!monsterPtr->alive) {
        return;
    }

    int dstX, dstY;
    if (monsterPtr->isPC()) {
        // PC does not move here.  His logic is handled elsewhere.
        return;
    }
    if (monsterPtr->abilities & MONSTER_ERRATIC) {
        if (rand() % 2) {
            // random movement
            generateRandMove(dungeonPtr, monsterPtr, &dstX, &dstY);
            moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
            return;
        }
    }
    if (monsterPtr->abilities & MONSTER_INTELLIGENT) {
        // intelligent
        if (monsterPtr->abilities & MONSTER_TELEPATHIC) {
            generateShortestMove(dungeonPtr, monsterPtr, &dstX, &dstY);
            moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
        } else {
            // Only move if the PC is visible or there is a last known location of the PC, otherwise stay put.
            if (movementIsLineOfSight(dungeonPtr->grid, monsterPtr->x, monsterPtr->y,
                                      dungeonPtr->PCPtr->x, dungeonPtr->PCPtr->y)) {
                // PC is visible
                generateShortestMove(dungeonPtr, monsterPtr, &dstX, &dstY);
                moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
            } else if (monsterPtr->lastPCX) {
                // PC is remembered
                generateDirectMove(dungeonPtr, monsterPtr, monsterPtr->lastPCX, monsterPtr->lastPCY, &dstX, &dstY);
                moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
            }
        }
    } else {
        // not intelligent
        if (monsterPtr->abilities & MONSTER_TELEPATHIC) {
            generateDirectMove(dungeonPtr, monsterPtr, dungeonPtr->PCPtr->x, dungeonPtr->PCPtr->y, &dstX, &dstY);
            moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
        } else {
            // not telepathic
            if (movementIsLineOfSight(dungeonPtr->grid, monsterPtr->x, monsterPtr->y,
                                      dungeonPtr->PCPtr->x, dungeonPtr->PCPtr->y)){
                // player is visible
                generateDirectMove(dungeonPtr, monsterPtr, dungeonPtr->PCPtr->x, dungeonPtr->PCPtr->y, &dstX, &dstY);
                moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
            } else {
                // player is not visible, move randomly
                generateRandMove(dungeonPtr, monsterPtr, &dstX, &dstY);
                moveMonster(dungeonPtr, monsterPtr, dstX, dstY);
            }
        }
    }

    // Keep track of line-of-sight memory
    if (movementIsLineOfSight(dungeonPtr->grid, monsterPtr->x, monsterPtr->y,
                              dungeonPtr->PCPtr->x, dungeonPtr->PCPtr->y)) {
        monsterPtr->lastPCX = dungeonPtr->PCPtr->x;
        monsterPtr->lastPCY = dungeonPtr->PCPtr->y;
    }
}