Try to keep the ball bouncing.
Move the white paddle using the A
and D
keys.
Move the purple paddle using the <-
and ->
keys.
You can play the game here: https://tlietz.github.io/Ball-Bounce-Client/index.html
Ball Bounce is a game created in Rust using the macroquad game engine. It is compiled to wasm so that it can be played in a browser. For now, it has only local multiplayer with 2 players and keyboard controls.
The game is created with an ECS (entity component system) architecture.
The Player
and Ball
are entities, which are represented by struct
s.
Velocity
, Position
, and Control
are components, which are also represented by struct
s. Entities can have any number of components depending on what characteristics they need. For example, the Ball
entity does not have a Control
component, but the Player
entities do.
System
s are functions that control everything.
All of the game logic complexity is contained within the system
s. This makes it easy to know where in the code features should be implemented.
This also explains why ECS was chosen instead of OOP. With OOP, it would be more difficult to determine where features should be implemented because games have many features that require interaction between mutliple objects.
For example, suppose we want to implement a bounce()
function that bounces a ball off our paddle.
In OOP, we would have to decide whether to add bounce()
to the Ball
or Player
object. Does a ball bounce off the paddle, or does the paddle bounce the ball? This may be easy to manage with a simple game, but as it gets more complex, OOP would become exponentially harder to manage.
With ECS, a system
takes in the game_state
and determines when to call bounce()
.
The system
is external to both the Ball
and the Player
, so we no longer have to worry about where to put methods that handle interaction between multiple objects, like we would with OOP.
- Make a
GameState
enum to replace the currently usedBallState
. This will allow adding states likePause
, andMenu
. - Create a
game_state_system
that handles changing theGameState
enum. For example, pressing thep
button for pause, and pressingq
to quit.