I'll personally get back to your code in a bit, but I just want to say that this book:
Clean Code, is one of the most useful pieces of work I have ever read as regards to learning about code structure and maintenance. I highly recommend it and you can even find free PDFs floating around online.
EDIT:
Right off the bat, I can tell that you are creating quads every frame in player_state. Just create them once and use those.
Secondly, please indent your lines, it makes it infinitely more maintainable and readable:
Code: Select all
function player_state (id, rotatable, state) -- Player Textures
for i,v in pairs (entity_list) do
local block = entity_list[i]
if block.entity_id == id then
frame_x, frame_y = 0, 0
if state == "Idle" then
frame_x ,frame_y = 0, 0
elseif state == "Idle2" then
frame_x ,frame_y = 13, 0
elseif state == "Crouch" then
frame_x ,frame_y = 26, 0
elseif state == "Crouch2" then
frame_x ,frame_y = 39, 0
elseif state == "Walk1" then
frame_x ,frame_y = 0, 19
elseif state == "Walk2" then
frame_x ,frame_y = 13, 19
elseif state == "Jump" then
frame_x ,frame_y = 26, 19
end
frame = love.graphics.newQuad(frame_x, frame_y, block.w, block.h, img:getWidth(), img:getHeight())
love.graphics.draw(img, frame, block.x, block.y, 0, -g_scale,g_scale,0,0)
end
end
end
Also, I'm not quite sure what your code is meant to do, so if you could elaborate, that would be great.