Example #1
0
void Player::toBoat(Display* display) {
	if(!((getCurrentTile(display) == display->getWaterHandle(1)) || getCurrentTile(display) == display->getWaterHandle(2))) {
		shipState = false;
	}
	if(keyboard->getState(SDLK_z)) {
		if((getNextTile(display) == display->getWaterHandle(1)) || (getNextTile(display) == display->getWaterHandle(2))) {
			shipState = true;
			goToNext();
		}
	}
}
Example #2
0
void Blob::update(){
	updatePassives();
	if(m_Health <= 0 && !ContainsFlags(m_UnitStatus,Dead)){
		die();
	}
	else if(!ContainsFlags(m_UnitStatus,Dead)){
		if(getTarget() && !ContainsFlags(m_UnitStatus,Consume)){
			if(m_Target->getHealth() <= 0){
				m_Target = NULL;
				stop();
			}
			else if(getTarget()->getCurrentTile() != getDestinationTile()){
				setDestinationTile(getTarget()->getCurrentTile());
			}
		}
		moveLerp();
		Enemy* enemy;
		if((enemy = BlobGame::instance()->enemyOnTile(getCurrentTile())) &&
			!ContainsFlags(m_UnitStatus,Consume) && 
			!ContainsFlags(enemy->getStatus(),Consumed)){
			m_Target = enemy;
			enemy->idle();
			enemy->fullStop();
			enemy->addStatus(Consumed);
			addPassive(&consume);
			addStatus(Consume);
			//MessageHandler::Instance()->createMessage
			//	(7,this,BlobGame::instance(),enemy,0);
		}
		updateAbilities();
	}
}
Example #3
0
void PsiBlob::update(){
	if(m_Health <= 0 && !ContainsFlags(m_UnitStatus,Dead)){
		die();
	}
	else if(!ContainsFlags(m_UnitStatus,Dead)){
		if(getTarget()){
			if(m_Target->getHealth() <= 0){
				m_Target = NULL;
				stop();
			}
			else if(getTarget()->getCurrentTile() != getDestinationTile()){
				setDestinationTile(getTarget()->getCurrentTile());
			}
		}
		moveLerp();
		Enemy* enemy;
		if((enemy = BlobGame::instance()->enemyOnTile(getCurrentTile()))){
			enemy->hit(enemy->getHealth());
		}
		updateAbilities();
	}
}
void ZombieDarkEntity::findNextRandomGoal()
{
  currentTile = getCurrentTile();

  DungeonMap* dMap = game().getCurrentMap();

  int backDirection = 0;
  switch (currentDirection)
  {
    case 4: backDirection = 6; break;
    case 6: backDirection = 4; break;
    case 2: backDirection = 8; break;
    case 8: backDirection = 2; break;
    default: break;
  }

  bool ok = false;
  {
    int r = 0;
    while (!ok)
    {
      r++;
      if (r == 150) // watchdog
        ok = true;
      else if (r == 40)
      {
        backDirection = 5;
      }

      int newDir = rand() % 4;
      if (newDir == 0)
      {
        if (backDirection != 4 && currentTile.x > 1 && (currentTile.y % 2 != 0) && dMap->isWalkable(currentTile.x - 1, currentTile.y))
        {
          currentDirection = 4;
          targetTile = IntCoord(currentTile.x - 1, currentTile.y);
          ok = true;
        }
      }
      else if (newDir == 1)
      {
        if (backDirection != 6 && currentTile.x < MAP_WIDTH - 2 && (currentTile.y % 2 != 0) && dMap->isWalkable(currentTile.x + 1, currentTile.y))
        {
          currentDirection = 6;
          targetTile = IntCoord(currentTile.x + 1, currentTile.y);
          ok = true;
        }
      }
      else if (newDir == 2)
      {
        if (backDirection != 8 && currentTile.y > 1 && (currentTile.x % 2 != 0) && dMap->isWalkable(currentTile.x, currentTile.y - 1))
        {
          currentDirection = 8;
          targetTile = IntCoord(currentTile.x, currentTile.y - 1);
          ok = true;
        }
      }
      else
      {
        if (backDirection != 2 && currentTile.y < MAP_HEIGHT - 2 && (currentTile.x % 2 != 0) && dMap->isWalkable(currentTile.x, currentTile.y + 1))
        {
          currentDirection = 2;
          targetTile = IntCoord(currentTile.x, currentTile.y + 1);
          ok = true;
        }
      }
    }
  }

  switch (currentDirection)
  {
    case 4: velocity.x = - creatureSpeed; velocity.y = 0.0f; break;
    case 6: velocity.x = + creatureSpeed; velocity.y = 0.0f; break;
    case 2: velocity.y = + creatureSpeed; velocity.x = 0.0f; break;
    case 8: velocity.y = - creatureSpeed; velocity.x = 0.0f; break;
    default: break;
  }

  nextFacingDirection = currentDirection;
}
void ZombieDarkEntity::findNextGoal()
{
  currentTile = getCurrentTile();

  float xPlayer = game().getPlayerPosition().x;
  float yPlayer = game().getPlayerPosition().y;

  float xDist = abs(x - xPlayer);
  float yDist = abs(y - yPlayer);

  int playerDirecion;
  if (xDist >= yDist)
  {
    if (xPlayer > x) playerDirecion = 6;
    else playerDirecion = 4;
  }
  else
  {
    if (yPlayer > y) playerDirecion = 2;
    else playerDirecion = 8;
  }

  switch (currentDirection)
  {
    case 4:
      if (playerDirecion != 6)
        currentDirection = playerDirecion;
      else
      {
        if (yPlayer > y) currentDirection = 2;
        else currentDirection = 8;
      }
      break;

    case 6:
      if (playerDirecion != 4)
        currentDirection = playerDirecion;
      else
      {
        if (yPlayer > y) currentDirection = 2;
        else currentDirection = 8;
      }
      break;

    case 2:
      if (playerDirecion != 8)
        currentDirection = playerDirecion;
      else
      {
        if (xPlayer > x) currentDirection = 6;
        else currentDirection = 4;
      }
      break;
    case 8:
      if (playerDirecion != 2)
        currentDirection = playerDirecion;
      else
      {
        if (xPlayer > x) currentDirection = 6;
        else currentDirection = 4;
      }
      break;
    default: break;
  }

  switch (currentDirection)
  {
    case 4:
      velocity.x = - creatureSpeed;
      velocity.y = 0.0f;
      targetTile = IntCoord(currentTile.x - 2, currentTile.y);
      break;
    case 6:
      velocity.x = + creatureSpeed;
      velocity.y = 0.0f;
      targetTile = IntCoord(currentTile.x + 2, currentTile.y);
      break;
    case 2:
      velocity.y = + creatureSpeed;
      velocity.x = 0.0f;
      targetTile = IntCoord(currentTile.x, currentTile.y + 2);
      break;
    case 8:
      velocity.y = - creatureSpeed;
      velocity.x = 0.0f;
      targetTile = IntCoord(currentTile.x, currentTile.y - 2);
      break;
    default: break;
  }
  nextFacingDirection = currentDirection;

  if (currentDirection == playerDirecion && attackTimer <= 0.0f)
  {
    giveRepulsion(false, Vector2D(velocity.x * 2.0f, velocity.y * 2.0f), 1.5f);
    attackTimer = 2.0f;
    SoundManager::getInstance().playSound(SOUND_ZOMBIE_ATTACKING);
    facingTimer = -1.0f;
  }
  else
    SoundManager::getInstance().playSound(SOUND_ZOMBIE_00 + rand() % 2);
}