You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB
C

#include "types.h"
// do not use any global variables to process gamestate
2 years ago
static void integrate_acceleration(struct Body *body, float dt)
{
2 years ago
// position
{
V2 current = body->position;
body->position = V2add(body->position, V2sub(current, body->old_position));
body->position = V2add(body->position, V2scale(body->acceleration, dt * dt));
body->old_position = current;
}
2 years ago
// rotation
{
float current = body->rotation;
body->rotation = body->rotation + (current - body->old_rotation);
body->rotation = body->rotation + body->angular_acceleration * dt * dt;
body->old_rotation = current;
}
}
2 years ago
void process(struct GameState *gs, float dt)
{
for (int i = 0; i < MAX_PLAYERS; i++)
{
2 years ago
struct Player *p = &gs->players[i];
if (!p->connected)
continue;
p->body.acceleration = V2scale(p->input, 5.0f);
2 years ago
p->body.angular_acceleration = p->input.x * 10.0f;
integrate_acceleration(&p->body, dt);
}
2 years ago
for (int i = 0; i < gs->num_boxes; i++)
{
2 years ago
integrate_acceleration(&gs->boxes[i].body, dt);
}
2 years ago
}