Added basic spawn points to enemies.
This commit is contained in:
+22
-12
@@ -24,7 +24,6 @@ Enemy :: struct {
|
||||
collider_h: f32
|
||||
}
|
||||
|
||||
|
||||
enemy_init :: proc(assets: ^Enemy_Assets, pos: [2]f32) -> Enemy {
|
||||
enemy := Enemy{}
|
||||
enemy.position = {pos.x, pos.y}
|
||||
@@ -46,12 +45,23 @@ get_enemy_collider :: proc(enemy: Enemy, pos: rl.Vector2) -> rl.Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
get_spawn_rect :: proc(max_x, max_y: f32) -> rl.Rectangle {
|
||||
// Get random x and y pos
|
||||
x_pos := rand.float32_range(TILE_SIZE, (max_x - TILE_SIZE))
|
||||
y_pos := rand.float32_range(TILE_SIZE, (max_y - TILE_SIZE))
|
||||
|
||||
return rl.Rectangle{x_pos, y_pos, TILE_SIZE, TILE_SIZE}
|
||||
get_spawn_rect :: proc(max_x, max_y: f32) -> rl.Rectangle {
|
||||
enemy_spawn_points: [4]rl.Rectangle = {
|
||||
// top right
|
||||
rl.Rectangle{TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE},
|
||||
// top left
|
||||
rl.Rectangle{(max_x - TILE_SIZE * 2), TILE_SIZE, TILE_SIZE, TILE_SIZE},
|
||||
// bottom right
|
||||
rl.Rectangle{(max_x - TILE_SIZE * 2), (max_y - TILE_SIZE * 2), TILE_SIZE, TILE_SIZE},
|
||||
// bottom left
|
||||
rl.Rectangle{TILE_SIZE, (max_y - TILE_SIZE * 2), TILE_SIZE, TILE_SIZE},
|
||||
}
|
||||
|
||||
rand_point := rand.int_range(0, len(enemy_spawn_points))
|
||||
rand_pos := enemy_spawn_points[rand_point]
|
||||
|
||||
return rand_pos
|
||||
}
|
||||
|
||||
// @TODO consider a self check, ie pass the enemy in question index and make sure to skip that
|
||||
@@ -82,10 +92,9 @@ spawn_enemy :: proc(enemy_array: ^[MAX_ENEMIES]Enemy, assets: ^Enemy_Assets, ene
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
update_enemies :: proc(enemy_array: ^[MAX_ENEMIES]Enemy, assets: ^Enemy_Assets, dt: f32) {
|
||||
for &enemy in enemy_array {
|
||||
update_enemies :: proc(enemy_array: ^[MAX_ENEMIES]Enemy, assets: ^Enemy_Assets, enemy_cnt: int, dt: f32) {
|
||||
for idx in 0..<enemy_cnt {
|
||||
enemy := &enemy_array[idx]
|
||||
moving := false
|
||||
|
||||
enemy.state = moving ? .WALK : .IDLE
|
||||
@@ -96,8 +105,9 @@ update_enemies :: proc(enemy_array: ^[MAX_ENEMIES]Enemy, assets: ^Enemy_Assets,
|
||||
}
|
||||
|
||||
|
||||
draw_enemies :: proc(enemy_array: ^[MAX_ENEMIES]Enemy) {
|
||||
for &enemy in enemy_array {
|
||||
draw_enemies :: proc(enemy_array: ^[MAX_ENEMIES]Enemy, enemy_cnt: int) {
|
||||
for idx in 0..<enemy_cnt {
|
||||
enemy := &enemy_array[idx]
|
||||
clip := enemy.animation.clip
|
||||
src_rect := animation_frame_rect(&enemy.animation)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user