Page 2 of 2

Re: score counter and putting objects to collect

Posted: Fri Jul 12, 2013 2:04 pm
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

Re: score counter and putting objects to collect

Posted: Fri Jul 12, 2013 2:41 pm
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 :)

Re: score counter and putting objects to collect

Posted: Fri Jul 12, 2013 4:05 pm
by Saltyham
I'm very grateful for the help still working on the scoring
but here it is at its current state.

Re: score counter and putting objects to collect

Posted: Thu May 05, 2022 2:19 am
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

Re: score counter and putting objects to collect

Posted: Wed May 11, 2022 7:31 pm
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.