Exemple #1
0
bool	Dir8TileMap::canMoveTo(int x1, int y1, int x2, int y2) const
{
	(x1);
	(y1);
	// x1, y1은 이전에 이미 검증되었다.
	// x1, y1, x2, y2가 서로 이웃이다라는 것은 검증하지 않았다.
	assert(isPassable(x1, y1) == true);
	if (isPassable(x2, y2) == false)
		return false;

	return true;
}
Exemple #2
0
bool	Dir8TileMap::lineOfSight(int x1, int y1, int x2, int y2, int* rx, int* ry) const
{
	if (isPassable(x1, y1) == false ||
		isPassable(x2, y2) == false)
		return false;

	int dx = ::abs(x2 - x1);
	int sx = x1 < x2 ? 1 : -1;

	int dy = ::abs(y2 - y1);
	int sy = y1 < y2 ? 1 : -1;

	int err = (dx > dy ? dx : -dy) / 2;

	int nx = x1;
	int ny = y1;

	for (;;)
	{
		if (nx == x2 && ny == y2)
		{
			// 성공시 마직막 지점
			if (rx != nullptr) *rx = x2;
			if (ry != nullptr) *ry = y2;
			break;
		}

		x1 = nx;
		y1 = ny;
		int temp = err;
		if (temp > -dx)
		{
			err -= dy;
			nx += sx;
		}
		if (temp < dy)
		{
			err += dx;
			ny += sy;
		}

		if (canMoveTo(x1, y1, nx, ny) == false)
		{
			// 충돌 직전 지점
			if (rx != nullptr) *rx = x1;
			if (ry != nullptr) *ry = y1;
			return false;
		}
	}

	return true;
}
Exemple #3
0
void Bullet::update(){
    float deltaX = 0;
    float deltaY = 0;

    deltaX = sin(this->angle) * this->moveSpeed;
    deltaY = -cos(this->angle) * this->moveSpeed;

    if(!inShop){
        if(this->playerShot){
            for(int i = 0; i < MAX_ZOMBIES; i++){
                if(zombieList[i] != NULL && zombieList[i]->checkActive()){
                    if(checkCollision(this->posX, this->posY, zombieList[i]->posX, zombieList[i]->posY, this->width, this->height, zombieList[i]->width, zombieList[i]->height)){
                        zombieList[i]->health -= this->damage;
                        this->active = false;
                    }
                }
            }
        }else{
            if(checkCollision(this->posX, this->posY, playerCenterX, playerCenterY, this->width, this->height, playerWidth, playerHeight)){
                playerHealth -= this->damage;
                this->active = false;
            }
        }

        if(isPassable(this->posX+deltaX, this->posY, this->width, this->height, deltaX, deltaY)){
            this->posX += deltaX;
        }else{
            this->active = false;
        }

        if(isPassable(this->posX, this->posY+deltaY, this->width, this->height, deltaX, deltaY)){
            this->posY += deltaY;
        }else{
            this->active = false;
        }
    }else{
        if(this->posX+deltaX >= 0 && this->posX+deltaX + this->width < 400 && this->posY >= 0 && this->posY + this->height < 400){
            this->posX += deltaX;
        }else{
            this->active = false;
        }
        if(this->posX >= 0 && this->posX + this->width < 400 && this->posY+deltaY >= 0 && this->posY+deltaY + this->height < 400){
            this->posY += deltaY;
        }else{
            this->active = false;
        }
    }
}
Exemple #4
0
    bool GameLevel::dropItemClosestEmptyTile(Item& item, const Actor& actor, const Misc::Point& position, Misc::Direction direction)
    {
        auto tryDrop = [&](const Misc::Point& pos) {
            bool res = false;
            if (isPassable(pos, &actor) && !mItemMap->getItemAt(pos))
                res = dropItem(std::unique_ptr<Item>{new Item(item)}, actor, FAWorld::Tile(pos));
            return res;
        };

        if (direction == Misc::Direction::none)
        {
            if (tryDrop(position))
                return true;
            direction = Misc::Direction::south;
        }

        constexpr auto directionCnt = 8;
        for (auto diff : {0, -1, 1})
        {
            auto dir = static_cast<Misc::Direction>((static_cast<int32_t>(direction) + diff + directionCnt) % directionCnt);
            auto pos = Misc::getNextPosByDir(position, dir);
            if (tryDrop(pos))
                return true;
        }

        return tryDrop(position);
    }
