diff --git a/client.c3 b/client.c3 index 8b8862c..9b41214 100644 --- a/client.c3 +++ b/client.c3 @@ -803,7 +803,7 @@ fn void key_down(uint key_code) @extern("key_down") @wasm { message.kind = AMMA_THROWING; platform_send_message(message); } else { - common::throw_bomb(me.position.x, me.position.y, me.direction, &common::bombs); + common::throw_bomb(me.position, me.direction, &common::bombs); } } } diff --git a/client.wasm b/client.wasm index 44c4bde..92e2d90 100755 Binary files a/client.wasm and b/client.wasm differ diff --git a/common.c3 b/common.c3 index 4e02bfe..16aadee 100644 --- a/common.c3 +++ b/common.c3 @@ -92,14 +92,14 @@ fn Scene *allocate_default_scene() { return scene; } -fn bool Scene.get_tile(Scene *scene, Vector2 p) { +fn bool Scene.get_tile(&scene, Vector2 p) { int x = (int)math::floor(p.x); int y = (int)math::floor(p.y); if (!(0 <= x && x < scene.width && 0 <= y && y < scene.height)) return false; return scene.walls[y*scene.width + x]; } -fn bool scene_can_rectangle_fit_here(Scene *scene, float px, float py, float sx, float sy) { +fn bool Scene.can_rectangle_fit_here(&scene, float px, float py, float sx, float sy) { int x1 = (int)math::floor(px - sx*0.5f); int x2 = (int)math::floor(px + sx*0.5f); int y1 = (int)math::floor(py - sy*0.5f); @@ -230,15 +230,13 @@ fn Bombs* allocate_bombs() @extern("allocate_bombs") @wasm { return mem::new(Bombs); } -fn int throw_bomb(float player_position_x, float player_position_y, float player_direction, Bombs *bombs) { +fn int throw_bomb(Vector2 position, float direction, Bombs *bombs) { foreach (index, &bomb: *bombs) { if (bomb.lifetime <= 0) { bomb.lifetime = BOMB_LIFETIME; - bomb.position.x = player_position_x; - bomb.position.y = player_position_y; + bomb.position = position; bomb.position_z = 0.6; - bomb.velocity.x = math::cos(player_direction); - bomb.velocity.y = math::sin(player_direction); + bomb.velocity = from_polar(direction, 1.0f); bomb.velocity_z = 0.5; bomb.velocity *= BOMB_THROW_VELOCITY; bomb.velocity_z *= BOMB_THROW_VELOCITY; @@ -409,11 +407,11 @@ fn void update_player(Player *player, Scene *scene, float delta_time) { player.direction = (player.direction + angular_velocity*delta_time)%(2*(float)math::PI); float nx = player.position.x + control_velocity.x*delta_time; - if (scene_can_rectangle_fit_here(scene, nx, player.position.y, PLAYER_SIZE, PLAYER_SIZE)) { + if (scene.can_rectangle_fit_here(nx, player.position.y, PLAYER_SIZE, PLAYER_SIZE)) { player.position.x = nx; } float ny = player.position.y + control_velocity.y*delta_time; - if (scene_can_rectangle_fit_here(scene, player.position.x, ny, PLAYER_SIZE, PLAYER_SIZE)) { + if (scene.can_rectangle_fit_here(player.position.x, ny, PLAYER_SIZE, PLAYER_SIZE)) { player.position.y = ny; } } diff --git a/server.c3 b/server.c3 index f046e77..b3f9262 100644 --- a/server.c3 +++ b/server.c3 @@ -237,7 +237,7 @@ List() thrown_bombs; fn void throw_bomb_on_server_side(uint player_id, Bombs *bombs) { if (try player = players.get(player_id)) { - int index = common::throw_bomb(player.player.position.x, player.player.position.y, player.player.direction, bombs); + int index = common::throw_bomb(player.player.position, player.player.direction, bombs); if (index >= 0) thrown_bombs.push(index); } } diff --git a/server.wasm b/server.wasm index fe7e580..4ec2920 100755 Binary files a/server.wasm and b/server.wasm differ