summaryrefslogtreecommitdiff
path: root/src/players.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/players.c')
-rw-r--r--src/players.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/players.c b/src/players.c
index 6bdac1d..fc3e050 100644
--- a/src/players.c
+++ b/src/players.c
@@ -60,6 +60,7 @@ void spawn_player(u32 id, network_client client) {
players[i].height = 0.0f;
players[i].client = client;
players[i].sprite = create_sprite(img_body, 4, 256, 256, 0.0f);
+ players[i].gun_sprite = create_sprite(img_gun_mp5, 4, 256, 256, 0.0f);
players[i].direction = DIRECTION_DOWN;
players[i].connection_state = CONNECTED;
players[i].throwables.grenades = 3;
@@ -279,8 +280,9 @@ void take_player_input(platform_window* window) {
dirx /= length;
diry /= length;
- float gun_offset_x = (get_player_size_in_tile()/2) + (dirx);
- float gun_offset_y = (get_player_size_in_tile()/2) + (diry);
+ float gunsize = get_gun_size(p->guntype);
+ float gun_offset_x = (get_player_size_in_tile()/2) + (dirx*gunsize);
+ float gun_offset_y = (get_player_size_in_tile()/2) + (diry*gunsize);
add_message_to_outgoing_queuex(create_protocol_user_look(player_id, gun_offset_x, gun_offset_y, dirx, diry), *global_state.client);
}
@@ -464,6 +466,38 @@ void draw_player(platform_window* window, player* p, int index) {
float player_render_x = player_pos.x;
float player_render_y = player_pos.y;
+ vec2f gun_pos = world_pos_to_screen_pos(window, p->gunx, p->guny, p->gun_height);
+ float gun_size = info.tile_width * get_gun_size(p->guntype);
+
+ // Gun
+ {
+ gun_pos.x -= gun_size/2;
+ gun_pos.y -= gun_size/2;
+
+ float rads = -atan2(p->diry, p->dirx);
+ renderer->render_set_rotation(rads);
+ log_infox("%f", rads);
+ vec2f tl = (vec2f){0.0f, 0.0f}, tr = (vec2f){1.0f, 0.0f}, bl = (vec2f){0.0f, 1.0f}, br = (vec2f){1.0f, 1.0f};
+ if (rads > M_PI/2 || rads < -M_PI/2) {
+ tl = (vec2f){1.0f, 0.0f};
+ tr = (vec2f){0.0f, 0.0f};
+ bl = (vec2f){1.0f, 1.0f};
+ br = (vec2f){0.0f, 1.0f};
+
+ renderer->render_set_rotation(-rads+M_PI);
+ }
+
+ image* gun_img = get_image_of_gun(p->guntype);
+ renderer->render_image_quad_partial(gun_img,
+ gun_pos.x, gun_pos.y,
+ gun_pos.x, gun_pos.y + gun_size,
+ gun_pos.x + gun_size, gun_pos.y + gun_size,
+ gun_pos.x + gun_size, gun_pos.y,
+ tl, tr, bl, br);
+
+ renderer->render_set_rotation(0.0f);
+ }
+
// Body
{
sprite_frame frame = sprite_get_frame(img_body, &p->sprite);