|
|
|
@ -32,24 +32,22 @@ player_st get_player(int x, int y) {
@@ -32,24 +32,22 @@ player_st get_player(int x, int y) {
|
|
|
|
|
player.physics.x_vel = 0; |
|
|
|
|
player.physics.y_vel = 0; |
|
|
|
|
|
|
|
|
|
/* Drawing */ |
|
|
|
|
|
|
|
|
|
void (*draw_function)(SDL_Renderer * ren, int x, int y); |
|
|
|
|
draw_function = &draw_player; |
|
|
|
|
player.draw = draw_function; |
|
|
|
|
player.max_walking_speed = 5; |
|
|
|
|
|
|
|
|
|
return (player); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void accel_thing(physics_thing * thing, float x, float y) { |
|
|
|
|
void accel_thing(physics_thing * thing, long x, long y) { |
|
|
|
|
/* takes acceleration in m/s2 and converts to m/ms adding
|
|
|
|
|
* it to physics_thing
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
long x_adj = (long ) x / 1000.0; |
|
|
|
|
long y_adj = (long ) y / 1000.0; |
|
|
|
|
long x_adj = x / 1000.0; |
|
|
|
|
long y_adj = y / 1000.0; |
|
|
|
|
|
|
|
|
|
(*thing).y_acc += (float)y_adj; |
|
|
|
|
(*thing).x_acc += (float)x_adj; |
|
|
|
|
logwrite(DEBUG, "Accel thing\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void advance_thing(physics_thing * thing) { |
|
|
|
@ -63,13 +61,74 @@ void advance_thing(physics_thing * thing) {
@@ -63,13 +61,74 @@ void advance_thing(physics_thing * thing) {
|
|
|
|
|
(*thing).x_vel = (*thing).x_acc * (float)time_delta; |
|
|
|
|
(*thing).y_vel = (*thing).y_acc * (float)time_delta; |
|
|
|
|
|
|
|
|
|
(*thing).x_pos = (*thing).x_acc * 1/2 * (float)time_delta;
|
|
|
|
|
(*thing).y_pos = (*thing).y_acc * 1/2 * (float)time_delta;
|
|
|
|
|
(*thing).x_pos += (int)((*thing).x_acc * 1/2 * (float)time_delta * (float)time_delta);
|
|
|
|
|
(*thing).y_pos += (int)((*thing).y_acc * 1/2 * (float)time_delta * (float)time_delta);
|
|
|
|
|
|
|
|
|
|
printf("%f, %f \n", (*thing).x_acc, (*thing).y_acc ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void add_to_world(world_thing thing) { |
|
|
|
|
world[things_in_world] = thing; |
|
|
|
|
things_in_world += 1; |
|
|
|
|
|
|
|
|
|
logwrite(INFO, "Added object to world"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void startgame(SDL_Renderer * ren) { |
|
|
|
|
player_st player; |
|
|
|
|
player = get_player(100,100); |
|
|
|
|
// draw_player(ren, player);
|
|
|
|
|
add_to_view(PLAYER, (void *)&player); |
|
|
|
|
things_in_world = 0; |
|
|
|
|
|
|
|
|
|
player = get_player(100,300); |
|
|
|
|
|
|
|
|
|
world_thing player_world; |
|
|
|
|
|
|
|
|
|
player_world.kind = PLAYER_W; |
|
|
|
|
player_world.player = &player; |
|
|
|
|
add_to_world(player_world); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float get_abs(x,y) { |
|
|
|
|
return (sqrt(x*x + y*y)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void walk(physics_thing * thing, int max_walking_speed, int x, int y) { |
|
|
|
|
if (get_abs(x, y) < max_walking_speed) { |
|
|
|
|
//accel_thing(thing, 0.001, 0.001 );
|
|
|
|
|
(*thing).x_acc = 0.00001; |
|
|
|
|
(*thing).y_acc = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void walk_player(int x, int y) { |
|
|
|
|
walk(&player.physics, player.max_walking_speed, x, y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void process_input(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) { |
|
|
|
|
advance_thing(&(player.physics)); |
|
|
|
|
// calc time interval
|
|
|
|
|
//
|
|
|
|
|
// advance game physics
|
|
|
|
|
|
|
|
|
|
logwrite(DEBUG, "Update Physics \n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|