forked from pilsprog/skyport-lovegraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.lua
156 lines (134 loc) · 4.99 KB
/
render.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
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
147
148
149
150
151
152
153
154
155
156
render = {}
function render.background( canvas )
love.graphics.setCanvas( canvas )
for i = 0, canvas:getWidth(), background:getWidth() do
for j = 0, canvas:getHeight(), background:getHeight() do
love.graphics.draw(background,i,j)
end
end
love.graphics.setCanvas()
end
function render.tiles( canvas )
love.graphics.setCanvas( canvas )
for j = 1, gamestate.map["j-length"] do
for k = 1, gamestate.map["k-length"] do
if gamestate.map.data[j][k] ~= "V" then
local realX = render.toRealX(j,k)
local realY = render.toRealY(j,k)
local thisImage = hex[gamestate.map.data[j][k]]
love.graphics.draw(thisImage, realX, realY)
end
end
end
love.graphics.setCanvas()
end
function render.players( canvas, players)
local colorArray = {{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255}}
for i,v in ipairs(players) do
render.player(canvas, v, colorArray[i])
end
end
function render.player( canvas, player, color)
love.graphics.setCanvas( canvas )
local realX = render.toRealX(player.realJ+1,player.realK+1)
local realY = render.toRealY(player.realJ+1,player.realK+1)
love.graphics.print(player.name,realX,realY)
love.graphics.setColor(color)
love.graphics.circle("fill", realX+20, realY+19,10)
love.graphics.setColor(255,255,255)
love.graphics.setCanvas()
end
function render.highlights(canvas,que)
love.graphics.setCanvas(canvas)
for i,v in ipairs(que) do
v.color[4] = 128
love.graphics.setColor(v.color)
local J,K = animations.setJKp(v.coordinate)
love.graphics.rectangle("fill",render.toRealX(J+1,K+1),render.toRealY(J+1,K+1),40,38)
love.graphics.setColor(255,255,255)
end
love.graphics.setCanvas()
end
function render.stats( canvas, state)
love.graphics.setCanvas(canvas)
love.graphics.setColor(40,40,40)
love.graphics.rectangle("fill",0,0,canvas:getWidth(),canvas:getHeight())
love.graphics.setColor(255,255,255)
local offset = 100
love.graphics.print("Turn number: " .. state.turn,20,20)
for i,player in ipairs(state.players) do
render.playerstats(canvas, player, (i-.5)*offset)
end
love.graphics.setCanvas()
end
function render.playerstats( canvas, player, offset )
if player == currentPlayer then
love.graphics.setColor(255,0,0)
end
love.graphics.print(player.name,25,offset,0,1.5,1.5)
love.graphics.setColor(255,255,255)
love.graphics.print("Score: " .. player.score,15,offset+25)
love.graphics.print("HP:",15,offset+40)
love.graphics.setColor(125,0,0)
love.graphics.rectangle("fill",50,offset+40,player.health,13)
love.graphics.setColor(255,255,255)
love.graphics.print(player.health,60,offset + 40)
love.graphics.print("Primary weapon: " .. player["primary-weapon"]["name"] .. " " .. player["primary-weapon"]["level"] .. "\nSecond weapon: " .. player["secondary-weapon"]["name"] .. " " .. player["secondary-weapon"]["level"], 15, offset + 60)
end
function render.laser(canvas,wd)
-- print("rendering laser")
-- tablePrint(wd)
love.graphics.setCanvas(canvas)
love.graphics.setColor(255,255,255,200)
love.graphics.draw(laserArt[wd.size],wd.x,wd.y,wd.rotation,wd.length,1,laserArt[wd.size]:getWidth()/2,laserArt[wd.size]:getHeight()/2)
love.graphics.setColor(255,255,255,255)
love.graphics.setCanvas()
end
function render.mortar(canvas,wd)
love.graphics.setCanvas(canvas)
if wd.atype == "bombthrow" then
love.graphics.setColor(0,0,0)
love.graphics.circle("fill",wd.x+20,wd.y+19,wd.size)
love.graphics.setColor(255,255,255)
elseif wd.atype == "explosion" then
love.graphics.setColor(255,255,255,wd.alpha)
love.graphics.draw(explosionImage,wd.x+20,wd.y+19,0,1,1,explosionImage:getWidth()/2,explosionImage:getHeight()/2)
love.graphics.setColor(255,255,255,255)
elseif wd.atype == "smallexplosion" then
love.graphics.setColor(255,255,255,wd.alpha)
love.graphics.draw(smallExplosionImage,wd.x+20,wd.y+19,0,1,1,
smallExplosionImage:getWidth()/2,smallExplosionImage:getHeight()/2)
love.graphics.setColor(255,255,255,255)
end
love.graphics.setCanvas()
end
function render.droid(canvas,wd)
love.graphics.setCanvas(canvas)
if wd.atype == "droidmove" then
love.graphics.setColor(128,128,128)
love.graphics.rectangle("fill",wd.x+17,wd.y+16,6,6)
love.graphics.setColor(255,255,255)
end
if wd.atype == "explosion" then
love.graphics.setColor(255,255,255,wd.alpha)
love.graphics.draw(explosionImage,wd.x+20,wd.y+19,0,1,1,explosionImage:getWidth()/2,explosionImage:getHeight()/2)
love.graphics.setColor(255,255,255,255)
end
love.graphics.setCanvas()
end
function render.mine( canvas, wd )
if wd.atype ~= "R" and wd.atype ~= "C" and wd.atype ~= "E" then return end
love.graphics.setCanvas(canvas)
love.graphics.draw(resources[wd.atype],wd.x+20,wd.y+19,0,1,1,resources[wd.atype]:getWidth()/2,resources[wd.atype]:getHeight()/2)
love.graphics.setCanvas()
end
function render.subtitle()
print("rendering subtitle!")
love.graphics.print(displayText,200,love.graphics.getHeight()-200,0,2)
end
function render.toRealX( j, k )
return 30 * (gamestate.map["k-length"]+k-j-1)
end
function render.toRealY( j, k )
return 19 * (j + k - 2)
end