예제 #1
0
bool BaseCreatureEntity::collideWithMap(int direction)
{
  calculateBB();

  int xTile0 = (boundingBox.left - offsetX) / tileWidth;
  int xTilef = (boundingBox.left + boundingBox.width - offsetX) / tileWidth;
  int yTile0 = (boundingBox.top - offsetY) / tileHeight;
  int yTilef = (boundingBox.top + boundingBox.height - offsetY) / tileHeight;

  if (boundingBox.top < 0) yTile0 = -1;

  for (int xTile = xTile0; xTile <= xTilef; xTile++)
    for (int yTile = yTile0; yTile <= yTilef; yTile++)
    {
      if (movingStyle == movWalking)
      {
        if ( dynamic_cast<DungeonMap*>(map)->isWalkable(xTile, yTile) == false ) return true;
      }
      else if (movingStyle == movFlying)
      {
        if ( dynamic_cast<DungeonMap*>(map)->isFlyable(xTile, yTile) == false ) return true;
      }
    }

    return false;
}
예제 #2
0
vec2 SVGPrimitive::getPosition() {
  if(hasMoved) {
    calculateBB();
    hasMoved = false;
  }
  vec2 position = vec2(0);
  switch(alignment) {
    case ALIGNMENT_CENTER: {
      position = vec2(bb.pos.x+bb.dim.x/2.0f,bb.pos.y+bb.dim.y/2.0f);
      break;
    }
    case ALIGNMENT_TOP_RIGHT: {
      position = vec2(bb.pos.x+bb.dim.x,bb.pos.y+bb.dim.y);
      break;
    }
    case ALIGNMENT_TOP_LEFT: {
      position = vec2(bb.pos.x,bb.pos.y+bb.dim.y);
      break;
    }
    case ALIGNMENT_BOT_RIGHT: {
      position = vec2(bb.pos.x+bb.dim.x,bb.pos.y);
      break;
    }
    case ALIGNMENT_BOT_LEFT: {
      position = vec2(bb.pos.x,bb.pos.y);
      break;
    }
    default: break;
  }
  return position;
}
예제 #3
0
UniformGrid::UniformGrid(unsigned int p_numTriangles, std::vector<RTMesh>* p_mesh, 
                         std::vector<RTMaterial>* p_material, std::vector<RTLight>* p_light, 
                         Vector3 p_numVoxels, Color clearColor)
