A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

161

This is the type of game where the same move performed twice reverses the board to its previous state. So to ensure a board is solvable, generate it by playing in reverse. Start with a solved (blank) board, then start programmatically "clicking" randomly either a certain number of times, or until the board has the desired number of white squares. One ...


92

While the above answers are clever (and probably how I would do it anyway), this particular game is very well known. It's called Lights Out, and has been mathematically solved. There is a solution if and only if two sums of various elements (given on the wikipedia page) add to zero mod 2 (i.e. an even number). In general a little linear algebra should give ...


37

You don't want to send player input to the server. What you probably want to do is send an abstracted representation of what the player wants to do to the server, and then run the logic on there. Likewise you don't necessarily want to send back everything the client needs to do. For example, you can send some kind of message saying "NPC X died", and the ...


20

An idea is to use the Visitor design pattern. You need a Renderer implementation that knows how to render props. Every object can call the renderer instance to handle the render job. In a few lines of pseudocode: class Renderer { public: void render( const ObjectA & obj ); void render( const ObjectB & obj ); }; class ObjectA{ public: ...


14

Well, you got answers but your real answer is at "try yourself". The things differ from game to game. I did couple of multiplayer games for some distributed network game design course. The most challenging was doing a realtime action game where many players involved and sending inputs like hell. When it comes to that point, everything becomes problem. As ...


13

Suppose you have a scene composed of a world, a player, and a boss. Oh, and this is a third person game, so you also have a camera. So your scene looks like this: class Scene { World* world Player* player Enemy* boss Camera* camera } (At least, that's the basic data. How you contain the data, is up to you.) You only want to update and ...


13

Go the other way around when generating your puzzle. Instead of randomly selecting the tiles and turning them from white to black, start from a blank slate, then select the tiles but instead of turning that tile to black, make it as if the user selected it, resulting in flipping all of the other tiles around it. This way you'll be guaranteed to have at ...


12

A lot of Adventure/RPG games handle this in two ways (there may be more I'm not aware of). Use of flags The first one is to set a flag if something happened (usually some bitmask). This is fine if you don't have many things to track. In the room/encounter there may be a check against a flag that alters something. In your example could add a rule: {"text" ...


10

Yes, it does make sense. As you said it will make less load on the system, which is good for thermals, and other applications. However.... Your games logic should NOT depend on the updates per second. Therefore I recommebd you to take a look at deltatime, which will make your game independent of the updates per second. I recommend you to take a look at ...


9

You could go for a linked list, as others suggested. But basically, a snake is just a FIFO stack (sometimes called a queue) of grid coordinates: When the snake grows one bit, you just push an element on top of the stack When it moves one square, you push an element on top and pop an element off the bottom For an implementation of a queue in Objective-C, ...


7

This is actually rather easy to do. Just get every item some bitmask to define how/where it can be equipped. Some random example: enum Slot { SLOT_NONE = 0x0000, SLOT_LEFT = 0x0001, SLOT_RIGHT = 0x0002, SLOT_TWOH = 0x0004, }; When trying to equip a weapon into a specific slot, you can check/compare flags to do different things: If ...


7

This depends on the combination of frameworks you are using. Sometimes a 2D game framework makes it very difficult to work with coordinates that are not bound to pixels because they were designed specifically for designers to think about their game world in pixel units. However, it's not a requirement. A game I'm currently working on relies on Box2D units ...


7

There are definitely some advantages in developing your game logic in an agnostic (non-Unity) environment. Pros It forces you to think about game design more purely. I find it is much easier to think about game design, whether on a board or on a computer screen, if I don't also have to think about writing or using an engine. It is easier to write and run ...


7

Your title asks a different question than your body content. In the title, you ask why logic and rendering should be separated, but in the body you ask for implementations of logic/graphics/rendering systems. The second question has been addressed previously, so I will focus on the first question. Reasons for separating logic and rendering: The widely ...


7

Ed and Alexandre have the right of it. But if you do want to know if every solution is possible, there are ways. There are a finite number of possible puzzles Clicking on the same square twice produces the same result as not clicking on it at all, no matter how many clicks were made between them. That means that every solution can be described by giving ...


6

Build a game and not an engine. You're getting caught up in what you inevitably get caught up in when you're making an engine: you have no specific requirements and you have no idea what will be most useful or pleasant, or how it will impact using your engine or your game's performance. You also have no way to know. Build a game, and the game will tell you ...


6

I think this can be done amazingly easy with regular expressions (provided you can provide the gameboard as string). Once you have the board in stringform, use the following regex: (\w) //capture any letter (\1{2,}) //capture that letter again twice or more. The beauty of this is that it works on any number of items, and any amount of ...


6

You are essentially creating 3 coordinate systems when you only need 2. The coordinate system for your grid is 0 to 800. Your "real" space is a normalized position from 0 to 1.0. And your "screen" space is measured from 0 to whatever your pixel width is. You will always need to convert between some kind of world coordinate system and screen space in order ...


6

This answer is only to build intuition of why separating rendering and logic is important, rather than directly suggesting practical examples. Let's assume we have a big one elephant, nobody in the room can see the whole elephant. maybe everybody even disagrees on what it actually is. Because everyone sees a different part of the elephant and can only deal ...


6

The best answer is: It depends. You don't have to limit neither one Updates: If your updates are not bound to an upper limit, then game logic should be dependent on a delta time amount, to avoid running the game faster or slower depending on the machine where it is run. This is a very common approach used by many games, but it is not the only one. ...


6

Gals Panic, is a Qix type game. You may search for Qix to get more information on how things work. The general concept here is, having two images. One is the picture that you want to be revealed. The 2nd one is the actual gamefield where the game is checked against. These two are combined to produce the end result. So suppose the filled game area is white ...


5

The problem is with your Input detection in OnGUI. Using OnGUI to trigger the Pause function can cause it to be called several times in one frame, which sets your savedTimescale to 0, thus UnPause just resets the Timescale to 0. On my machine Pause (GetKeyDown(E)) was being called 4 times when the key was pressed. Use Update() for Input checking, add some ...


5

You are asking for a concept of scenes inside one activity. This is as easy as creating an abstract scene or an interface that will have methods like renderMe() and onUpdate(long timeElapsed). Then in your engine or game-loop you simply render the current scene. How do you switch between scenes is upto you. You can have a governing class SceneManager. So how ...


5

To have the gun heat up quickly but reach its overheat threshold slowly, you could take the gun's current temperature into account in the heat dissipation, rather than having a constant rate of heat dispersion. That's actually how it works in the real world: the rate of heat / thermal transfer is proportional to the difference in temperature. Wikipedia has a ...


5

Since Hearthstone is written in Unity it is trivial to decompile the scripts (because .NET), and this does in fact allow us to see the algorithm for deck building. The algorithm (found in RandomDeckMaker.GetChoices) is actually very simple. It basically tries to pick random cards to bring the deck to the following distribution: 12 class-specific cards 4/4/...


5

It's called a flood fill, and it's what you see in paint programs. It's very fast. Pseudocode: declare visited list //the results you want declare unvisited list add current element (where red dot is) to unvisited list while unvisited list not empty get current element from unvisited list add current element to visited list for all (8) neighbours ...


5

I was considering voting to close this question as opinion-based, but I think there are a couple of misunderstandings about Entity-Component Systems and Data-Oriented Design here that are worth addressing. ECS is just a tool Like any programming pattern or principle, it exists to help you write good software. It is not an unbreakable law of physics or a ...


4

I'm a beginner too, but I just tackled this problem in my own game, so hopefully you will find this helpful: First off: you have screenOffsetY spelled as screenOffestY, with the e and s reversed. So I'm not sure if that was intentional or not. Secondly: Since there is only limited source code provided to base my answer on, I'm going to have to generalize ...


4

This is a very simple programming problem. Here's a straight forward solution. For every piece check if previous two pieces are same color if true, destroy those three pieces. for every piece after that, if current color == destroyed color, destroy it. If not, break out of the loop. If it's possible to have more than one set of three at once in a ...


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