I'm currently stuck on trying to find ways to improve the code I created. Is there any way to make parts of it smaller?
--W to change maps
--Up/Down to make a player jump
Ways for improving code?
-
- Prole
- Posts: 39
- Joined: Sat Nov 28, 2015 10:13 am
Ways for improving code?
- Attachments
-
- Game Experiment4.LOVE
- (991.43 KiB) Downloaded 66 times
Re: Ways for improving code?
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:
Also, I'm not quite sure what your code is meant to do, so if you could elaborate, that would be great.
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
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
-
- Prole
- Posts: 39
- Joined: Sat Nov 28, 2015 10:13 am
Re: Ways for improving code?
Thank you!
Who is online
Users browsing this forum: Google [Bot] and 8 guests