Bluenix2 / crackout

A now archived breakout clone, crackout! Because crack is a synonym of break.
MIT License
1 stars 0 forks source link

Reset Level upon Ball death #11

Open Bluenix2 opened 4 years ago

Bluenix2 commented 4 years ago

Currently a big problem with our test level is the inability to restart when the ball has died, which is when it all should end because you can't continue without a ball. Workaround for this is to refresh or start the application itself, which will not be accepted.

To do this there are several ways to do it we need to look over, biggest being how we know when the ball has died. We want to remember the rules of OOP and not create hard-coded dependencies breaking these. Valid ways we can do this is through dependency injection, and Godot signals. For now it's okay to create a loose dependency where only the parent is dependent on its children but NOT vice versa.

More on signals: https://docs.godotengine.org/en/stable/getting_started/step_by_step/scripting.html

The much prefered Dependency Injection does not have a designated documentation. But the best way to do it in Godot is export it with NodePath type and through the editor a new property is shown where you can drag in the Node. To get access to the Node you need to GetNode() with the path. Here exporting can be seen: https://godotengine.org/qa/51552/export-custom-type-variable-on-inspector-mono-c%23

The next step is deleting the Level1 instance, and adding a new one as a child to Game, which can be seen done here Lastly a initial velocity must be added like done in _Ready here

Bluenix2 commented 4 years ago

For a working example of Dependency Injection currently in our game see b3f1eb80aee46ba6513904d6aabcad9d200e5849.