Ejemplo n.º 1
0
    void UpdatePhysics()
    {
        const float kPushPower = 5.0f;
        // sht::math::Vector3 force(0.0f);
        // if (keys_.key_down(sht::PublicKey::kLeft))
        //     force.z += kPushPower;
        // if (keys_.key_down(sht::PublicKey::kRight))
        //     force.z -= kPushPower;
        // if (keys_.key_down(sht::PublicKey::kDown))
        //     force.x += kPushPower;
        // if (keys_.key_down(sht::PublicKey::kUp))
        //     force.x -= kPushPower;

        sht::math::Vector3 force = ball2_->body()->position() - ball_->body()->position();
        force.Normalize();
        force *= 10.0; // gravity force
        if (keys_.key_down(sht::PublicKey::kLeft))
            force.z += kPushPower;
        if (keys_.key_down(sht::PublicKey::kRight))
            force.z -= kPushPower;
        if (keys_.key_down(sht::PublicKey::kDown))
            force.x += kPushPower;
        if (keys_.key_down(sht::PublicKey::kUp))
            force.x -= kPushPower;
        // Update forces
        ball_->body()->Activate(); // this body may be sleeping, thus we activate it
        ball_->body()->ApplyCentralForce(force);

        // Update physics engine
        physics_->Update(GetFrameTime());
    }
Ejemplo n.º 2
0
/***********************************************************************************
 Function Name      : GLES2FlushBuffersGC
 Inputs             : hContext, psSurface, bFlushAllSurfaces, bNewExternalFrame, bWaitForHW
 Outputs            : -
 Returns            : Success
 Description        : Flush any buffered graphics commands
************************************************************************************/
static IMG_EGLERROR GLES2FlushBuffersGC(EGLContextHandle hContext,
										 EGLRenderSurface *psSurface,
										 IMG_BOOL bFlushAllSurfaces,
										 IMG_BOOL bNewExternalFrame,
										 IMG_BOOL bWaitForHW)
{
	GLES2Context *gc = (GLES2Context *)hContext;
	IMG_EGLERROR eError = IMG_EGL_NO_ERROR;
	EGLRenderSurface *psRenderSurface;
	
	if(psSurface)
	{
		psRenderSurface = psSurface;
	}
	else
	{
		psRenderSurface = gc->sFrameBuffer.sDefaultFrameBuffer.sDrawParams.psRenderSurface;
	}

#if defined(TIMING) || defined(DEBUG)
	GetFrameTime(gc);
#endif

	if(bFlushAllSurfaces)
	{
		if(!FlushAllUnflushedFBO(gc, bWaitForHW))
		{
			eError = IMG_EGL_GENERIC_ERROR;
		}
	}

	if(psRenderSurface)
	{
		IMG_UINT32 ui32Flags = 0;
		
		if (psRenderSurface->bInFrame)
		{
			ui32Flags |= GLES2_SCHEDULE_HW_LAST_IN_SCENE;
			GLES2_INC_COUNT(GLES2_TIMER_SWAP_BUFFERS, 1);
		}

		if(bWaitForHW)
		{
			ui32Flags |= GLES2_SCHEDULE_HW_WAIT_FOR_3D;
		}

		if(psRenderSurface->bInFrame || bWaitForHW)
		{
			eError = ScheduleTA(gc, psRenderSurface, ui32Flags);
		}

		if((eError == IMG_EGL_NO_ERROR) && bNewExternalFrame)
		{
			psRenderSurface->bInExternalFrame = IMG_FALSE;
		}
	}

	return eError;
}
Ejemplo n.º 3
0
void CGameBoard::drawExplosions()
{
    QList<CExplosion *>::iterator it;
    for (it = m_explosionsList.begin(); it != m_explosionsList.end(); ++it)
    {
        QVector<CParticle *> particles = (*it)->getParticles();
        if (static_cast<unsigned>(particles[0]->GetCurrentFrame()) ==
                particles[0]->GetAnim()->Size() - 1)
        {
            m_explosionsList.removeOne(*it);
            delete *it;
        }

        for (int j = 0; j < particles.size(); j++)
        {
            unsigned x = particles[j]->getX();
            unsigned y = particles[j]->getY();
            if (m_map.getBlock(x, y) == Box)
            {
                m_map.setBlock(x, y, Floor);
            }
            else if (m_map.getBlock(x, y) == BonusBox)
            {
                m_map.setBlock(x, y, Bonus);
            }
            Draw(*particles[j]);
            particles[j]->anim(GetFrameTime());
            for (int i = 0; i < m_playersList.size(); ++i)
            {
                CPlayer *player = m_playersList[i];
                if (collision(*particles[j], *player))
                {
                    if (player->IsPaused())
                    {
                        player->Play();
                    }
                    player->explode();
                    player->setDirection(Stopped);

                    // int lastPlayer = lastPlayerAlive(); /* Get the ID of the last player alive */
                    //if (lastPlayer >= 0) /* Just one player still alive, he wins */
                    //{
                        /*
                        CPlayer *winner = m_playersList[lastPlayer];
                        winner->score++;
                        playersRespawn();
                        */
                    //}
                }
            }
        }
    }
}
Ejemplo n.º 4
0
void Camera::initCamera()
{
	frameCount++;					//Increases our frame count
	if (GetTime() > 1.0f)			//Calls the GetTime function
	{
		fps = frameCount;
		frameCount = 0;
		StartTimer();				//Calls the StartTimer function
	}

	frameTime = GetFrameTime();		//Stores the result of the GetFrameTime function

	DetectInput(frameTime);			//Calls the DetectInput function
}
Ejemplo n.º 5
0
	void Update() final
	{
		const float kFrameTime = GetFrameTime();

		camera_manager_->Update(kFrameTime);

		angle_ += 0.1f * kFrameTime;
		light_position_.Set(light_distance_ * cosf(angle_), 1.0f, light_distance_ * sinf(angle_));
		//light_position_.Set(1.0f, light_distance_, 1.0f);

		// Update matrices
		renderer_->SetViewMatrix(camera_manager_->view_matrix());
		UpdateProjectionMatrix();
		projection_view_matrix_ = renderer_->projection_matrix() * renderer_->view_matrix();

		BindShaderVariables();
	}