:m_clearColor(clearColor)
{
	m_min = Vector3(std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity());
	m_max = Vector3(0, 0, 0);

	calculateBB(p_mesh, p_numVoxels);
	calculateGrid(p_numTriangles, p_mesh, p_material, p_light, p_numVoxels);
}
bool CollidingSpriteEntity::collideWithEntity(CollidingSpriteEntity* entity)
{
  calculateBB();
  entity->calculateBB();

  return boundingBox.intersects(entity->boundingBox);

  /*if (boundingBox.left > entity->boundingBox.left + entity->boundingBox.width) return false;
  if (boundingBox.Right < entity->boundingBox.Left) return false;
  if (boundingBox.Top > entity->boundingBox.Bottom) return false;
  if (boundingBox.Bottom < entity->boundingBox.Top) return false;*/

  return true;
}
bool CollidingSpriteEntity::isOnGround()
{
  calculateBB();

  int xTile0 = (boundingBox.left - offsetX) / tileWidth;
  int xTilef = (boundingBox.left + boundingBox.width - offsetX) / tileWidth;
  int yTile = (boundingBox.top + boundingBox.height + 1 - offsetY) / tileHeight;

  for (int xTile = xTile0; xTile <= xTilef; xTile++)
  {
    if (map->isDownBlocking(xTile, yTile)) return true;
  }
  return false;
}
예제 #6
0
bool SlimePetEntity::collideWithMap(int direction)
{
    calculateBB();

    int xTile0 = (boundingBox.left - offsetX) / tileWidth;
    int xTilef = (boundingBox.left + boundingBox.width - offsetX) / tileWidth;
    int yTile0 = (boundingBox.top - offsetY) / tileHeight;
    int yTilef = (boundingBox.top + boundingBox.height - offsetY) / tileHeight;

    if (boundingBox.top < 0) yTile0 = -1;

    for (int xTile = xTile0; xTile <= xTilef; xTile++)
        for (int yTile = yTile0; yTile <= yTilef; yTile++)
        {
            if (!game().getCurrentMap()->isFlyable(xTile, yTile))
            {
                switch (direction)
                {
                case DIRECTION_LEFT:
                    if (map->isLeftBlocking(xTile, yTile)) return true;
                    break;

                case DIRECTION_RIGHT:
                    if (map->isRightBlocking(xTile, yTile)) return true;
                    break;

                case DIRECTION_TOP:
                    if (map->isUpBlocking(xTile, yTile)) return true;
                    break;

                case DIRECTION_BOTTOM:
                    if (map->isDownBlocking(xTile, yTile)) return true;
                    break;
                }
            }
        }

    return false;
}
예제 #7
0
void GiantSlimeEntity::animate(float delay)
{
  slimeTimer -= delay;
  if (slimeTimer <= 0.0f)
  {
    slimeTypeEnum slimeType = SlimeTypeStandard;
    if (game().isAdvancedLevel())
    {
      slimeType =  (slimeTypeEnum)(slimeType + rand() % 3);
    }
    switch (slimeCounter)
    {
    case 0:
      new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * 1.5f, slimeType, true);
      break;
    case 1:
      new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * 1.5f, slimeType, true);
      break;
    case 2:
      new SlimeEntity(TILE_WIDTH * (MAP_WIDTH - 2) + TILE_WIDTH * 0.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
      break;
    case 3:
      new SlimeEntity(TILE_WIDTH * 1.5f, TILE_HEIGHT * (MAP_HEIGHT - 2) + TILE_HEIGHT * 0.5f, slimeType, true);
      break;
    }
    slimeTimer = 7.0f;
    slimeCounter ++;
    if (slimeCounter == 4) slimeCounter = 0;
  }

  if (age <= 0.0f)
  {
    age += delay;
    return;
  }
  EnemyEntity::animate(delay);
  if (specialState[SpecialStateIce].active) delay *= specialState[SpecialStateIce].param1;

  timer -= delay;
  if (timer <= 0.0f)
  {
    if (state == 0) // walking
    {
      counter--;
      if (counter >= 0)
      {
        timer = 0.5f;
        if (hp <= hpMax / 4)
          creatureSpeed = GIANT_SLIME_SPEED * 1.4f;
        if (hp <= hpMax / 2)
          creatureSpeed = GIANT_SLIME_SPEED * 1.2f;
        else
          creatureSpeed = GIANT_SLIME_SPEED;

        setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), GIANT_SLIME_SPEED ));
      }
      else
      {
        int r = rand() % 3;
        if (r == 0) changeToState(1);
        else if (r == 1) changeToState(3);
        else changeToState(5);
      }
    }
    else if (state == 1) // waiting for jumping
    {
      changeToState(2);
    }
    else if (state == 2) // jumping
    {
      changeToState(8);
    }
    else if (state == 3)
    {
      changeToState(4);
    }
    else if (state == 4) // walking
    {
      counter--;
      if (counter >= 0)
      {
        if (hp <= hpMax / 4)
          timer = missileDelay * 0.6f;
        if (hp <= hpMax / 2)
          timer = missileDelay * 0.8f;
        else
          timer = missileDelay;
        fire();
      }
      else
      {
        changeToState(8);
      }
    }
    else if (state == 5)
    {
      changeToState(6);
    }
    else if (state == 6)  // jump
    {
      changeToState(7); // fall
    }
    else if (state == 7)  // jump
    {
    }
    else if (state == 8)  // jump
    {
      changeToState(0); // fall
    }
  }

  if (state == 0) // walking
  {
    frame = ((int)(age * 2.0f)) % 2;
  }
  else if (state == 1 || state == 5) // waiting to jump
  {
    if (timer < 0.25f)
      frame = 1;
    else
      frame = 0;
  }
  else if (state == 2)  // jumping
  {
    hVelocity -= 700.0f * delay;

    h += hVelocity * delay;

    if (h <= 0.0f)
    {
      if (hp <= 0)
        dying();
      else
      {
        h = 0.0f;
        if (isFirstJumping)
        {
          isFirstJumping = false;
          hVelocity = 160.0f;
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT);
        }
        else
        {
          SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT_WEAK);
          viscosity = 0.96f;
          changeToState(0);
        }
      }
    }
    if (hVelocity > 0.0f) frame = 2;
    else frame = 0;
  }
  else if (state == 6) // ultra jump
  {
    if (h < 2000)
      h += hVelocity * delay;
  }
  else if (state == 7) // ultra jump
  {
    if (!isFalling && timer <= 2.2f)
    {
      isFalling = true;
      x = game().getPlayer()->getX();
      y = game().getPlayer()->getY();
      // to prevent collisions
      float x0 = TILE_WIDTH + 1;
      float xf = TILE_WIDTH * (MAP_WIDTH - 1) - 1;
      float y0 = TILE_HEIGHT + 1;
      float yf = TILE_HEIGHT * (MAP_HEIGHT - 1) - 1;

      calculateBB();

      if (boundingBox.left < x0) x += (x0 - boundingBox.left);
      else if (boundingBox.left + boundingBox.width > xf) x -= (boundingBox.left + boundingBox.width - xf);

      if (boundingBox.top < y0) y += (y0 - boundingBox.top);
      else if (boundingBox.top + boundingBox.height > yf) y -= (boundingBox.top + boundingBox.height - yf);
    }
    if (timer < 2.3f)
    {
      h += hVelocity * delay;
      if (h <= 0)
      {
        h = 0;
        changeToState(8);
        game().makeShake(0.8f);
        SoundManager::getInstance().playSound(SOUND_CYCLOPS_IMPACT);
      }
    }
  }

  if (state == 6 && timer < 0.5f)
  {
    int fade = timer * 512;
    if (fade < 0) fade = 0;
    sprite.setColor(sf::Color(255, 255, 255, fade));
  }
  else if (state == 7 && timer < 1.5f)
    sprite.setColor(sf::Color(255, 255, 255, 255));
  else if (state == 7 && timer < 2.0f)
    sprite.setColor(sf::Color(255, 255, 255, (2.0f - timer) * 512));
  else if (state == 7)
    sprite.setColor(sf::Color(255, 255, 255, 0));

  isMirroring = (frame == 2) && (velocity.x < 0.0f);
  z = y + 26;
}