Skip to content

Latest commit

 

History

History
382 lines (271 loc) · 13.5 KB

spawn_objects.rst

File metadata and controls

382 lines (271 loc) · 13.5 KB

Objects Spawn & Properties

Objects Spawn

The object spawn action has been conducted in two scripts in parallel:

  • SpawnManager.cs (which takes charge of all items spawn in the sea)
  • SpawnSeaGullManager.cs (which only takes charge of spawning seagull)

The two classes have no interactions and effect on each other and working simulataniously.

Spawning Sea Objects

The spawn of the sea objects starts since 2s after the beginning of the game, every 2s, a new object will be spawned:

In the SpawnObject() function, two random values have been generated first to determine which object to spawn and which altitute to spawn that:

Then an if-else statement will firstly determine which object to spawn under the constraint of play mode:

  • Under Only "Right Leg" or "Left Leg" play mode: the object will only be spawn in the higher altitude.
  • Under "Both Leg" mode, the object will be spawned via two lanes each of 50% chance.

Lastly, an "if-else" statement has been implemented to determine which object being spawned according to the sprite defined as configuration parameters above:

Spawning SeaGull

SeaGull spawn on the other hand, is much simpler since there is only one spawn altitude and one plausible object being spawned:

Constant Leftward Movement

The constant leftward movement of the sea objects pursue with the following logic:

  1. when a new object has been spawned, append it to the current spawn manager parent object
  2. in each iteration of Update() function being called, loop through all the current children of the parent spawn manager object in a for-loop
  3. apply a left-ward vector to every single child in the loop

Note

since the child objects of spawn manager could be distroyed due being eaten by the Whale or self-destructed outside the boundary of the screen, the number of items within the spawn manager is varying thus need a agile and flexible approach on a dynamic array instance of collection of all children objects.

The append of child happend during the creation of each object:

Destroy Objects

If the object spawned hasn't been eaten, it will continue to move left-wards and stack in the spawn manager parent object, which will consume plenty of computer memory and thus harmful for the program.

Therefore, all object will be destroyed if they are outside the left boundary of the screen to save the computational power.

Object Properties

Properties of Objects in the Sea

Collision Trigger

Following the last section, the health point manipulations has been triggered in each of the object's class. The triggering ultilise OnTriggerEnter2D() function rather than OnCollisionEnter2D() because we want the object to pass through and trigger the event rather than collide and bounce away. Using small fish as an example:

Sprite Transition

In order to increase the repetibility of the game by adding more fun factors into the UI design, sprite transitions has been implemented to the two kinds of fishes:

  • When the fish the far from the whale, it shows a normal fish
  • When the fish is close to the whale but not passed yet, the fish shows a frigtened face inspired by rage faces from memes
  • When the whale miss eating a fish, the fish shows a grin face
Normal Frigtened Grin
sfish_idol sfish_frightened sfish_smile
Normal Frigtened Grin
bfish_idol bfish_frightened bfish_smile

The implementation involves basically getting the component of the sprite renderer and change the correponding sprite which has been pre-defined in the [SerializeField]. The following example uses smalle fish as an example:

Properties of the SeaGull

The movement of the SeaGull is more complicated than the previous fishes since it involves the a dropping mechanism. This has been implemented using the manipulations of rigidbody type of the object.

  • When a seagull has been spawned, the rigidbody type has been set to kinematic where there is no effect of gravity onto the object.
  • When the seagull hit with the splash box collider, change the rigidbody type to dynamic where gravity has an effect on the object and therefore it falls into the water.

When it falls into water, ignore the gravity again and apply a horizontal left-wards vector onto it for it to flow.

The Sprite also changed from the normal one to a frightened one:

Normal Frigtened
seagull_normal seagull_frightened