Creating a Da○saba○ber (No. 3)

It's been a while since we last posted due to internal study sessions and other issues.
Thank you for your hard work.
This is Matsuyama-san from the System Development Department.

We are pleased to present the third issue of "Creating a Da○saba○bar," which began abruptly in the previous issue

The first issue is here ↓

Creating a Da○saba○bar (First Issue)

Issue 2 is here ↓

Creating a Da○saba○ber (No. 2)

In the second issue, we 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 leveling up with collected experience points.

Zombie Creation

In terms of the game system, I think the zombies will survive for a certain period of time, so I think the requirement is to increase the number of zombies that appear over time.
Therefore, I have prepared two types of generation processes.

① One appears every certain time (short)
② A large number of them appear (waves) every certain time (long)

① is the image of making it easier to gradually earn experience points when your weapon level is low at the beginning, and
② is the image of raising your weapon level while fleeing when a large number of enemies appear, and the exhilaration you get when your weapon level increases and you enter genocide mode.

Both events should occur at a certain distance from the player's position.
Also, use a coroutine to handle waiting for a certain period of time.

The process for generating one at a time is as follows:

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) { // Spawn so that there are always MAX enemies if(enemies.Count < MAX_BASE_ENEMYS) { // Player position Vector2 playerPos = playerController.GetPlayer().Position; // Determine placement radius float r = UnityEngine.Random.Range(spawnRadiusMin, spawnRadiusMax); // Determine placement angle float angle = UnityEngine.Random.Range(0, 360); // Spawn spawn(playerPos, r, angle); } yield return waitTime; } else { yield return null; } }

- Every 1 second
- Up to 50
- 8.0 to 10.0 away from the player
- Random angle between 0.0 and 360.0 from the player -
Instantiate using the spawn function They
will be generated in this manner.

The basic implementation of wave (②) is the same as ①.
The coordinates, angles, and generation are repeated for the number of zombies generated.
The number of zombies generated is gradually increased, with more second occurrences than first occurrences.
I've only excerpted that part.

// Determine the number of spawns from the wave (maximum 100) float spawnNum = Mathf.Min(wave * 10, MaxSpawnNum); // Place at equal intervals float angleRange = 360 / spawnNum; // Player position Vector2 playerPos = playerController.GetPlayer().Position; // Spawn for(int i = 0; i < spawnNum; i++) { // Determine the placement radius float r = spawnRadiusMax + UnityEngine.Random.Range(-1.0f, 1.0f); // Determine the placement angle float angle = angleRange * i; // Spawn spawn(playerPos, r, angle); }

It looks like this

Zombie Movement

Looking at the original, I got the following impression:
・Slower than the player
・Moves towards the player
・Low tracking ability
, so the process should
1) Find the vector towards the player
2) Move in that direction for a certain amount of time
3) Return to 1
.

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; // Reset the timer when it falls below 0 if(walkInfo.timer < 0) { walkInfo.timer = walkInfo.interval; // Timer walkInfo.course = (walkInfo.player.Position - this.transform.localPosition).normalized; // Walking direction } }

There is no stopping, so all you have to do is run Update() every frame

It looks like this

Experience points

I'm not sure if "experience points" is the correct term, but they are collected to acquire weapons and level up.
They are placed when a zombie is killed and collected when the player approaches.
The Enemy class generates an Exp object through the ExpController class when the death animation ends.

Generation process

public void OnAnimationEnd() { // Destroy once death animation is over if (status == Status.Dead) { expController.Spawn(this.transform.localPosition); Destroy(this.gameObject); } }

The collection is done by calculating the distance to the player using the Vector2.Distance function, and moving objects within the threshold towards the player's coordinates. This is also processed in a coroutine

Collection 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 looks like this

Weapon Level UI

Once you collect a certain amount of experience points, you can get a weapon or level up.
We implemented level control for each weapon in issue 2, so we will prepare it so that it can be operated with the UI.

・Gray writing pad: Panel
・Weapon icon: Button
・Text and ★☆: TextBy
combining these, you can create something that looks similar.

Here is the finished product

When you combine this implementation with the first and second issues, it will look something like this

It looks pretty similar now, doesn't it?
Now

I'd like to complete it by adding some things like player HP management
, a time limit
, and magnets

As usual, the entire project is available on GitHub.
This blog post contains a lot of source code, so if you want to see the whole project, please check it out here. I hope it
will be helpful.
BeBe Survivor

Well, that's all for today

The first issue is here ↓
https://beyondjapan.com/blog/2024/02/survivor/

Issue 2 is here ↓
https://beyondjapan.com/blog/2024/03/survivor2/

If you found this article useful, please click [Like]!
7
Loading...
7 votes, average: 1.00 / 17
524
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Matsuyama Kensho

He has long worked in programming and project management at a game development company.
In 2019, he joined Beyond Inc. and works in the Yokohama office.
He is primarily responsible for project management of server-side development work (occasionally programming).
His hobbies are cycling (road racing) and watching horse racing.