score counter and putting objects to collect

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.
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: score counter and putting objects to collect

Post by Saltyham »

Oops I that came out a little different than what I meant, I got pickup sounds down now all I need is to have the fruits swapped with another graphic when walked over, anyone have any idea how to do this? . :3
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: score counter and putting objects to collect

Post by Plu »

The only way to really stop the player from getting massive points by standing on top of the fruit with the swapped graphic, is by making it a different kind of object. In the method where the collission with the item is detected, create a new entity with a different graphic but on the same location as the previous fruit.

I can't access your code from work so I can't really give any code based examples, but you really should try to figure this stuff out on your own anyway :)
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: score counter and putting objects to collect

Post by Saltyham »

I'm very grateful for the help still working on the scoring
but here it is at its current state.
Attachments
the adventure of based god.love
(3.37 MiB) Downloaded 124 times
vires
Prole
Posts: 1
Joined: Thu May 05, 2022 2:15 am

Re: score counter and putting objects to collect

Post by vires »

Hi - I'm somewhat new to coding and wondering about the same issue of object collection. For some reason when I download the two .love files in the thread above, I'm not able to open them, with love or with VSC. If anyone can advise me on a possible solution so I can benefit from the advice/help already offered, that would be rad
User avatar
Azzla
Prole
Posts: 43
Joined: Sun Mar 29, 2020 2:23 am

Re: score counter and putting objects to collect

Post by Azzla »

vires wrote: Thu May 05, 2022 2:19 am Hi - I'm somewhat new to coding and wondering about the same issue of object collection. For some reason when I download the two .love files in the thread above, I'm not able to open them, with love or with VSC. If anyone can advise me on a possible solution so I can benefit from the advice/help already offered, that would be rad
This thread is 9 years old, which means the love files provided are using a heavily outdated version of LOVE2D. Many functions and methods from that version are deprecated. You'll probably get more help if you created a new thread (I think it's fine in this instance since this one is so old) and get more specific with your questions, code examples included.

That said, sounds like you want to do some basic collision and drawing logic. My game has lots of collectible objects (coins, powerups, etc), here is a simplified example of how I'm handling coin collection.

Code: Select all

function updateGold(dt)
  if round.gameState == 2 then
    for i,c in ipairs(coins) do
      if distanceBetween(c.x, c.y, player.x, player.y) < 6 then -- basic 'collision' detection
        gold.total = gold.total + c.value -- add the coin value to the players total gold
        c.collected = true -- flag used to 'despawn' the coin once collected
      end
    end
    
    for i=#coins,1,-1 do
      local c = coins[i]
      if c.collected == true then
        table.remove(coins, i)
      end
    end
  end
end
All the active coins are stored in a big parent table. When the for loop iterates over a coin that has c.collected set to true, it removes it from that parent table. Hope this helps.
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Nikki and 6 guests