Page 1 of 1

COINS & HURDLES

Posted: Sat Oct 10, 2020 8:35 pm
by angletri
I am making a game like Mario. I am facing a problem. I have spawned coins and hurdles but they are coming limitlessly. but I want coins to show and then a gap and show again but randomize the amount of it . How should I add coins and hurdles. I am new to game developing and I will really appreciate your help. ;)

Re: COINS & HURDLES

Posted: Sat Oct 10, 2020 9:37 pm
by Xugro
Could you upload a .love file of your project and a small sketch of what you want please? That would make it much easier for us to help you.

I am not sure what you want. If I had to guess: You want a coin block that has multiple coins inside. Something like this: https://www.youtube.com/watch?v=qovHBHuj5QA&t=254

Re: COINS & HURDLES

Posted: Sun Oct 11, 2020 11:08 am
by angletri
Hey! I have uploaded a .love file of my project. In my game coins and hurdles are coming but the problem is 1 coin come and then after some distance another coin come. but I want coins to be in a continuous way after some gap and again some coins. I don't know how to do it.

Re: COINS & HURDLES

Posted: Sun Oct 11, 2020 11:45 am
by sphyrth
Update your Love2D version (and push library) to the latest one. I actually loled when I saw that you accidentally put in a "Microsoft Solitary" shortcut in your love file.

Re: COINS & HURDLES

Posted: Sun Oct 11, 2020 11:58 am
by angletri
Oh! I will update it. but what about my problem of coins and hurdles.
PS: it happens when you have a naughty little brother meddling in your things

Re: COINS & HURDLES

Posted: Sun Oct 11, 2020 5:06 pm
by Xugro
You use the init-function of the coin to set its position. Create a(n additional) constructor where you can give the coin the x-position you want it to have:

Code: Select all

function Coin:initWithX(x)
    self.x = x
    self.y =  600
    self.width = Coin_image:getWidth()
    self.height =  32
end
Now create a CoinSeries-Object, that create a series of coins:

Code: Select all

CoinSeries = Class{}

local coins = {}
local startX = love.math.random(10, WINDOW_WIDTH + 20000)
local spaceBetweenCoins = 5

function CoinSeries:init()
     local number_of_coins = love.math.random(2, 8)
     for i=1,number_of_coins do
         local x = startX + i*Coin.width + (i-1)*spaceBetweenCoins
         table.insert(coins, Coin(x))
     end
end

function CoinSeries:render()
    for _, coin in ipairs(coins) do
        coin:render()
    end
end
And then you can create random series of coins. Place those series with a little bit of space between each other and you have what you want. To create multiple series of coins you could give the CoinSeries-class startX as a init-parameter and use something like the CoinSeries-class (a CoinSeriesSeries-class?). Or you can create a generator, that creates an unlimited amount of CoinSeries all the time.

If you want the coins to appear one after the other then add a update-method to the CoinSeries-class and add coin after coin to the internal coins-list. It can be done analogue to the timer you are using in love.update with the spawntimer.

Re: COINS & HURDLES

Posted: Mon Oct 12, 2020 12:02 pm
by angletri
Well, I have tried that but it is still not working. I am so confused. The logic seems right but it is not rendering. I have attached my a .love file. Check it.

Re: COINS & HURDLES

Posted: Mon Oct 12, 2020 5:23 pm
by Xugro
You have to init the CoinSeries. If you dont there are no coins in the coins-list. And therefore no coins will be rendered.