From 8558ee8a45353063f26dc972e984d36d3abd38c8 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 25 Aug 2024 19:05:23 +0700 Subject: [PATCH] Get everything properly on delta time --- game.odin | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/game.odin b/game.odin index 901cb3e..f3b2007 100644 --- a/game.odin +++ b/game.odin @@ -17,10 +17,10 @@ SCALE: f32 = 0.37 SHIP_W: f32 = 70 * SCALE SHIP_H: f32 = 100 * SCALE -THRUST_SPEED : f32 = 0.03 -ANGULAR_SPEED : f32 = 2.5 +THRUST_SPEED : f32 = 2.3 +ANGULAR_SPEED : f32 = 0.045 -BULLET_SPEED : f32 = 0.05 +BULLET_SPEED : f32 = 7.5 BULLET_RADIUS : f32 = 5 Bullet :: struct { @@ -86,14 +86,14 @@ player_input :: proc(s: ^GameState) { switch &player in s.player_state { case Player: if rl.IsKeyDown(.D) { - player.angle += ANGULAR_SPEED * s.dt + player.angle += ANGULAR_SPEED } if rl.IsKeyDown(.A) { - player.angle -= ANGULAR_SPEED * s.dt + player.angle -= ANGULAR_SPEED } if rl.IsKeyDown(.W) { - player.vel.x += math.cos(player.angle) * THRUST_SPEED * s.dt - player.vel.y += math.sin(player.angle) * THRUST_SPEED * s.dt + player.vel.x += math.cos(player.angle) + player.vel.y += math.sin(player.angle) } if rl.IsKeyPressed(.SPACE) { b_vel := Vec2{ math.cos(player.angle) , math.sin(player.angle) } * BULLET_SPEED @@ -110,11 +110,11 @@ update :: proc(s: ^GameState) { switch &player in s.player_state { case Player: update_ship_shape(&player) - player.pos += player.vel * (5000 * s.dt) + player.pos += player.vel * (THRUST_SPEED * s.dt) ship_collision := false for i := 0; i < len(s.asteroids); i += 1 { - s.asteroids[i].rect.x += s.asteroids[i].vel.x - s.asteroids[i].rect.y += s.asteroids[i].vel.y + s.asteroids[i].rect.x += s.asteroids[i].vel.x * s.dt + s.asteroids[i].rect.y += s.asteroids[i].vel.y * s.dt for j := 0; j < len(player.points); j += 1 { if rl.CheckCollisionPointRec(player.points[j], s.asteroids[i].rect) { ship_collision = true @@ -161,7 +161,6 @@ update :: proc(s: ^GameState) { if player.pos.y + SHIP_H < 0 { player.pos.y = BH + SHIP_H} if player.pos.y - SHIP_H > BH { player.pos.y = -SHIP_H} } - case Death: } } @@ -188,6 +187,7 @@ draw2d :: proc(s: ^GameState) { main :: proc() { rl.SetTraceLogLevel(.ERROR) rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Asteroids") + rl.SetTargetFPS(60) start_pos := Vec2{BW / 2 - SHIP_W / 2, BH / 2 - SHIP_H / 2} s := GameState{ @@ -215,7 +215,7 @@ main :: proc() { rand_vy := f32(rl.GetRandomValue(1, 2)) * 0.5 asteroid := Asteroid { rect = {rand_pos.x,rand_pos.y,rand_size,rand_size}, - vel = Vec2{rand_angle, rand_vy} * 0.005, + vel = Vec2{rand_angle, rand_vy} * 50, rot = 0, } append(&s.asteroids, asteroid)