Пример #1
0
bool Ball::Update(std::vector <std::string>& levelData, glm::vec2 startPos, glm::vec2 endPos, std::vector <glm::vec2>& bricksPosition, std::vector <glm::vec2>& upgradesPosition)
{
	m_position += m_direction * m_speed;

	// Colliding with player
	if (CollideWithPlayer(startPos, endPos))
	{
		return true;
	}

	// Colliding with level
	if (CollideWithLevel(levelData))
	{
		return true;
	}
	// Colliding with bricks
	if (CollideWithBricks(levelData, bricksPosition))
	{
        m_points += 10;
		return true;
	}
	//Colliding with upgrades is in MainGame -> GameLoop()

	// Check if ball is under player
	if (CheckLose(startPos))
	{
		return false;
	}
	return true;
}
Пример #2
0
void SceneGroup::Update()
{
	cnt++;
	if(cnt%25==0)
	{
		Vec3 start_pos = RandomVec3(Vec3(-220, -220, 250), Vec3(220, 220, 280));
		Vec3 start_speed = RandomVec3(Vec3(-0.2, -0.2, 0), Vec3(0.2, 0.2, 0));
		AddBomb(start_pos, start_speed);

		if(cnt%(3*25)==0 && !GameOver())
		{
			Vec3 player_pos = Vec3(0,0,0) * player_matrix->getMatrix() + Vec3(0,0,250);
			AddBomb(player_pos, Vec3(0,0,0));
		}
	}

	std::list<Bomb*>::iterator iter;
	for(iter = bomb_list.begin(); iter!=bomb_list.end();)
	{
		if(CollideWithScene(*iter))
		{
			if(!GameOver() && CollideWithPlayer(*iter))
			{
				hurt_cnt = 60;
				health_num -=3;
			}
			remove_list.push(*iter);
			iter = bomb_list.erase(iter);
		}
		else
		{
			iter++;
		}
	}

	if(hurt_cnt > 0 && hurt==false)
	{
		hurt = true;
		player_matrix->getOrCreateStateSet()->setAttributeAndModes(program_red, StateAttribute::Values::ON);
	}
	else if(hurt_cnt == 0 && hurt == true)
	{
		hurt = false;
		player_matrix->getOrCreateStateSet()->setAttributeAndModes(program_normal, StateAttribute::Values::ON);
	}

	if(hurt_cnt > 0)
		hurt_cnt--;

	s_stream.clear();
	for(int i=1; i<=health_num; i++)
	{
		s_stream<<(char)(3);
	}
	std::string health_text;
	s_stream>>health_text;
	health->setText(health_text);

	if(GameOver())
	{
		player_matrix->setNodeMask(0);
	}
	else
	{
		std::string score_text;
		s_stream.clear();
		s_stream<<"Score: "<<(cnt/10);
		s_stream>>score_text;
		score->setText(score_text);
	}

	while(!remove_list.empty())
	{
		Entity* now_node = remove_list.front();
		remove_list.pop();
		scene_root->removeChild(now_node);
	}
}
Пример #3
0
void CPlayer::OnFrameMove( double fTime, float fElapsedTime, CSim* pSim )
{
    m_vPosition[1] = m_vPosition[0];
    m_vVelocity[1] = m_vVelocity[0];
    m_vAcceleration[1] = m_vAcceleration[0];

    // Collide with other balls
    UINT NumGrids = m_GridArray.GetSize();
    for( UINT i = 0; i < NumGrids; i++ )
    {
        GRID_CELL* pCell = pSim->GetGridCell( m_GridArray.GetAt( i ) );
        UINT NumPlayers = pCell->BallArray.GetSize();
        for( UINT b = 0; b < NumPlayers; b++ )
        {
            CPlayer* pPlayer = pSim->GetPlayer( pCell->BallArray.GetAt( b ) );
            if( pPlayer->GetID() != m_ID )
            {
                CollideWithPlayer( pPlayer );
            }
        }
    }

    // Euler integration for now
    m_vPosition[1] = m_vPosition[1] + m_vVelocity[1] * fElapsedTime;
    D3DXVECTOR3 accel = m_vAcceleration[0] + m_vGravity;
    m_vVelocity[1] = m_vVelocity[1] + accel * fElapsedTime;
    D3DXVECTOR3 vMotion;
    D3DXVec3Normalize( &vMotion, &m_vVelocity[1] );
    m_vAcceleration[1] = m_vAcceleration[1] - vMotion * m_fDrag;
    if( D3DXVec3Dot( &m_vAcceleration[1], &m_vVelocity[1] ) < 0 )
        m_vAcceleration[1] = D3DXVECTOR3( 0, 0, 0 );

    float fWorld = m_pTerrain->GetWorldScale() / 2.0f;
    if( m_vPosition[1].x < -fWorld )
    {
        m_vPosition[1].x = -fWorld;
        m_vVelocity[1].x = fabs( m_vVelocity[1].x );
    }
    if( m_vPosition[1].x > fWorld )
    {
        m_vPosition[1].x = fWorld;
        m_vVelocity[1].x = -fabs( m_vVelocity[1].x );
    }
    if( m_vPosition[1].z < -fWorld )
    {
        m_vPosition[1].z = -fWorld;
        m_vVelocity[1].z = fabs( m_vVelocity[1].z );
    }
    if( m_vPosition[1].z > fWorld )
    {
        m_vPosition[1].z = fWorld;
        m_vVelocity[1].z = -fabs( m_vVelocity[1].z );
    }

    // Perturb the velocity vector by the terrain
    float fHeight = m_pTerrain->GetHeightOnMap( &m_vPosition[1] );
    m_vPosition[1].y = fHeight + m_fRadius;
    D3DXVECTOR3 norm = m_pTerrain->GetNormalOnMap( &m_vPosition[1] );

    D3DXVECTOR3 right;
    D3DXVECTOR3 tan;
    D3DXVec3Cross( &right, &norm, &m_vVelocity[1] );
    D3DXVec3Cross( &tan, &right, &norm );
    D3DXVec3Normalize( &tan, &tan );
    float fMag = D3DXVec3Dot( &tan, &m_vVelocity[1] );
    m_vVelocity[1] = fMag * tan;
}