-
Notifications
You must be signed in to change notification settings - Fork 2
/
attack.moon
85 lines (67 loc) · 1.69 KB
/
attack.moon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
g = love.graphics
import timer, keyboard, audio from love
export ^
class Spear
watch_class self
ox: 0, oy: 0
w: 9
h: 9
box_offsets: {
left: {-8, -5}
right: {8, -5}
up: {-1, -13}
down: {2, 5}
}
sprite_offsets: {
left: {-7,-3}
right: {3,-3}
up: {0,-12}
down: {3,0}
}
new: (@player) =>
@counter = 0
@box = Box @player.box.x, @player.box.y, @w, @h
@sprite = with Spriter "img/sprite.png"
@anim = StateAnim "down", {
left: \seq {"39,5,12,5"}, 0, true
up: \seq {"43,13,5,12"}
right: \seq {"39,5,12,5"}
down: \seq {"43,13,5,12"}, 0, true, true
}
-- draw on player
draw: =>
direction = @player.last_direction
return unless direction
@anim\set_state direction
ox, oy = unpack @sprite_offsets[direction]
@anim\draw @player.box.x + ox + @ox, @player.box.y + oy + @oy
-- @box\outline! -- if @is_attacking
update: (dt) =>
direction = @player.last_direction
if direction
ox, oy = unpack @box_offsets[direction]
@box\set_pos @player.box.x + @ox + ox, @player.box.y + @oy + oy
if @attack
alive = @attack\update dt
@attack = nil unless alive
try_attack: =>
return if @attack
sfx\play "player_strike"
direction = @player.last_direction
@counter += 1
@attack = Sequence ->
@is_attacking = true
tween self, 0.05, switch direction
when "right"
ox: 4
when "left"
ox: -4
when "down"
oy: 4
when "up"
oy: -4
wait 0.05
@is_attacking = false
tween self, 0.1, ox: 0, oy: 0
calc_damage: (entity) =>
math.random 8,10