Ejemplo n.º 6
0
void cMotion::Output(const std::string& out_filepath) const
{
	FILE* file = cFileUtil::OpenFile(out_filepath, "w");

	fprintf(file, "{\n");
	fprintf(file, "\"%s\": ", gLoopKey.c_str());

	if (mLoop)
	{
		fprintf(file, "true,\n");
	}
	else
	{
		fprintf(file, "false,\n");
	}

	fprintf(file, "\"Frames\":\n[\n");

	int num_frames = GetNumFrames();
	for (int f = 0; f < num_frames; ++f)
	{
		if (f != 0)
		{
			fprintf(file, ",\n");
		}

		Eigen::VectorXd curr_frame = mFrames.row(f);
		double curr_time = curr_frame[eFrameTime];
		double dur = 0;
		if (f < num_frames - 1)
		{
			double next_time = GetFrameTime(f + 1);
			dur = next_time - curr_time;
		}
		curr_frame[eFrameTime] = dur;
		std::string frame_json = cJsonUtil::BuildVectorJson(curr_frame);
		fprintf(file, "%s", frame_json.c_str());
	}

	fprintf(file, "\n]");
	fprintf(file, "\n}");
	cFileUtil::CloseFile(file);
}
Ejemplo n.º 7
0
int D3DApp::messageloop(){	//The message loop

	MSG msg;	//Create a new message structure
	ZeroMemory(&msg, sizeof(MSG));	//clear message structure to NULL

	while (true)	//while there is a message
	{
		//if there was a windows message
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)	//if the message was WM_QUIT
				break;	//Exit the message loop

			TranslateMessage(&msg);	//Translate the message

			//Send the message to default windows procedure
			DispatchMessage(&msg);
		}

		else{
			// run game code    
			frameCount++;
			if (GetTime() > 1.0f)
			{
				fps = frameCount;
				frameCount = 0;
				StartTimer();
			}

			frameTime = GetFrameTime();

			DetectInput(frameTime);
			UpdateScene(frameTime);
			DrawScene();
		}


	}

	return (int)msg.wParam;		//return the message

}
Ejemplo n.º 8
0
// Once connected to the network, check the sockets for pending information
// and when information is ready, send either a Ping or a Pong.
void NetworkUpdate()
{
	// CheckSockets
	//
	// If any of the sockets in the socket_set are pending (received data, or requests)
	// then mark the socket as being ready. You can check this with IsSocketReady(client_res->socket)
	int active = CheckSockets(socket_set, 0);
	if (active != 0) {
		TraceLog(LOG_DEBUG,
				 "There are currently %d socket(s) with data to be processed.", active);
	}

	// IsSocketReady
	//
	// If the socket is ready, attempt to receive data from the socket
	//  int bytesRecv = 0;
	//  if (IsSocketReady(server_res->socket)) {
	//      bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);
	//  }
	int bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen);

	// If we received data, was that data a "Ping!" or a "Pong!"
	if (bytesRecv > 0) {
		if (strcmp(recvBuffer, pingmsg) == 0) { pong = true; }
		if (strcmp(recvBuffer, pongmsg) == 0) { ping = true; }
	}

	// After each delay has expired, send a response "Ping!" for a "Pong!" and vice versa
	elapsed += GetFrameTime();
	if (elapsed > delay) {
		if (ping) {
			ping = false;
			SocketSend(server_res->socket, pingmsg, msglen);
		} else if (pong) {
			pong = false;
			SocketSend(server_res->socket, pongmsg, msglen);
		}
		elapsed = 0.0f;
	}
}
Ejemplo n.º 9
0
    void UpdatePhysics()
    {
        if (!object_manager_->editor_mode())
        {
            const float kPushPower = 5.0f;
            sht::math::Vector3 force(0.0f);
            if (keys_.key_down(sht::PublicKey::kLeft))
                force.z += kPushPower;
            if (keys_.key_down(sht::PublicKey::kRight))
                force.z -= kPushPower;
            if (keys_.key_down(sht::PublicKey::kDown))
                force.x += kPushPower;
            if (keys_.key_down(sht::PublicKey::kUp))
                force.x -= kPushPower;
            // Update forces
            ball_->body()->Activate(); // this body may be sleeping, thus we activate it
            ball_->body()->ApplyCentralForce(force);
        }

        // Update physics engine
        physics_->Update(GetFrameTime());
    }
