Weeeeee/modules/draw_callback.lua

45 lines
1.8 KiB
Lua
Raw Normal View History

2022-03-02 18:36:52 +01:00
local spritesheets = {}
local player = {}
local game = {}
2022-03-02 20:31:33 +01:00
local camera = {}
2022-03-03 13:13:17 +01:00
local floors = {}
2022-03-02 18:36:52 +01:00
2022-03-03 13:13:17 +01:00
function drawerinit(spritesheetst, playert, gamex, camerax, floorsx)
2022-03-02 18:36:52 +01:00
spritesheets = spritesheetst
player = playert
game = gamex
2022-03-02 20:31:33 +01:00
camera = camerax
2022-03-03 13:13:17 +01:00
floors = floorsx
2022-03-02 18:36:52 +01:00
end
local function draw()
2022-03-02 20:31:33 +01:00
camera:attach()
2022-03-03 13:13:17 +01:00
--draw rectangle with bottom at 980y and top at 850y which stretches acress the entire modules/player
2022-03-02 18:36:52 +01:00
--draw background
2022-03-03 13:13:17 +01:00
love.graphics.draw(game:getcurlevel().background, 0, -(game:getcurlevel().height) + 280)
--draw floors
for i = 1, #floors, 1 do
love.graphics.setColor(love.math.colorFromBytes(floors[i].color[1], floors[i].color[2], floors[i].color[3], floors[i].color[4]))
love.graphics.rectangle("fill", floors[i].x, floors[i].y, floors[i].width, floors[i].height)
end
2022-03-02 18:36:52 +01:00
--draw player_animation
2022-03-03 13:13:17 +01:00
player.animation:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
if player.state == "idle" then
2022-03-03 13:13:17 +01:00
spritesheets["player_idle"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
elseif player.state == "walk_left" then
2022-03-03 13:13:17 +01:00
spritesheets["player_walk_left"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
elseif player.state == "walk_right" then
2022-03-03 13:13:17 +01:00
spritesheets["player_walk_right"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
elseif player.state == "jump" then
2022-03-03 13:13:17 +01:00
spritesheets["player_jump"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
elseif player.state == "die" then
2022-03-03 13:13:17 +01:00
spritesheets["player_die"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
else
2022-03-03 13:13:17 +01:00
spritesheets["player_default"]:draw(player.object.body:getX(), player.object.body:getY())
2022-03-02 18:36:52 +01:00
end
2022-03-02 20:31:33 +01:00
camera:detach()
2022-03-02 18:36:52 +01:00
end
return {
drawerinit = drawerinit,
draw = draw
}