Skip to content

Instantly share code, notes, and snippets.

@a327ex
Created January 18, 2021 19:49
Show Gist options
  • Save a327ex/631d93dd3daa3a3a7c06c8c239deb1ad to your computer and use it in GitHub Desktop.
Save a327ex/631d93dd3daa3a3a7c06c8c239deb1ad to your computer and use it in GitHub Desktop.
class Enemy
new: =>
draw_enemy_ui: =>
graphics.push @x, @y, 0, @spring.x, @spring.x
if @show_hp
hp_color = red[0]
if @hit_flash then hp_color = fg[0]
graphics.line @x - 0.5*@shape.w, @y - @shape.h, @x + 0.5*@shape.w, @y - @shape.h, bg[-3], 2
n = math.remap @hp, 0, @max_hp, 0, 1
graphics.line @x - 0.5*@shape.w, @y - @shape.h, @x - 0.5*@shape.w + n*(@shape.w), @y - @shape.h, hp_color, 2
graphics.pop!
graphics.push @x, @y, 0, @spring.x, @spring.x
oys = {}
i = 0
if @slowed
table.insert oys, {oy: i, type: 'slow'}
i += 4
if @rooted
table.insert oys, {oy: i, type: 'root'}
i += 4
for t in *oys
if t.type == 'slow'
graphics.rectangle @x + 0.6*@shape.w, @y + 0.6*@shape.h + t.oy, 2, 2, nil, nil, fg[0]
elseif t.type == 'root'
graphics.rectangle @x + 0.6*@shape.w, @y + 0.6*@shape.h + t.oy, 2, 2, nil, nil, yellow[0]
graphics.pop!
hit: (damage=0) =>
if @dead then return
@spring\pull 0.25, 200, 10
@hit_flash = true
@timer\after 0.15, (-> @hit_flash = false), 'hit_flash'
@show_hp = true
@timer\after 2, (-> @show_hp = false), 'show_hp'
@hp -= damage
if @hp <= 0
node.player\barrage_on_kill!
@dead = true
for i = 1, random\int(4, 6) do HitParticle effects, @x, @y, {color: @color}
with HitCircle effects, @x, @y, {rs: 12}
\scale_down 0.3
\change_color 0.25, @color
push: (f, r) =>
@being_pushed = true
@steering_enabled = false
@\apply_impulse f*math.cos(r), f*math.sin(r)
@\apply_angular_impulse random\float(-12*math.pi, 12*math.pi)
@\set_damping 1.5
@\set_angular_damping 1.5
slow: (amount=0.5, duration=4) =>
@slowed = true
@slow_max_v = @max_v
@max_v = @max_v*amount
@timer\after duration, (->
@slowed = false
@max_v = @slow_max_v
), 'slow'
root: (duration=4) =>
@rooted = true
@root_max_v = @max_v
@max_v = 0
@timer\after duration, (->
@rooted = false
@max_v = @root_max_v
), 'root'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment