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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
local enemyData = require "data.enemyData"
local graphics = require "utils.graphics"
require "data.directions"
require "render.sprite"
local draws = {}
function draws.aloot()
for i, v in pairs(G.currentRoom.objects.loots) do
sprite.drawSquare(v.type, v, config.heartSize)
end
end
local function drawAttackPreview()
if not G.player then return end
local mx, my = love.mouse.getX(), love.mouse.getY()
local attack_radius = config.player.punch.radius + G.player.r/2
local attack_angle = config.player.punch.angle
local player_radius = G.player.r
-- calculate attack direction
local dx = mx - G.player.x
local dy = my - G.player.y
local attack_angle_rad = utils.atan2(dy, dx)
local start_angle = attack_angle_rad - math.rad(attack_angle / 2)
local end_angle = attack_angle_rad + math.rad(attack_angle / 2)
local arc_center_x = G.player.x + math.cos(attack_angle_rad)
local arc_center_y = G.player.y + math.sin(attack_angle_rad)
-- draw an arc indicating attack range
if G.player:punchCoolingDown() then
love.graphics.setColor(1, 0.2, 0.2, 0.3)
else
love.graphics.setColor(0.7, 0.7, 0.7, 0.3)
end
love.graphics.arc("fill", arc_center_x, arc_center_y, attack_radius, start_angle, end_angle)
-- arrow position
local arrow_length = attack_radius * 0.6
local arrow_x = G.player.x + math.cos(attack_angle_rad) * (player_radius + arrow_length)
local arrow_y = G.player.y + math.sin(attack_angle_rad) * (player_radius + arrow_length)
-- arrow angle
local arrow_side_angle = math.rad(20)
local left_x = arrow_x - math.cos(attack_angle_rad - arrow_side_angle) * (arrow_length * 0.3)
local left_y = arrow_y - math.sin(attack_angle_rad - arrow_side_angle) * (arrow_length * 0.3)
local right_x = arrow_x - math.cos(attack_angle_rad + arrow_side_angle) * (arrow_length * 0.3)
local right_y = arrow_y - math.sin(attack_angle_rad + arrow_side_angle) * (arrow_length * 0.3)
-- draw an arrow pointing to the aim
love.graphics.setColor(0.8,0.8,0.8)
love.graphics.line(G.player.x + math.cos(attack_angle_rad) * player_radius,
G.player.y + math.sin(attack_angle_rad) * player_radius,
arrow_x, arrow_y)
love.graphics.line(arrow_x, arrow_y, left_x, left_y)
love.graphics.line(arrow_x, arrow_y, right_x, right_y)
graphics.reset()
end
function draws.player()
drawAttackPreview()
if G.player:isShielded() then
love.graphics.setColor(0.4,0.4,0.4)
else
love.graphics.setColor(1,1,1)
end
local cf = G.player.frameTimer.currentFrame
local facing = { [Direction.UP] = 4, [Direction.DOWN] = 1, [Direction.LEFT] = 10, [Direction.RIGHT] = 7 }
local moving = { [Direction.UP] = { 5,6 }, [Direction.DOWN] = { 2,3 }, [Direction.LEFT] = { 11,12 }, [Direction.RIGHT] = { 8,9 } }
local index = facing[G.player.facing]
if G.player.moving then
index = moving[G.player.facing][cf]
end
local r = G.player.r
local graphicR = r * G.player.zoom
local x, y = G.player.x - r, G.player.y - r
sprite.drawQuad("apple", index, x, y, graphicR, graphicR, 0)
graphics.reset()
end
function draws.bullets()
for k, bullet in pairs(G.currentRoom.objects.shots) do
local x, y, angle = bullet.x, bullet.y, bullet.orientation
sprite.draw(bullet.type, x, y, angle, config.bullet.size, config.bullet.size)
end
end
function draws.enemies()
for _, enemy in pairs(G.currentRoom.objects.enemies) do
local data = enemyData[enemy.type]
if data.sprite then
-- handle quad index
local index = data.sprite.frames[enemy:facing()][enemy.frameTimer.currentFrame]
if enemy.type == "pokob" then
-- pokob has different appearances in different health states
local healthRatio = enemy.health / enemy.maxHealth
local breakpoints = { 0.75, 0.5, 0.25, 0 }
for i, breakpoint in ipairs(breakpoints) do
if healthRatio >= breakpoint then
index = index + (i-1) * 12
break
end
end
end
-- arguments
local r = enemy.r
local graphicR = r * enemy.zoom
local x, y = enemy.x - r, enemy.y - r
-- draw sprite
sprite.drawQuad(data.sprite.name, index, x, y, graphicR, graphicR, 0)
-- draw effects
if enemy.sticky then
sprite.draw("spiderweb", x, y, 0, r*2, r*2)
elseif enemy.stunned then
sprite.draw("stunningstars", x, y, 0, r*2, r*2)
end
graphics.reset()
end
graphics.reset()
end
end
function draws.obstacles()
for _, obstacle in ipairs(G.currentRoom.objects.obstacles) do
if obstacle ~= nil then
love.graphics.setColor(0.85,0.85,0.85)
graphics.drawRect(obstacle)
graphics.reset()
end
end
end
return draws
|