Skip to content

v1.0.3

Choose a tag to compare

@Alessio-Marchese Alessio-Marchese released this 29 Nov 14:18
· 4 commits to master since this release

Release Summary 🛠️ the following things were added:

Event Driven Architecture:

I implement this architecture with the following pieces:

  • IEvent → a container that is used to incapsulate an event

  • IEventSubscriber → define the behaviour of a class that subscribe an event inside a world, it provides a Register method that takes a World as input, the class that extend this Interface should Subscribe a function connected to a specific event, for example

            public void Register(World world)
            {
               //When event Collision inside this world is published invoke OnEvent
                world.Events.Subscribe<CollisionEvent>(OnEvent);
            }
  • IEventBus → define the behavious of the EventBus, i created the interface for the sake of testing.. the EventBus is responsible for managing Subscribers and Events, it provides method to add Subscribers and publish Events (Enqueue events) and then a method that Dispatch the enqueued events and invoke the Subscribers that listen for every enqueued Event.

    A World contain an EventBus, so all the subscribers and events are linked to that specific world. The world is responsible to invoke the Dispatch method of EventBus in order to dequeue events and invoke the subscriber that listen for the enqueued event.

Collision System:

The pieces that i created for this feature are the followings:

  • Collider → a component that marks an object as collider, just like the sprite it contains Width, Height and Scale. It doesn’t necessary get those value from the Sprite itself because we might want a colliding box different than the Sprite actual size.
  • CollisionEvent → Extend IEvent, it contains GameObject A(mover), GameObject B, the two entities that are colliding
  • CollisionSystem → Get all the gameobject with Transform and Collider (we also get Transform because an object can’t collide if it doesn’t have a position in the world) then compare all the components bewteen them to understand if they’re touching, if they does it publish an event of CollisionEvent with inside the two objects that are colliding.
  • PhysicsCollisionSubscriber → Extend IEventSubscriber, when a collision event is published this subscriber catches it, calculate the direction of the mover object (A) that is colliding and blocks that direction.

Zoom camera fix:

While playing around in the project i noticed that the Zoom wasn’t working properly, so i adjusted the formula that calculate the camera position based on Zoom

General refactoring as usual:

General code and architectural cleaning, such as renaming, moving the centric Pivot logic of the rendering from MonoGameAdapter to Engine and more like those.

Video

Assets credit: https://kenney.nl/

I had to change assets because the old player asset did contain invisible spaces, this was creating problem on collision demonstration, since i wanted the collision of the player and static object to end right where the sprite ends

Sandbox3.mp4