示例#1
0
void Missile::RecvObject(RakNet::BitStream* bs, MyMsgIDs type)
{
	char _deleted;

	switch (type)
	{
		case ID_UPDATEMISSILE:
		{
			bs->Read(_deleted);
			// So were we deleted this time?
			if (_deleted == 1)
			{
				deleted = 1;
			}
			else
			{
				// Since we weren't deleted, let's update ourselvs
				float x, y, w;
				bs->Read(x);
				bs->Read(y);
				bs->Read(w);
				UpdateLoc(x, y, w);
				bs->Read(x);
				SetVelocityX(x);
				bs->Read(y);
				SetVelocityY(y);
			}
			break;
		}
	}
}
示例#2
0
void cAiBlock::Collision(cObject* a_pOther)
{
   if (a_pOther->GetType() == GetType())
   {
      SitFlush(a_pOther);
      m_AiLabel.setPosition(
         static_cast<int32_t>(GetPosition().x + GetBoundingBox().width / 2 - m_AiLabel.getLocalBounds().width / 2),
         static_cast<int32_t>(GetPosition().y + GetBoundingBox().height / 2 - m_AiLabel.getCharacterSize() / 2.0 - 10)
         );
      SetVelocityY(0, kNormal);

      sMessage l_Message;
      l_Message.m_From = GetUniqueId();
      l_Message.m_Category =GetResources()->GetMessageDispatcher()->Any();
      l_Message.m_Key = GetResources()->GetMessageDispatcher()->Any();
      l_Message.m_Value = "Settled";
      GetResources()->GetMessageDispatcher()->PostMessage(l_Message);

      m_Falling = false;

      PlaySound("Media/Sounds/BigFall.ogg");


   }
}
示例#3
0
void PlayerObject::HandleEvent(Event* pEvent)
{
	if (pEvent->GetEventID() == "playerKeyUp.Up")
	{
		SetVelocityY(0.0);
		ChangeAnimation("Idle");
	}
	else if (pEvent->GetEventID() == "playerKeyUp.Down")
	{
		SetVelocityY(0.0);
		ChangeAnimation("Idle");
	}
	else if (pEvent->GetEventID() == "playerKeyUp.Right")
	{
		SetVelocityX(0.0);
		ChangeAnimation("Idle");
		m_Animations[m_currentAnimation]->SetScale(XMFLOAT2(1.0f, 1.0f));
	}
	else if (pEvent->GetEventID() == "playerKeyUp.Left")
	{
		SetVelocityX(0.0);
		ChangeAnimation("Idle");
		m_Animations[m_currentAnimation]->SetScale(XMFLOAT2(-1.0f, 1.0f));
	}
	else if (pEvent->GetEventID() == "playerKeyDown.Up")
	{
		SetVelocityY(25.0f);
		ChangeAnimation("Walk");
	}
	else if (pEvent->GetEventID() == "playerKeyDown.Down")
	{
		SetVelocityY(-25.0f);
		ChangeAnimation("Walk");
	}
	else if (pEvent->GetEventID() == "playerKeyDown.Right")
	{
		SetVelocityX(25.0f);
		ChangeAnimation("Walk");
		m_Animations[m_currentAnimation]->SetScale(XMFLOAT2(1.0f, 1.0f));
	}
	else if (pEvent->GetEventID() == "playerKeyDown.Left")
	{
		SetVelocityX(-25.0f);
		ChangeAnimation("Walk");
		m_Animations[m_currentAnimation]->SetScale(XMFLOAT2(-1.0f, 1.0f));
	}
}
示例#4
0
void FallingObject::OnDestroy() {
	dying = true;
	SetPower(0);
	SetVelocityX(0);
	SetVelocityY(0);

	if( m_currentSprite == 24)
	{
		SetX(rand() % World::GetScreenWidth());
		SetY(0);
		SetVelocityY(5 + rand() % 10);
		SetVelocityX(-4);
		SetPower(1);
		SetHealth(1);
		dying = false;
		m_currentSprite = 5;
	}
}
示例#5
0
void cBonusShot::Initialize()
{
   m_OriginalPosition = GetPosition();

   // Initial angle starts away from destination
   m_AngleInRadians = atan2(m_Destination.y - m_OriginalPosition.y, m_Destination.x - m_OriginalPosition.x);
   m_AngleInRadians += g_kPI;

   SetVelocityX(cos(m_AngleInRadians) * m_Speed, kNormal);
   SetVelocityY(sin(m_AngleInRadians) * m_Speed, kNormal);
}
示例#6
0
void cAiBlock::Step(uint32_t a_ElapsedMiliSec)
{
   if (m_Falling)
   {
      SetVelocityY(1500, kNormal);
      m_AiLabel.setPosition(
         static_cast<int32_t>(GetPosition().x + GetBoundingBox().width / 2 - m_AiLabel.getLocalBounds().width / 2),
         static_cast<int32_t>(GetPosition().y + GetBoundingBox().height / 2 - m_AiLabel.getCharacterSize() / 2.0 - 10)
         );
   }
}
示例#7
0
Character::Character(World* world, int initialPosX, int initialPosY, int velX, int velY)
	: ControlableGameObject(world, initialPosX, initialPosY, CLIP_WIDTH,
			CLIP_HEIGHT , velX, velY, CHAR_HEALTH, CHAR_POWER, LOAD_PATH)
{
	m_currentSprite = 0;
	jumpFrame = 0;
	SetVelocityX(0);
	SetVelocityY(0);

	currentFrame = 0;
}
示例#8
0
void Character::Jumping()
{
    for (int i = 0; i < GetJumpSpeed(); i++)
    {
        float nextPosY = GetCurrentPositionY()*Constants::TileSize() + GetVelocityY();
        if (CheckNextYPositionJumping(GetCurrentPositionX()*Constants::TileSize(), nextPosY))
        {
            SetCurrentPositionY(nextPosY / Constants::TileSize());
        }
    }
    //Every tick update the fall speed
    if (GetVelocityY() + GetAccelerationY() <= 0)
    {
        SetVelocityY(GetVelocityY() + GetAccelerationY());
    }
    else
    {
        SetVelocityY(0.125);
        SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);
    }
}
示例#9
0
//this is moving in Y direction
bool Character::CheckNextYPositionJumping(float nextPosX, float nextPosY)
{
    float width = GetWidth()*Constants::TileSize();
    //check if tile is going off bounds return false;
    if ((nextPosY) / Constants::TileSize() < 0) {
        SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);
        SetVelocityY(0.125);
        //set no moving
        return false;
    }
    for (int i = 0; i < width; i++)
    {
        auto cellFuture = &cellMap_->at((nextPosX + i) / Constants::TileSize()).at((nextPosY) / Constants::TileSize() );
        if (cellFuture->GetTileType() == TILETYPE::SOLIDTILE)
        {
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);
            SetVelocityY(0.125);
            return false;
        }
    }
    return true;
}
示例#10
0
//this is moving in Y direction
bool Character::CheckNextYPositionFalling(float nextPosX, float nextPosY)
{
    float width = GetWidth()*Constants::TileSize();
    //check if tile is going off bounds return false;
    if ((nextPosY) / Constants::TileSize() + GetHeight() >= mapHeight_) {
        SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERONGROUND);
        SetVelocityY(0.125);
        //set no moving
        return false;
    }
    for (int i = 0; i < width; i++)
    {
        auto cellFuture = &cellMap_->at((nextPosX + i) / Constants::TileSize()).at((nextPosY) / Constants::TileSize() + GetHeight());
        if (cellFuture->GetTileType() == TILETYPE::SOLIDTILE || cellFuture->GetTileType() == TILETYPE::COLLISIONTOPTILE)
        {
            SetCurrentPositionY(cellFuture->GetCurrentPositionY() - GetHeight());
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERONGROUND);
            SetVelocityY(0.125);
            return false;
        }
    }
    return true;
}
示例#11
0
Character::Character(Settings *settings, int mapWidth, int mapHeight, std::vector<std::vector<Cell>> *cellMap)
{
    hasText_ = false;
    movespeed_ = 0;
    currentRotation_ = 0;
    hasImage_ = false;
    hasColor_ = false;
    hasImageReference_ = false;
    aiEnabled_ = true;

    mapWidth_ = mapWidth;
    mapHeight_ = mapHeight;

    cellMap_ = cellMap;


    settings_ = settings;
    KeyLeft_ = false;
    KeyRight_ = false;
    KeySpace_ = false;
    SetCurrentPosition(mapWidth_ / Constants::TileSize() + 1, mapHeight_ / Constants::TileSize() + 1);
    SetColor(al_map_rgb_f(1, 1, 1));
    SetWidth(0.8);
    SetHeight(0.8);

    SetGravityY(-9.8);
    SetVelocityY(0.125);
    SetMaxVelocityY(1);
    SetAccelerationY(0.03125);


    SetMoveSpeedDelta(0.0625);
    SetMoveSpeed(30);
    SetJumpSpeed(12);

    font30_ = al_load_font("arial.ttf", Constants::TileSize(), 0);



    SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);



}
示例#12
0
int Character::Keypress(ALLEGRO_EVENT *ev)
{
    int val = -2;
    if (ev->type == ALLEGRO_EVENT_KEY_DOWN)
    {
        switch (ev->keyboard.keycode)
        {
        case ALLEGRO_KEY_SPACE:
            if (GetCharacterYAxisState() == CHARACTERYAXISSTATES::CHARACTERONGROUND)
            {
                SetVelocityY(-0.5);
                SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERJUMPING);
                val = 1;
            }
            break;
        case ALLEGRO_KEY_RIGHT://choose later....
            KeyRight_ = true;
            break;
        case ALLEGRO_KEY_LEFT://choose later....
            KeyLeft_ = true;
            break;
            //case ALLEGRO_KEY_SPACE://choose later....
            //	KeySpace_ = true;
            //	break;
        }
    }
    if (ev->type == ALLEGRO_EVENT_KEY_UP)
    {
        switch (ev->keyboard.keycode)
        {
        case ALLEGRO_KEY_RIGHT://choose later....
            KeyRight_ = false;
            break;
        case ALLEGRO_KEY_LEFT://choose later....
            KeyLeft_ = false;
            break;
            //case ALLEGRO_KEY_SPACE://choose later....
            //	KeySpace_ = false;
            //	break;
        }
    }
    return val;
}
示例#13
0
void CFlower::UpdateCollison(CGameObject* _orther, CInput* _input , float _time)
{
	float time = m_collision->CheckAABBCollision(this,_orther,_time);
	if(time<1.0f)
	{
		//ListObjectColision
		switch (_orther->GetType())
		{
		case PIPETYPE:
		case LANDTYPE:
		case COINQUESTIONTYPE:
			{
				if(m_collision->GetDirectCollision() == BOTTOM)
				{
					m_pos.y += GetVelocity().y*_time*time +2;
					m_pos.y = (int)m_pos.y;//_orther->GetBound().top + m_sprite->GetSpriteHeight()/2 + 2;
					SetVelocityY(0);
					m_accel.y = 0;
					SetBound();

				}
				if(m_collision->GetDirectCollision()== TOP)
				{

				}
				if(m_collision->GetDirectCollision() == LEFT)
				{

					m_direct = 1;
				}

				if(m_collision->GetDirectCollision() == RIGHT)
				{
					m_direct = -1;
				}
				break;
			}
		}
	}
}
示例#14
0
void CFlower::Update(CInput *_input,float _time,CCamera* _camera,vector<CGameObject*> ListObjectInViewPort){
	if (m_GrowUp == true && GrowUpFinish ==false)
	{
		if (m_pos.y < StartPostion.y + m_sprite->GetSpriteHeight() )
		{
			m_accel.y = -m_maxAccelemeter.y/10;
		}

		else
		{
			GrowUpFinish = true;
			SetVelocityY(0);
			m_accel.y = 0;

		}
	}

	UpdateAnimation(_input,_time);
	CGameObject::Update(_input,_time,_camera,ListObjectInViewPort);

	/**************************************************************************************/
}
示例#15
0
void Character::Falling()
{
    for (int i = 0; i < GetMoveSpeed(); i++)
    {
        float nextPosY = GetCurrentPositionY()*Constants::TileSize() + GetVelocityY();
        if (CheckNextYPositionFalling(GetCurrentPositionX()*Constants::TileSize(), nextPosY))
        {
            SetCurrentPositionY(nextPosY / Constants::TileSize());
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);

        }
        else {
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERONGROUND);

            break;
        }
    }
    //Every tick update the fall speed
    if (GetVelocityY() + GetAccelerationY() <= GetMaxVelocityY() && GetCharacterYAxisState() != CHARACTERYAXISSTATES::CHARACTERONGROUND)
    {
        SetVelocityY(GetVelocityY() + GetAccelerationY());
    }
}
示例#16
0
void cBonusShot::Step (uint32_t a_ElapsedMiliSec)
{
   // Calculate angle to destination
   double l_AngleToDest =
      atan2(m_Destination.y - GetPosition().y, m_Destination.x - GetPosition().x);

   if (m_AngleInRadians < l_AngleToDest + g_kPI / 40 || m_AngleInRadians > l_AngleToDest - g_kPI / 40)
   {
      // We need to rotate our angle towards destination. Figure out direction.
      bool l_IsClockwise = false;
      if (l_AngleToDest < -g_kPI / 2.0)
      {
         l_IsClockwise = true;
      }

      double l_AngleDiff = l_AngleToDest - m_AngleInRadians;
      l_AngleDiff = std::fmod(l_AngleDiff, 2 * g_kPI);
      //~ if (l_AngleDiff > 0)
      //~ {
         //~ l_IsClockwise = false;
      //~ }
//~
      //~ if (l_AngleDiff > g_kPI)
      //~ {
         //~ l_IsClockwise = !l_IsClockwise;
      //~ }

      // Now rotate
      if (m_Speed < g_kMaxSpeed)
      {
         m_Speed += g_kAcceleration * a_ElapsedMiliSec / 1000;
      }
      //~ else
      //~ {
         //~ std::cout << "MAXXXXXXXXXXXX" << std::endl;
      //~ }

      double l_DistanceToRotate = m_Speed / 1000 * 4 * g_kPI * a_ElapsedMiliSec / 1000.0;
      if (l_DistanceToRotate > fabs(l_AngleDiff))
      {
         m_AngleInRadians = l_AngleToDest;
      }
      else if (l_IsClockwise)
      {
         m_AngleInRadians -= l_DistanceToRotate;
         if (m_AngleInRadians < -g_kPI)
         {
            m_AngleInRadians += 2 * g_kPI;
         }
      }
      else
      {
         m_AngleInRadians += l_DistanceToRotate;
         if (m_AngleInRadians > g_kPI)
         {
            m_AngleInRadians -= 2 * g_kPI;
         }
      }

   }

   SetVelocityX(cos(m_AngleInRadians) * m_Speed, kNormal);
   SetVelocityY(sin(m_AngleInRadians) * m_Speed, kNormal);

   // If the destination is between our position and original position then we
   // made it.
   sf::Vector3<double> l_Distance1 = m_Destination - m_OriginalPosition;
   sf::Vector3<double> l_Distance2 = GetPosition() - m_OriginalPosition;
   if (fabs(l_Distance2.x) > fabs(l_Distance1.x))
   {
      UnregisterObject(true);
   }

}