Updated simulation to be on a 512x512 area.

This commit is contained in:
Barra Ó Catháin 2023-07-13 00:44:25 +01:00
parent 43e7a76637
commit 1725b244e1
2 changed files with 13 additions and 15 deletions

View File

@ -44,25 +44,21 @@ void doGameTick(struct gameState * state)
// Do movement:
state->clients[index].xPosition += state->clients[index].xVelocity;
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].xVelocity = 0;
state->clients[index].xPosition = 0;
}
if(state->clients[index].xPosition < 0)
{
state->clients[index].xPosition = 0;
state->clients[index].xVelocity = 0;
state->clients[index].xPosition = 512;
}
if(state->clients[index].yPosition > 1000)
if(state->clients[index].yPosition > 512)
{
state->clients[index].yPosition = 1000;
state->clients[index].yVelocity = 0;
state->clients[index].yPosition = 0;
}
if(state->clients[index].yPosition < 0)
{
state->clients[index].yPosition = 0;
state->clients[index].yVelocity = 0;
state->clients[index].yPosition = 512;
}
}
}

View File

@ -62,7 +62,10 @@ void * networkThreadHandler(void * arguments)
while (true)
{
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)
{
@ -114,8 +117,7 @@ int main(int argc, char ** argv)
signal(SIGINT, sigintHandler);
pthread_create(&networkThread, NULL, networkThreadHandler, globalState);
pthread_create(&gameThread, NULL, gameThreadHandler, globalState);
// Setup TCP Master Socket:
printf("Setting up master socket... ");
masterSocket = socket(AF_INET, SOCK_STREAM, 0);
@ -237,8 +239,8 @@ int main(int argc, char ** argv)
{
currentMessage.type = 0;
globalState->state->clients[index].registered = true;
globalState->state->clients[index].xPosition = 300;
globalState->state->clients[index].yPosition = 300;
globalState->state->clients[index].xPosition = 256;
globalState->state->clients[index].yPosition = 256;
globalState->state->clients[index].xVelocity = 0;
globalState->state->clients[index].yVelocity = 0;
currentMessage.content = (uint8_t)index;