Add Komodo enemy class and enhance enemy spawning logic
- Introduce Komodo class with high health and attack mechanics. - Modify Enemy class to accept type parameter during initialization. - Update EnemyAI to set speed based on enemy type. - Implement random spawning of enemies in boss rooms. - Adjust health bar calculations to use max health.
This commit is contained in:
+7
-8
@@ -1,28 +1,27 @@
|
||||
class EnemyAI
|
||||
AGGRO_RADIUS = 2000
|
||||
BASE_SPEED = 130.0
|
||||
CORNER_OFFSET = 35 # how far from tile center to place corner waypoint
|
||||
ATTACK_COOLDOWN = 0.2 # seconds
|
||||
|
||||
def initialize(enemy, type)
|
||||
@enemy = enemy
|
||||
@type = type
|
||||
@base_speed = case type
|
||||
when :komodo then 60
|
||||
when :force then 130
|
||||
end
|
||||
@tile_path = [] # raw tile coords from solver
|
||||
@waypoints = [] # actual world positions to move through
|
||||
@last_player_tile = nil
|
||||
@avoiding_obstacle = false
|
||||
@speed = BASE_SPEED
|
||||
@speed = @base_speed
|
||||
@time_since_attack = ATTACK_COOLDOWN
|
||||
end
|
||||
|
||||
def update(player_x, player_y, dt, force = false)
|
||||
distance = Math.sqrt((player_x - @enemy.x)**2 + (player_y - @enemy.y)**2)
|
||||
return unless distance < AGGRO_RADIUS
|
||||
|
||||
if @enemy.lorentz && distance < 230
|
||||
@speed = BASE_SPEED * 0.3
|
||||
@speed = @base_speed * 0.3
|
||||
else
|
||||
@speed = BASE_SPEED
|
||||
@speed = @base_speed
|
||||
end
|
||||
|
||||
player_tile = [(player_x - 90) / 120, (player_y - 90) / 120].map(&:round)
|
||||
|
||||
+7
-4
@@ -20,12 +20,14 @@ class Enemy
|
||||
[@i_w, @i_h, @s]
|
||||
end
|
||||
|
||||
def initialize(x, y, health = 100)
|
||||
def initialize(x, y, type, health = 100)
|
||||
@x = x
|
||||
@y = y
|
||||
@w = 25
|
||||
@h = 30
|
||||
@max_health = health
|
||||
@health = health
|
||||
@type = type
|
||||
@stun = 0
|
||||
@last_lock = :none
|
||||
@lorentz = $bus.get(:lorentz_field?) || false
|
||||
@@ -34,7 +36,7 @@ class Enemy
|
||||
@lorentz = lorentz
|
||||
end
|
||||
|
||||
@ai = EnemyAI.new(self, :chase)
|
||||
@ai = EnemyAI.new(self, @type)
|
||||
|
||||
$bus.on(:collides?) do |rect|
|
||||
next collides?(rect) ? :enemy : nil
|
||||
@@ -78,7 +80,7 @@ class Enemy
|
||||
end
|
||||
|
||||
player_pos = $bus.get(:player_position)
|
||||
closest_event_horizon = $bus.get(:closest_event_horizon, @x, @y, 200)
|
||||
closest_event_horizon = $bus.get(:closest_event_horizon, @x, @y, 2000)
|
||||
if closest_event_horizon
|
||||
@ai.update(*closest_event_horizon, dt, @last_lock != :event_horizon)
|
||||
@last_lock = :event_horizon
|
||||
@@ -108,7 +110,8 @@ class Enemy
|
||||
|
||||
# Health bar
|
||||
|
||||
health_width = (@w * @health / 100.0)
|
||||
health_width = (@w * @health / @max_health)
|
||||
Gosu::draw_rect(screen_x - @w / 2, screen_y - @h / 2 - 10, @w, 5, Gosu::Color.new(0xFF555555), Float::INFINITY)
|
||||
Gosu.draw_rect(screen_x - @w / 2, screen_y - @h / 2 - 10, health_width, 5, Gosu::Color.new(0xFF00FF00), Float::INFINITY)
|
||||
|
||||
if $bus.get(:settings, :debug)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ class Force < Enemy
|
||||
load 'assets/images/force.png', 21, 32, 1.7
|
||||
|
||||
def initialize(x, y)
|
||||
super(x, y, 100)
|
||||
super(x, y, :force, 100)
|
||||
|
||||
$bus.on(:attack) do |attack_x, attack_y, range, damage|
|
||||
# Whoa, did'nt know ruby had hypot functions built in!
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require_relative 'force'
|
||||
require_relative 'komodo'
|
||||
|
||||
class EnemyHandler
|
||||
def initialize
|
||||
@@ -16,10 +17,11 @@ class EnemyHandler
|
||||
end
|
||||
|
||||
def spawn!
|
||||
# For now, just spawn a single enemy at a fixed location
|
||||
start_room_coords = $bus.get(:start_room_coords)
|
||||
if @enemies.empty? && start_room_coords
|
||||
@enemies << Force.new((start_room_coords[0] * 2 + 1 + 4) * 60 + 30, (start_room_coords[1] * 2 + 1 + 4) * 60 + 30)
|
||||
boss_rooms = $bus.get(:boss_rooms) || []
|
||||
if @enemies.count < 4 && rand < (1.0 / (60 * 10))
|
||||
boss_room = boss_rooms.sample
|
||||
type = rand < 0.1 ? Komodo : Force
|
||||
@enemies << (type).new((boss_room[0] * 2 + 4) * 60 + 30, (boss_room[1] * 2 + 4) * 60 + 30)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
require_relative 'base'
|
||||
|
||||
class Komodo < Enemy
|
||||
load 'assets/images/komodo.png', 31, 48, 1.7
|
||||
|
||||
def initialize(x, y)
|
||||
super(x, y, :komodo, 1000)
|
||||
|
||||
$bus.on(:attack) do |attack_x, attack_y, range, damage|
|
||||
if Math.hypot(@x - attack_x, @y - attack_y) <= range
|
||||
take_damage(damage)
|
||||
next true
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user