In the continuation of the first article (
it is here ), I continue to develop a platformer based on the
article “Patterns of level design for 2D games” .
After the release of the first article, it was unambiguously decided that the push-button control, which was described in it, was not at all convenient. Therefore, the control in the game was redone on the joystick. Further, unfortunately the game did not pass moderation in the playmarket. Last Friday I received a notification that the project was rejected due to the collection of metadata. By the way, my first platformer "Knight Cadavar" was also rejected for the first time, due to the alleged request for permission to manage calls and view SMS (which was utterly stupid on the part of their bot. The game did not require any permissions). Google then demanded a written notice from me about why I needed it. But it all ended with the fact that I corrected a couple of errors that I noticed and sent the game to re-moderation. She was successfully added to the playmarket. Now, I plan to do the same with this game.
So, as soon as the second scene was created, the pattern was automatically closed.
Scene
a level / peace fragment based on a concept is usually a surmount.
')
Bonus
collected item that has a positive effect on players
We realize 2 types of bonuses for Lukas:
- The first-aid kit that will fall out when destroying monsters
- Chests with swords that Lucas will be able to throw at enemies
To realize the bonus with the first-aid kit, you must modify the prefabs with monsters. More specifically, indicate the place from which the bonuses will fall.

Then, modify the Enemy.cs script:
Spoiler header [SerializeField] private GameObject bonusPref;
Call the function with the return type Damage (0) and check if Health returns 0. If yes, that we call the random number generator. If the generator stops at choosing the number 0, then we throw out the bonus to the player and destroy the monster.
Further we describe what can be done with this bonus. To do this, create its prefab with the components SpriteRenderer, BoxCollider2D and Rigidbody2D. Also, create a script that will be responsible for what needs to be done if an apple collides with a player:
Spoiler header public void OnTriggerEnter2D(Collider2D collision) { switch (collision.gameObject.tag) { case "Player": { HeroScript.Health = 100; Destroy(this.gameObject); } break; } }
See
preview video .
Next, we realize the bonus swords fallout. It can be implemented on the same principle as in the first part the logs were dropped. The interesting part will be that when Lucas chooses swords, they will need to be thrown only in the visibility zone of opponents, and not when Lucas collects logs. After all, in the form in which the Attacks \ Item Collection button is now implemented, it would do just that. Swords were thrown in every situation. To do this, modify the attack \ gather script code:
Spoiler header [SerializeField] private GameObject swordPref;
What do these lines of code mean? First, we define an array of colliders and check everything that got into our cube:
Collider2D[] ED = Physics2D.OverlapBoxAll(Hero.position, new Vector2(attackInBoxX, attackInBoxY), lEnemy);
Pay attention to the parameters passed, they are very different from those used for OvelapCircleAll. Key parameters -
Vector2(attackInBoxX, attackInBoxY)
Then the condition is satisfied that if the array of colliders is greater than 0, then we check the inventory for the presence of swords. If the number of swords is 0, then we do nothing and execute the method
ED[i].GetComponent<Enemy>().Damage(1);
as if it was an ordinary blow. If more than 0, then release the sword and reduce the number of swords by 1.
Further, the implementation of the instantiateSword () method;
Spoiler header private void instantiateSword() { GameObject newArrow = Instantiate(swordPref) as GameObject; newArrow.transform.position = instSword.transform.position; Rigidbody2D rb = newArrow.GetComponent<Rigidbody2D>(); if (GameObject.Find("Hero").GetComponent<HeroScript>().localScale.x > 0) { rb.velocity = new Vector3(swordSpeed, 0, 0); } else { rb.velocity = new Vector3(-swordSpeed, 0, 0); newArrow.transform.Rotate(0,0,-180); } }
If you read the previous article well, you might have noticed that this code resembles a section of code that is responsible for shooting sunflower. In this section of the code added lines that are responsible for determining the scale of Lucas. That is, he looks left or right:
(GameObject.Find("Hero").GetComponent<HeroScript>().localScale.x > 0)
If Lucas is looking to the left, then
rb.velocity = new Vector3(-swordSpeed, 0, 0); newArrow.transform.Rotate(0,0,-180);
the sword flies to the left and rotates it 180 degrees in the same way.
See
preview video .
After completing this action, we automatically closed another 1 pattern:
An object
any entity that appears in the game scene and is capable of changing its state. Objects include dangers, enemies, bonuses, etc.Although, most likely, this pattern was implemented earlier when the first monster was programmed.
As a result, at the moment there are not 3 patterns left:
- Unreachable area
- Mechanics
- Boss
The mechanics at the moment cause me increased interest. Because I can not say to myself that I understand exactly what different people put into this definition.
Further,
unreachable area . In this question, I will do some time level design issues. First, because I want to make the third level dark. Most likely a cave or dungeon. With the ability to realize light effects.
Boss ! There will also be a cherry on the cake. I want to make it as independent as possible and with the ability to change my appearance.
Link to my application store on
Google PlayLink to Lucas Jones at
sourceforge.net .
Feel free and write comments on Habré or me on the post worldofonehero@gmail.com.
Thanks for reading, good luck.