COINS & HURDLES
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
COINS & HURDLES
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 183 times
Last edited by angletri on Sun Oct 11, 2020 11:04 am, edited 1 time in total.
Re: COINS & HURDLES
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
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
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
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
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
PS: it happens when you have a naughty little brother meddling in your things
Re: COINS & HURDLES
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:
Now create a CoinSeries-Object, that create a series of coins:
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.
Code: Select all
function Coin:initWithX(x)
self.x = x
self.y = 600
self.width = Coin_image:getWidth()
self.height = 32
end
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
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
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 190 times
Re: COINS & HURDLES
You have to init the CoinSeries. If you dont there are no coins in the coins-list. And therefore no coins will be rendered.
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 16 guests