aboutsummaryrefslogtreecommitdiff
path: root/src/player.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.odin')
-rw-r--r--src/player.odin19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/player.odin b/src/player.odin
index 2e05ea1..135bcf6 100644
--- a/src/player.odin
+++ b/src/player.odin
@@ -37,7 +37,7 @@ init_player :: proc() {
body := phys.make_body(
phys.Rect{{-4, -8}, {8, 16}},
layers = {.Player},
- mask = {.Default}
+ mask = {.Hard}
)
player.body = body
@@ -123,7 +123,8 @@ _default_state :: proc(dt: f32) {
rel_mouse_pos := fw.get_mouse_pos() - pos
- if fw.is_keybind_just_down(actions.shoot) {
+ // if fw.is_keybind_just_down(actions.shoot) {
+ if fw.is_keybind_down(actions.shoot) {
mouse_dir := linalg.normalize0(rel_mouse_pos + {0, PLAYER_GUN_HEIGHT})
bullet_pos := pos
@@ -275,7 +276,6 @@ update_player :: proc(dt: f32) {
player.sprite.pos = pos
update_sprite(&player.sprite, dt)
-
mouse_dir := linalg.normalize0(fw.get_mouse_pos() - player.gun.sprite.pos)
player.gun.sprite.rotation = math.atan2(mouse_dir.y, mouse_dir.x)
@@ -309,6 +309,19 @@ draw_player :: proc() {
if player.state != .Dash {
draw_sprite(player.gun.sprite)
}
+
+ rc_start := phys.get_position(player.body)
+ dir := Vec2{math.cos(player.gun.sprite.rotation), math.sin(player.gun.sprite.rotation)}
+ bodies := phys.get_colliding_bodies(phys.make_raycast(rc_start, dir), allocator = context.temp_allocator)
+ is_colliding := len(bodies) > 0
+
+ color := fw.GREEN if is_colliding else fw.RED
+ fw.draw_line(rc_start, rc_start + dir * 500, color = color)
+
+ for body in bodies {
+ rect := phys.get_rect(body)
+ fw.draw_rect(rect.start, rect.size, color = fw.RED)
+ }
}
@(private = "file")