Simon game - Showing answers

In my quest to make tiny games to actually finish projects, I decided to clone the game Simon, where you have 4 colored squares and you click patterns that slowly get longer as you get them correct. However, I’m trying to show the pattern to recreate and it goes by took quickly, not allowing for duplicates and making the pattern hard to repeat. Any help would be appreciated.

This is the problem code:

if (showingAnswer) {
			if (answer.size() == 0) {
				answerFrames = 0;
				generateAnswer();
				indexShownOfAnswer = 0;
				showOne = true;
			} else {
				if (indexShownOfAnswer >= answer.size()) {
					showingAnswer = false;
				} else {
					boolean isYellow = answer.get(indexShownOfAnswer) == 0;
					boolean isBlue = answer.get(indexShownOfAnswer) == 1;
					boolean isRed = answer.get(indexShownOfAnswer) == 2;
					boolean isGreen = answer.get(indexShownOfAnswer) == 3;
					answerFrames++;
					if (answerFrames % 70 == 0) {
						indexShownOfAnswer++;
						showOne = !showOne;
					}
					yellow.render(false, false);
					if (isYellow && showOne) yellow.showSelect();
					blue.render(false, false);
					if (isBlue && showOne) blue.showSelect();
					red.render(false, false);
					if (isRed && showOne) red.showSelect();
					green.render(false, false);
					if (isGreen && showOne) green.showSelect();
				}
			}
			return true;
		}

Source: https://github.com/CopyableCougar4/Tiny-Projects and then click on Simon

CopyableCougar4

It doesn’t seem like you reset the answerFrames after each blip in the pattern.

The answerFrames doesn’t get reset until the puzzle resets. I just see if it’s a multiple of 70 (so once per second) and if it is then I increase the indexShownOfAnswer.

First of all you don’t keep tracxk of frame times?
every frame you should calculate the delta like so:


long lastFrame = System.nanoTime();
protected float getDelta() {
    long time = System.nanoTime();
    float delta = (time - lastFrame) / 1000000000f;
    lastFrame = time;
    return delta;
}

Now to avoid all the answers from being shown all at once do this:


long lastTime = System.currentTimeMillis();
if (System.currentTimeMillis() - lastTime < (1000 * "seconds to display current answer")) {
    
} else {
    setup for next answer
    lastTime = System.currentTimeMillis()
}

In the code I use [icode]Display.sync(70);[/icode] so I have a pretty good (not exact) idea of timesteps being similar.

That will cause issues. For example, if you drag the window it pauses the display updates.
So imagine a walking character once you start dragging for awhile then stop the character will still be in the same spot.

With frame delta the character will be interpolated to the correct position.

But the second code block should prevent all answers from showing up at once.