Page 2 of 2

Re: Enemies, obstacle's, power ups, life's and health bar (help)

Posted: Wed Jan 17, 2018 5:20 pm
by MadByte
You just iterate through the second object layer. Add another loop to iterate through all layers and to update and draw your objects.
Some more things I noticed:
  • You don't indent your code. Proper line indention would make your code much more readable and easier to debug.
  • Code: Select all

    love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 20, 30, love.graphics.setColor(255,255,255))
    
    Interesting way to set your desired color, but calling setColor in the arguments list seems to be a very dirty way to do this imo.
  • Code: Select all

     love.graphics.print("A is for left, D is for right, W is for jump.", 10, 1230, 200, 2, 2, love.graphics.setColor(255, 0, 0)) 
    The text position is hard-coded which makes it hard to find the right position. You could use the position of your "solids" objects to make your code more flexible. You also print your text again for every object you draw. Move the print functions somewhere outside of the for loop, otherwise this is wasted processing power.
  • Code: Select all

    function player.move(dt)
    
    if love.keyboard.isDown("e") then
    love.event.quit()
    end
    
    if love.keyboard.isDown("r") then  
    love.event.quit("restart")
    	 end
    	 
     if love.keyboard.isDown("q") then  
    love.window.setMode( 1800, 900)
    end
    Changes like restarting the game or quitting shouldn't be made in your player.move function because it doesn't have anything to do with it.
    Apart from that, you could make this more efficient by using the love.keypressed callback.
  • Code: Select all

    function player.setPosition(x, y)
    	player.x, player.y = x, 1100
    end
    If you need a method to set the player position, then it doesn't make sense to hard-code the y value. Just use the method somewhere and pass the y argument to the variable.

Re: Enemies, obstacle's, power ups, life's and health bar (help)

Posted: Sat Feb 10, 2018 8:24 pm
by ShadowPenguins
Ok, i will edit it and try making it neater since i fixed my laptop. Thank you.