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_W: f32 = 70 * SCALE
|
||||||
SHIP_H: f32 = 100 * SCALE
|
SHIP_H: f32 = 100 * SCALE
|
||||||
|
|
||||||
THRUST_SPEED : f32 = 0.03
|
THRUST_SPEED : f32 = 2.3
|
||||||
ANGULAR_SPEED : f32 = 2.5
|
ANGULAR_SPEED : f32 = 0.045
|
||||||
|
|
||||||
BULLET_SPEED : f32 = 0.05
|
BULLET_SPEED : f32 = 7.5
|
||||||
BULLET_RADIUS : f32 = 5
|
BULLET_RADIUS : f32 = 5
|
||||||
|
|
||||||
Bullet :: struct {
|
Bullet :: struct {
|
||||||
@ -86,14 +86,14 @@ player_input :: proc(s: ^GameState) {
|
|||||||
switch &player in s.player_state {
|
switch &player in s.player_state {
|
||||||
case Player:
|
case Player:
|
||||||
if rl.IsKeyDown(.D) {
|
if rl.IsKeyDown(.D) {
|
||||||
player.angle += ANGULAR_SPEED * s.dt
|
player.angle += ANGULAR_SPEED
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(.A) {
|
if rl.IsKeyDown(.A) {
|
||||||
player.angle -= ANGULAR_SPEED * s.dt
|
player.angle -= ANGULAR_SPEED
|
||||||
}
|
}
|
||||||
if rl.IsKeyDown(.W) {
|
if rl.IsKeyDown(.W) {
|
||||||
player.vel.x += math.cos(player.angle) * THRUST_SPEED * s.dt
|
player.vel.x += math.cos(player.angle)
|
||||||
player.vel.y += math.sin(player.angle) * THRUST_SPEED * s.dt
|
player.vel.y += math.sin(player.angle)
|
||||||
}
|
}
|
||||||
if rl.IsKeyPressed(.SPACE) {
|
if rl.IsKeyPressed(.SPACE) {
|
||||||
b_vel := Vec2{ math.cos(player.angle) , math.sin(player.angle) } * BULLET_SPEED
|
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 {
|
switch &player in s.player_state {
|
||||||
case Player:
|
case Player:
|
||||||
update_ship_shape(&player)
|
update_ship_shape(&player)
|
||||||
player.pos += player.vel * (5000 * s.dt)
|
player.pos += player.vel * (THRUST_SPEED * s.dt)
|
||||||
ship_collision := false
|
ship_collision := false
|
||||||
for i := 0; i < len(s.asteroids); i += 1 {
|
for i := 0; i < len(s.asteroids); i += 1 {
|
||||||
s.asteroids[i].rect.x += s.asteroids[i].vel.x
|
s.asteroids[i].rect.x += s.asteroids[i].vel.x * s.dt
|
||||||
s.asteroids[i].rect.y += s.asteroids[i].vel.y
|
s.asteroids[i].rect.y += s.asteroids[i].vel.y * s.dt
|
||||||
for j := 0; j < len(player.points); j += 1 {
|
for j := 0; j < len(player.points); j += 1 {
|
||||||
if rl.CheckCollisionPointRec(player.points[j], s.asteroids[i].rect) {
|
if rl.CheckCollisionPointRec(player.points[j], s.asteroids[i].rect) {
|
||||||
ship_collision = true
|
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 < 0 { player.pos.y = BH + SHIP_H}
|
||||||
if player.pos.y - SHIP_H > BH { player.pos.y = -SHIP_H}
|
if player.pos.y - SHIP_H > BH { player.pos.y = -SHIP_H}
|
||||||
}
|
}
|
||||||
|
|
||||||
case Death:
|
case Death:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,6 +187,7 @@ draw2d :: proc(s: ^GameState) {
|
|||||||
main :: proc() {
|
main :: proc() {
|
||||||
rl.SetTraceLogLevel(.ERROR)
|
rl.SetTraceLogLevel(.ERROR)
|
||||||
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Asteroids")
|
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Asteroids")
|
||||||
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
start_pos := Vec2{BW / 2 - SHIP_W / 2, BH / 2 - SHIP_H / 2}
|
start_pos := Vec2{BW / 2 - SHIP_W / 2, BH / 2 - SHIP_H / 2}
|
||||||
s := GameState{
|
s := GameState{
|
||||||
@ -215,7 +215,7 @@ main :: proc() {
|
|||||||
rand_vy := f32(rl.GetRandomValue(1, 2)) * 0.5
|
rand_vy := f32(rl.GetRandomValue(1, 2)) * 0.5
|
||||||
asteroid := Asteroid {
|
asteroid := Asteroid {
|
||||||
rect = {rand_pos.x,rand_pos.y,rand_size,rand_size},
|
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,
|
rot = 0,
|
||||||
}
|
}
|
||||||
append(&s.asteroids, asteroid)
|
append(&s.asteroids, asteroid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user