DEV Community

Akira Game
Akira Game

Posted on

Our game progress ~ Timer ~

Introduction

In the previous posts, I introduced the basic concept of the game and implemented the login screen. From this article onwards, I will introduce the implementation of the main part of the game. We will cover the following topics, each of which is currently under active development.

  • User Animation and Items
  • Timer
  • Basic Rules ( Victory, Defeat )
  • Mirror
  • Mirror Movement ( Through, Break, Trap )

This post will shows the implementation of Timer.

Summary of timer

In our game, there is a set playtime, and once that time elapses, the Survivor side wins. Additionally, we need to spawn items at appropriate times and make sure the Survivor escape gates appear.

Main Functions

  1. Playtime
  2. Spawn items at specific time
  3. Spawn escape gates for Survivor

Playtime

We have set the playtime to 5 minutes. Users also need to check the playtime and play accordingly. We have implemented the timer with the following code.

// count total time
totalTime = minute * 60 + seconds;
totalTime -= Time.deltaTime;

// set again
minute = (int)totalTime / 60;
seconds = totalTime - minute * 60;

// display timer 
if((int)seconds != (int)oldSeconds)
{
  timerText.text = minute.ToString("00") + ":" + ((int)seconds).ToString("00");
}
oldSeconds = seconds;
Enter fullscreen mode Exit fullscreen mode

Image description

Spawn items at specific time

In the game, players can use items, which appear randomly. To ensure that items can appear at any time during the game, we have implemented them using coroutines like the below code.

void Start()
{
  StartCoroutine(ExcuteShowCircle());
}

IEnumerator ExcuteShowCircle()
{
   yield return new WaitForSeconds(120f); // wait 120second
   healthCircleManager.ShowCircle();
}
Enter fullscreen mode Exit fullscreen mode

Spawn escape gates for Survivor

The victory condition for the Survivor side is to escape from the room. To balance the game, the exit gate is not available from the start. It appears after a certain time has passed to prevent the Survivor from gaining an early advantage.

if (totalTime <= showExitTime)
{
  Debug.Log("Show Exit");
  showExitTime = -1.0f;
  exitManger.ShowExit();
}
Enter fullscreen mode Exit fullscreen mode

We handle object appearances in a separate program file to ensure clear and distinct roles for each class. By doing that, the readability and maintainability of the program are significantly improved.

Conclusion

In our game, the implementation was relatively straightforward, but I felt that managing events based on time progression could become more complex in more complex games. In actual development environments, I'm interested in researching how such management is handled in more complex scenarios.

Next Step

I will show Timer implementation.

  • User Animation and Items
  • Timer
  • Basic Rules ( Victory, Defeat )
  • Mirror
  • Mirror Movement ( Through, Break, Trap )

Top comments (0)