Ejemplo n.º 10
0
    void Update() final
    {
        const float kFrameTime = GetFrameTime();

        // Update light parameters
        light_angle_ += 0.2f * kFrameTime;
        light_position_.Set(light_distance_*cosf(light_angle_), light_distance_, light_distance_*sinf(light_angle_));

        UpdatePhysics();

        console_->Update(kFrameTime);

        // Camera should be updated after physics
        camera_manager_->Update(kFrameTime);

        // Update matrices
        UpdateProjectionMatrix();
        renderer_->SetViewMatrix(camera_manager_->view_matrix());
        projection_view_matrix_ = renderer_->projection_matrix() * renderer_->view_matrix();

		BindShaderVariables();
    }
Ejemplo n.º 11
0
bool CClientFXMgr::UpdateAllActiveFX(LTBOOL bAppHasFocus)
{
	if(!m_hCamera)
	{
		assert(!"No camera specified for this effect manager");
		return false;
	}

	//Update our frame time, before any early outs so there aren't giant pops when the early
	//out fails
	float fFrameTime = GetFrameTime();

	//add in all the effects from our next update list and clear that out
	m_collActiveGroupFX.AppendList(m_collNextUpdateGroupFX);

	HCONSOLEVAR hVar = m_pClientDE->GetConsoleVar("UpdateClientFX");
	if (hVar)
	{
		float fVal = m_pClientDE->GetVarValueFloat(hVar);

		if (!fVal) 
			return true;
	}

	//see if we should even update
	if(IsPaused())
	{
		//no time has elapsed, don't bother updating
		return true;
	}

	//setup the callback
	SetupCreateEffectCallback();

	//get the position of the camera
	LTVector vCameraPos;
	g_pLTClient->GetObjectPos(m_hCamera, &vCameraPos);

    // Set params....
	CClientFXDB::GetSingleton().SetAppFocus( bAppHasFocus ? true : false );
    
    // This call is no longer referenced
    /*
	CClientFXDB::GetSingleton().SetPlayer( g_pPlayerMgr->GetMoveMgr()->GetObject() );
    */
	
	//
	// Update the group Instances
	//
	
	CLinkListNode<CLIENTFX_INSTANCE *>	*pInstNode = m_collActiveGroupFX.GetHead();
	CLinkListNode<CLIENTFX_INSTANCE *>	*pNextNode;

	while( pInstNode )
	{
		CLIENTFX_INSTANCE *pInst		= pInstNode->m_Data;

		//cache the next pointer in case the instance gets removed
		pNextNode	= pInstNode->m_pNext;

		//see if this instance is suspended, if so, just call the suspended update
		if(UpdateInstanceSuspended(vCameraPos, pInst))
		{
			//just run through all effects and give them a suspended updata
			CLinkListNode<FX_LINK> *pActiveNode = pInst->m_collActiveFX.GetHead();
			while( pActiveNode )
			{
				pActiveNode->m_Data.m_pFX->SuspendedUpdate(fFrameTime);
				pActiveNode = pActiveNode->m_pNext;
			}

			//don't bother with any interval updating
			pInstNode = pNextNode;
			continue;
		}


		//determine the start and end of our update interval, relative to the instance
		//time frame
		float fStartInterval	= pInst->m_tmElapsed;
		float fEndInterval		= fStartInterval + fFrameTime;

		//we now need to iteratively break this interval down into a series of intervals that
		//do not extend past the end of the effect
		bool bLastSegment = false;
		while(!bLastSegment)
		{
			//pick whichever is closest, the end of the interval, or the duration of the
			//effect
			float fEndSegment = pInst->m_fDuration;

			if(fEndInterval < pInst->m_fDuration)
			{
				bLastSegment = true;
				fEndSegment = fEndInterval;
			}
			
			//alright, we now have an interval, update all the effects that lie within it
			UpdateInstanceInterval(pInst, fStartInterval, fEndSegment);

			//now move on to the next interval if necessary
			if(!bLastSegment)
			{
				fStartInterval	= 0.0f;
				fEndInterval	-= pInst->m_fDuration;
			}
		}

		//all done, save our time
		pInst->m_tmElapsed = fEndInterval;

		//see if we are done with this effect
		if( pInst->m_collActiveFX.GetSize() == 0 )
		{				
			// Destroy the instance
			g_pCLIENTFX_INSTANCE_Bank->Delete( pInst );
			m_collActiveGroupFX.Remove(pInstNode);
		}

		//and move onto the next node
		pInstNode = pNextNode;
	}

	// Success !!
	return true;
}	
Ejemplo n.º 12
0
/**
  Function called to refresh the view on canvas
*/
void CGameBoard::OnUpdate()
{
    Clear(sf::Color(195, 195, 195)); /* Grey */
    sf::Shape rightBorder = sf::Shape::Rectangle(510, 0, 630, 510, sf::Color(127, 127, 127));
    Draw(rightBorder);

    if (m_fpsRefreshTime.GetElapsedTime() >= 1.0f)
    {
        m_frameRate = 1.f / GetFrameTime();
        m_fpsRefreshTime.Reset();
    }
    drawMap();
    drawFPS();
    drawStatus();
    drawExplosions();
    drawPlayers();
    drawBonusCanvas();

    if (!m_gameBegin || !m_connected)
    {
        return;
    }

    /* Handling Event */
    CPlayer *me = m_playersList[0]; /* I am the first player of the list */
    float x = me->GetPosition().x;
    float y = me->GetPosition().y;
    std::string pos = QString("%1 %2").arg(me->GetPosition().x).arg(me->GetPosition().y)
                                      .toStdString();
    if (me->isDead())
    {
        return;
    }

    sf::Event event;
    while (GetEvent(event))
    {
        switch (event.Type)
        {
        case sf::Event::KeyPressed:
            if (event.Key.Code == sf::Key::Space)
            {
                plantBomb();
            }
            else if (event.Key.Code == sf::Key::E)
            {
                useSpecialBonus();
            }
            break;
        default:
            break;
        }
    }


    if (GetInput().IsKeyDown(sf::Key::Right) ||
        GetInput().IsKeyDown(sf::Key::D))
    {
        switch (me->getCollision(Right, m_map))
        {
        case Floor:
        case Bonus:
            if (me->getDirection() != Right)
            {
                m_networkManager->sendMovePacket(me->getNick(), Right, x, y);
                me->setDirection(Right);
            }
            break;
        case Bomb:
            if (me->getBonus(CBonus::BombPass) != NULL)
            {
                me->setDirection(Right);
            }
            else if (me->getBonus(CBonus::BombKick) != NULL)
            {
                QList<CBomb *>::iterator it;
                for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                {
                    CBomb *bomb = *it;
                    if (bomb->getX() == me->getX() + 1 && bomb->getY() == me->getY())
                    {
                        bomb->setDirection(CBomb::Right);
                        m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                        break;
                    }
                }
            }
            break;
        default:
            break;
        }

        if (me->IsPaused())
        {
            me->Play();
        }
    }
     else if (GetInput().IsKeyDown(sf::Key::Left) ||
              GetInput().IsKeyDown(sf::Key::Q))
     {
         switch (me->getCollision(Left, m_map))
         {
         case Floor:
         case Bonus:
              if (me->getDirection() != Left)
              {
                  me->setDirection(Left);
                  m_networkManager->sendMovePacket(me->getNick(), Left, x, y);
              }
              break;
         case Bomb:
              if (me->getBonus(CBonus::BombPass) != NULL)
              {
                  me->setDirection(Left);
              }
              else if (me->getBonus(CBonus::BombKick) != NULL)
              {
                  QList<CBomb *>::iterator it;
                  for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                  {
                      CBomb *bomb = *it;
                      if (bomb->getX() == me->getX() - 1 && bomb->getY() == me->getY())
                      {
                          bomb->setDirection(CBomb::Left);
                          m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                          break;
                      }
                  }
              }
              break;
         default:
              break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }
     }
     else if (GetInput().IsKeyDown(sf::Key::Down) ||
              GetInput().IsKeyDown(sf::Key::S))
     {
         switch (me->getCollision(Down, m_map))
         {
         case Floor:
         case Bonus:
             if (me->getDirection() != Down)
              {
                   me->setDirection(Down);
                   m_networkManager->sendMovePacket(me->getNick(), Down, x, y);
              }
             else if (me->getBonus(CBonus::BombKick) != NULL)
             {
                 QList<CBomb *>::iterator it;
                 for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                 {
                     CBomb *bomb = *it;
                     if (bomb->getX() == me->getX() && bomb->getY() == me->getY() + 1)
                     {
                         bomb->setDirection(CBomb::Down);
                         m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                         break;
                     }
                 }
             }
             break;
         case Bomb:
             if (me->getBonus(CBonus::BombPass) != NULL)
             {
                 me->setDirection(Down);
             }
             break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else if (GetInput().IsKeyDown(sf::Key::Up) ||
              GetInput().IsKeyDown(sf::Key::Z))
     {
         switch (me->getCollision(Up, m_map))
         {
         case Floor:
         case Bonus:
               if (me->getDirection() != Up)
               {
                    m_networkManager->sendMovePacket(me->getNick(), Up, x, y);
                    me->setDirection(Up);
               }
               break;
         case Bomb:
               if (me->getBonus(CBonus::BombPass) != NULL)
               {
                   me->setDirection(Up);
               }
               else if (me->getBonus(CBonus::BombKick) != NULL)
               {
                   QList<CBomb *>::iterator it;
                   for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                   {
                       CBomb *bomb = *it;
                       if (bomb->getX() == me->getX() && bomb->getY() == me->getY() - 1)
                       {
                           bomb->setDirection(CBomb::Up);
                           m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                           break;
                       }
                   }
               }
               break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else
     {
         if (me->getDirection() != Stopped && me->getElapsedTime() >= me->getStopTime())
         {
             me->setDirection(Stopped);
             m_networkManager->sendMovePacket(me->getNick(), Stopped, x, y);
             me->Pause();
         }
     }
}
Ejemplo n.º 13
0

////////////////////////////////////////////////////////////
/// Limit the framerate to a maximum fixed frequency for a window
////////////////////////////////////////////////////////////
void sfWindow_SetFramerateLimit(sfWindow* Window, unsigned int Limit)
{
    CSFML_CALL(Window, SetFramerateLimit(Limit))
}


////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window
////////////////////////////////////////////////////////////
float sfWindow_GetFrameTime(sfWindow* Window)
{
    CSFML_CALL_RETURN(Window, GetFrameTime(), 0.f)
}

////////////////////////////////////////////////////////////
/// Change the joystick threshold, ie. the value below which
/// no move event will be generated
///
/// \param Threshold : New threshold, in range [0, 100]
///
////////////////////////////////////////////////////////////
void sfWindow_SetJoystickThreshold(sfWindow* Window, float Threshold)
{
    CSFML_CALL(Window, SetJoystickThreshold(Threshold))
}
Ejemplo n.º 14
0
void CGameBoard::drawPlayers()
{
    unsigned rectx = 520, recty = 70;
    for (int i = 0; i < m_playersList.size(); ++i)
    {
        CPlayer *player = m_playersList[i];
        player->checkBonusTime();

        if (player->getDirection() != Stopped)
        {
            unsigned x = player->getX();
            unsigned y = player->getY();

            switch (player->getCollision(player->getDirection(), m_map))
            {
            case Floor:
                player->move(player->getDirection(), GetFrameTime());
                break;
            case Box:
            case BonusBox:
            case Wall:
                break;
            case Bonus:
                if (i == 0) /* If I got the bonus */
                {
                    if (m_bonusCanvas == NULL)
                    {
                        m_bonusCanvas = new CBonusCanvas(0.05f, 1.0f, sf::Rect<int>(535, 320,605, 390));
                        m_map.setBlock(x, y, Floor);
                    }
                    else
                    {
                        m_bonusCanvas->Reset();
                        m_bonusCanvas->Play();
                        m_map.setBlock(x, y, Floor);
                    }
                }
                else
                {
                    m_map.setBlock(x, y, Floor);
                }
                QSound::play(SND_BONUS);
                break;
            case Bomb:
                if (player->getBonus(CBonus::BombPass) != NULL)
                {
                    player->move(player->getDirection(), GetFrameTime());
                }
                else if (player->getBonus(CBonus::BombKick) != NULL)
                {
                    unsigned _x = 0, _y = 0;
                    CBomb::Direction direction = CBomb::Fixed;
                    switch (player->getDirection())
                    {
                    case Right:
                       _x = player->getX() + 1;
                       _y = player->getY();
                       direction = CBomb::Right;
                       break;
                    case Left:
                       _x = player->getX() - 1;
                       _y = player->getY();
                       direction = CBomb::Left;
                       break;
                    case Up:
                       _x = player->getX();
                       _y = player->getY() - 1;
                       direction = CBomb::Up;
                       break;
                    case Down:
                       _x = player->getX();
                       _y = player->getY() + 1;
                       direction = CBomb::Down;
                    default:
                       break;
                    }
                    QList<CBomb *>::iterator it;
                    for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                    {
                        CBomb *bomb = *it;
                        if (bomb->getX() == _x && bomb->getY() == _y)
                        {
                            bomb->setDirection(direction);
                            m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                            break;
                        }
                    }
                }
                break;
            default:
                break;
            }
        }

        if (player->isDead())
        {
            if (static_cast<unsigned>(player->GetCurrentFrame()) ==
                player->GetAnim()->Size() - 1)
            {
                player->Pause();
                continue;
            }
        }
        player->anim(GetFrameTime());
        Draw(*player);

        sf::Color rectColor;
        const std::string &playerColor = player->getColor();
        if (playerColor == "red")
        {
            rectColor = sf::Color(255, 0, 0);
        }
        else if (playerColor == "blue")
        {
            rectColor = sf::Color(9, 169, 255);
        }
        else if (playerColor == "green")
        {
            rectColor = sf::Color(3, 180, 32);
        }
        else
        {
            rectColor = sf::Color(128, 128, 128);
        }

        sf::Shape rect = sf::Shape::Rectangle(rectx, recty, rectx + 100, recty + 15, rectColor, 1.0f,
                                              sf::Color::Black);
        Draw(rect);
        sf::String nick;
        nick.SetText(player->getNick());
        nick.SetPosition(rectx + 5, recty + 2);
        nick.SetSize(10.0f);
        nick.SetStyle(sf::String::Bold);
        Draw(nick);
        sf::String score;
        score.SetText(QString("%1").arg(player->score).toStdString());
        score.SetPosition(rectx + 90, recty + 2);
        score.SetSize(10.0f);
        score.SetStyle(sf::String::Bold);
        Draw(score);
        recty += 20;
    }
    sf::String txtRounds(QString("Round %1/%2").arg(m_currentRound).arg(m_roundsNumber)
                         .toStdString());
    txtRounds.SetPosition(540, 200);
    txtRounds.SetColor(sf::Color::Black);
    txtRounds.SetStyle(sf::String::Bold);
    txtRounds.SetSize(15.0f);
    Draw(txtRounds);
}
Ejemplo n.º 15
0
/**
  Draw all the blocks of the map
*/
void CGameBoard::drawMap()
{
    /* Drawing the map */
    for(unsigned i = 0; i < MAP_WIDTH; i++)
    {
        for(unsigned j = 0; j < MAP_HEIGHT; j++)
        {
            switch(m_map.getBlock(i, j))
            {
            case Wall:
                m_wall.SetPosition(BLOCK_SIZE * i, BLOCK_SIZE * j);
                Draw(m_wall);
                break;
            case Box:
            case BonusBox:
                m_box.SetPosition(BLOCK_SIZE * i, BLOCK_SIZE * j);
                Draw(m_box);
                break;
            case Bonus:
                m_bonus.SetPosition((BLOCK_SIZE * i) + 5, (BLOCK_SIZE * j) + 5);
                Draw(m_bonus);
                break;
            case Floor:
                break;
            case Player:
                break;
            case Bomb:
                break;
            default:
                break;
            }
        }
    }

    /* Drawing the bombs */
    QList<CBomb *>::iterator it = m_bombsList.begin();
    while(it != m_bombsList.end())
    {
        CBomb *bomb = *it;
        unsigned x = bomb->getX();
        unsigned y = bomb->getY();
        /* It the bomb must explode */
        if (bomb->explode())
        {
            CPlayer *me = m_playersList[0];
            CPlayer *player = getPlayerFromNick(bomb->getBomber());
            QSound::play(SND_EXPLOSION);
            m_explosionsList.push_back(new CExplosion(x, y, player->bombRange, m_map,
                                                      bomb->getBomber(), m_explosion));
            if (bomb->getBomber() == me->getNick()) /* If I am the bomber */
            {
                me->pausedBombs--;
            }
            m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
            it = m_bombsList.erase(it);
            delete bomb;
        }
        else
        {
            /* Let's check if the bomb has been kicked (bomb kick) */
            if (bomb->getDirection() != CBomb::Fixed)
            {
                switch (bomb->getCollision(bomb->getDirection(), m_map))
                {
                case Floor:
                case Bonus:
                    {
                    /* The bomb still can move */
                    unsigned last_x = bomb->getX(), last_y = bomb->getY();
                    bomb->move(bomb->getDirection(), GetFrameTime());
                    unsigned new_x = bomb->getX(), new_y = bomb->getY();
                    if (last_x != new_x && last_y != new_y)
                    {
                        if (m_map.getBlock(new_x, new_y) != Bonus)
                        {
                            m_map.setBlock(new_x, new_y, Bomb);
                            if (m_map.getBlock(last_x, last_y) != Bonus)
                            {
                                m_map.setBlock(last_x, last_y, Floor);
                            }
                        }
                    }
                }
                    break;
                case Wall:
                case Box:
                case BonusBox:
                case Bomb:
                    /* We reached a block, we stop the move */
                    bomb->SetPosition((bomb->getX() * BLOCK_SIZE) + 6, (bomb->getY() * BLOCK_SIZE) + 6);
                    bomb->setDirection(CBomb::Fixed);
                    m_map.setBlock(bomb->getX(), bomb->getY(), Bomb);
                    break;
                default:
                    break;
                }
            }
            Draw(*bomb);
            ++it;
        }
    }
}
Ejemplo n.º 16
0
void CGameBoard::drawBonusCanvas()
{
    if (m_bonusCanvas != NULL)
    {
        /* Header : bonus name */
        sf::Shape header = sf::Shape::Rectangle(
                m_bonusCanvas->getCanvasPosition().Left, m_bonusCanvas->getCanvasPosition().Top - 20,
                m_bonusCanvas->getCanvasPosition().Right, m_bonusCanvas->getCanvasPosition().Bottom - 20,
                sf::Color(127, 127, 127), 1.0f, sf::Color(0, 0, 0));
        Draw(header);

        /* Bonus Name */
        sf::String bonusName;
        bonusName.SetText(m_bonusCanvas->getBonus()->toString());
        bonusName.SetSize(11.0f);
        bonusName.SetColor(sf::Color(255, 255, 255));
        bonusName.SetPosition(m_bonusCanvas->getCanvasPosition().Left + 3,
                              m_bonusCanvas->getCanvasPosition().Top - 17);
        Draw(bonusName);

        sf::Shape canvas = sf::Shape::Rectangle(
                m_bonusCanvas->getCanvasPosition().Left, m_bonusCanvas->getCanvasPosition().Top,
                m_bonusCanvas->getCanvasPosition().Right, m_bonusCanvas->getCanvasPosition().Bottom,
                sf::Color(127, 127, 127), 1.0f, sf::Color(0, 0, 0));
        Draw(canvas);
        Draw(*m_bonusCanvas);

        m_bonusCanvas->playNextBonus(GetFrameTime());
        if (m_bonusCanvas->isFinished())
        {
            CPlayer *me = m_playersList[0];
            if (!m_bonusCanvas->isPaused())
            {
                /* Let's check which bonus we've got */
                CBonus::BonusType type;
                switch ((type = m_bonusCanvas->getBonus()->getType()))
                {
                case CBonus::BombDown:
                    me->addBonus(new CBonus(CBonus::BombDown));
                    break;
                case CBonus::BombUp:
                    me->addBonus(new CBonus(CBonus::BombUp));
                    break;
                case CBonus::SpeedDown:
                    if (me->getBonus(CBonus::SpeedDown) == NULL)
                    {
                        me->addBonus(new CLimitedBonus(CBonus::SpeedDown, 10.f));
                    }
                    break;
                case CBonus::SpeedUp:
                    if (me->getBonus(CBonus::SpeedUp) == NULL)
                    {
                        me->addBonus(new CLimitedBonus(CBonus::SpeedUp, 10.f));
                    }
                    break;
                case CBonus::FireUp:
                    me->addBonus(new CBonus(CBonus::FireUp));
                    break;
                case CBonus::FireDown:
                    me->addBonus(new CBonus(CBonus::FireDown));
                    break;
                case CBonus::FullFire:
                    me->addBonus(new CBonus(CBonus::FullFire));
                    break;
                case CBonus::RemoteMine:
                    if (me->getBonus(CBonus::RemoteMine) == NULL)
                    {
                        me->addBonus(new CBonus(CBonus::RemoteMine));
                    }
                case CBonus::BombPass:
                    me->removeBonus(CBonus::BombKick);
                    me->addBonus(new CBonus(CBonus::BombPass));
                    break;
                case CBonus::BombKick:
                    me->removeBonus(CBonus::BombPass);
                    me->addBonus(new CBonus(CBonus::BombKick));
                    break;
                default:
                    break;
                }
                m_networkManager->sendBonusPacket(me->getNick(), type);
                m_bonusCanvas->Pause();
            }
            else
            {
                CBonus *lastBonus = me->getBonusList().back();
                if (lastBonus != NULL && dynamic_cast<CLimitedBonus *>(lastBonus))
                {
                    CLimitedBonus *bonus = static_cast<CLimitedBonus *>(lastBonus);

                    unsigned remainingTime = static_cast<unsigned>(bonus->getRemainingTime());
                    if (remainingTime == 0)
                    {
                        delete m_bonusCanvas;
                        m_bonusCanvas = NULL;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 17
0
////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window
////////////////////////////////////////////////////////////
float sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow)
{
    CSFML_CALL_RETURN(renderWindow, GetFrameTime(), 0.f);
}