Exemple #1
0
void ClientGame::OnInitializeGame(Protocol::InitializeGamePacket& packet)
{
    LogDebug("Initializing game with seed %i", packet.mapSeed);
    m_time = packet.time;
    m_clientId = packet.clientId;
    m_xMapSize = packet.xMapSize;
    m_yMapSize = packet.yMapSize;
    m_gridSpacing = packet.gridSpacing;
    m_totalNumIntels = packet.totalNumIntels;
    m_map.Generate(m_xMapSize, m_yMapSize, packet.mapSeed);
    CenterMap(m_xMapSize / 2, m_yMapSize / 2);

    m_gameState = GameState_Playing;
}
Exemple #2
0
BLWorld::BLWorld(BLApp& oBLApp, Canvas& canva, int w, int h, const char* tilesname)
	: m_oBLApp(oBLApp)
	, m_oCanva(canva)
	, m_iGrid(0)
	, m_bDraging(false)
	, m_iStartDragX(0)
	, m_iStartDragY(0)
{
	m_pTiles = new BLTiles(*canva.GetGEngine(), tilesname);
	m_iGrid = m_pTiles->GetTilesWidth();
	ASSERT(m_pTiles->GetTilesWidth() == m_pTiles->GetTilesHeight());

	m_pMap = new BLMap(w, h, *m_pTiles);
	m_pMap->Generate();
	int i, j;
	m_pMap->RandomFullGroundLoc(i, j);

	m_pBot = new BLBot(*canva.GetGEngine(), *this, oBLApp.GetPlannerCanvas());
	m_pBot->SetLoc((float)i*m_iGrid + m_iGrid/2, (float)j*m_iGrid + m_iGrid/2);
	m_pBot->SetPos(i, j);
	m_pBot->SetState(BLBot::Idle);
	CenterMap((int)m_pBot->GetLocX(), (int)m_pBot->GetLocY());

	m_pMap->RandomFullGroundLoc(i, j);
	new BLLightProp(*this, "Coin", DATA_DIR "/BotLife/Coin.png", Vector2(i,j));
	m_pMap->RandomFullGroundLoc(i, j);
	new BLLightProp(*this, "Diam", DATA_DIR "/BotLife/Diam.png", Vector2(i,j));
	m_pMap->RandomFullGroundLoc(i, j);
	new BLHeavyProp(*this, "Box", DATA_DIR "/BotLife/Box.png", Vector2(i,j));

	//BLDoor* pDoor = new BLDoor(*this, "Door", BLDoor::Verti, Vector2(3, 6));
	//pDoor->Close();

	//m_pBot->AddGoal("IBFactDef_BotAtPos", new IBVector2("Dest", 14, 14));
	//m_pBot->AddGoal("IBFactDef_BotHasObject", m_pProp);
}
Exemple #3
0
void ClientGame::OnMouseDown(int x, int y, int button)
{

    if (m_gameState == GameState_MainMenu)
    {
        return;
    }
    
    if (m_gameState != GameState_Playing)
    {
        return;
    }

    Vec2 location;
    if (m_notificationLog.OnMouseDown(x, y, button, location))
    {
        CenterMap(static_cast<int>(location.x), static_cast<int>(location.y));
        return;
    }

    if (button == 1)
    {

        ButtonId buttonId = GetButtonAtPoint(x, y);

        if (buttonId != ButtonId_None)
        {
            m_activeButton = buttonId;
            m_activeButtonDown = true;
            m_mapState = State_Button;

            Protocol::OrderPacket order;
            order.order = kButtonToOrder[buttonId];
            order.agentId = m_selectedAgent;
            SendOrder(order);
        }
        else if (y < m_ySize - yStatusBarSize)
        {
            bool hasSelection = (m_selectedAgent != -1);
            int agentUnderCursor = GetAgentUnderCursor(x, y);
            
            int xWorld, yWorld;
            ScreenToWorld(x, y, xWorld, yWorld);


            int stopUnderCursor = m_map.GetNearestStopForPoint( Vec2(static_cast<float>(xWorld), static_cast<float>(yWorld)) );

            if (agentUnderCursor == -1 && stopUnderCursor != -1 && m_selectedAgent != -1)
            {
                const Entity* selectedEntity = GetEntity(m_selectedAgent);
                if (selectedEntity != NULL)
                {
                    int fromStop = selectedEntity->Cast<AgentEntity>()->m_currentStop;
                    m_pathLength = m_map.GetPath(fromStop, stopUnderCursor, m_path);
                    if (m_pathLength > 1)
                    {
                        m_nextStop = 0;
                    }
                    else
                    {
                        m_pathLength = 0;
                        m_nextStop = -1;
                    }
                }
            }
            else if (m_selectedAgent != agentUnderCursor)
            {
                m_selectedAgent = agentUnderCursor;
                m_pathLength = 0;
                m_nextStop = -1;
            }

            UpdateActiveButtons();
        }

    }

    // Zoom.
    if (button == 4)
    {
        SetMapScale(1, x, y);
    }
    if (button == 5)
    {
        SetMapScale(2, x, y);
    }


    if (button == 2)
    {
        int blipX, blipY;
        ScreenToWorld(x, y, blipX, blipY);

    }

    if (button == 3)
    {
        if (y < m_ySize - yStatusBarSize)
        {
            // Pan with right mouse button.
            if (m_mapState == State_Idle)
            {
                m_mapState = State_Panning;
                m_stateX = x;
                m_stateY = y;
            }
        }
    }

}