bool GameStateManager::fall(WorldCoords & wbelow)
{
  // This really shouldn't ever be able to happen...
  if (!m_map.haveChunk(getChunkCoords(wbelow))) return false;

  const Chunk & chunk = m_map.chunk(getChunkCoords(wbelow));

  for ( ; ; wbelow += BLOCK_YMINUS)
  {
    // An item that drops on something hot or out of the world dies.
    if (chunk.blockType(getLocalCoords(wbelow)) == BLOCK_Lava           ||
        chunk.blockType(getLocalCoords(wbelow)) == BLOCK_StationaryLava ||
        chunk.blockType(getLocalCoords(wbelow)) == BLOCK_Fire           ||
        wY(wbelow) < 0 )
    {
      return false; // won't even spawn an item that's died.
    }

    if (!isPassable(EBlockItem(chunk.blockType(getLocalCoords(wbelow))))) break;
  }

  wbelow += BLOCK_YPLUS; // wbelow is now the last passable block

  return true;
}
Exemple #6
0
    Misc::Point GameLevel::getFreeSpotNear(Misc::Point point, int32_t radius) const
    {
        // partially based on https://stackoverflow.com/a/398302

        int32_t xOffset = 0;
        int32_t yOffset = 0;

        int32_t dx = 0;
        int32_t dy = -1;

        while (xOffset <= radius && yOffset <= radius)
        {
            Misc::Point targetPoint = point + Misc::Point{xOffset, yOffset};
            if (targetPoint.x >= 0 && targetPoint.x < width() && targetPoint.y >= 0 && targetPoint.y < height())
            {
                if (isPassable(targetPoint, nullptr))
                    return targetPoint;
            }

            if (xOffset == yOffset || (xOffset < 0 && xOffset == -yOffset) || (xOffset > 0 && xOffset == 1 - yOffset))
            {
                int32_t tmp = dx;
                dx = -dy;
                dy = tmp;
            }

            xOffset = xOffset + dx;
            yOffset = yOffset + dy;
        }

        return Misc::Point::invalid();
    }
