-
Notifications
You must be signed in to change notification settings - Fork 0
/
melees.lua
84 lines (72 loc) · 2.58 KB
/
melees.lua
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
melee = {}
melee.equipped = nil
melee.active = false
melee.timer = globalTimer.new()
melee.weapons = {}
melee.weapons.katana = {}
melee.weapons.katana.sprite = love.graphics.newImage('sprites/melees/katana.png')
melee.weapons.katana.sheet = love.graphics.newImage('sprites/melees/chromeMelee.png')
melee.weapons.katana.grid = anim8.newGrid(60, 60, 540, 60)
melee.weapons.katana.animation = anim8.newAnimation(
melee.weapons.katana.grid("1-9",1, "9-1",1),
{['1-3']=0.08, ['4-9']=0.03, ['10-14']=0.08, ['15-18']=0.1}
)
melee.weapons.katana.height = melee.weapons.katana.sprite:getHeight()
melee.weapons.katana.width = 3
melee.weapons.katana.id = -1
melee.weapons.katana.v = 100
melee.weapons.katana.offsX = 33
melee.weapons.katana.offsY = 31
melee.weapons.katana.dmg = 30
melee.weapons.katana.speed = 800
melee.weapons.katana.knockback = -10
melee.weapons.katana.slowdown = .5
melee.weapons.katana.swipeTime = 1.04
function meleeAttack()
canShoot = false
melee.equipped = melee.weapons.katana
melee.equipped.animation:gotoFrame(1)
melee.equipped.direction = player_angle()
melee.startA = { math.pi/3 }
melee.finalA = { math.pi*1.3 }
melee.tween = tween.new(.7, melee.startA, melee.finalA, "inOutBack")
--
melee.active = true
melee.coll = HC.rectangle(player.x, player.y, melee.weapons.katana.sprite:getWidth(), melee.weapons.katana.sprite:getHeight())
melee.coll:rotate(player_angle() + math.pi/2, player.x, player.y)
melee.coll.parent = melee
melee.colliding = true
melee.canCollide = false
love.audio.play(soundFX.swordslash)
melee.timer:after(.1, function() melee.canCollide = true end)
melee.timer:after(melee.equipped.swipeTime, function()
melee.active = false
canShoot = true
end)
melee.timer:after(.55, function()
melee.colliding = false
HC.remove(melee.coll)
melee.tween:reset()
end)
end
function drawMelee()
if melee.active then
melee.equipped.animation:draw(melee.equipped.sheet, melee.equipped.x, melee.equipped.y, melee.equipped.direction, 1, 1, melee.equipped.offsX, melee.equipped.offsY)
end
end
function updateMelee(dt, pAngle)
melee.timer:update(dt)
if melee.active then
if melee.colliding then
melee.tween:update(dt)
local newAngle = pAngle + melee.startA[1]
melee.coll:setRotation(newAngle, player.x, player.y - 2)
local cX,cY = melee.coll:center()
melee.coll:moveTo(cX + player.vx * dt, cY + player.vy * dt)
end
melee.equipped.animation:update(dt)
melee.equipped.direction = player_angle()
melee.equipped.x = player.x
melee.equipped.y = player.y
end
end