Making Da○Saba○ Bar (No. 3)
table of contents
I also had an in-house study session, so I had some free time.
thank you for your hard work.
This is Mr. Matsuyama from the System Development Department.
We bring you the third issue of ``Making a D○Saba○ Bar,'' which started abruptly from the last time.
Click here for the first issue↓
Click here for issue 2↓
In issue 2, we even implemented three types of weapons (maximum level 3) that players can use.
In the third issue, we will implement the ecology of zombies (generation and movement) and level up using the collected experience points.
zombie generation
I think the game system is to survive for a certain amount of time, so I think the requirement is to increase the number of zombies that appear as time passes.
Therefore, I prepared two types of generation processing.
① One body appears every certain period of time (short)
② A large number of creatures appear every certain period of time (long) (wave)
① is an image where the initial weapon level is low, and it is easy to earn experience points here and there.
② is an image where a large number of weapons occur and you have to run away but raise the level of the weapon, and the exhilaration when the weapon level goes up and enters genocide mode. It's a touching image.
Both spawn at a certain distance from the player's location.
Also, use coroutines to handle waits for a certain amount of time.
The process that generates one body every certain period of time is like this.
private IEnumerator spawnBase() { const int MAX_BASE_ENEMYS = 50; const float spawnRadiusMin = 8.0f; const float spawnRadiusMax = 10.0f; const float spawnInterval = 1f; var waitTime = new WaitForSeconds(spawnInterval); while(true) { // Always MAX Generate body enemies so that they exist if(enemies.Count < MAX_BASE_ENEMYS) { // Player position Vector2 playerPos = playerController.GetPlayer().Position; // Determine the placement radius float r = UnityEngine.Random.Range(spawnRadiusMin , spawnRadiusMax); // Determine the placement angle float angle = UnityEngine.Random.Range(0, 360); // Generate spawn(playerPos, r, angle); } yield return waitTime; } else { yield return null; } }
・Every second
・Up to 50 objects
・At a distance of 8.0 to 10.0 from the player
・Randomly at an angle of 0.0 to 360.0 with the player at the center
is performed using the spawn function
The basic implementation of wave (②) is the same as ①.
The coordinates, angles, and generation will be repeated for the number of zombies that are generated.
The number of occurrences will gradually increase, with the second occurrence being more frequent than the first occurrence.
Only that part is excerpted.
// Determine the number of spawns from wave (maximum 100) float spawnNum = Mathf.Min(wave * 10, MaxSpawnNum); // Arrange at equal intervals float angleRange = 360 / spawnNum; // Player position Vector2 playerPos = playerController.GetPlayer ().Position; // Generate for(int i = 0; i < spawnNum; i++) { // Determine the placement radius float r = spawnRadiusMax + UnityEngine.Random.Range(-1.0f, 1.0f); // Placement Determine the angle float angle = angleRange * i; // Spawn spawn(playerPos, r, angle); }
It's like this.
zombie move
This is what I got when I looked at the main house.
・Slower than the player
・Moves towards the player
・Followability seems to be low
, so the processing is
1) Find the vector towards the player
2) Move in that direction for a certain amount of time
3) Return to 1)
This seems to be enough.
private void walk() { // Walk this.transform.localPosition += new Vector3(walkInfo.course.x * WalkSpeed * Time.deltaTime, walkInfo.course.y * WalkSpeed * Time.deltaTime, 0); // Update timer walkInfo.timer -= Time.deltaTime; // If the timer is less than 0, reset it if(walkInfo.timer < 0) { walkInfo.timer = walkInfo.interval; // Timer walkInfo.course = (walkInfo.player.Position - this.transform.localPosition).normalized; // Walking direction } }
There is no need to stop, so just execute every frame from Update().
It's like this.
Experience points
I don't know if it's called experience points correctly, but it's something you collect to acquire weapons and level up.
They are placed when a zombie is defeated and collected when the player approaches.
At the end of the death animation in the Enemy class, generate his Exp object through the ExpController class.
Generation process
public void OnAnimationEnd() { // Destroy after death animation ends if (status == Status.Dead) { expController.Spawn(this.transform.localPosition); Destroy(this.gameObject); } }
To collect, find the distance from the player using the Vector2.Distance function, and move objects within the threshold toward the player coordinates. This is also handled by a coroutine.
Recovery process
private IEnumerator move() { var elapsedTime = 0f; var startPosition = transform.localPosition; while (elapsedTime < 1f) { var targetPosition = playerController.GetPosition(); elapsedTime += Time.deltaTime * MoveSpeed; transform.localPosition = Vector2.Lerp (startPosition, targetPosition, elapsedTime); yield return null; } Destroy(gameObject); }
It's like this.
UI for weapon levels
If you collect a certain number of experience points, you can get a weapon or level up.
Level control for each weapon was implemented in issue 2, so we will prepare it so that it can be operated with the UI.
・Gray underlay: Panel
・Weapon icon: Button
・Text and ★☆: Text
By combining these, you can create something that looks like that.
Here is the finished product
Combining this implementation with the first and second issues, it will look like this.
Isn't it more like that now?
Also,
I would like to complete the game by adding things like・Player's girlfriend's HP management
, time limit
, and magnets
As usual, the entire project is available on GitHub.
This blog has a lot of sources, so if you want to see the whole thing, please check here.
I hope this will be of some help to you.
BeBe Survivor
Well, that's all for now.
Click here for the first issue ↓
https://beyondjapan.com/blog/2024/02/survivor/
Click here for issue 2↓
https://beyondjapan.com/blog/2024/03/survivor2/