10

Transmitting the full game state regularly is usually not feasible, though it does depend a lot on the complexity of you game. For a simple game with a small world model it may work. I've personally had much more success with the following model: Game state stored in a well defined object model in a spatial data structure (e.g. an octree) All changes to ...


7

Oldschool RPGs with lots of these switch/lock-and-key style steps but a strictly linear progression would often implement this as a "Quest Stage" integer or enumeration. Let's imagine a linear dungeon with a key to open the entrance door, two rooms of puzzles to solve, and a boss to defeat: the dungeon's quest stage begins at 0 == QUEST_START finding the ...


6

The synchronization is usually split into two part: incremental and absolute. Sometimes you must transmit everything, it is large, but if you pack it the right way you can do this once every few seconds. It is good to put everithing in place, correcting the faults of incremental refreshes. To achieve real-time experience, you must transmit some changes ...


6

You should clearly separate GUI (view) from the actual game state (model). GUI just shows the model to the player (in one way or another) and lets the player control it, but the model itself is solid enough to know everything it needs (level, player, etc). The GUI should know only things GUI needs, which model does not care about (e.g. controls positions).


6

In broad terms, there are a few standard architectures for networking systems. In terms of topology, you have: Client-Server: All clients talk to a single server, which may be a dedicated server executable, or may be another copy of the game, just operating in "server mode". (this is the one you mentioned) Promiscuous Peer-to-Peer: Every peer talks ...


5

In object-oriented programming, you expose private data with getter-methods. When your player-class wants to know the terrain-type of a tile, it would call level.getTerrain(int x, int y). That public function of class Level would access the private terrain array and returns the value of the terrain tile. When you don't want the player-class to depend on ...


4

you can use a forward declaration of the class that are in circular dependency. Here an explanation class firstClass; //Here the forward declaration class secondClass { public: private: }; Then in the cpp of the second class you can include the firstClass header file.


4

iOS 9 actually introduces a GameplayKit framework that includes State objects. This link shows you the implementation of their GKState class. It inherits from NSObject, but not from any SpriteKit node class, or any SpriteKit class at all. The thing to remember is that SpriteKit is all about drawing and physics simulation. SpriteKit tends to confuse the ...


4

It is probably due to your gameloop is faster then your pressing speed. You should stop detecting space key when you pressed it once. For checking purpose you can use a flag for now. Like, bool _isKeyPressed = false; if (currentGameState == GameState.TitleScreen && !_isKeyPressed) { if (keyboard.IsKeyDown(Keys.Space)) { ...


4

This is sort of open ended, but I would generally recommend that you have a list of open quests, separate from your other state. When something interesting happens, you generate an event that describes what happened ("player ship took 9 points damage from enemy Foo"), and pass that event through your quest queue - each quest would then decide if it cared ...


3

I found the solution myself:- Before going to a different state, use the input.clearKeyPressedRecord() to clear all previously recorded key-Presses, or else even after changing a state, previously stored keyPress event will cause problems. So instead of doing this, public void changeState(GameContainer gc, StateBasedGame sbg) { Input input = gc....


3

Having just one generic "Map" class and have each instance of this class load its layout, objects, scripts etc. from an external file is the usual way to do it. Usually a WYSIWYG map editor is used to create and edit these map files. This map editor can be integrated into your game or be a stand-alone program. In the latter case you can often safe lots of ...


3

In the vast majority of cases, your best bet is with loose values like this: int hitPointsMax; int hitPointsCurrent; This is by far the easiest thing to think about and to modify. The "structure" (including putting the values close together in memory for performance) should be provided by whatever class (eg: Player) they reside in. Leave the Player class ...


3

You should probably generalize when you can to prevent code duplication. For instance (pseudo code): class BoundedVal<class T> { // Normal val can be used for attributes like defense or attack // that are temporarily buff/debuffed T min, max, normal_val, val; void inc_val(T amount){ val = min(max, val + amount); } ...


3

You can calculate snapshot delta (changes to its previous synced state) by keeping two snapshots instances: current one and last synced one. When client input arrives you modify current snapshot. Then when it's time to send delta to clients, you calculate last synced snapshot with current one field-by-field (recursively) and calculate and serialise delta. ...


3

Singletons, PlayerPrefs and the DontDestroyOnLoad flag are already three ways to pass data between scenes. There is also a fourth one: static variables which do not use the Singleton pattern but are only available to the local class. There is also SceneManager.LoadScene ("play_scene", LoadSceneMode.Additive); which loads a new scene without destroying ...


3

Is it possible to save the game's current state to disk? If yes (hint, the answer is always yes) then you have a means by which you can synchronize players. Even if it is horribly inefficient. But optimization is just a matter of working out which bits and bytes any given player doesn't need, either because: they already know (eg, what level is being played ...


2

Use a piece of data to denote your scenes. A simple enumeration is the easy way; even a string works just fine in a pinch. Your interface should be extended to have something like ESceneType getSceneType(); which returns the type of that scene (e.g. ESceneType.MainMenu or ESceneType.Pause or whatever). You then create a factory object which, using ...


2

There are many issues that could be dealt with using a variety of techniques. Does the game have physics? If so, are physics being checked on the server securely? How is lag handled? What is the behaviour on the client-side when the round trip times increases? Is there a logging system in place to allow further debugging or studying in case of errors, ...


2

Don't go with a class for each area! Make you area have certain parameters! Unless its something really specific - when I mean specific is that really changes the concept of area and you can't fit it anywhere. Then, you should make a event system for you game (you will thank me later) this will make creating different area lore and dynamic actions a lot ...


2

glossary: what I call "sequence point" is a logical grouping of "when everything is done" and it's mostly synonymous with "each frame" or "each full AI cycle" depending on the game, etc... No one sends an entire game's state at each sequence point (frame, heartbeat, whatever). Only changes are sent and, in games with large areas only changes local to the ...


2

First, the answer to your direct question which is whether threads continue running when the main() thread ends can be found at this Stack Overflow answer: https://stackoverflow.com/a/4667273/377922 when the main thread (that is, the thread that runs the main() function) terminates [...] the process terminates and all other threads stop. So, as long as ...


2

First you need to know how to represent your relevant data in a protocol compliant manner. This depends on the data relevant to the game. I will use an RTS game as an example. For networking purposes, all entities in the game are enumerated (e.g. pickups, units, buildings, natural resources, destructibles). The players need to have the data relevant to ...


2

As https://gamedev.stackexchange.com/users/30331/ben points out in his comment, this may not be the best way, especially if your state info is big. Otherwise: Is there a pattern to store multiple independent copies of the game state from different times, so that they can be easily compared? Have a look at the Memento pattern. You could have Mementos ...


2

Similar to RDeving's answer, here's my usual code: var keys = {}; window.onkeydown = function(evt) { keys[evt.keyCode] = true; } window.onkeyup = function(evt) { delete keys[evt.keyCode]; } Then, in your update loop: if (37 in keys) { //keycode 39 is down } if (38 in keys) { //keycode 38 is down } // ... etc


2

In your situation, having states within states is perfectly acceptable and is often the expected architecture. Here is something to think about: generally, during development, you could start your game directly in the "play" state (you set up a bunch of parameters that would normally be set up by the previous state), and you make the game end instead of it ...


2

The PS4 controller has a lightbar. It is used in (for example) Towerfall Ascension to indicate player id (red for player one, blue for player 2 etc.) and Transistor (mimics the swords speech). Those games are made in C#/Monogame. I also understood that Unity, provided you have the PS4 license, can access the lightbar. So there is definitely a possibility to ...


Only top voted, non community-wiki answers of a minimum length are eligible