Refactor enemy system: enhance EnemyAI with attack cooldown, update Force class to handle damage, and improve EnemyHandler for enemy removal; add OccamsRazor weapon with attack mechanics.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
require_relative 'lorentz_field'
|
||||
#require_relative 'occams_razor'
|
||||
require_relative 'occams_razor'
|
||||
#require_relative 'quantum_bow'
|
||||
#require_relative 'blade_of_recursion'
|
||||
|
||||
@@ -7,7 +7,7 @@ class WeaponHandler
|
||||
def initialize
|
||||
@weapons = {
|
||||
lorentz_field: LorentzField.new,
|
||||
#occams_razor: OccamsRazor.new,
|
||||
occams_razor: OccamsRazor.new,
|
||||
#quantum_bow: QuantumBow.new,
|
||||
#blade_of_recursion: BladeOfRecursion.new
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class LorentzField
|
||||
$bus.emit(:consume, :lorentz_field, 1)
|
||||
@active = true
|
||||
@time = 0
|
||||
$bus.emit(:lorentz_field)
|
||||
$bus.emit(:lorentz_field?, true)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
@@ -42,7 +42,7 @@ class LorentzField
|
||||
if @time >= BASE_TIME
|
||||
@time = 0
|
||||
@active = false
|
||||
$bus.emit(:lorentz_field_end)
|
||||
$bus.emit(:lorentz_field?, false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
class OccamsRazor
|
||||
BASE_TIME = 0.2 # seconds per attack
|
||||
|
||||
def initialize
|
||||
#
|
||||
@time = 0
|
||||
@active = false
|
||||
@damage = 20
|
||||
@range = 45 # how many pixels from player center to enemy center the attack hits, this is a melee weapon so it should be small
|
||||
end
|
||||
|
||||
def attack(dt)
|
||||
#
|
||||
def attack
|
||||
return if @active
|
||||
|
||||
@active = true
|
||||
@time = BASE_TIME
|
||||
|
||||
# Check for enemies in range and deal damage
|
||||
player_x, player_y = $bus.get(:player_position)
|
||||
$bus.emit(:occams_razor_attack, player_x, player_y, @range, @damage)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
return unless @active
|
||||
|
||||
@time -= dt
|
||||
if @time <= 0
|
||||
@active = false
|
||||
@time = 0
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
# Nothing for now, but player attack animation would go here
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user