- Home /
How can I make the keys randomly change after each keypress?
Hi guys, I made a Tetris game and want to make the key for rotating the blocks change randomly after each keypress. For example: first time using the "R" button in order to rotate the block but if I want to rotate the same block again, then I need to try another button...
void Update() {
if (State != TetrimoState.Fixed && State != TetrimoState.Preview && State != TetrimoState.Spawning) {
if (State != TetrimoState.Landed && Input.GetAxis("Vertical") < 0)
StartCoroutine(FallingDown());
if (Input.GetButtonDown("Horizontal"))
StartCoroutine(MoveHorizontal());
// Set "up" as alternative button for Jump (Project => Input)
if ((Input.GetButton("Jump")) && Time.time > NextSwap) {
if (this.CanRotate) {
StartCoroutine(RotateTetrimo());
NextSwap = Time.time + SwapCooldown;
}
}
// Automatic falling down
if (NextFall < 0) {
StartCoroutine(FallingDown());
NextFall = FallingCooldown;
}
NextFall -= FallingSpeed * Time.deltaTime;
}
if (State == TetrimoState.Preview) {
transform.Rotate(0, 1f, 0, Space.World);
}
Are you going to tell the player which new key they need to press(like a type $$anonymous$$ching game)? Just a thought as if not it may not be the best design decision otherwise...???
No, the player have to guess the new key, but the keys might be random numbers from 1 to 7 or random keys as "Z","X","C","V","B","N","$$anonymous$$".
I think you stand a very high chance of alienating Tetris fans by doing this(your target audience)... It sounds like a frustrating and limiting game mechanic to introduce...
Yes I know, but it is only an assignment for tomorrow.
No problem, normally I would not say anything(and should not have really), but as a big Tetris fan I found it impossible not too, sorry! :D
Answer by AlwaysSunny · Nov 24, 2014 at 10:00 PM
Store a string collection containing your keys.
Pick a random index within the collection's length.
Use the string key at that index as your GetKeyDown argument.
Repeat.