Weeeeee/modules/draw_callback.lua

45 lines
1.8 KiB
Lua

local spritesheets = {}
local player = {}
local game = {}
local camera = {}
local floors = {}
function drawerinit(spritesheetst, playert, gamex, camerax, floorsx)
spritesheets = spritesheetst
player = playert
game = gamex
camera = camerax
floors = floorsx
end
local function draw()
camera:attach()
--draw rectangle with bottom at 980y and top at 850y which stretches acress the entire modules/player
--draw background
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
--draw player_animation
player.animation:draw(player.object.body:getX(), player.object.body:getY())
if player.state == "idle" then
spritesheets["player_idle"]:draw(player.object.body:getX(), player.object.body:getY())
elseif player.state == "walk_left" then
spritesheets["player_walk_left"]:draw(player.object.body:getX(), player.object.body:getY())
elseif player.state == "walk_right" then
spritesheets["player_walk_right"]:draw(player.object.body:getX(), player.object.body:getY())
elseif player.state == "jump" then
spritesheets["player_jump"]:draw(player.object.body:getX(), player.object.body:getY())
elseif player.state == "die" then
spritesheets["player_die"]:draw(player.object.body:getX(), player.object.body:getY())
else
spritesheets["player_default"]:draw(player.object.body:getX(), player.object.body:getY())
end
camera:detach()
end
return {
drawerinit = drawerinit,
draw = draw
}