Get everything properly on delta time
This commit is contained in:
parent
1ec3c577fe
commit
8558ee8a45
24
game.odin
24
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user