Exemple #7
0
boolean isLineClear(LEVELMAP *map, int x, int y) {
    int i;

    for (i = y; i < y + 5; i++) {
        if (!isPassable(map,x,i)) return 0;
    }
    return 1;
}
Exemple #8
0
void Player::update(){

    if(isPassable(this->posX + this->deltaX, this->posY, this->width, this->height) && !this->colX){
        this->posX += this->deltaX;
    }

    if(isPassable(this->posX, this->posY + this->deltaY, this->width, this->height) && !this->colY){
        this->posY += this->deltaY;
    }

    this->updateCenter();

    this->updateAnimation();

    this->deltaX = 0;
    this->deltaY = 0;
}
Exemple #9
0
bool Map::isPassable(int x, int y)
{
	QChar c = getChar(x, y);
	if(!c.isNull())
	{
		return isPassable(c);
	}
	return false;
}
Exemple #10
0
bool	Dir8TileMap::isPassableNeighbor(int x1, int y1, int x2, int y2) const
{
	// x1, y1은 이전에 이미 검증되었다.
	// x1, y1, x2, y2가 서로 이웃이다라는 것은 검증하지 않았다.
	if (isPassable(x2, y2) == false)
		return false;

	return true;
}
Exemple #11
0
void Unit::update(){
    if(this->health <= 0){
        this->active = false;
    }

    float deltaY, deltaX;

    if(this->unitId == 0){

    }

    if(isPassable(this->posX+deltaX, this->posY)){
        this->posX += deltaX;
    }

    if(isPassable(this->posX, this->posY+deltaY)){
        this->posY += deltaY;
    }
}
Exemple #12
0
void Bullet::update(){
    this->playHitSound = false;

    float deltaX = 0;
    float deltaY = 0;

    deltaX = sin(this->angle * 6.28318530718/* PI*2 */) * this->moveSpeed;
    deltaY = -cos(this->angle * 6.28318530718/* PI*2 */) * this->moveSpeed;

    if(this->playerShot){
        for(int i = 0; i < MAX_ENEMIES; i++){
            if(enemyList[i] != NULL && enemyList[i]->checkActive()){
                if(checkCollision(this->posX, this->posY, enemyList[i]->posX, enemyList[i]->posY, this->width, this->height, enemyList[i]->width, enemyList[i]->height)){
                    enemyList[i]->health -= this->damage;
                    this->active = false;
                    this->playHitSound = true;
                }
            }
        }
    }else{
        if(checkCollision(this->posX, this->posY, playerCenterX - playerHitBoxWidth/2, playerCenterY - playerHitBoxHeight/2, this->width, this->height, playerHitBoxWidth, playerHitBoxHeight)){
            playerHealth -= this->damage;
            this->active = false;
            this->playHitSound = true;
        }
    }

    if(isPassable(this->posX+deltaX, this->posY, 0, 0)){
        this->posX += deltaX;
    }else{
        this->active = false;
    }

    if(isPassable(this->posX, this->posY+deltaY, 0, 0)){
        this->posY += deltaY;
    }else{
        this->active = false;
    }
}
Exemple #13
0
TOSMWidget::TWeight TCarProfile::getWayWeight(TOSMWidget::TNWay *way, TOSMWidget::TID nodeFrom, TOSMWidget::TID nodeTo)
{
    if (!isPassable(way, nodeFrom, nodeTo)) return W_INF;
    TOSMWidget::TWeight spd;
    switch(way->roadClass())
    {
        case TOSMWidget::TNWay::EW_Motorway: spd = 110; break;
        case TOSMWidget::TNWay::EW_Trunk: spd = 70; break;
        case TOSMWidget::TNWay::EW_Primary: spd = 90; break;
        case TOSMWidget::TNWay::EW_Secondary: spd = 80; break;
        case TOSMWidget::TNWay::EW_Tertiary: spd = 80; break;
        case TOSMWidget::TNWay::EW_LivingStreet: spd = 40; break;
        case TOSMWidget::TNWay::EW_Residental: spd = 60; break;
        case TOSMWidget::TNWay::EW_Unclassified: spd = 40; break;
        case TOSMWidget::TNWay::EW_Service: spd = 20; break;
        case TOSMWidget::TNWay::EW_Track: spd = 10; break;
        case TOSMWidget::TNWay::EW_Raceway: spd = 180; break;
        case TOSMWidget::TNWay::EW_Road: spd = 40; break;
        default: spd = 5;
    }
    return way->getLength(nodeFrom, nodeTo)/spd;
}
Exemple #14
0
Message* MapBlock::getBlockInfo() {
	char buf[512];
	sprintf_s(&buf[0], 512, "Entities: %d, Props: %d, passable: %d", entityList.size(), propList.size(), isPassable());
	return new Message(new std::string(buf));
}
Exemple #15
0
void Actor::update(){
    if(this->health >= 7){
        this->colorCode = 1;
    }else if(this->health >= 4){
        this->colorCode = 2;
    }else if(this->health >= 1){
        this->colorCode = 3;
    }else if(this->health <= 0){
        this->active = false;
        this->posY = -1;
        this->posX = -1;
        playerMoney += killMoney;
        playerTotalMoneyEarned += killMoney;
        playerXP += playerXPGet;
        playerZombiesKilled++;
    }
    if(rand()%20 == 0){
        this->movementSpeedHelper++;
    }
    if(this->movementSpeedHelper >= movementSpeed){
        int deltaY = 0;
        int deltaX = 0;
        int y = cursorY;
        int x = cursorX;
        bool check = false;
        int temp = 0;
        int temp2 = 0;

        if(this->posY - y >= 0 && this->posX - x >= 0){
            if(this->posY - y <= this->maxRange && this->posX - x <= this->maxRange)
                check = true;

        }else if(this->posY - y <= 0 && this->posX - x >= 0){
            temp = posY - y;
            if(this->posY - y - temp - temp <= this->maxRange && this->posX - x <= this->maxRange)
                check = true;

        }else if(this->posY - y >= 0 && this->posX - x <= 0){
            temp = posX - x;
            if(this->posY - y <= this->maxRange && this->posX - x - temp - temp <= this->maxRange)
                check = true;

        }else if(this->posY - y <= 0 && this->posX - x <= 0){
            temp = posY - y;
            temp2 = posX - x;
            if(this->posY - y - temp - temp <= this->maxRange && this->posX - x - temp2 - temp2 <= this->maxRange)
                check = true;
        }

        if(this->posY > y && check){
            deltaY--;
        }else if(this->posY < y && check){
            deltaY++;
        }
        if(this->posX > x && check){
            deltaX--;
        }else if (this->posX < x && check){
            deltaX++;
        }

        if((this->posY+deltaY == y && this->posX+deltaX == x) || (this->posY == y && this->posX == x)){
            playerHealth -= 5;
            playerTimesHit++;
            deltaY = 0;
            deltaX = 0;
            movementSpeedHelper = 0;
        }

        if(!check){
            deltaY = 1 - rand() % 3;
            deltaX = 1 - rand() % 3;
        }

        int smart = 0;
        if(metObstacle){
            deltaY = 1 - rand() % 3;
            deltaX = 1 - rand() % 3;

            metObstacle = false;

            if(isPassable(this->posY+deltaY, this->posX) || mapArray[this->posY+deltaY][this->posX] == 3 || (mapArray[this->posY+deltaY][this->posX] == 4 && (this->posY+deltaY != cursorY || this->posX != cursorX))){
                this->posY += deltaY;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }

            if(isPassable(this->posY, this->posX+deltaX) || mapArray[this->posY][this->posX+deltaX] == 3 || (mapArray[this->posY][this->posX+deltaX] == 4 && (this->posY != cursorY || this->posX+deltaX != cursorX))){
                this->posX += deltaX;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }
        }else{
            if(isPassable(this->posY+deltaY, this->posX) || mapArray[this->posY+deltaY][this->posX] == 3 || mapArray[this->posY+deltaY][this->posX] == 4){
                this->posY += deltaY;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }else if(deltaX != 0 || deltaY != 0){
                smart++;
            }

            if(isPassable(this->posY, this->posX+deltaX) || mapArray[this->posY][this->posX+deltaX] == 3 || mapArray[this->posY][this->posX+deltaX] == 4){
                this->posX += deltaX;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }else if(deltaX != 0 || deltaY != 0){
                smart++;
            }
        }

        if(smart == 2){
            deltaY = 1 - rand() % 3;
            deltaX = 1 - rand() % 3;

            metObstacle = true;

            if(isPassable(this->posY+deltaY, this->posX) || mapArray[this->posY+deltaY][this->posX] == 3 || (mapArray[this->posY+deltaY][this->posX] == 4 && (this->posY+deltaY != cursorY || this->posX != cursorX))){
                this->posY += deltaY;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }

            if(isPassable(this->posY, this->posX+deltaX) || mapArray[this->posY][this->posX+deltaX] == 3 || (mapArray[this->posY][this->posX+deltaX] == 4 && (this->posY != cursorY || this->posX+deltaX != cursorX))){
                this->posX += deltaX;
                movementSpeedHelper = 0;
                if(mapArray[this->posY][this->posX] == 3 || mapArray[this->posY][this->posX] == 4){
                    movementSpeedHelper -= movementSpeed;
                }
            }
        }

    }else{
        this->movementSpeedHelper++;
    }
}
Exemple #16
0
int main()
{
    cursorY = 0;
    cursorX = 0;

    int deltaY = 0;
    int deltaX = 0;

    srand(time(0));

    initscr();

	raw();
	keypad(stdscr, TRUE);
	noecho();
	curs_set(0);
	start_color();

	resize_term(30, 80);

    init_pair(1, COLOR_GREEN, COLOR_BLACK);
    init_pair(2, COLOR_YELLOW, COLOR_BLACK);
    init_pair(3, COLOR_RED, COLOR_BLACK);
    init_pair(4, COLOR_CYAN, COLOR_BLACK);
    init_pair(5, COLOR_WHITE, COLOR_RED);
    init_pair(6, COLOR_WHITE, COLOR_GREEN);
    init_pair(7, COLOR_WHITE, COLOR_YELLOW);
    init_pair(8, COLOR_RED, COLOR_RED);
    init_pair(9, COLOR_RED, COLOR_GREEN);
    init_pair(10, COLOR_RED, COLOR_YELLOW);
    init_pair(11, COLOR_WHITE, COLOR_BLACK);
    init_pair(12, COLOR_MAGENTA, COLOR_BLACK);

    while(retry){

        Shop shop;
        SkillTree skillTree;

        breakLoop = false;
        int timeStart = time(0);

        clear();

        cursorY = mapHeight/2;
        cursorX = mapWidth/2+5;

        playerMovementSpeed = 50;
        playerMovementSpeedHelper = 0;

        playerHealth = 100;
        playerMaxHealth = 100;
        playerStamina = 10;
        playerMaxStamina = 10;
        playerStaminaRegen = 250;
        playerStaminaRegenHelper = 0;
        playerAmmo = 100;
        playerBulletSpeed = 30;
        playerDamage = 1;
        playerBulletRange = 20;
        playerFiringSpeed = 500;
        playerFiringSpeedHelper = 0;
        playerClip = 10;
        playerClipLimit = 10;
        playerHiddenClip = 0;
        playerReloading = false;
        playerReloadingRate = 4000;
        playerReloadingHelper = 0;
        playerReloadingModifier = 0;
        playerSpecialWeaponTypes = {0,0,0,0,0,0,0,0,0,0};
        playerWeaponName = {'P','i','s','t','o','l'};
        playerCurrentWeapon = {0,0};
        playerBandages = 0;
        playerBandaging = false;
        playerBandagesHelper = 0;
        playerMeleeDamage = 0;
        playerMeleeDirecton = 0;
        playerMeleeHelper = 0;
        playerStaminaPills = 0;

        playerMoney = 0;
        killMoney = 1;
        playerXP = 0;
        playerXPNeeded = 10;
        playerXPGet = 1;
        playerSkillPoints = 0;
        playerLevel = 1;
        lastTiersUnlocked = false;

        round = 1;
        roundZombies = 5;
        roundZombiesFloat = 5;
        roundZombiesHelper = 0;
        zombieSpawnRate = 5000;
        zombieSpawnRateHelper = 0;
        betweenRoundPause = false;
        betweenRoundPauseHelper = 0;
        zombieForceSpawnHelper = 500;

        playerTimeSurvived = 0;
        playerZombiesKilled = 0;
        playerBulletsFired = 0;
        playerTotalMoneyEarned = 0;
        playerMoves = 0;
        playerTimesBandaged = 0;
        playerTimesReloaded = 0;
        playerAmountBought = 0;
        playerAmountEnteredShop = 0;
        playerAmountEnteredSkillTree = 0;
        playerPeakMoneyOwned = 0;
        playerTotalStaminaPillsUsed = 0;
        playerAmountMelee = 0;
        playerTotalAmountForce = 0;
        playerTimesHit = 0;
        playerTimesPaused = 0;

        timeout(0); //time before the getch passes with no input

        for(int i = 0; i < MAX_ACTORS; i++){
            actorList[i] = NULL;
        }

        for(int i = 0; i < MAX_BULLETS; i++){
            bulletList[i] = NULL;
        }

        for(int y = 0; y < mapHeight; y++){
            for(int x = 0; x < mapWidth; x++){
                if(mapArray[y][x] == 7){
                    mapArray[y][x] = 0;
                }
            }
        }

        int z = 25 + rand() % 125;

        for(int i = 0; i < z; i++){
            int y = rand() % mapHeight;
            int x = rand() % mapWidth;

            if(mapArray[y][x] == 0 && isPassable(y, x) && (cursorY != y || cursorX != x) && mapArray[y-1][x] != 2){
                mapArray[y][x] = 7;
            }
        }

        //put stuff before the game loop here

        while(!breakLoop){
            drawMap();
            drawStats();

            playerTimeSurvived = time(0) - timeStart;

            if(playerMoney > playerPeakMoneyOwned)
                playerPeakMoneyOwned = playerMoney;

            if(playerHealth <= 0){
                if(gameOver()){
                    breakLoop = true;
                    retry = true;
                }else{
                    breakLoop = true;
                    retry = false;
                }
            }

            if(playerStaminaRegenHelper >= playerStaminaRegen){
                if(playerStamina < playerMaxStamina){
                    playerStamina++;
                }
                playerStaminaRegenHelper = 0;
            }

            if(playerClip == 0 && !playerReloading && playerAmmo > 0){
                reloadGun();
            }

            if(playerXP >= playerXPNeeded){
                playerSkillPoints++;
                playerLevel++;
                playerXPNeeded *= 1.1;
                playerXP = 0;
            }

            for(int i = 0; i < MAX_ACTORS; i++){
                if(actorList[i] != NULL && actorList[i]->checkActive()){
                    actorList[i]->update();
                    actorList[i]->draw();
                }
            }

            for(int i = 0; i < MAX_BULLETS; i++){
                if(bulletList[i] != NULL && bulletList[i]->checkActive()){
                    bulletList[i]->update();
                    bulletList[i]->draw();
                }
            }

            for(int i = 0; i < MAX_BULLETS; i++){
                if(specialBulletList[i] != NULL && specialBulletList[i]->checkActive()){
                    specialBulletList[i]->update();
                    specialBulletList[i]->draw();
                }
            }

            if(roundZombiesHelper >= roundZombies){
                betweenRoundPause = true;
            }

            if(betweenRoundPause){
                betweenRoundPauseHelper++;
                if(betweenRoundPauseHelper >= 100000){
                    roundStart();
                }
            }

            if(zombieSpawnRateHelper >= zombieSpawnRate && !betweenRoundPause){
                int y, x;
                int side = rand() % 4;
                switch(side){
                    case 0:
                        y = 0;
                        x = rand() % mapWidth;
                        break;

                    case 1:
                        y = mapHeight - 1;
                        x = rand() % mapWidth;
                        break;

                    case 2:
                        y = rand() % mapHeight;
                        x = 0;
                        break;

                    case 3:
                        y = rand() % mapHeight;
                        x = mapWidth - 1;
                        break;

                }
                if(isPassable(y, x)){
                    Actor *newActor = new Actor();

                    newActor->setAppearance('@', 1);
                    newActor->setPos(y, x);
                    newActor->setSpeed(600-round*3);
                    newActor->setHealth(10);
                    newActor->setMaxRange(20);
                    addActorToList(newActor);
                    zombieSpawnRateHelper = 0;
                    roundZombiesHelper++;
                }
            }

            attron(COLOR_PAIR(0));
            move(cursorY, cursorX);
            addch('@');
            attroff(COLOR_PAIR(0));

            bool donePause = false;

            int input = getch();

            switch(input){
                case KEY_UP:
                    deltaY = -1;
                    playerMeleeDirecton = 0;
                    break;

                case KEY_DOWN:
                    deltaY = 1;
                    playerMeleeDirecton = 1;
                    break;

                case KEY_LEFT:
                    deltaX = -1;
                    playerMeleeDirecton = 2;
                    break;

                case KEY_RIGHT:
                    deltaX = 1;
                    playerMeleeDirecton = 3;
                    break;

                case 'w':
                    addBulletToList(0);
                    break;

                case 's':
                    addBulletToList(1);
                    break;

                case 'a':
                    addBulletToList(2);
                    break;

                case 'd':
                    addBulletToList(3);
                    break;

                case 'r':
                    reloadGun();
                    break;

                case 'n':
                    if(betweenRoundPause){
                        roundStart();
                        playerTotalAmountForce++;
                    }
                    break;

                case 'm':
                    if(!betweenRoundPause && zombieForceSpawnHelper >= 500){
                        int y, x;
                        int side = rand() % 4;
                        switch(side){
                            case 0:
                                y = 0;
                                x = rand() % mapWidth;
                                break;

                            case 1:
                                y = mapHeight - 1;
                                x = rand() % mapWidth;
                                break;

                            case 2:
                                y = rand() % mapHeight;
                                x = 0;
                                break;

                            case 3:
                                y = rand() % mapHeight;
                                x = mapWidth - 1;
                                break;

                        }
                        if(isPassable(y, x)){
                            Actor *newActor = new Actor();

                            newActor->setAppearance('@', 1);
                            newActor->setPos(y, x);
                            newActor->setSpeed(600-round*3);
                            newActor->setHealth(10);
                            newActor->setMaxRange(20);
                            addActorToList(newActor);
                            zombieSpawnRateHelper = 0;
                            roundZombiesHelper++;
                            zombieForceSpawnHelper = 0;
                        }
                        playerTotalAmountForce++;
                    }
                    break;

                case 't':
                    playerAmountEnteredSkillTree++;
                    skillTree.skillScreen();
                    break;

                case 'b':
                    if(playerHealth < playerMaxHealth && playerBandages > 0 && !playerReloading){
                        playerBandaging = true;
                    }
                    break;

                case 'v':
                    if(playerStaminaPills > 0 && playerStamina < playerMaxStamina){
                        if(playerStamina + playerStamina/2 <= playerMaxStamina){
                            playerStamina += playerStamina/2;
                        }else{
                            playerStamina = playerMaxStamina;
                        }
                        playerStaminaPills--;
                    }

                case 'e':
                    if(playerMeleeDamage > 0 && playerMeleeHelper >= 500){
                        for(int i = 0; i < MAX_BULLETS; i++){
                            if(bulletList[i] == NULL || !bulletList[i]->checkActive()){
                                int y, x;
                                Bullet *newBullet = new Bullet();
                                y = cursorY;
                                x = cursorX;
                                newBullet->setDirection(playerMeleeDirecton);
                                if(playerMeleeDamage < 4){
                                    if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){
                                        newBullet->setAppearance('|', 11);
                                    }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){
                                        newBullet->setAppearance('-', 11);
                                    }
                                }else if(playerMeleeDamage >= 4){
                                    if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){
                                        newBullet->setAppearance('|', 12);
                                    }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){
                                        newBullet->setAppearance('-', 12);
                                    }

                                }
                                newBullet->setPos(y, x);
                                newBullet->setSpeed(50);
                                if(playerMeleeDamage == 5){
                                    newBullet->setRange(3);
                                }else{
                                    newBullet->setRange(2);
                                }
                                newBullet->setDamage(playerMeleeDamage);
                                bulletList[i] = newBullet;
                                playerMeleeHelper = 0;
                                playerAmountMelee++;
                                break;
                            }
                        }
                    }
                    break;

                case 'p':
                    mvprintw(13, mapWidth+2, "GAME PAUSED - PRESS P TO UNPAUSE");
                    mvprintw(14, mapWidth+2, "PRESS R TO RESET THE GAME");
                    mvprintw(15, mapWidth+2, "WARNING: YOU WON'T SEE THE FINAL STATS");
                    playerTimesPaused++;
                    while(!donePause){
                        int input = getch();
                        if(input == 'p'){
                            donePause = true;
                        }else if(input == 'r'){
                            breakLoop = true;
                            donePause = true;
                        }
                    }
                    break;

                case ' ':
                    if(mapArray[cursorY][cursorX] == 5){
                        playerAmountEnteredShop++;
                        shop.shopScreen();
                    }
                    break;

                default:
                    break;

            }

            if(isPassable(cursorY + deltaY, cursorX + deltaX) && playerMovementSpeedHelper >= playerMovementSpeed && playerStamina > 0){
                cursorY += deltaY;
                cursorX += deltaX;
                if(input == KEY_UP || input == KEY_DOWN || input == KEY_LEFT || input == KEY_RIGHT){
                    playerMovementSpeedHelper = 0;
                    playerMoves++;
                    playerStamina--;
                    playerStaminaRegenHelper = 0;
                }
            }

            deltaX = 0;
            deltaY = 0;

            playerMovementSpeedHelper++;
            playerStaminaRegenHelper++;
            playerFiringSpeedHelper++;
            playerMeleeHelper++;
            zombieSpawnRateHelper++;
            zombieForceSpawnHelper++;

            if(playerReloading){
                playerReloadingHelper++;
                if(playerReloadingHelper >= playerReloadingRate){
                    playerReloading = false;
                    playerAmmo += playerHiddenClip;
                    if(playerAmmo - playerClipLimit > 0){
                        playerAmmo -= playerClipLimit;
                        playerClip = playerClipLimit;
                    }else{
                        playerAmmo -= playerClipLimit;
                        playerClip = playerClipLimit + playerAmmo;
                        playerAmmo = 0;
                    }
                    playerTimesReloaded++;
                    playerHiddenClip = 0;
                    playerReloadingHelper = 0;
                }
            }

            if(playerBandaging){
                playerBandagesHelper++;
                if(playerBandagesHelper >= 1500){
                    if(playerHealth + (playerMaxHealth/4) <= playerMaxHealth){
                        playerHealth += (playerMaxHealth/4);
                    }else{
                        playerHealth = playerMaxHealth;
                    }
                    playerBandaging = false;
                    playerBandages--;
                    playerTimesBandaged++;
                    playerBandagesHelper = 0;
                }
            }

            refresh();
        }
    }

	endwin();
}
Exemple #17
0
 bool GameLevel::isPassableFor(int x, int y, const Actor* actor) const
 {
     auto actorAtPos = getActorAt(x, y);
     return mLevel.get(x, y).passable() && (actorAtPos == nullptr || actorAtPos == actor || actorAtPos->isPassable());
 }