Enemy and gameplay


Update this week


The main update this week is mainly about the construction of game logic. As mentioned in the previous week, during the implementation process, our levels are dynamically loaded from local files, rather than simply repeated through Unity. interface to create, so that level design can be more flexible.

The config file

The configuration file of each level is as follows, where speed and bulletCount are both integers, representing the speed of bullets and the number of bullets in each level respectively, and the string of characters 01010101010 represents the dynamically generated enemy arrangement in the scene, where 0 represents Vacancy, 1 represents the enemy's life, which will be reduced by 1 after each collision, until the enemy disappears when it reaches 0.

During the dynamic generation of the scene, buildWithLine() is responsible for reading the string, calculating the number of enemies in the line, and then generating it based on the enemy's health value to dynamically determine the enemy's position, so different level designs and position arrangements can be achieved. , this is very effective in the design of ordinary levels.

speed
bulletCount
01010101010

Data flow

As mentioned in the last week, we use a singleton GameManager class to manage the global state of the game, including the current game level, current game state, current background music playback state, etc. This ensures that the game state is maintained throughout the game. It exists during the life cycle to avoid the game state being lost due to interface switching being destroyed. At the same time, it exposes some public functions, such as addScore, etc., which are used to call when a collision event occurs to update the game's score.

Status check

When implementing the current game state (win or lose), we added a new asynchronous function StatusCheck in GameManager. This function will skip the time of the first frame to ensure that all updates on the current field have occurred, such as brick destruction, ball destruction, etc. Destroy, etc., and then check the status to ensure the accuracy of the game status.

How the infinite level works

Different from ordinary levels, the endless level mode will first read the configuration of the level from the configuration file, dynamically generate enemies, and call InvokeRepeating("moveDown", 0, 5), that is, it will be called every 5 seconds. The moveDown function is responsible for moving the enemies in the scene downward and randomly generating a row of new enemies at the previous position of the row, thus realizing endless levels of play.

Files

html.zip Play in browser
May 23, 2024

Leave a comment

Log in with itch.io to leave a comment.