Time spent: 4-5 hours
No plugins used.
My personal purpose for this project was to manually implement everything and avoid using any method I didn't write myself. However, I won't necessarily be faithful to this approach when writing big scaled games. where the goal is optimized polished output. That being said, here's anything you might need for this project...
Features:
- Top-down 2D game, where a triangle wanders through objects it shouldn't collide with
- A simplistic player movement controller (with GetAxis - Works with ArrowKeys)
- A simplistic camera movement controller (to follow player with a smooth delay)
- Collision OnTrigger Detection
Implementation (Classes discussed alphabetically):
- Camera Color Changer: When damage is caused, this class will be notified through an Action implemented in Player.cs. Changes the Camera.backgroundColor value changes through white and pale red.
- Camera Movement Controller: To implement the smooth delay, I calculate the direction vector on Update(), so that every time it's multiplied by a <1 number, the closer the target pos gets, the smaller the dir vector becomes. To achieve a constant speed, now you know which line to play with.
- Level Manager: Adds itself to 2 actions on Player.cs, where both refer to the same method with a bool parameter. Lambda was used to make this easier.
- Player: Has 3 actions in total (OnBeingDamaged, OnLevelWon, OnLevelLost). Disables damage detector for half a second to give player time to flee (with a mini coroutine). This is where collision On Trigger is detected.
- Player Movement Controller: could be merged with the Player class, however, I personally prefer to not have one class do more than one task. This code is mapped into arrowkeys. If you don't want to have the player rotate, apply line #13 to Translate and you'd be good to go.
- UI Manager: Also added to the damage action on Player. The rest is straight-forward.
Final notes:
- Almost all classes have some version of Singleton implemented.
- The only art file in this project is the sprite of the player and I drew it on MS Paint. That's why it's not transparent, and i did a trick to visually hide it. Don't tell anyone. :)