Ejemplo n.º 1
0
void Panzerfaust::update(float deltaTime)
{
	bool forwardVelocity = m_IOHandler.m_keyIsDown['W'];
	bool backwardVelocity = m_IOHandler.m_keyIsDown['S'];
	bool leftwardVelocity = m_IOHandler.m_keyIsDown['A'];
	bool rightwardVelocity = m_IOHandler.m_keyIsDown['D'];

	//HACK
	const float SPEED_OF_CAMERA = 50.f;

	g_localUser.m_unit.m_target.x += (rightwardVelocity - leftwardVelocity)*SPEED_OF_CAMERA*deltaTime;
	g_localUser.m_unit.m_target.y += (forwardVelocity - backwardVelocity)*SPEED_OF_CAMERA*deltaTime;
	g_localUser.update(deltaTime);

	GamePacket currentPacket;
	do 
	{
		bool newUser = true;
		currentPacket = g_serverConnection->receivePackets();
		if (currentPacket.ID != 0)
		{
			Color3b packetColor = Color3b();
			packetColor.r = currentPacket.r;
			packetColor.g = currentPacket.g;
			packetColor.b = currentPacket.b;

			for (unsigned int ii = 0; ii < g_users.size(); ii++)
			{
				
				if (Color3b(g_users[ii].m_unit.m_color) == packetColor)
				{
					newUser = false;
					g_users[ii].m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y);
				}
			}
			if (newUser)
			{
				User tempUser = User();
				tempUser.m_unit.m_position = Vector2f(currentPacket.x, currentPacket.y);
				tempUser.m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y);
				tempUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f);
				tempUser.m_userType = USER_REMOTE;
				g_users.push_back(tempUser);
			}
		}
	} while (currentPacket.ID != 0);

	for (unsigned int ii = 0; ii < g_users.size(); ii++)
	{
		g_users[ii].update(deltaTime);
	}

	mouseUpdate();

	m_internalTime += deltaTime;

	//m_world.update(deltaTime);
}
Ejemplo n.º 2
0
GamePacket User::sendInput()
{
	if (m_userType == USER_REMOTE)
	{
		return GamePacket();
	}
	else
	{
		Color3b tempColor = Color3b(m_unit.m_color);
		GamePacket outPacket = {2, tempColor.r, tempColor.g, tempColor.b, m_unit.m_position.x, m_unit.m_position.y};
		g_serverConnection->sendPacket(outPacket);
	}
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------------------
//Pack up the position data in to a packet
CS6Packet Entity::packForSend()
{
	CS6Packet preparedPacket;
	preparedPacket.packetType = TYPE_Update;
	Color3b cleanedColor = Color3b(m_color);
	memcpy(preparedPacket.playerColorAndID, &cleanedColor, sizeof(cleanedColor));
	preparedPacket.data.updated.xPosition = m_position.x;
	preparedPacket.data.updated.yPosition = m_position.y;
	preparedPacket.data.updated.xVelocity = m_velocity.x;
	preparedPacket.data.updated.yVelocity = m_velocity.y;
	preparedPacket.data.updated.yawDegrees = m_orientation;
	preparedPacket.packetNumber = 0;
	return preparedPacket;
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------------------------
Color3b GameServer::GetPlayerColorForID( unsigned int playerID )
{
	if( playerID == 0 )
		return Color3b( 255, 0, 0 );
	if( playerID == 1 )
		return Color3b( 0, 255, 0 );
	if( playerID == 2 )
		return Color3b( 0, 0, 255 );
	if( playerID == 3 )
		return Color3b( 255, 255, 0 );
	if( playerID == 4 )
		return Color3b( 255, 0, 255 );
	if( playerID == 5 )
		return Color3b( 0, 255, 255 );
	if( playerID == 6 )
		return Color3b( 255, 165, 0 );
	if( playerID == 7 )
		return Color3b( 128, 0, 128 );

	return Color3b( 255, 255, 255 );
}
Ejemplo n.º 5
0
void Panzerfaust::update(float deltaTime)
{
	bool forwardVelocity = m_IOHandler.m_keyIsDown['W'];
	bool backwardVelocity = m_IOHandler.m_keyIsDown['S'];
	bool leftwardVelocity = m_IOHandler.m_keyIsDown['A'];
	bool rightwardVelocity = m_IOHandler.m_keyIsDown['D'];

	//HACK
	const float SPEED_OF_CAMERA = 50.f;

	g_localUser.m_unit.m_target.x += (rightwardVelocity - leftwardVelocity)*SPEED_OF_CAMERA*deltaTime;
	g_localUser.m_unit.m_target.y += (forwardVelocity - backwardVelocity)*SPEED_OF_CAMERA*deltaTime;
	g_localUser.update(deltaTime);

	if (g_localUser.m_unit.m_position.distanceSquared(g_flag.m_position) < 100.f)
	{
		CS6Packet vicPacket;
		vicPacket.packetType = TYPE_Victory;
		Color3b userColor = Color3b(g_localUser.m_unit.m_color);
		memcpy(vicPacket.playerColorAndID, &userColor, sizeof(userColor));
		memcpy(vicPacket.data.victorious.playerColorAndID, &userColor, sizeof(userColor));
		g_serverConnection->sendPacket(vicPacket);
	}

	CS6Packet currentPacket;
	do 
	{
		bool newUser = true;
		currentPacket = g_serverConnection->receivePackets();
		if (currentPacket.packetType == TYPE_Reset)
		{
			//Reset type things
			g_localUser.m_unit.m_position = Vector2f(currentPacket.data.reset.playerXPosition, currentPacket.data.reset.playerYPosition);
			g_localUser.m_unit.m_target = g_localUser.m_unit.m_position;
			Color3b packetColor = Color3b();
			memcpy(&packetColor, currentPacket.playerColorAndID, sizeof(packetColor));
			g_localUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f);
			g_flag.m_position = Vector2f(currentPacket.data.reset.flagXPosition, currentPacket.data.reset.flagYPosition);
			g_flag.m_target = g_flag.m_position;
			g_localUser.m_isInGame = true;

		}
		else if (currentPacket.packetType != 0)
		{
			Color3b packetColor = Color3b();
			memcpy(&packetColor, currentPacket.playerColorAndID, sizeof(packetColor));

			for (unsigned int ii = 0; ii < g_users.size(); ii++)
			{
				
				if (Color3b(g_users[ii].m_unit.m_color) == packetColor)
				{
					newUser = false;
					g_users[ii].processUpdatePacket(currentPacket);
				}
			}
			if (newUser)
			{
				User tempUser = User();
				tempUser.processUpdatePacket(currentPacket);
				//tempUser.m_unit.m_position = Vector2f(currentPacket.x, currentPacket.y);
				//tempUser.m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y);
				//tempUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f);
				tempUser.m_userType = USER_REMOTE;
				g_users.push_back(tempUser);
			}
		}
	} while (currentPacket.packetType != 0);

	for (unsigned int ii = 0; ii < g_users.size(); ii++)
	{
		g_users[ii].update(deltaTime);
	}

	mouseUpdate();

	m_internalTime += deltaTime;

	//m_world.update(deltaTime);
}