Code Monkey home page Code Monkey logo

Comments (2)

Hopson97 avatar Hopson97 commented on May 18, 2024 1

Hey @Unarelith

Apologies I did not reply sooner, I been looking into many ways I can do this and I realise now that you are absolutely right!

Organizing game code into a game state system is something I typically did before, but throwing Lua into the mix really confused me here, and instead I went with this weird route that game states don't exist, and the game is always there but inactive. This was pretty horrible way to do things.

Looking back at your comment here now, I now understand that's exactly what I want,, as it enables the organisation of different stages of the game, while also being more flexible with what can be done.

For example, before if I wanted to have an animated GUI (eg, Minecraft the main menu sort of rotates around a world), then I would have to awkwardly fit it in between the game logic code, which is bad for obvious reasons.

The reasons I didn't do it before is because I was way too inclined on making as much as possible done from the Lua, which led to a code spagetti soup. Instead, I should be sticking with what I know, and delegate only very specific things to the Lua code, as after all this is a game and not a game engine.

What I am thinking is having the GUIs still defined in the Lua, but don't allow to have an ability to change the game state (or whatever I was doing before). Instead, I could have a GUI defined as a root menu, and make the game switch to that from the "C++ side" when switching to a game state etc etc

But yeah thanks so much for making me realise good ways to do things! 😄

from open-builder.

Unarelith avatar Unarelith commented on May 18, 2024

Ok, I see your issue here. I'll try to explain how it works in OpenMiner to give you ideas.

Basically, your Client class is divided among multiple things.

First, the state stack:

  • gk::ApplicationStateStack handles the game states (Title screen, game, pause menu, chat, etc..)
  • gk::ApplicationState, main class for all the game states, it's an abstract class that has:
    • A constructor to init the parent
    • A virtual function onEvent() for OS events (mouse moved, key press, etc..)
    • A pure virtual function update()
    • A virtual function draw()

This allows to split the code for the different states of the game.

Next, you're interested about what is in GameState.

Basically, three main classes:

GameState also handles the shader used for 3D rendering, the camera and the HUD class (which will render the hotbar, fps counter and debug info).

It's also responsible for PlayerBox drawing (basically the other players model).

If you have any questions, just ask. :)


EDIT: Just noticed about the chest opening.

Basically in OpenMiner it works like this:

  • User right-click on a block
  • Client send BlockActivated packet to server
  • Server execute the Lua function associated to this block
  • In the Lua function (for a workbench or a furnace), a GUI is created and sent to the client
  • The client receives the GUI info and display it

from open-builder.

Related Issues (20)

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.