aboutsummaryrefslogtreecommitdiff
path: root/src/enemy.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/enemy.odin')
-rw-r--r--src/enemy.odin45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/enemy.odin b/src/enemy.odin
index e806b37..5ff3d00 100644
--- a/src/enemy.odin
+++ b/src/enemy.odin
@@ -3,6 +3,7 @@ package demonchime
import "base:intrinsics"
import "core:math"
+import "core:math/linalg"
import "core:log"
import hm "core:container/handle_map"
@@ -13,6 +14,7 @@ Enemy_Ai :: enum(u16) {
None,
Corpse,
Muntik,
+ Hugbug,
}
Enemy_Update_Callback :: #type proc(^Enemy, f32)
@@ -21,6 +23,7 @@ update_funcs := [Enemy_Ai]Enemy_Update_Callback{
.None = noop_ai,
.Corpse = corpse_ai,
.Muntik = update_muntik,
+ .Hugbug = update_hugbug,
}
Enemy_Stats :: struct {
@@ -43,6 +46,7 @@ Enemy :: struct {
variant: union {
^Muntik,
+ ^Hugbug,
},
}
@@ -105,6 +109,20 @@ draw_enemies :: proc() {
}
}
+draw_enemy_bodies :: proc() {
+ for e in state.enemy_list {
+ pos := phys.get_position(e.body)
+ rect := phys.get_rect(e.body)
+
+ fw.draw_rect(
+ rect.start + pos,
+ rect.size,
+ color = fw.RED,
+ lines = true,
+ )
+ }
+}
+
clear_enemies :: proc() {
for e in state.enemy_list {
phys.remove_body(e^.body)
@@ -118,6 +136,33 @@ on_room_open_enemies :: proc(room_id: Room_Id) {
clear_enemies()
}
+accelerate_to_point :: proc(
+ b: phys.Body_Handle,
+ point: Vec2,
+ speed: f32,
+ accel: f32,
+) {
+ pos := phys.get_position(b)
+ dir := linalg.normalize0(point - pos)
+ vel := phys.get_velocity(b)
+ phys.set_velocity(b, dt_lerp(vel, dir * speed, accel))
+}
+
+contact_damage :: proc(body: phys.Body_Handle, damage: i16) {
+ collisions := phys.get_colliding_bodies(body)
+ defer delete(collisions)
+
+ pos := phys.get_position(body)
+ for other_body in collisions {
+ layers := phys.get_layers(other_body)
+ if .Player in layers {
+ other_pos := phys.get_position(other_body)
+ dir := linalg.normalize0(other_pos - pos) * 500
+ player_take_damage(damage, dir)
+ }
+ }
+}
+
noop_ai :: proc(e: ^Enemy, _: f32) {}
corpse_ai :: proc(e: ^Enemy, dt: f32) {