Advertisement

How can a boost be triggered for the player after collecting 10 items in a second?

Started by November 30, 2023 09:37 AM
2 comments, last by StandDev 1 year ago

Hi, I had an interview question and it's bugging me. The question was presented with a similar image to the below image. The question asked how would you give the player a boost when 10 of the circles have been picked up in 1 second. One solution I can think of is creating a group of 10 circles by hand like below, when the player collects the first circle in the group, take a note of the game timer and do the same for the last circle and workout the difference. But what if the coins are randomly generated and what if it is possible to collect the first two circles plus the 8 circles in the group of 10 within a second. So I thought of another solution where you keep a count of circles collected with using the same method of using the game timer above and work out the difference from collecting the first and last circle. They didn't seem too happy with either answer. What other ways could it be done or more likely to be the correct answer for the solution?

I feel like I am missing something simple

Thanks

My first inclination is a circular array of ten timestamps. Add a timestamp with each collection. After you add a tenth, test the oldest for its time. If it was on time then all ten were in time, grant it. You could also prune the collection at that point to only those in the time range, but it is not necessary. You only need to test against the oldest one. If the buffer is initialized to an old time relative to the clock, you don't even need to verify it had ten; just compare the next item in the circular queue against the current time to know how long ago it was added, and blanks are “a long time ago” so they don't satisfy the comparison.

Advertisement

I really @frob like that idea, I might give it ago at some point

This topic is closed to new replies.

Advertisement