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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

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

Post 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.
User avatar
ShadowPenguins
Prole
Posts: 14
Joined: Thu Sep 21, 2017 5:50 am

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

Post by ShadowPenguins »

Ok, i will edit it and try making it neater since i fixed my laptop. Thank you.
Current Projects, Insomnia and The Wolf's Spiral
Insomnia Progress and files if you want to help can be found here https://github.com/TheShadowPenguin/Insomnia

~Silver~
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 50 guests