|
|
|
@ -1,51 +1,156 @@
@@ -1,51 +1,156 @@
|
|
|
|
|
|
|
|
|
|
#include "game.h" |
|
|
|
|
|
|
|
|
|
#define GRAVITY_ACCEL 2 |
|
|
|
|
|
|
|
|
|
player_st *glob_player; |
|
|
|
|
|
|
|
|
|
// @param uninitialised physics_thing pointer
|
|
|
|
|
// @result: malloc and configure a physics thing pointer
|
|
|
|
|
void get_new_physics(physics_thing **phys) { |
|
|
|
|
/* physics */ |
|
|
|
|
physics_thing * physics = malloc(sizeof(physics_thing)); |
|
|
|
|
memset(physics, 0, sizeof(physics_thing)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*typedef enum { |
|
|
|
|
* sdl_shape; |
|
|
|
|
* image; |
|
|
|
|
* |
|
|
|
|
*} render_type; |
|
|
|
|
*/ |
|
|
|
|
physics->glob_gravity = false; |
|
|
|
|
physics->glob_friction = 0.0000; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*typedef struct { |
|
|
|
|
* char image_path[]; |
|
|
|
|
* // poly
|
|
|
|
|
*} sprite; |
|
|
|
|
*/ |
|
|
|
|
physics->obj_mass = 100; |
|
|
|
|
//kgs
|
|
|
|
|
|
|
|
|
|
physics->motors = malloc(sizeof(Motor) * 100); |
|
|
|
|
memset(physics->motors, 0, sizeof(Motor) * 100); |
|
|
|
|
physics->max_motors = 100; |
|
|
|
|
physics->num_motors = 0; |
|
|
|
|
add_motor(physics, 0.0, 0.0); |
|
|
|
|
|
|
|
|
|
*phys = physics; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
player_st get_player(int x, int y) { |
|
|
|
|
/* creates player at given postion and zeroes physics */ |
|
|
|
|
|
|
|
|
|
player_st player; |
|
|
|
|
memset(&player, 0, sizeof(player)); |
|
|
|
|
player.max_walking_speed = 100;
|
|
|
|
|
|
|
|
|
|
/* physics */ |
|
|
|
|
get_new_physics(&player.physics); |
|
|
|
|
|
|
|
|
|
player.physics->x_pos = x; |
|
|
|
|
player.physics->y_pos = y; |
|
|
|
|
|
|
|
|
|
player.physics.x_pos = x; |
|
|
|
|
player.physics.y_pos = y; |
|
|
|
|
add_motor(player.physics, 0.0, 0.0); |
|
|
|
|
|
|
|
|
|
player.physics.x_acc = 0; |
|
|
|
|
player.physics.y_acc = 0; |
|
|
|
|
return (player); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
player.physics.x_vel = 0; |
|
|
|
|
player.physics.y_vel = 0; |
|
|
|
|
|
|
|
|
|
player.max_walking_speed = 1001;
|
|
|
|
|
wall_node get_wall_node(int x, int y) { |
|
|
|
|
wall_node wn; |
|
|
|
|
memset(&wn, 0, sizeof(wn)); |
|
|
|
|
|
|
|
|
|
player.physics.glob_gravity = false; |
|
|
|
|
player.physics.glob_friction = 0.0000005; |
|
|
|
|
wn.physics.x_pos = x; |
|
|
|
|
wn.physics.y_pos = y; |
|
|
|
|
|
|
|
|
|
player.physics.obj_mass = 100; |
|
|
|
|
//kgs
|
|
|
|
|
wn.physics.x_acc = 0; |
|
|
|
|
wn.physics.y_acc = 0; |
|
|
|
|
wn.physics.obj_mass = 10; |
|
|
|
|
wn.physics.glob_gravity = false; |
|
|
|
|
wn.physics.glob_friction = 0.00000000; |
|
|
|
|
|
|
|
|
|
player.physics.motor_x= 0; |
|
|
|
|
player.physics.motor_y = 0; |
|
|
|
|
wn.physics.x_vel = 0; |
|
|
|
|
wn.physics.y_vel = 0; |
|
|
|
|
|
|
|
|
|
return (player); |
|
|
|
|
return wn; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Wall *get_stat_wall(int st_x, int st_y, int en_x, int en_y) { |
|
|
|
|
Wall wall; |
|
|
|
|
memset(&wall, 0, sizeof(wall)); |
|
|
|
|
wall.numNodes = 2; |
|
|
|
|
wall.nodes = malloc(sizeof(wall_node) * wall.numNodes); |
|
|
|
|
|
|
|
|
|
wall.nodes[0] = get_wall_node(st_x, st_y); |
|
|
|
|
wall.nodes[1] = get_wall_node(en_x, en_y); |
|
|
|
|
|
|
|
|
|
Wall *wallwall = malloc(sizeof(wall)); |
|
|
|
|
*wallwall = wall; |
|
|
|
|
return wallwall; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void collision(int numNodes1, physics_thing *nodes1,
|
|
|
|
|
int numNodes2, physics_thing *nodes2) { |
|
|
|
|
int x_1, y_1, x_2, y_2, xa_1, ya_1, xa_2, ya_2; |
|
|
|
|
for (int i = 0; i < numNodes1; i++) { |
|
|
|
|
x_1 = nodes1[2*i].x_pos; |
|
|
|
|
y_1 = nodes1[2*i].y_pos; |
|
|
|
|
x_2 = nodes1[2*i+1].x_pos; |
|
|
|
|
y_2 = nodes1[2*i+1].y_pos; |
|
|
|
|
for (int j = 0; j < numNodes2; j++) { |
|
|
|
|
xa_1 = nodes2[2*j].x_pos; |
|
|
|
|
ya_1 = nodes2[2*j].y_pos; |
|
|
|
|
xa_2 = nodes2[2*j+1].x_pos; |
|
|
|
|
ya_2 = nodes2[2*j+1].y_pos; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
physics_thing *get_player_collision_test(physics_thing *player) { |
|
|
|
|
physics_thing up, right; |
|
|
|
|
physics_thing *nodes = malloc(sizeof(physics_thing) * 2); |
|
|
|
|
|
|
|
|
|
up = *player; |
|
|
|
|
right = *player; |
|
|
|
|
|
|
|
|
|
up.y_pos += 1; |
|
|
|
|
right.x_pos += 1; |
|
|
|
|
|
|
|
|
|
nodes[0] = up; |
|
|
|
|
nodes[1] = right; |
|
|
|
|
|
|
|
|
|
return nodes; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void check_collision(int numNodes, physics_thing *things) { |
|
|
|
|
for (int i = 0; i < things_in_world; i++) { |
|
|
|
|
world_thing worldThing = world[i]; |
|
|
|
|
Wall *wall; |
|
|
|
|
physics_thing *nodes; |
|
|
|
|
if (worldThing.collisions) { |
|
|
|
|
switch (worldThing.kind) { |
|
|
|
|
case PLAYER_W:
|
|
|
|
|
collision(2, get_player_collision_test(things), 1, worldThing.player->physics); |
|
|
|
|
break; |
|
|
|
|
case STATIC_WALL_W: |
|
|
|
|
wall = worldThing.wall; |
|
|
|
|
nodes = malloc(sizeof(physics_thing) * wall->numNodes); |
|
|
|
|
for (int i = 0; i < wall->numNodes; i++) { |
|
|
|
|
nodes[i] = wall->nodes[i].physics; |
|
|
|
|
} |
|
|
|
|
collision(numNodes, things, wall->numNodes, nodes); |
|
|
|
|
free(nodes); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Wall *get_long_wall(int numNodes, int *nodes) { |
|
|
|
|
Wall wall; |
|
|
|
|
memset(&wall, 0, sizeof(wall)); |
|
|
|
|
|
|
|
|
|
wall.numNodes = numNodes; |
|
|
|
|
wall.nodes = malloc(sizeof(wall_node) * numNodes); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numNodes; i++) { |
|
|
|
|
wall.nodes[i] = get_wall_node(nodes[2*i], nodes[2*i+1]); |
|
|
|
|
//set_motor_ms(&(wall.nodes[i].physics), 2.0 , 1.0);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Wall *wallwall = malloc(sizeof(wall)); |
|
|
|
|
*wallwall = wall; |
|
|
|
|
return wallwall; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void accel_thing(physics_thing * thing, float x, float y) { |
|
|
|
@ -53,8 +158,9 @@ void accel_thing(physics_thing * thing, float x, float y) {
@@ -53,8 +158,9 @@ void accel_thing(physics_thing * thing, float x, float y) {
|
|
|
|
|
* it to physics_thing
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
float x_adj = x / 1000.0; |
|
|
|
|
float y_adj = y / 1000.0; |
|
|
|
|
// convert to m / millisecond
|
|
|
|
|
float x_adj = x / 1000.0;
|
|
|
|
|
float y_adj = y / 1000.0; |
|
|
|
|
|
|
|
|
|
(*thing).y_acc += (float)y_adj; |
|
|
|
|
(*thing).x_acc += (float)x_adj; |
|
|
|
@ -63,28 +169,30 @@ void accel_thing(physics_thing * thing, float x, float y) {
@@ -63,28 +169,30 @@ void accel_thing(physics_thing * thing, float x, float y) {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void set_motor_ms(physics_thing * thing, float x, float y) { |
|
|
|
|
// set motor force in newtons
|
|
|
|
|
|
|
|
|
|
float x_adj = x; |
|
|
|
|
float y_adj = y; |
|
|
|
|
|
|
|
|
|
(*thing).motor_x = (float)y_adj; |
|
|
|
|
(*thing).motor_y = (float)x_adj; |
|
|
|
|
void set_motor_newtons(physics_thing *thing, int motorID, double x, double y) { |
|
|
|
|
thing->motors[motorID].x =x; |
|
|
|
|
thing->motors[motorID].y =y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
logwrite(DEBUG, "set motor thing\n"); |
|
|
|
|
void add_motor_newtons(physics_thing *thing, int motorID, double x, double y) { |
|
|
|
|
thing->motors[motorID].x +=x; |
|
|
|
|
thing->motors[motorID].y +=y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void add_motor_ms(physics_thing * thing, float x, float y) { |
|
|
|
|
// set motor force in newtons
|
|
|
|
|
|
|
|
|
|
float x_adj = x; |
|
|
|
|
float y_adj = y; |
|
|
|
|
void add_motor(physics_thing *thing, double x, double y) { |
|
|
|
|
|
|
|
|
|
(*thing).motor_x += (float)y_adj; |
|
|
|
|
(*thing).motor_y += (float)x_adj; |
|
|
|
|
Motor motor; |
|
|
|
|
memset(&motor, 0, sizeof(Motor)); |
|
|
|
|
motor.x = x; |
|
|
|
|
motor.y = y; |
|
|
|
|
|
|
|
|
|
if (thing->num_motors == thing->max_motors) { |
|
|
|
|
thing->motors = realloc(thing->motors, sizeof(Motor) * (thing->max_motors *=2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
logwrite(DEBUG, "set motor thing\n"); |
|
|
|
|
thing->motors[thing->num_motors] = motor; |
|
|
|
|
thing->num_motors += 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -93,15 +201,13 @@ int advance_glob(physics_thing * thing) {
@@ -93,15 +201,13 @@ int advance_glob(physics_thing * thing) {
|
|
|
|
|
|
|
|
|
|
// gravity
|
|
|
|
|
if ((*thing).glob_gravity == true) { |
|
|
|
|
accel_thing(thing, 0, 9.81); |
|
|
|
|
accel_thing(thing, 0, GRAVITY_ACCEL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// friction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((*thing).glob_friction != 0.0) { |
|
|
|
|
logwrite(DEBUG, "Friction\n"); |
|
|
|
|
/* god this is so jank */ |
|
|
|
|
float normal = (*thing).obj_mass * 9.81; |
|
|
|
|
float F_force = normal * (*thing).glob_friction; |
|
|
|
|
float dir = atan2((*thing).y_vel, (*thing).x_vel); |
|
|
|
@ -121,57 +227,60 @@ int advance_glob(physics_thing * thing) {
@@ -121,57 +227,60 @@ int advance_glob(physics_thing * thing) {
|
|
|
|
|
(*thing).y_acc += f_y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* if (fabs((*thing).x_acc ) < fabs(f_x)) { |
|
|
|
|
* (*thing).x_acc = 0; |
|
|
|
|
* } |
|
|
|
|
* else { |
|
|
|
|
* (*thing).x_acc += f_x; |
|
|
|
|
* } |
|
|
|
|
* if (fabs((*thing).y_acc) < fabs(f_y)) { |
|
|
|
|
* (*thing).y_acc = 0; |
|
|
|
|
* |
|
|
|
|
* } |
|
|
|
|
* else { |
|
|
|
|
* (*thing).y_acc += f_y; |
|
|
|
|
* } |
|
|
|
|
*/ |
|
|
|
|
/*if (fabs((*thing).x_acc ) < fabs(f_x)) {*/ |
|
|
|
|
/*(*thing).x_acc = 0;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
/*else {*/ |
|
|
|
|
/*(*thing).x_acc += f_x;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
/*if (fabs((*thing).y_acc) < fabs(f_y)) {*/ |
|
|
|
|
/*(*thing).y_acc = 0;*/ |
|
|
|
|
|
|
|
|
|
/*}*/ |
|
|
|
|
/*else {*/ |
|
|
|
|
/*(*thing).y_acc += f_y;*/ |
|
|
|
|
/*}*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void advance_thing(physics_thing * thing) { |
|
|
|
|
thing->x_acc = 0; |
|
|
|
|
thing->y_acc = 0; |
|
|
|
|
|
|
|
|
|
(*thing).x_acc = 0; |
|
|
|
|
(*thing).y_acc = 0; |
|
|
|
|
uint32_t time_delta = SDL_GetTicks() - thing->last_advance_time ; |
|
|
|
|
|
|
|
|
|
static uint32_t last_advance_time; |
|
|
|
|
thing->last_advance_time = SDL_GetTicks(); // in milliseconds
|
|
|
|
|
|
|
|
|
|
uint32_t time_delta = SDL_GetTicks() - last_advance_time ; |
|
|
|
|
|
|
|
|
|
last_advance_time = SDL_GetTicks(); // in milliseconds
|
|
|
|
|
for (int i = 0; i < thing->num_motors; i++) { |
|
|
|
|
double acc_x = thing->motors[i].x / thing->obj_mass; |
|
|
|
|
double acc_y = thing->motors[i].y / thing->obj_mass; |
|
|
|
|
accel_thing(thing, acc_x, acc_y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// motor
|
|
|
|
|
|
|
|
|
|
float motor_x = (float)(*thing).motor_x / (float)(*thing).obj_mass ;
|
|
|
|
|
float motor_y = (float)(*thing).motor_y / (float)(*thing).obj_mass ; |
|
|
|
|
//float motor_x = (float)(*thing).motor_x / (float)(*thing).obj_mass ;
|
|
|
|
|
//float motor_y = (float)(*thing).motor_y / (float)(*thing).obj_mass ;
|
|
|
|
|
//printf("MOTOR: %f, %f\n", motor_x, motor_y);
|
|
|
|
|
//accel_thing(thing, motor_x, motor_y);
|
|
|
|
|
|
|
|
|
|
accel_thing(thing, motor_x, motor_y); |
|
|
|
|
advance_glob(thing); |
|
|
|
|
|
|
|
|
|
// accelerate based on accel
|
|
|
|
|
|
|
|
|
|
(*thing).x_vel += (*thing).x_acc * (float)time_delta; |
|
|
|
|
(*thing).y_vel += (*thing).y_acc * (float)time_delta; |
|
|
|
|
printf("time: %f", (float)time_delta); |
|
|
|
|
(*thing).x_vel = (*thing).x_acc * (float)time_delta; |
|
|
|
|
(*thing).y_vel = (*thing).y_acc * (float)time_delta; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(*thing).x_pos += (int)((*thing).x_vel * 1/2 * (float)time_delta);
|
|
|
|
|
(*thing).y_pos += (int)((*thing).y_vel * 1/2 * (float)time_delta);
|
|
|
|
|
|
|
|
|
|
printf("player position: %d, %d \n", (*thing).x_pos, (*thing).y_pos ); |
|
|
|
|
printf("player acc: %f, %f \n", (*thing).x_acc, (*thing).y_acc); |
|
|
|
|
printf("player position: %d, %d ", (*thing).x_pos, (*thing).y_pos ); |
|
|
|
|
printf(" player acc: %f, %f \n", (*thing).x_acc, (*thing).y_acc); |
|
|
|
|
|
|
|
|
|
if (fabs((*thing).x_vel) < 0.00001) { |
|
|
|
|
(*thing).x_vel = 0;
|
|
|
|
@ -179,107 +288,96 @@ void advance_thing(physics_thing * thing) {
@@ -179,107 +288,96 @@ void advance_thing(physics_thing * thing) {
|
|
|
|
|
if (fabs((*thing).y_vel) < 0.00001) { |
|
|
|
|
(*thing).y_vel = 0;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// apply global forces
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void advance_things(void) { |
|
|
|
|
for (int i = 0; i < things_in_world; i++) { |
|
|
|
|
switch (world[i].kind) { |
|
|
|
|
case PLAYER_W : |
|
|
|
|
logwrite(INFO, "ADVANCE PLAYER\n"); |
|
|
|
|
advance_thing((world[i].player->physics)); |
|
|
|
|
break; |
|
|
|
|
case STATIC_WALL_W: |
|
|
|
|
logwrite(INFO, "ADVANCE WALL\n"); |
|
|
|
|
for (int j = 0; j < world[i].wall->numNodes; j++) { |
|
|
|
|
advance_thing(&(world[i].wall->nodes[j].physics)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// grow array of world things if needed
|
|
|
|
|
void add_to_world(world_thing thing) { |
|
|
|
|
world[things_in_world] = thing; |
|
|
|
|
|
|
|
|
|
if (things_in_world == world_size) { |
|
|
|
|
logwrite(INFO, "Increased world size."); |
|
|
|
|
world = realloc(world, sizeof(world_thing) * (world_size*=2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
thing.nid = things_in_world; |
|
|
|
|
memcpy(world + things_in_world, &thing, sizeof(world_thing)); |
|
|
|
|
|
|
|
|
|
things_in_world += 1; |
|
|
|
|
|
|
|
|
|
logwrite(INFO, "Added object to world\n"); |
|
|
|
|
//printf("Added to world: %d\n", thing.kind);
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void startgame(SDL_Renderer * ren) { |
|
|
|
|
logwrite(INFO, "STARTGAME"); |
|
|
|
|
things_in_world = 0; |
|
|
|
|
world_size = 100; |
|
|
|
|
world = malloc(sizeof(world_thing) * 100); |
|
|
|
|
memset(world, 0, sizeof(world_thing) * 100); |
|
|
|
|
|
|
|
|
|
player = get_player(100,400); |
|
|
|
|
|
|
|
|
|
world_thing player_world; |
|
|
|
|
|
|
|
|
|
player_world.kind = PLAYER_W; |
|
|
|
|
player_world.player = &player; |
|
|
|
|
player_world.player = malloc(sizeof(player)); |
|
|
|
|
*player_world.player = player; |
|
|
|
|
glob_player = player_world.player; |
|
|
|
|
|
|
|
|
|
add_to_world(player_world); |
|
|
|
|
|
|
|
|
|
world_thing wall_world; |
|
|
|
|
int wall_nodes[] = {500, 100, 200, 100, 100, 200, 900, 200}; |
|
|
|
|
wall_world.wall = get_long_wall(4, wall_nodes); |
|
|
|
|
wall_world.kind = STATIC_WALL_W; |
|
|
|
|
printf("WALLNODES"); |
|
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
|
|
printf(": %d", wall_world.wall->nodes[i].physics.x_pos); |
|
|
|
|
} |
|
|
|
|
printf("\n\n\n\n"); |
|
|
|
|
add_to_world(wall_world); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float get_abs(float x,float y) { |
|
|
|
|
return (sqrt(x*x + y*y)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void walk(physics_thing * thing, float max_walking_speed, int x, int y) { |
|
|
|
|
|
|
|
|
|
if (get_abs((*thing).x_vel, (*thing).y_vel) < max_walking_speed/1000 ) { |
|
|
|
|
// accel_thing(thing, max_walking_speed * x, max_walking_speed * y );
|
|
|
|
|
(*thing).x_acc += max_walking_speed * 0.001 * x ; |
|
|
|
|
(*thing).y_acc += max_walking_speed * 0.001 * y ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void walk_player(int x, int y) { |
|
|
|
|
// walk(&player.physics, player.max_walking_speed, x, y);
|
|
|
|
|
|
|
|
|
|
//set_motor_ms(&player.physics, player.max_walking_speed * 0.01 * x, player.max_walking_speed * 0.01 * y);
|
|
|
|
|
|
|
|
|
|
add_motor_ms(&player.physics, 100 * y , 100 * x); |
|
|
|
|
|
|
|
|
|
// player.physics.x_acc = player.max_walking_speed * 0.00001 * x ;
|
|
|
|
|
// player.physics.y_acc = player.max_walking_speed * 0.00001 * y ;
|
|
|
|
|
|
|
|
|
|
add_motor_newtons(glob_player->physics, M_PLAYER_WALK, 100 * x , 100 * y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void process_keydown(SDL_Keysym key) { |
|
|
|
|
/*
|
|
|
|
|
*switch (key.sym) { |
|
|
|
|
* case SDLK_w: |
|
|
|
|
* walk_player(0, 1); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_a: |
|
|
|
|
* walk_player(-1, 0); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_s: |
|
|
|
|
* walk_player(0, -1); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_d: |
|
|
|
|
* walk_player(1, 0); |
|
|
|
|
* break; |
|
|
|
|
*} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void process_keyup(SDL_Keysym key) { |
|
|
|
|
/*
|
|
|
|
|
*switch (key.sym) { |
|
|
|
|
* case SDLK_w: |
|
|
|
|
* walk_player(0, -1); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_a: |
|
|
|
|
* walk_player(1, 0); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_s: |
|
|
|
|
* walk_player(0, 1); |
|
|
|
|
* break; |
|
|
|
|
* case SDLK_d: |
|
|
|
|
* walk_player(-1, 0); |
|
|
|
|
* break; |
|
|
|
|
*} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void step(int interval) {
|
|
|
|
|
const uint8_t * keyboard; |
|
|
|
|
// player.physics.x_acc = 0;
|
|
|
|
|
// player.physics.y_acc = 0;
|
|
|
|
|
|
|
|
|
|
printf("THINGS IN WORLD: %d\n", things_in_world); |
|
|
|
|
|
|
|
|
|
keyboard = SDL_GetKeyboardState(NULL); |
|
|
|
|
|
|
|
|
|
set_motor_ms(&player.physics, 0 ,0); |
|
|
|
|
//set_motor_ms(&player.physics, 0 ,0);
|
|
|
|
|
|
|
|
|
|
if (keyboard[SDL_SCANCODE_W]) { |
|
|
|
|
walk_player(0, -1); |
|
|
|
|
} if (keyboard[SDL_SCANCODE_A]) { |
|
|
|
@ -290,7 +388,7 @@ void step(int interval) {
@@ -290,7 +388,7 @@ void step(int interval) {
|
|
|
|
|
walk_player(1, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
advance_thing(&(player.physics)); |
|
|
|
|
advance_things(); |
|
|
|
|
logwrite(DEBUG, "Update Physics \n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|