COINS & HURDLES

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.
Post Reply
angletri
Prole
Posts: 7
Joined: Sat Oct 10, 2020 7:59 pm

COINS & HURDLES

Post 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. ;)
Attachments
a.love.zip
GAME
(1.46 MiB) Downloaded 169 times
Last edited by angletri on Sun Oct 11, 2020 11:04 am, edited 1 time in total.
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: COINS & HURDLES

Post 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
angletri
Prole
Posts: 7
Joined: Sat Oct 10, 2020 7:59 pm

Re: COINS & HURDLES

Post 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.
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: COINS & HURDLES

Post 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.
angletri
Prole
Posts: 7
Joined: Sat Oct 10, 2020 7:59 pm

Re: COINS & HURDLES

Post 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
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: COINS & HURDLES

Post 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.
angletri
Prole
Posts: 7
Joined: Sat Oct 10, 2020 7:59 pm

Re: COINS & HURDLES

Post 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.
Attachments
a.love.zip
Game
(1.46 MiB) Downloaded 145 times
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: COINS & HURDLES

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 48 guests