Updated simulation to be on a 512x512 area.
This commit is contained in:
parent
43e7a76637
commit
1725b244e1
|
@ -44,25 +44,21 @@ void doGameTick(struct gameState * state)
|
||||||
// Do movement:
|
// Do movement:
|
||||||
state->clients[index].xPosition += state->clients[index].xVelocity;
|
state->clients[index].xPosition += state->clients[index].xVelocity;
|
||||||
state->clients[index].yPosition += state->clients[index].yVelocity;
|
state->clients[index].yPosition += state->clients[index].yVelocity;
|
||||||
if(state->clients[index].xPosition > 1000)
|
if(state->clients[index].xPosition > 512)
|
||||||
{
|
{
|
||||||
state->clients[index].xPosition = 1000;
|
state->clients[index].xPosition = 0;
|
||||||
state->clients[index].xVelocity = 0;
|
|
||||||
}
|
}
|
||||||
if(state->clients[index].xPosition < 0)
|
if(state->clients[index].xPosition < 0)
|
||||||
{
|
{
|
||||||
state->clients[index].xPosition = 0;
|
state->clients[index].xPosition = 512;
|
||||||
state->clients[index].xVelocity = 0;
|
|
||||||
}
|
}
|
||||||
if(state->clients[index].yPosition > 1000)
|
if(state->clients[index].yPosition > 512)
|
||||||
{
|
{
|
||||||
state->clients[index].yPosition = 1000;
|
state->clients[index].yPosition = 0;
|
||||||
state->clients[index].yVelocity = 0;
|
|
||||||
}
|
}
|
||||||
if(state->clients[index].yPosition < 0)
|
if(state->clients[index].yPosition < 0)
|
||||||
{
|
{
|
||||||
state->clients[index].yPosition = 0;
|
state->clients[index].yPosition = 512;
|
||||||
state->clients[index].yVelocity = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,10 @@ void * networkThreadHandler(void * arguments)
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
returnvalue = recvfrom(*(args.udpSocket), args.message, sizeof(struct clientInput), 0, (struct sockaddr *)&clientAddress, &test);
|
returnvalue = recvfrom(*(args.udpSocket), args.message, sizeof(struct clientInput), 0, (struct sockaddr *)&clientAddress, &test);
|
||||||
memcpy(&(args.clientAddresses[args.message->clientNumber]), &clientAddress, sizeof(struct sockaddr_in));
|
if (args.message->clientNumber < 16 && args.message->clientNumber > -1)
|
||||||
|
{
|
||||||
|
memcpy(&(args.clientAddresses[args.message->clientNumber]), &clientAddress, sizeof(struct sockaddr_in));
|
||||||
|
}
|
||||||
|
|
||||||
if(returnvalue > 0)
|
if(returnvalue > 0)
|
||||||
{
|
{
|
||||||
|
@ -114,8 +117,7 @@ int main(int argc, char ** argv)
|
||||||
signal(SIGINT, sigintHandler);
|
signal(SIGINT, sigintHandler);
|
||||||
pthread_create(&networkThread, NULL, networkThreadHandler, globalState);
|
pthread_create(&networkThread, NULL, networkThreadHandler, globalState);
|
||||||
pthread_create(&gameThread, NULL, gameThreadHandler, globalState);
|
pthread_create(&gameThread, NULL, gameThreadHandler, globalState);
|
||||||
|
|
||||||
|
|
||||||
// Setup TCP Master Socket:
|
// Setup TCP Master Socket:
|
||||||
printf("Setting up master socket... ");
|
printf("Setting up master socket... ");
|
||||||
masterSocket = socket(AF_INET, SOCK_STREAM, 0);
|
masterSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
@ -237,8 +239,8 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
currentMessage.type = 0;
|
currentMessage.type = 0;
|
||||||
globalState->state->clients[index].registered = true;
|
globalState->state->clients[index].registered = true;
|
||||||
globalState->state->clients[index].xPosition = 300;
|
globalState->state->clients[index].xPosition = 256;
|
||||||
globalState->state->clients[index].yPosition = 300;
|
globalState->state->clients[index].yPosition = 256;
|
||||||
globalState->state->clients[index].xVelocity = 0;
|
globalState->state->clients[index].xVelocity = 0;
|
||||||
globalState->state->clients[index].yVelocity = 0;
|
globalState->state->clients[index].yVelocity = 0;
|
||||||
currentMessage.content = (uint8_t)index;
|
currentMessage.content = (uint8_t)index;
|
||||||
|
|
Loading…
Reference in New Issue