Giter Site home page Giter Site logo

Design Pattern about se102-intro-game-development HOT 4 OPEN

dxv2k avatar dxv2k commented on June 19, 2024
Design Pattern

from se102-intro-game-development.

Comments (4)

dxv2k avatar dxv2k commented on June 19, 2024

Think about how input and drawing propagates through your engine. Input: the game window registers some input, and then needs to pass it down to the current scene through the SceneManager, and the Scene passes it down to the Player entity. Input probably can't be a part of SceneManager, because input comes from the game window, which probably belongs to the Game, not the SceneManager.
Drawing is similar - the Game decides where the game is to be drawn (probably the window, or perhaps some intermediate render texture), and passes that into the current scene, and the scene draws its Map, which draws the MapObject and then the Enemies and Player. The camera determines where on the screen everything is drawn.

from se102-intro-game-development.

dxv2k avatar dxv2k commented on June 19, 2024

You need an explicit SceneManager. "Manager"s are rarely useful in practice. All the work it does can probably be done by the Game and the Scenes - the Game just needs to keep track of which scene is currently active, and to change the active scene when asked (e.g. if the player goes to the next map, or opens a menu)

from se102-intro-game-development.

dxv2k avatar dxv2k commented on June 19, 2024

image

from se102-intro-game-development.

dxv2k avatar dxv2k commented on June 19, 2024

Different Components communicate with each other using Events (different ones from the events the window emits for inputs, but the same idea). So for example, whena physics component detects that the player landed on the ground, it'll emit an event. The actor's Sound Component listens for that event and plays the "landed" sound when it happens. Animations can be updated similarly. The event system works using a Subject-Observer pattern, where Subjects emit events and Observers listen for them. A single object may be both a subject and an observer (e.g. an Animation Component might be an Observer reacting to physics events, while being the Subject of a Sound Component that reacts to new animations starting by playing sounds). Info on this pattern: http://gameprogrammingpatterns.com/observer.html
Different scenes also communicate with each other and other objects using this same system. The menus, for example, mostly just emit events, and it's the observing game or scene that does the actual work.

from se102-intro-game-development.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.