title: Low coupling and tight cohesion

text:
# Question
Title: Low coupling and tight cohesion
Of course it depends on the situation. But when a lower lever object or system communicate with an higher level system, should callbacks or events be preferred to keeping a pointer to higher level object?

For example, we have a `world` class that has a member variable `vector<monster> monsters`. When the `monster` class communicates with the `world`, should I prefer using a callback function then or should I have a pointer to the `world` class inside the `monster` class?

# Answer
There's three main ways that one class can talk to another without being tightly coupled to it:

1. Through a callback function.
2. Through an event system.
3. Through an interface.

The three are closely related to each other. An event system in many ways is just a list of callbacks. A callback is more or less an interface with a single method.

In C++, I rarely use callbacks:

1. C++ doesn't have good support for callbacks that retain their `this` pointer, so it's hard to use callbacks in object-oriented code.
2. A callback is basically a non-extensible one-method interface. Over time, I find that I almost always end up needing more than one method to define that interface and a single callback is rarely enough.

In this case, I'd probably do an interface. In your question, you don't actually spell out what `monster` actually needs to communicate to `world`. Taking a guess, I'd do something like:

```
class IWorld {
public:
  virtual Monster* getNearbyMonster(const Position & position) = 0;
  virtual Item*    getItemAt(const Position & position) = 0;
};

class Monster {
public:
  void update(IWorld * world) {
    // Do stuff...
  }
}

class World : public IWorld {
public:
  virtual Monster* getNearbyMonster(const Position & position) {
    // ...
  }

  virtual Item*    getItemAt(const Position & position) {
    // ...
  }

  // Lots of other stuff that Monster should not have access to...
}

```

The idea here is that you only put in `IWorld` (which is a crappy name) the bare minimum that `Monster` needs to access. Its view of the world should be as narrow as possible.
> 10 votes

# Answer
Don't use a callback function to hide what function you're calling. If you were to put in a callback function, and that callback function will have one and only one function assigned to it, then you're not really breaking the coupling at all. You're just masking it with another layer of abstraction. You're not gaining anything (other than maybe compilation time), but you're losing clarity.

I wouldn't exactly call it a best practice, but it's a common pattern to have entities that are contained by something to have a pointer to their parent.

That being said, it might be worth your while to use the interface pattern to give your monsters a limited subset of functionality they can call on the world.
> 12 votes

# Answer
Generally I try and avoid bidirectional links, but if I must have them, I make absolutely sure that there is one method to make them and one to break them, so that you never get inconsistencies.

Often you can avoid the bidirectional link entirely by passing in data as it is necessary. A trivial refactoring is to make it so that instead of having the monster keeping a link to the world, you pass the world in by reference to the monster methods that need it. Better still is to only pass in an interface for the bits of the world that the monster strictly needs, meaning the monster doesn't come to rely on the world's concrete implementation. This corresponds to the Interface Segregation Principle and the Dependency Inversion Principle, but doesn't start to introduce the excess abstraction you can sometimes get with events, signals+slots, etc.

In a way, you can argue that using a callback is a very specialised mini-interface, and that is fine. You have to decide whether you can more meaningfully achieve your goals via one collection of methods in an interface object or several assorted ones in different callbacks.
> 7 votes

# Answer
I try to avoid having contained objects call their container because I find it leads to confusion, it becomes too easy to justify, it'll become overused and it creates dependencies that can't be managed.

In my opinion, the ideal solution is for the higher level classes to be smart enough to manage the lower level classes. For example, the world knowing to determine if a collision between a monster and a knight occurred without either knowing about the other is better too me than the monster asking the world if it collided with a knight.

Another option in your case, I would probably figure out why the monster class needs to know about the world class and you'll most likely find that there's something in the world class that can be broken out into a class of its own that it makes sense for the monster class to know about.
> 3 votes

# Answer
You won't go very far without events, obviously, but before even begin to write (and design) an event system, you should ask you the real question : why would the monster communicate with the world class ? Should it really ?

Let's take a "classical" situation, a monster attacking a player.

Monster is attacking : the world can very well identify the situation where a hero is next to a monster, and tell the monster to attack. So the function in monster would be :

```
void Monster::attack(LivingCreature l)
{
  // Call to combat system
}

```

But the world (who already knows the monster) doesn't not need to be knowed by the monster. Actually, the monster can ignore the very existence of the class World, which is probably better.

Same thing when monster is moving (I let sub-systems get the creature and handle move computation / intention for it, the monster being just a bag of data, but lots of people would say this is not real OOP).

My point being : events (or callback) are great, of course, but they are not the only answer to every problem you'll face.
> 2 votes

# Answer
Whenever I can, I try to restrict communication between objects to a request-and-respond model. There is an implied partial ordering on the objects in my program such that between any two objects A and B, there may be a way for A to directly or indirectly call a method of B or for B to directly or indirectly call a method of A, but it is never possible for A and B to mutually call each others' methods. Sometimes, of course, you want to have backward communication to the caller of a method. There are a couple ways I like to do this, and neither of them are callbacks.

One way is to include more information in the return value of the method call, which means the client code gets to decide what to do with it *after* the procedure returns control to it.

The other way is to call out to a mutual child object. That is, if A calls a method on B, and B needs to communicate some information to A, B calls a method on C, where A and B can both call C, but C cannot call A or B. Object A would then be responsible for getting the information from C after B returns control to A. Note that this isn't really fundamentally different from the first way I proposed. Object A can still only retrieve the information from a return value; none of object A's methods are invoked by B or C. A variation of this trick is to pass C as a parameter to the method, but the restrictions on the relationship of C to A and B still apply.

Now, the important question is *why* I insist on doing things this way. There are three main reasons:

* It keeps my objects more loosely coupled. My objects may encapsulate other objects, but they will never depend on the context of the caller, and the context will never depend on the encapsulated objects.
* It keeps my control flow easy to reason about. It's nice to be able to assume that the only code that can change the internal state of `self` while a method executing is that one method and no other. This is the same kind of reasoning that might lead one to put mutexes on concurrent objects.
* It protects invariants on the encapsulated data of my objects. Public methods are allowed to depend on invariants, and those invariants may be violated if one method can be called externally while another is already executing.

I'm not against all uses of callbacks. In keeping with my policy on never "calling the caller," if an object A invokes a method on B and passes a callback to it, the callback may not change the internal state of A, and that includes the objects encapsulated by A and the objects in A's context. In other words, the callback may only invoke methods on objects given to it by B. The callback, in effect, is under the same restrictions that B is.

One last loose end to tie up is that I will allow the invocation of any pure function, regardless of this partial ordering I've been talking about. Pure functions are a bit different from methods in that they can't change or depend on mutable state or side effects, so there is no worry about them confusing matters.
> 1 votes

# Answer
Personally? I just use a singleton.

Yeah, okay, bad design, not object-oriented, etc. You know what? *I don't care*. I'm writing a game, not a technology showcase. Nobody's going to be grading me on the code. The purpose is to make a game that is fun, and everything that gets in my way is going to result in a game that is less fun.

Will you ever have two worlds running at once? Maybe! Maybe you will. But unless you can think of that situation right now, you probably won't.

So, my solution: make a World singleton. Call functions on it. Be done with the entire mess. You *could* pass in an extra parameter to every single function - and make no mistake, that's where this leads. Or you could just write code that works.

Doing it this way requires a bit of discipline to clean things up when it gets messy (that's "when", not "if") but there's no way you can prevent code from getting messy - either you have the spaghetti problem, or the thousands-layers-of-abstraction problem. At least this way you're not writing large amounts of unnecessary code.

And if you decide you don't want a singleton anymore, it's usually pretty simple to get rid of it. Takes some work, takes passing a billion parameters around, but those are parameters you'd need to pass around anyway.
> 0 votes

---
Tags: architecture, software-engineering
---


title: How much info can I store in a cookie?

text:
# Question
Title: How much info can I store in a cookie?
Im developing a flash game and I'd like to know how much info can I store in a browser cookie.

The game is simple, but it needs to store several variables in order to save all the details of your current progress.

The game is only one swf file, no server, no nothing.

I need to know how should I use the cookies to achieve this, and if they have the posibility of doing it, of course.

(several = 200 variables i.e)

# Answer
It is important to note that Flash cookies (or Local Shared Objects, as they are called) are different from browser cookies stored by webpages and JavaScript.

From the Wikipedia article on Local Shared Objects:

> By default, a Flash application may store up to 100kb of data to user's hard drive (browser cookies have a limit of just 4kb). The defined storage sizes are 0kb, 10kb, 100kb, 1Mb, 10Mb, and Unlimited. If the current limit is exceeded, the user is shown a dialog requesting storage space of the next size. The user may override the amount manually by clicking the Flash application with right mouse button and selecting Settings; however, this applies only to the domain of the Flash movie. If the selected setting is smaller than the current data size, the data is deleted.
> 9 votes

# Answer
Browser cookies are generally limited to 4k, Flash LSOs default to 100k but the user and raise or lower this I think: http://en.wikipedia.org/wiki/Local\_Shared\_Object
> 4 votes

# Answer
Two things to note:

* Browser cookies need to be transferred back and forth between the client and the server when each page is loaded, which can slow down a site's loading speed.
* The new HTML 5 client storage APIs can provide a much better solution to storing data on the client side. This can, of course, be transferred back and forth between the client and the server when necessary. Check this article for more info.
> 0 votes

---
Tags: flash, actionscript-3, swf
---


# Question
Title: Using box2d DrawDebugData with multi layer scene?
In my Game, a Scene is composed by several layers. Each layer has different camera transformations.

This way I can have a layer at z=3 (GUI), z=2 (Monsters), z=1 (scrolling background), and this 3 layers compose my whole Scene.

My render loop looks something like:

```
renderLayer()

   applyTransformations()

   renderVisibleEntities()

   renderChildLayers()

end

```

If I call `DrawDebugData()` in the render loop, the whole b2world debug data will be rendered once for each layer in my scene, this generates a mess, because the "debug boxes" get duplicated, some of them get the camera transformations applied and some of them don't, etc.

What I would like to do, would be to make DrawDebugData to draw only certain debug boxes. In that way, I could call something like

```
b2world->DrawDebugDataForLayer(int layer_id)

```

and call that on each layer like :

```
renderLayer()

   applyTransformations()

   renderVisibleEntities()

   //Only render my corresponding layer debug data
   b2world->DrawDebugDataForLayer(layer_id)

   renderChildLayers()

end

```

Is there a way to subclass `b2World` so I could add this functionality ( specific to my game ) ?

If not, what would be the best way to achieve this (Cocos2d uses a similar scene graph approach and box2d, but I'm not sure if debugDraw works in Cocos2d... )

Thanks

# Answer
> 2 votes
Fundamentally, the right approach is to only call DrawDebugData exactly once, at the start or end of your render loop usually. Everything is coming from the same b2World - which is the same coordinate system - which should mean, the same view/projection matrix.

The point is to dump everything about the world onto the screen in as simple a way as possible - the more game logic you add to the debug data, the less useful it becomes for debugging. If your architecture makes this tricky, you should step back and look at why you're switching between projections so much in the first place.

# Answer
> 1 votes
You are over thinking it. When will one b2World have bodies it two layers? I don't think you'll find one use case that isn't contrived. Box2D has one coordinate system. At any time world will is one way that world is represented to the player. That mean there is one projection matrix and one one layer.

What maybe misleading you is the desire to use Box2D in more than one layer. For instance you could use Box2D to do some crazy GUI effects. In this case you'll want to use two b2Worlds. You could do it with one and some clever collision masking but it's not worth the effort.

I like your approach of using layers in a scene (I use the same in my games). In my game I have a layer dedicated to `DrawDebugData`. I make sure the debug layer is higher than the game layer and uses the same camera view.

---
Tags: physics, box2d
---


# Question
Title: Any way to track speed of hand movements below iPhone 3.2?
I have used the pan gesture for tracking the Pixel-Per-Second (or speed of the movement of the hand) but the real trouble is that the PanGesture library doesn't support any deployment target less than 3.2.

So how would I track the speed of hand movements below a deployment target of 3.2?

# Answer
> 1 votes
HI Friends I Got The Perfect Answer From The Following Link

> https://stackoverflow.com/questions/5075291/i-want-to-track-the-speed-of-the-fingure-movement-in-pixel-per-second-is-it-possi/5083653#5083653

---
Tags: iphone, cocoa
---


title: Character Stats and Power

text:
# Question
Title: Character Stats and Power
I'm making an RPG game system and I'm having a hard time deciding on doing detailed or abstract character statistics. These statistics define the character's natural - not learned - abilities. For example:

* Mass Effect: **0** *(None that I can see)*
* X20 *(Xtreme Dungeon Mastery)*: **1** "STAT"
* Diablo: **4** "Strength, Magic, Dexterity, Vitality"
* Pendragon: **5** "SIZ, STR, DEX, CON, APP"
* Dungeons & Dragons (3.x, 4e): **6** "Str, Dex, Con, Wis, Int, Cha"
* Fallout 3: **7** "S.P.E.C.I.A.L."
* RIFTS: **8** "IQ, ME, MA, PS, PP, PE, PB, Spd"
* Warhammer Fantasy Roleplay (1st ed?): **12**-ish "WS, BS, S, T, Ag, Int, WP, Fel, A, Mag, IP, FP"
* HERO (5th ed): **14** "Str, Dex, Con, Body, Int, Ego, Pre, Com, PD, ED, Spd, Rec, END, STUN"

The more stats, the more complex and detailed your character becomes. This comes with a trade-off however, because you usually only have limited resources to describe your character. D&D made this infamous with the whole min/max-ing thing where strong characters were typically not also smart.

But also, a character with a high Str typically also has high Con, Defenses, Hit Points/Health. Without high numbers in all those other stats, they might as well not be strong since they wouldn't hold up well in melee combat. So things like that force trade-offs *within the category* of strength.

So my original (now rejected) idea was to force players into deciding between offensive and defensive stats:

* Might / Body
* Dexterity / Speed
* Wit / Wisdom
* Heart
* Soul

But this left some stat's without "opposites" (or opposites that were easily defined). I'm leaning more towards the following:

* Body (Physical Prowess)
* Mind (Mental Prowess)
* Heart (Social Prowess)
* Soul (Spiritual Prowess)

This will define a character with just 4 numbers. Everything else gets based off of these numbers, which means they're pretty important. There won't, however, be ways of describing characters who are fast, but not strong or smart, but absent minded. Instead of defining the character with these numbers, they'll be detailing their character by buying skills and powers like these:

> **Quickness**
> Add a +2 Bonus to **Body** Rolls when Dodging.

for a character that wants to be faster, or the following for a big, tough character

> **Body Building**
> Add a +2 Bonus to **Body** Rolls when Lifting, Pushing, or Throwing objects.

**What are some pitfalls with a small stat list and a large amount of descriptive powers?** Is this more difficult to port cross-platform (pen&paper, PC) for example? Are there examples of this being done well/poorly?

# Answer
> 14 votes
I'll take a stab at this but first a couple of comments:

> "The more stats, the more complex and detailed your character becomes.

If you mean complex and detailed in the sense that you've got more numbers in flight, sure. If you mean complex in terms of "Hey, my character is a nuanced being with a unique story!", eh. This especially falls short when dealing with min-maxing... if there are dozens of stats, but only one really useful combination, all you've done is put the annoyance of looking up the optimal build into your players' gameplay experience. You can have perfectly detailed characters (detailed in their interactions with the world) without a lot of stats--see *Munchkin*, *S.T.A.L.K.E.R.*, or *System Shock 2* (granted, that last does have a bit of a skill system involved).

> But also, a character with a high Str typically also has high Con, Defenses, Hit Points/Health. Without high numbers in all those other stats, they might as well not be strong since they wouldn't hold up well in hand-to-hand combat. So things like that force trade-offs within the category of strength.

So, the distressing thing here is that you are assuming a playstyle where people are trying to actually have 'optimal' complimentary attribute loadouts. Why should a person not dump Con to get that many more points in Strength, or dump Defense to get more Health? What's wrong with letting people make glass-cannon characters? Obviously, not everyone will do this--but the option shouldn't be removed.

Now, as to your questions:

***What are some pitfalls with a small stat list and a large amount of descriptive powers?***

With a very small stat list you potentially limit what the user can do. The trick here is that, depending on gameplay, this can be avoided.

*Dungeon Siege* only had four stats, if I remember correctly: melee, archery, magic, and max health. These each incremented over time as the player used them, and each had a clear effect on gameplay. This system was a success, because while there were few stats each one completely governed some important aspect of gameplay.

Having secondary powers, or skills as D&D or Fallout would call them, is a good way of combining a limited number of stats into a larger number of game-influencing traits. Moreover, any mistakes the players make in allocating attributes is resolved after some gameplay as skill points are assigned.

The problem you face in those two-tiered systems is that anything that causes stat degradation (attribute damage in D&D terms) needs to be propagated forwards into the skills. For a computer, this isn't a big deal, and players will pick up on "Hey, my lockpicking isn't quite up to par today... lemme fix my agility". For a pen/paper game, this means an extra level of bookkeeping, which is annoying at best and error-prone at worse.

Note that a perk/powerup system is a way of patching up any mechanics or effects not covered by a two-tier system. *Fallout* did this especially well--"Lady Killer" is a perk whose effects are clearly felt, but have absolutely no convenient way of being expressed using the attribute/skill system.

***Is this more difficult to port cross-platform (pen&paper, PC) for example?***

The biggest issue going to pen/paper is that the more numbers you have the slower gameplay goes. Character creation goes from being a quick "roll numbers, start playing" to a "roll numbers/calculate armor class/frob spreadsheet" affair. Remember, computers are *really good* at crunching numbers. Every addition/multiplication you add to a pen/paper game adds delay to the player's actions, whether at creation or during game. This is pretty much unforgivable, and it's why every D&D group I've ever been with uses a strict subset of all of the calculations exposed by the game books.

Which brings us to...

***Are there examples of this being done well/poorly?***

So, as I already mentioned, *Dungeon Siege* is a really good example of a game that gets away with having very few stats.

*Deus Ex* had something on the order of ten skills/stats, each one again directly impacting some aspect of gameplay in a clear and obvious fashion. The player still could make useful decisions about their character's path in the game, but the system was simple enough that doing so was not burdensome. Similarly, the augmentation system as well as in-game items helped improve the skills usage yet further or--perhaps even more importantly--helped mitigate any problems the player would've had encountering a situation for which they didn't quite spec skills for.

*Fallout* does a good job on handling skills, as mentioned above. The big advantage for them was the ability to use a computer, as most of the bookkeeping is hidden from the player unless they look for it, and so minimally impacts the gameplay. This was so much the case, in fact, that they were able to turn the series into a first-person shooter in *Fallout 3*.

On the other end of the spectrum, you have *FATAL*. Look it up; it's got more numbers than you could ever need. Ever. I can't imagine this actually being played in a pen/paper setting, and it is so convoluted a system I can barely imagine implementing it in code (or even worse, as data-driving XML).

*GURPS* and *RIFTS* have similar issues with somewhat computationally-expensive systems. The sourcebooks are interesting to read, and full of detail, but actually running through a session can be a chore.

*Pathfinder*, in my opinion, cleaned up a lot of the issues that D&D 3/3.5 had with their skill system and game mechanics. For example, I no longer have to worry about rolling a rogue who is great at ropes but terrible at acrobatics and climbing, or vice versa. Other than deprecating a large variety of increasingly troublesome sourcebooks, *Pathfinder*'s other big win is combining skills so as to give each a clearer influence on gameplay.

**Conclusions**

* Don't worry about the exact number of stats, as long as they mean something to the player and aid gameplay.
* Don't worry about the exact number of skills, as long as they clearly influence gameplay.
* Do worry about how tedious calculations will become if you intend to make a pen/paper sytem.
* Don't worry about tedious calculations as much if you are writing a system for a computer.
* Two-tiered systems (primary stats, skills/derived stats) have been shown to work well.
* One-tiered systems (skills or stats) have also been shown to work well.
* **Most importantly, do what is best for your players, and after that, what is best for your game.** Anything else is just stroking your ego as a designer.

# Answer
> 5 votes
Pure roleplaying aside, the stats should have some kind of effect in gameplay. Like with interactive fiction, whenever you introduce a new physics element, the whole game changes.

For example, if you add a torch in an interactive fiction game, the players will start to try to burn everything, and you'll have to have some kind of answer to what happens when the player tries to light something obviously flammable, or at least some reason why the player shouldn't do it.

So how does this relate to stats? There's no point in adding a stat if it doesn't have anything to do with the game. Adding charisma, for example, means the game world has to react to, at least, extremely high and extremely low charisma values differently.

# Answer
> 4 votes
Basically what I think you're trying to do is compare two things: a game where your character has a relatively large number of base stats and everything is based off of a direct stat roll (canonical example being D&D) or a game where your character has a smaller number of base stats but a large number of "special abilities" or "feats" that give bonuses to a stat in a specific situation. And from your update, it looks like you are trying to compare these specifically with the design goal of portability between pen-and-paper and computer games.

The design goal is important here, because either method can work in some cases but not others. Overall, for a PC game, the fewer your abilities (in total, including both the base stats and specials), the simpler the coding will be -- consider that every new stat or ability is basically an extra special case that needs to be coded. Since you mentioned Diablo, realize that this game really had a minimal number of stats, only a handful of special abilities granted by equipment, and that's about it... but also realize that as an action-RPG, an overly complicated and detailed system would just make the game much harder to play because the player can't process that much info in real time anyway. On the other hand, as you're noticing, fewer stats offers less self-expression through character creation (which may or may not be important to the system you're designing -- for a total hack-and-slash game, who cares about personality anyway?).

That said, your main concern at this point should be what kind of system makes for good gameplay. Keep in mind that the ability to have a stat for every little thing a character might want to do is "realistic" but not necessarily fun; do you really want your characters spending half an hour making a series of die-rolls to determine the hardness and mass of their latest bowel movement? Decide what it is that is the "core" of the game, what do you want the players to spend most of their time doing, and then design the system and stats to emphasize the core.

# Answer
> 2 votes
To my way of thinking, the main pitfall of a small core stat list is when disparate capabilities wind up tied together in a counter-dramatic way. Maybe the most recurrent example is when *perception* winds up being a function of *intelligence*, making it impossible, or at least against the grain of the system, to play the extremely-brainy-professor-with-his-head-in-the-clouds type, or to represent animals having highly acute senses! The enormous mass of things that get lumped together under a Body stat can be pretty questionable, too, and don't get me started on Wisdom.

Your deviation-from-baseline traits can address this concern in a lot of cases, which is very helpful. The cases where they can't address it are probably a key indicator of where separate underlying stats are needed.

# Answer
> 1 votes
Personally, I'm of the opinion that the fewest needed to represent the kind of experience you want for the players is the appropriate number. I'll always take decreased complexity for the user over increased simulation-accuracy - when that accuracy doesn't provide a measurable improvement in satisfaction.

You'll find a lot of pen and paper RPG designers at forum.rpg.net.

But I'd be careful of making sure the ideas translates medium well.

# Answer
> 1 votes
Well im kind of late to the party here but I once had been working on a system that went a little bit like this, There were 5 main stats, Body, Agility, Mind, Personality and Spirit. Each stat had two connected substats. For example the Body stat had strength and toughness. When characters were created the amount of points put into each stat dictated how many points could be put into each substat. Which in the end gave the characters the ability to put something like 15 points of strength into body and 0 in toughness. Thus making a "Glass Cannon" as someone earlier had mentioned. The Mind stat was also sort of unique in that the two substats were Knowledge and Understanding. Knowledgd being the booksmarts side and Understanding being the ability to well... understand things. So a character with a low Knowledge and a very high Understanding wouldnt know squat but could figure out almost anything... The whole point of this rant is to stress that a system can work very well with what I call a 1.5 tiered system so long as the derived substats are the two most important apsects of the core Stat.

SonofSpock

P.S. Sorry about the grammar and puncuation... I sort of just typed what I was saying out loud and didnt feel like proof reading. I hope it is somewhat helpful.

---
Tags: game-design, game-mechanics, character
---


# Question
Title: Tips for building an AI for a 2D racing game
I have a school project to build an AI for a 2D racing game in which it will compete with several other AIs (**no collision**).

We are given a black and white bitmap image of the racing track, we are allowed to choose basic stats for our car (handling, acceleration, max speed and brakes) after we receive the map. The AI connects to the game's server and gives to it several times a second numbers for the current acceleration and steering. The language I chose is C++, by the way. The questions are:

What is the best strategy or algorithm (since I want to try and win)? I currently have in mind some ideas found on the net and one or two of my own, but I would like before I start to code that my perspective is one of the best. What good books are there on that matter? What sites should I refer to?

# Answer
Set up a basic AI, then set up an API to handle your own car. If you can beat it, you should set up a recording algorithm that can then positively reinforce your AI. This could be a neural network to tweak your AI's actions. Such as gradual braking into a corner etc.

Are you allowed to use external libraries in your project? If so, I suggest you look at FANN. It is a fast neural network library; to save you writing your own. If you need the source code, you could always write it yourself, it can take some time however.
> 2 votes

# Answer
If you can preprocess the map before running the AI, then just calculate the best racing lines through segments of the map.

This post on GameDev.net has a number of suggestions.

The AI Wisdom books have A LOT of articles about racing AI. I'd definitely recommend them, especially the first one which has articles describing how you can represent the map as a data structure within your AI.

Another method I've seen is simple reinforcement learning (Q-learning), which will probably take a good few thousand iterations to get the optimal path. It's described in this paper: http://www.cs.ubc.ca/~zhijin/540report.pdf
> 2 votes

# Answer
Here is an excellent reference for driving AI: Steering Behaviours for Autonomous Characters. Posted here for everyone's reference. There is plenty of information to get you started, but also a lot of information, so don't get too bogged down in the details.
> 1 votes

---
Tags: 2d, c++, ai, racing
---


# Question
Title: Need help starting with a game in Flash/AS3
I am kinda new to flash/AS3. I have written some stuff and now I now the basics of AS. I want to develop a game in which my character moves. exactly like the way Super Mario moves(the background changes and new obstacles come in the way like and animation with which you can interact by climbing and shooting etc.) There is one big thing that I don't understand is that how to make my background moving and introduce new obstacles when my character moves forward. Currently my scene is static which means the background is the same and obstacles are also stationary. Can some point me to a tutorial or give me an answer that solves my confusion? thanks

# Answer
> 1 votes
You want your game-world to consist of several "chunks", so that you can add/remove elements to your scene when necessary. Some games use chunks the size of one screen, so you'll always see 4 of these chunks at the max.

The most flexible way for this kind of game though, is to use a tilemap. You can create those maps by using an existing editor, like Tiled or Ogmo Editor.

For the scrolling, you'll need some sort of "2D camera" that moves around with your character and defines the visible portion of your screen. You can also apply some drag to the camera, so that it follows the character with a delay.

To add the illusion of depth, you can create one or multiple background layers that move with a fraction of the camera speed (parallax scrolling).

All this stuff is already present in game engines like flixel or flashpunk so it might be worthwhile to check these out if you want to start create the game right away. If you want to implement that stuff all by yourself for learning purposes, that's fine too.

# Answer
> 1 votes
You are looking for a basic side scrolling tile engine.. In the case of later Mario games it has multiple layers for the parallax scrolling background (which just makes what is really far away scrolls slower than what is close by). A quick google search should give you quite a few ways to accomplish this task.

In later Mario games, as far as screen scrolling goes, using two bounding boxes is also a good idea. One central box that mario can move around in that does not require the screen to scroll. As soon as mario gets outside that box the game should move slowly to keep him in it.. A secondary box thats a bit larger would be used as a 'mario cant get out of this box' sort of deal. This would be when the game Has to scroll at the speed mario is moving at.

Hope this helps, those were the major things I had to accomplish when I made a mario clone for school all those years ago.

---
Tags: flash, actionscript-3
---


title: Good GUI for OpenGL?

text:
# Question
Title: Good GUI for OpenGL?
I am starting to learn OpenGL with FreeGLUT using the Superbible and the knowledge I have from my elementary graphics to brush up on my skills.

To get more from this experience I want to integrate a GUI to overwrite the one FreeGLUT uses, now my question is this: is this thing possible and what library should I use?

Some characteristics for the library:

* Open source
* Multi-platform (Linux and Windows)
* C/C++

If you have any other recommendations please feel free to post them along with your answers for my problem.

# Answer
I haven't yet tried it myself, but this looks very interesting:

librocket

EDIT: Since you'll need a context to render to, I would recommend either SFML or SDL 1.3.
> 33 votes

# Answer
Crazy Eddie's GUI (CEGUI) is popular, and you can either crib one of the existing renderer backends or write your own targeting whatever OpenGL-backed API you want. It is open source, multi-platform, and C++. However, it values consistency, which is not always a good UI principle for games, which may have dozens of custom controls used in exactly one place.

A recent popular pattern is immediate mode GUI (IMGUI), which is kind of "no GUI library". It has pluses and minuses - it's very straightforward, but can be tricky to optimize, and I've yet to see really good IMGUI models for advanced controls like combo boxes or tree views. Nor have I see a good implementation of an IMGUI windowing system (and I spend some time trying to write one, which I was never happy with) - it is excellent for simple HUD elements however, and simple to do one-off controls.
> 19 votes

# Answer
I recently stumbled across Gwen. It's a GUI library written by the author of Gary's Mod. It's MIT licensed as any good game library should be.
The library has several things going for it.

* Large widget set
Gwen has been under development for a few years and it shows.
* Easy backend renderer customization
This is a big one. The library comes with an OpenGL renderer rebuilt. But making a renderer is simple enough that you'll likely want to build a renderer specific to your game's render system.
* Less filling
Gwen seems to be on the lighter side of game GUI's. No XML, no HTML renderer, just simple C++. Gwen doesn't ship with image loaders either. It expects the renderer backend to handle loading. I like this feature as it keeps the library small and my game's render system already manages textures.
* Skinable
Not the first thing in your milestones but eventually you'll need to customize your GUI to your game.
* C++ skinning
I'm not a web developer and find the html css centric GUIs difficult.
* Input injection
This is big for games. It's always a pain to use GUI systems that want to own the input polling.
* cross-platform
The library strives to be cross platform but they admit that you may find problems on less used platforms.
* actively developed
Further, it's much smaller than CEGUI or MyGUI so hacking on it or submitting patches is much more practical.

However, here are the cons for it:

* There's not a single page of documentation. Not even a website anymore, just the github repo.
* The packaged renderers lack portability, so you'll need to write your own in case you need it.
* ???
> 13 votes

# Answer
Sorry for the late reply, but you may want to take a look at an OpenGL UI framework called GG. GG was developed as part of the FreeOrion project and is included in their SVN repository (and their downloadable SDK). It seems pretty capable. I've included a screenshot below; you can click the image to view the full version.
> 7 votes

# Answer
MyGUI is a rather good solution for both DirectX and OpenGL.
> 5 votes

# Answer
Have a look at AntTweakBar, it's being used by Cinder. There is also a new GUI library developed for Cinder in the works: SimpleGUI.

If you want to go HTML+CSS there is Awesomium (used by Wolfire Games in their Overgrowth game) and a free alternative called Berkelium.
> 4 votes

# Answer
I've been fiddling with both QuickGUI and MyGUI. They're both Ogre GUI libraries that recent dropped the ogre requirement. I don't have too much experience with either yet, but it looks like I'll be sticking with QuickGUI, as it is much smaller and simpler.

I'm not sure if the QuickGUI wiki has been updated yet to point to the newest Ogre-free version. Here is the latest release.

http://www.stormsonggames.com/downloads/QuickGUI\_10\_8.zip

There repo has seen a few cross-platform updates, so you'll be better off using the svn directly.

http://stormsonggames.com/svn/SSE/Gaia2/QuickGUI
http://stormsonggames.com/svn/SSE/Gaia2/QuickGUIOgreDemo
http://stormsonggames.com/svn/SSE/Gaia2/QuickGUIOgrePlatform

Username: Anonymous
Password: QuickGUI

Lastly here is the brief wiki on how to add diferent rendering backends. http://www.ogre3d.org/tikiwiki/QuickGUI+Integration+Tutorial

MyGUI seems to have more features at the cost of getting bloated. And honestly if simplicity isn't a requirement CEGUI blows MyGUI out of the water.
> 3 votes

# Answer
The creators may shoot me for saying so, but I found GLFW to be just awesome at creating cross-platform GUI frameworks. The GLFW development folks go on and on about GLFW does *not* handle GUI. It *does* however do a nice, simple, clean and totally portable job of handling graphics, events and mouse/keyboard/joystick tasks.

The nice thing about GLFW for me is that it is fairly small, requires no system specific code, no GLUT *and* is well maintained. Has been stable for use on OpenGL 4.1 projects so far. Compared to something like SDL I love the tiny overhead and it was easy as pie to write GUI handler classes.

Alternatively, take a look at FLTK. It can be used for all sorts of things and re-purposed very simply. It is used really for application building but is perfectly capable of handling 3D objects and is built on OpenGL. Very small, well supported and while I don't see many people making custom interfaces on the game design level, there are some that seem to work great.
> 3 votes

# Answer
I would recommend QT, as it's cross platform, C++ and you can get an Open Source version of it with the LGPL license. It's also easy to use and have a lot of pre-made components you can use.
> 2 votes

---
Tags: opengl, c++, gui, cross-platform
---


title: Open Source AI Bot interfaces

text:
# Question
Title: Open Source AI Bot interfaces
What are some open source AI Bot interfaces? Similar to **Pogamut 3 GameBots2004** for custom Unreal Tournament bots or **Brood Wars API** for Starcraft bots etc.

If you could please post one AI bot interface per answer (make sure to provide a link) and give a brief summary as to the content of the blog posts.

Please include what type of bot interface structure it is, client/server, server/server, etc

e.g. **BWAPI** is client/server which emulates a real player

# Answer
**Planet Wars / Galcon Clone AI**

Ran as a **Google AI Challenge**

> Planet Wars is a strategy game set in outer space. The objective is to take over all the planets on the map, or altenatively eliminate all of your opponents ships.
>
> Players start with 1-3 home planets and send off ships to conquer other planets around them. The numbers on each planet indicate how many ships it will take to conquer them. The numbers on a player's own planet indicate the amount of ships that their planet holds. Each planet a player owns produces ships for that player with more ships at a faster rate produced depending on the planet's size. Players can select what percentage of the ships to send from a planet and players can redirect ships in midair. The aim of the game is to defeat the other opponent(s).

Implemented as a **Server/Server** architecture you can implement your AI bot in C++/Java/Python/C#/Go/etc etc.
> 4 votes

# Answer
Brood Wars API is a dll injection type interface which natively is Server/Server design but also has extensions to support Client/Server architectures for additional language support.

Extensions support Java, Python, C#, Php, etc.

> The Brood War Application Programming Interface (BWAPI) is a free and open source C++ framework for creating AI modules for Starcraft: Broodwar. Using BWAPI, programmers can retrieve information on players and individual units in Starcraft as well as issue a wide variety of commands to units, opening the doors for custom AIs with new micro and macro algorithms.
> 3 votes

# Answer
**Pogamut 3 GameBots2004**

Extension of the original GameBots work done by USC which supports UT2004/ UDK/ and Defcon. Allows an external program to control bots in game in a **Client/Server** fashion as if they were a human player.

> External control mechanisms can be connected to many of these games using the scripting languages, thereby providing a tool to control the in-game characters from the outside. Pogamut utilizes UnrealScript (UT2004 scripting language) in this way and also NetBeans Java platform to provide an out-of-the box development environment for AI of virtual characters inhabiting **UT2004**, **Unreal Development Kit (UDK)** and **DEFCON** worlds.
> 1 votes

# Answer
The **Mario AI** Allows you to implement an AI Agent to control Mario. Different levels of map details are available to allow a simple implementation or implementations with near engine level map details. The API is a server/server type implementation using Java.

Additionally a Level Generation API is provided for creating user generated levels.
> 1 votes

---
Tags: ai, bot
---


# Question
Title: Marketing games for the android - what are the best sites to contact for reviews/advertising?
WE are in final dev stages of our latest game and want to release it for the android market. What are the best sites to contact for reviews/advertising that specifically target the android users???

# Answer
> 1 votes
Triplepoint PR helped Dave Whatley sell a few hundred thousand iOS copies of geoDefense. Chris Pruett, creator of Replica Island and Google employee talked about the importance of PR somewhere on his blog and also in this video. He has all kinds of great graphs and stuff too.

Also, TalkAndroid and AndroidCentral seem to always be happy to do reviews of apps. I personally follow them both on Twitter.

---
Tags: android
---


title: How to implement an experience system?

text:
# Question
Title: How to implement an experience system?
I'm currently writing a small game that is based on earning experience when killing enemies. As usual, each level requires more experience gain than the level before, and on higher levels, killing enemies awards more experience.

But I have a problem balancing this system. Are there any prebuilt algorithms that help to calculate how the experience curve required for each level should look like? And how much experience an average enemy on a specific level should provide?

# Answer
You would want some kind of exponential curve, probably something like:

```
base_xp * (level_to_get ^ factor)

```

base\_xp is a constant that decides how much xp you need to go up a level.
level\_to\_get is the level you are aiming for; at level 1, this will be level 2.
factor is another constant that decides how much of an increase of xp you need for each level.

Having a base\_xp of 200 and a factor of, say, 2 gives something like this:

Whereas a base\_xp of 50 and a factor of 2.6 gives:

The second has a much lower starting xp rate, but you need more xp very quickly.

As for monster xp, this is something you want to test. Try out various values. You want something that is not too high (you'll quickly become overpowered) yet not too low (players don't want to grind). Think about how many 'standard' enemies you would want the player to kill for level 10-\>11, for example.
> 14 votes

# Answer
There is no right answer for the question of how much experience an enemy should give, or how steep the experience curve should be. It may help to think about the playing time required to level up for each level and then base the experience required per level, and average experience rewarded per enemy on this.

This article is a detailed breakdown of levelling mathematics in Lineage II. http://web.archive.org/web/20100303164314/http://www.tstonramp.com/~mykel/lineage/
> 6 votes

---
Tags: game-design
---


# Question
Title: What is an active Indie iOS development community?
I've just gotten into iOS development, and would love to develop some games, but need inspiration/support, all that stuff a great community gives you.

Does anyone know of a community to get involved with?

# Answer
> 1 votes
I'd say check out the cocos2d forums. They are really active and supportive. There is also iDevGames.

# Answer
> 0 votes
It is not a specifically iOS forum, but try Gamedev.net. They are friendly and \[very\] active. (Unless you act like a moron)

---
Tags: ios
---


title: How to Create a Grid for a 2D Game?

text:
# Question
Title: How to Create a Grid for a 2D Game?
So I'm currently writing the engine for my videogame. I've almost integrated Tiled (I think) so I should have a map-creator here soon.

My question is, how do I actually make the grid? I'm really confused here. If I create a large map with, say, 20x20 grids the size of 32x32 (screen size 640x640), then what do I do with it?

Let's say I have the code for creating a window, and then place a player sprite that I can move with input, that's fine. If I use one map that's as big as the screen, then every pixel on the map is also a pixel on the game screen. The mapping is exact.

Now what happens if I have a 2000x2000 map, for example? My character would have to keep moving and move the map around (or rather the camera focused on the player moves). Then I can no longer say that the screen maps exactly to the pixel position of the map.

I tried making a Grid class that maps out the screen area to 32x32 tiles, but I'm not sure if that makes any sense. Once the map moves each tile would have to update its information, or something. I'm just really confused here.

How do I actually make the tiles and a grid and map them to the data I get from tiled, or that I make myself? Are there any good examples of source code that I could look at?

# Answer
> 4 votes
I found this very helpful: http://www.sdltutorials.com/sdl-maps/

# Answer
> 2 votes
I'm not sure what language you're doing this in but this is how I generally do it in XNA:

When your character has moved around and you want to move the camera then you change a Vector2 called something like `_screenPos` or something, which is a variable holding the current position of the screen.

Then, whenever you want to check like a mouse click on a tile or whatever it is you want it to check pixels for then you would add `_screenPos` to your current mouse position to get the absolute position over the tiles and find which tile you're clicking in the grid.

---
Tags: 2d, maps, tiles
---


# Question
Title: Pathfinding with MicroPather : costs calculations with sectors and portals
I'm considering using micropather to help me with pathfinding. I'm not using a discrete map : I'm working in 2d with sectors and portales. However, I'm just wondering what is the best way to compute costs with this library in this context.

Just to be more clear about geometrical shapes I'm using : sectors are basically convex polygons, and portals are segments that lies on sector's edge.

**Micropather** exposes a pure virtual *Graph* class that you must inherate and overrides 3 functions. I understand how pathfinding works, so there's no problem in overriding those functions. Right now, my implementation give me results, i.e I'm able to find a path in my map, but I'm not sure I'm using an optimal solution.

For the **AdjacentCost** method : I just take the distance between sector's centers as the cost. I think a better solution should be to use the portal between the two sectors, compute its center, and then the cost should be : **distance***( sector A center, portal center )* \+ **distance** *( sector B center, portal center )*. I'm pretty sure the approximation I'm using with just sector's center is enough for most cases, but maybe with thin and long sectors that are perpendicular, this approximation could mislead the A\* algorithm.

For the **LeastCostEstimate** method : I just take the midpoint of the two sectors.

So, as you understand, I'm always working with sectors' centers, and it's working fine. And I'm pretty sure there's a better way to work.

Any suggestions or feedbacks? Thanks in advance!

# Answer
I've been looking at micropather as well. If you are happy with the results, stick with it. If not...

Since you have control over the Graph, you can add arbitrary nodes. Thus, rather than going through the calculation to add distance from sector center to portal center, just stick a node in the middle of your sectors, connected to each portal for that sector. Micropather will take the distance from the portal to the middle of the sector in it's path finding algorithm.

You could also go crazy and add edges between the portals bounding a sector. (If I understand correctly, a sector is like a room, and portals are the doors out of the rooms). Then the path finding would be able to "cut corners" if it didn't need to go to the center of the room.

Should be easy to try these out.

For example, if your sectors are square rooms with doors on all four sides, your graph might look like this:

```
N - N - N
|   |   |
N - N - N

```

Where N are nodes/sectors, and the lines represent edges. There is no explicit node for portals.

If you include portals/doors in the graph you get for one room (with P for portal):

```
     P
     |
P -  N  - P
     |
     P

```

If you put a bunch of these together:

```
     P       P
     | \   / |
P -  N - P - N  - P
     |  /  \ |
     P       P

```

So you can go directly from the north door to the east door in the left hand room.
> 3 votes

---
Tags: c++, ai, path-finding
---


# Question
Title: How can I approximate walking physics via simpler sliding physics?
I am modeling walking insects. I implement them as cuboids and use forces (including friction and drag), to control motion. However, the movement characteristics of this 'sliding box' physics don't match those due to a legged creature.

For example, legged creatures near-instantly accelerate to their top speed; whereas applying a force to a box takes time to accelerate it.

The applied force can be increased along with the counteracting drag, giving much quicker acceleration (via force) to a max speed (via drag). However, this also means the force that creatures can exert when pushing on other objects is increased.

Does anyone know of any techniques using a physics engine to cheaply model walking creatures?

# Answer
**High movement impulse, with high drag, will work perfectly.** For collisions, you **don't** use the force that is being applied for movement in the collision calculation, you use the resulting speed, mass, elasticity, etc.
> 4 votes

---
Tags: physics
---


title: Moving around/avoiding obstacles

text:
# Question
Title: Moving around/avoiding obstacles
I would like to write a "game", where you can place an obstacle (red), and then the black dot tries to avoid it, and get to the green target.
I'm using a very easy way to avoid it, if the black dot is close to the red, it changes its direction, and moves for a while, then it moves forward to the green point.

How could I create a "smooth" path for the computer controlled "player"?
***Edit:*** Not the smoothness is the main point, but to avoid the red blocking "wall" and not to crash into it and *then* avoid it.

How could I implement some path finding algorithm if I just have basically 3 points?
(And what would it make the things much more complicated, if you could place multiple obstacles?)

# Answer
A very common and general approach is to divide your world space into grids and use algorithms like A\*.

This link helped me get started with understanding and implementing the A\* algorithm.

A simpler thought that comes to my mind is once you have the world into grid-cells. Always, have the black dot follow Manhattan distance to the green dot. Then, you can assign weights to each cell. Obstacles can have a high weight on the grid-cell and free-to-move can have (let's say) 0 weight. As you move along the Manhattan distance, for each move, check to see if the weight of the next cell is not higher than the weight of the current cell. If it is higher, check the adjacent cell's weight and then move on.

Hope this helps
> 9 votes

# Answer
Steering behaviors are designed for pretty much this exact problem set.

http://www.red3d.com/cwr/steer/

Basically you would combine the obstacle avoidance behavior with probably the seek or pursue behavior. That page has a bunch of java animations of the different behaviors and what they do. There are several open source implementations of steering behaviors. Here's one.
> 19 votes

# Answer
An easy thing to try is to have an invisible dot that goes ahead of the black dot and executes the path in your first image. The black dot then follows the invisible dot at a small distance behind.
I've seen this work with good results but of course might not suite your needs.
> 2 votes

---
Tags: ai, path-finding
---


title: Video Encoding library for C++ game

text:
# Question
Title: Video Encoding library for C++ game
I'm looking for a video encoding library in C++ that I can use to record game footage.

It can not be an external application like Fraps, it must be a library.

Ideally the encoding can be done in real time without affecting game performance too much, although this is not a must have requirement.

Another preference is that the video file being saved from the game is already compressed and ready to be used by most video players without any further processing. I realize that this might not be possible especially for real time encoding, so I would accept a trade off of having to process the file later for better compression and/or better file format.

I'd like to hear about your experience integrating the library into a game if possible and any interesting trade offs you had to make.

Some libraries support more that one file format or codec, so advice on the file format would also be appreciated.

# Answer
> 5 votes
It depends on the use-case.

For recording games, I've seen that a general 'game record' mode where the game records the user input on a timeline so as to be able to recreate the game at any point to be really useful, and you can generate the video afterwards, or pass around these recorded games and others can watch using the game engine rather than a video player.

Or maybe you mean in-game capture that immediately converts to a video live and stores only the video. Assuming so:

The classic library is ffmpeg's libavcodec. You can compile this so it as to avoid GPL codecs and such.

Codecs like H.264 (libx264) are GPL - if that's ok with you, then fast presets and baseline profiles will work better than most. H.263 or even MJPEG otherwise.

But I normally stream y4m (its trivial to generate this format yourself without using the GPL lib) to an ffmpeg exe using my popen3. Why don't you want an external exe? Its a tidy way of allowing it to run on separate cores and coping with the fact that it may take longer to compress your video than it the game time it represents.

I have also concatentated to MJPEG using libjpeg internally and post-converted with FFMPEG.

And finally I have made live FLV streams so games could be watched live. This is surprisingly easy.

---
Tags: c++, video
---


# Question
Title: How to get quality sprite sheet generation with rotations
I'm working on a game that uses sprite sheets with rotation for animations. While the effect is pretty good, the quality of the rotations is somewhat lacking. I exported a flash animation to png sequence and then used a C# app to do matrix based rotations (System.Drawing.Drawing2D.Matrix).

Unfortunately, there are several places where the image gets clipped.

What would you suggest for a way to get high quality rotations from either flash or the exported PNGs? A circle should fit within the same image boundaries. I don't mind a new program that I must write or an existing program I must download/buy.

# Answer
> 3 votes
**Write some Actionscript to generate the spritesheets for you, and either use the BitmapData in flash, or use as3corelib to export the pngs for you.**

If your originals are vector, it is probably best for flash to take care of the rendering at different rotations/scales, as rotating a png is destructive, and lowers the quality.

If you are doing a game in ActionScript, there is no need to export a PNG for the graphics, you can make sprite sheets in memory from regular Timeline Animations.

If you need the PNGs for a non ActionScript game, you could make the sprite sheets in ActionScript from timeline animations and export the BitmapData with this library that can export different formats with the help of a webserver with PHP.

http://github.com/mikechambers/as3corelib

Edit: I tried to explain it, but I realized my explaination was broken.

Instead of trying to poorly retype it. This is a better resource. Although I don't know why he draws the clips to the stage with EnterFrame for each rotation, you can just loop through the clip without ever having to make it a display child.

http://www.8bitrocket.com/2008/1/20/Tutorial-Using-Flash-CS3-and-Actionscript-3-to-create-Atari-7800-Asteroids-Part-1/

# Answer
> 4 votes
You need a bigger image, or a (slightly) smaller ball.

It is a known issue that raster image algorithms tend to create ugly aliases on round(ish) objects, if they touch the 'edges'.

The easiest fix is adding a small 'background space' to all your balls. So for each of your generated tiles, instead of this:

```
+-----+
|.000.|
|00000|
|00000|
|00000|
|.000.|
+-----+

```

You add some blank space, like so:

```
+-------+
|.......|
|..000..|
|.00000.|
|.00000.|
|.00000.|
|..000..|
|.......|
+-------+

```

For such small images, a 1-pixel border should be enough. Bigger ones sometimes require 2 or 3 pixels.

# Answer
> 2 votes
Whenever I need to do large batch image transformations, I immediately turn to the GIMP. You can very easily write a Scheme program that uses the (thorougly documented, easily searchable) GIMP data API to manipulate images in any way you can name, and it's possible to do it all from the command line, as well. Over time I've developed a host of scripts that have made my life as a developer *much* easier, and gotten good experience working with Scheme in the process. If you're not comfortable working in Scheme, there are language bindings for Perl as well. You can use the Script-Fu Procedure Browser that comes with the GIMP to search the documentation.

Some procedures of interest to get you started:

* `gimp-image-new`
* `gimp-image-resize`
* `gimp-image-get-layers`
* `gimp-drawable-transform-rotate`
* `gimp-image-merge-visible-layers`
* `gimp-image-set-active-layer`

# Answer
> 1 votes
You will always get some clipping if you restrict the rotated images to the same dimensions as the original image. Even your circular image is ultimately made up of squares, and when you rotate a square, the corners will move outside the original boundaries.

To accommodate a 10 pixel square in all possible rotations you need at least 15 pixels to accommodate the 45° rotation, ie. the length of the diagonal. You can calculate this using Pythagoras' theorem: for squares you need about 42% extra space in both directions, for example.

# Answer
> 1 votes
Write a Script in Schema language in Gimp.That will be easy to handle this.

# Answer
> 0 votes
http://zwoptexapp.com/ might do what you want (It's a Mac OS X application)

---
Tags: flash, sprites, spritesheet, image, rotation
---


# Question
Title: How do I move from mainstream to indie development?
I'm a game programmer for a AAA-level developer and publisher—which I know falls into the 'nice problem to have' category. However, I'm becoming disenchanted with the direction of both the company and the AAA-portion of the industry as a whole.

I want to do something fundamentally different.

It seems the market has never been better for smaller-scale projects, and I'd love to jump into that (and I've done small demos for Android and have started digging into iOS), but I obviously can't put anything out while I'm working for the company. I'm concerned that I shouldn't even do substantial development in my spare time on anything I'd eventually like to release on my own.

At the same time, I'm leery of leaving my job, for hopefully-obvious reasons, especially without a specific plan in place.

Has anyone out there got experience with 'going indie' out of a mainstream job? Do you have specific suggestions as to a best approach and what to specifically think about or be careful of?

# Answer
I recently quit a triple-A development house out of frustration; but, instead of going indie, I found a smaller developer that does a broader array of projects. So, instead of working on one FPS for three years, they do several facebook/social/casual games a year.

While that sounds like "more of the same problem", it's actually turned out in my favor. I just managed to get one of my projects greenlit by the executive team. Meaning, we're building something I'm totally in love with!

Now, that's not really answering your question; but, it could prove another avenue for thought. Finding a good developer to work for is just like trying to discover your life long partner. You have to find a company you love... or found one.

As for going the indie route:

1. Plan for it -- you're going to need to have money to live off while you're not working; or, you're going to have to do freelance work. Build those funds and relationships now. Set a date and execute it. Possibly even tell your company that you're unhappy and looking to go indie, maybe you can pitch working two or three days a week to them.
2. Get yourself up and running -- I know Jari said to get a team; but, honestly? If you can go it yourself, you're far more likely to finish the project. Pull in as few people as you can and, preferably, find individuals that are also fully invested (not working at a large developer most of the time).
3. Plan your project -- don't just jump ship and say, "Great! Now I can build something!" You've done Android development and iOS development. Awesome. You know what you're going to have to code. What's your spec? What's your deadline? What product do you want to build? What platforms are you deploying to? Have a plan for success. Do you want to pitch a demo of your game to a publisher? Do you want to compete in an indie competition?

You have a lot of soul searching to do; but, the end result could be spectacular. The way I always looked at it was this: the worst case is that you've just boosted your resume.

Good luck!
> 13 votes

# Answer
I'm not a lawyer and all those standard disclaimers.

First, talk to your boss. Maybe you can work on iphone apps and release them. You may have to ask for permission for everything you do put out, but it may still be possible. Self-development is a great selling point; you're investing your own free time into becoming a better employee.

Eventually, if you really do want to go indie, just.. quit. Before you do, however, there's a few things you can (and in some cases, should) do.

1. Save money. After you quit, your savings is what you'll be living on.
2. Seek partnerships. Other like-minded people may be interested in starting a small studio for you. Even if you're not going to pay salaries for them, knowing people you can trust to do projects (like outsourced art, music, whatever) is a great asset. If you manage to be successful, you may consider hiring them; or maybe they'll hire you. =)
3. Investigate possibilities for angel investors. Be warned though, taking other people's money always means giving up something, like your freedom. Savings help here.
4. Possibly, work on something without releasing it. This is where we're far into the I'm-not-a-lawyer category. This depends on how aggressive your employer is and how cutthroat your contract is.

You may also want to check out this seminar by a couple friends of mine. ("Indie Startup for Dummies")
> 3 votes

---
Tags: career, business
---


# Question
Title: Can I change the order of these OpenGL / Win32 calls?
I've been adapting the NeHe OpenGL/Win32 code to be more object-oriented and I don't like the way some of the calls are structured.

The example has the following pseudo-structure:

> Register window class
> **Change display settings with a DEVMODE**
> Adjust window rect
> Create window
> Get DC
> **Find closest matching pixel format**
> **Set the pixel format to closest match**
> **Create rendering context**
> **Make that context current**
> Show the window
> Set it to foreground
> Set it to having focus
> **Resize the GL scene**
> **Init GL**

The points in **bold** are what I want to move into a rendering class (the rest are what I see being pure Win32 calls) but I'm not sure if I can call them *after* the Win32 calls.
Essentially what I'm aiming for is to encapsulate the Win32 calls into a `Platform::Initiate()` type method and the rest into a sort of `Renderer::Initiate()` method.

So my question essentially boils down to: **"Would OpenGL allow these methods to be called in this order?"**

> Register window class
> Adjust window rect
> Create window
> Get DC
> Show the window
> Set it to foreground
> Set it to having focus
>
> **Change display settings with a DEVMODE**
> **Find closest matching pixel format**
> **Set the pixel format to closest match**
> **Create rendering context**
> **Make that context current**
> **Resize the GL scene**
> **Init GL**

(obviously passing through the appropriate window handles and device contexts)

Thanks in advance.

# Answer
Off I don't see any reason why you couldn't, unless some of the operations depend on values produced by earlier operations. An easy way to "try it and see" is to simply re-order the calls where there are now, without actually implementing any of the extra abstraction layers you want. That should let you know if anything is trivially wrong that I'm forgetting.

If there is a more subtle problem, it is likely to be in an interaction between your new proposed setup and your other code that you have not shown, so we couldn't really diagnose it reliably now anyhow. You can always debug later -- don't be afraid of making the wrong decision now. That's why we refactor.

I wouldn't necessarily show the window before it is prepared for rendering, though.

You also might consider not separating the Win32 and GL calls, but just encapsulating them together. They are quite tightly tied together on a practical level -- especially if you are not *currently* developing your code against multiple OSs, it can neatly tie up your higher-level graphics API.
> 2 votes

---
Tags: opengl, windows
---


# Question
Title: Is C++ being replaced by C# in industry games?
In industry games I mean like Quake, CoD etc.

# Answer
> 53 votes
In a sense, C++ is really being replaced - not only by C#, but by a slew of other languages. But if you ask, is it going to by replaced *completely* \- then the answer is definitely **no**.

That's because C++ is traditionally used in two capacities. First, to create the game *engine*: the low-level components that load resources, push polygons to screen and crunch numbers in physics simulations. Second, to code the game *logic*: the actual rules that make gameplay.

This second capacity does not require C++'s strong points (such as complete control over low-level details), but suffers from its weaknesses (such as bug-prone hand-coded memory management). And in this second capacity C++ is being replaced by different scripting languages. A lot of developers use Lua; some use Python. But if a CLI platform is available, in form of either .NET or Mono, it presents a great scripting host candidate. These platforms are quite fast, reliable, offer a widely known language (C#) and a comprehensive base class library. Let's not forget tools: MS Visual studio and SharpDevelop/MonoDevelop might not be the very best IDEs in the world, but they're quite good.

That said, the game *engine* is not going to be written in C# (or Lua, or Python for that matter). Why? Because they're just not fast enough.

Contrary to many popular beliefs, *the single biggest performance hit today is due to memory latency*. This means that accessing memory is serious business. And managed languages don't allow user to control memory access - that's precisely why they're "managed" in the first place. So, no managed language will allow to write a really fast game engine. Actually, all big "C#" engines I can think of - XNA, MOGRE, Unity - are based on *native* C++ code; but allow to write game logic in C#.

**To sum it up**: C# is going to be used in place of C++ or other languages. But it will never replace C++, at least until someone invents latency-free, instant-access memory.

# Answer
> 6 votes
Language choice heavily depends on platform. Right now it seems really unlikely that anything but a Microsoft platform would actually require .NET as an implementation.

Conventional wisdom would say that a small platform would need to be close to the metal to be performant, but on the other hand, managed platforms are *safer*. That's probably the reason Windows Phone 7 forces you to use .NET.

It would certainly be interesting if the a new Xbox required a managed platform. If a phone's hardware can handle it (and it does), I could certainly see them using it on a full sized console. It would stir up the console ecosystem quite a bit as it would be harder to write cross-platform games without writing all your game code in a scripting language. If that's the case, then C# wouldn't *replace* C++, but it would go hand-in-hand.

Right now you *could* use Mono as a scripting back end (similar to what Unity does), but I would imagine that most engine makers would either want to roll their own, or use something more compact like Lua or Python than C#.

Either way, it's all about the right tool for the right job. You really should learn both languages anyway, since C# makes it easier to do certain things (tools development, server development probably, etc), and you can't use anything but C++ in some cases.

# Answer
> 3 votes
It's not likely. C++ has the benefit of being low level so that developers can actually tweak the tiniest detail to gain the best performance possible.

With C# and .NET you have garbage collection which is very useful, but when working with platforms with limited memory and resouces (portable consoles and to some extent home consoles) you need to have as much control over memory as possible to make the best use of the resources. Allowing managed languages to allocate and free up memory for you would most likely cause you lots of problems.

The speed is also an issue (although probably less so). Over time, I'm sure that managed languages could be made to perform comparably to C++ compilers.

Overall, in my experience anyway, game developers tend to be control freaks when it comes to memory, CPU times and resources (to squeeze out as much performance as they can), which is why C/C++ are the mainly used languages.

# Answer
> 2 votes
AFAIK .NET GC still suffers from stop the world style algorithm. While this can be appropriate for a wide variety of applications -- it's unacceptable for real-time apps like games.

In fact, it is very difficult to use managed languages effectively for real-time programs until we have some breakthroughs in GC.

# Answer
> 1 votes
No. Depending on .NET would imply massive re-writes for platforms with no available Framework, like the PS3, and the performance disadvantages may be perfectly acceptable on the PC or for Live Arcade games, but larger games are going to need every scrap of performance from their consoles to run quickly enough. More than that, there are huge existing code-bases in C++ that nobody could afford to upgrade, even if they wanted to. C++ is in the game industry and it's going to stay there for a long time.

# Answer
> 0 votes
At the times where computer power where scarce, everything needed to be programmed in C or C++, simply because garbage collected languages take memory control away from the programmer, and thus, performance can drop.

Nowadays, computers are faster, but as Knuth says and to put it short, optimization can be evil:

* it's obvious that low level core functionalities need to be optimized, because computing 3D geometry, physics, collisions, lighting, can quickly bloat the best processor available. You can easily tell that rising visual quality on a machine almost always significantly kills performance.
* Now, there are other functionalities, such as game states, AI, sound, input, network, which are still important in a game, but which will hardly never take as much computer resource. Those functionalities, most of the time, have not to be optimized. That's the goal of scripting language and garbage collected languages: you don't have to think about your memory coherence and your application organization, because the code you will write with these languages, if you are not coding low level stuff, will never be a bottleneck.

Example with 2 cases

* Ship 500kg of furniture with a truck.
* Ship 30 tons of material with a boat.

both are at 500 kms distance.

In both cases does it matter to make the loading/unloading process faster to make the whole transport time smaller, knowing you CANT make the boat nor the truck move faster ?

Answer is: it mattered with the truck, but not with the boat anymore, because you already did a lot by moving the stock with the boat.

I don't know if you understand this metaphor, but in a way, it can make you imagine the mathematical problem, which is more important than understanding the answer.

Scripting languages allows to make games faster if you already have an engine programmed in C/C++: the 3D engine solves the low-level problems, now you have to make the game with your scripts.

But remember: you absolutely never will be able to replace low level compiled language, EVER. Statically typed, compiled languages are the core of performance and you CAN'T rule them out, would it be a kernel, a 3D engine or a graphic card driver.

But of course, if your game is graphically simple and doesn't require a lot of vector computation, you can focus on the gameplay and forget about optimisation, because in this case you will never have to deal with optimisation since your machine are really fast for that

Except if you plan to port ir on the DS. But I'll stop there.

# Answer
> 0 votes
Look, I know this is a rant but i am not just splitting hairs. I feel most programmers don't really put this together. A language itself has nothing to do with run speed/performance. It's the compiler/framework. You could better argue gcc against cl (microsoft compiler pre 2010) or msbuild (current c++ compiler for 2010). Every release these compilers get better so you also have to compare them to previous versions of themselves. I am very impressed with .net and it does perform well but even if it was slightly better performing i don't see it taking over, one reason: portability.

AAA games want to be on Windows, Linux, Mac, XBox, PS3, Nintendo, etc.

---
Tags: c++, c#
---


title: Building (simple) stellar systems

text:
# Question
Title: Building (simple) stellar systems
I'm currently looking at how to easily simulate some stellar systems (meaning some central stars and then some planets with maybe satellites), in order to allow later some space based strategy game (hence with space ships moving around). This should all be based around time (so the state of each system differs through time)

I'm quite struggling with the math behind this topic, like for example:
\- ellipse related math,
\- creating the path from planet A to B having time in mind (respective positions will change over time)...

Do you know of any resources for that ? I wouldn't mind even buying books about it...

side note: how to display all this stuff isn't a matter at this point in time, I'll simple plans for that (basically sticking to 2D and a "high level view" with no space ships/planets details, just markers)

# Answer
I am not a math brain, but my S.F. reading and Google lead me to this page on orbital mechanics. It starts with explanations I can follow and follows it up with equations I can't. The type of motion I was looking for is called a Hohmann Transfer Orbit, which is one that uses the least fuel.
> 5 votes

# Answer
There is another issue which you may want to give some thought to as well besides the physics of simulating a stellar system.

Floating point precision will likely be an issue depending on how much of a "simulation" it is. When you think about it, the actual distances between a planet relative to the distance of an object orbiting around one of those planets is huge. Trying to simulate both a distant planet and an orbiting object in the same "environment" would likely break under the limitations of floating point accuracy.

http://www.floatingorigin.com/mirror/oneil\_01.htm
> 2 votes

# Answer
As Jason mentions above, take a look at this web page -- it goes pretty deeply into orbital mechanics...

http://www.braeunig.us/space/orbmech.htm

I am wondering if you might be able to work out a simple rule based system for navigation. Simply "launch" the vehicle on some vector, then on each pass of your event loop, have it look at it's current trajectory in relationship to the destination, and apply a correction.

When it gets tricky is where you have to take into account what you might call the motivations of the spaceship. Does it have a finite fuel supply? Is it better to get there faster, or to use less fuel? Is the velocity you approach the target important? I.e., can it just come flying in at a high speed or does it need to slow down to enter orbit?
> 1 votes

# Answer
Do you even need to solve this? Hohmann transfer orbits are *SLOW*--1/2 the orbital period of the outer body and they also require a proper alignment of the planets to work.

Do you really want to limit players to such motions? And if you're doing that you are obviously using some sort of jump drive to get to the other star systems--why can't you use that within a system?

If you have any sort of continuous thrust system of non-trivial power you don't need to do such fancy orbital calculations. Instead:

1) Figure the velocity change needed between the bodies. This is both orbital velocity and the energy needed to move to the new orbit.

2) Figure the distance between A and B at their current positions.

3) Adjust this for the burn needed in part #1. If you're going outward figure an extra burn at the start for the velocity change, if you're going in the extra burn is at the end. Subtract this distance from the distance between the planets, add the time needed to the total time.

4) Take the remaining distance, divide in half and figure how long it will take your rocket to do this. Double the result.

5) Add the times involved, figure where the target planet will be after that burn is over. If it's moved too much use the new location of the planet as your target, redo the calculations. This will rapidly converge.

Yes, this isn't up to NASA-spec but it's plenty close enough for game use.
> 1 votes

# Answer
> creating the path from planet A to B having time in mind (respective positions will change over time)

Lookup linear interpolation. It lets you update a position from point A to B along a straight line using a function of time.

This link might help.
> -1 votes

---
Tags: mathematics, game-mechanics
---


# Question
Title: What are the fundamentals of game development?
I completely do not understand how a video game can be coded.

I'm a beginner programmer and only have experience writing console applications that do math and what not. I do not understand how these logical processes can make images move on the screen (video games). Obviously if I jumped into a game development book or something like that I would understand but I am currently still getting a grasp of the fundamentals of programming in general. Could anyone give a simple explanation, coding wise, on the jump between making a computer do simple math to making a computer produce amazing graphical programs such as video games? Maybe there are some introductory videos someone can point me to?

# Answer
Assuming you're an absolute beginner in programming, and in order to base my example on something you might know, while writing a console application which has a menu where you want the user to choose among the available option, what will you do first?

If you thought about creating your menu, you got a point, but what if after the user pressed a key which is not part of the available option,

1. will your application exit, or
2. shall it continue until the user presses the "Exit" key?

My bet would be #2, the application shall continue until the user expressly press the key to exit from the console application.

A game is somehow the like! When do you want the game to exit? When the user chooses to, right? Hence, the action or the game menu has to last until the user wishes to exit. Then, you will have to create a loop that tells the program to continue until this very key to exit has been pressed.

You've just been introduced to the Game Loop. A game is just another program that runs until it is expressly exited by the user.

While in the game loop, when you're playing the game, the moves are images drawn on the screen at specific coordinates. When the user/player presses a directional key such as `[Left]`, then you make your image refresh its coordinates while decrementing its X coordinate so that you give the impression for a motion toward the left direction. You got to get these inputs in order to get what action the player wants his character/ship to do next. Then, the Game Loop continues to loop until you can get another desired action from the player, until the game is exited.

Well, I'm afraid this answer begins to be fairly long enough, so allow me to point you to two other questions that might be of interest to you, I hope.

1. Where to start writing games, any tutorials or the like?
2. Moving my sprite in XNA using classes.

This third link is not about how to begin to write games, but about how to make a sprite move on the screen. Since you also asked about how to make the graphics move on screen, I thought this could interest you.

I hope this helps! =)
> 14 votes

# Answer
While you're making console applications, you most likely use functions called print() or read() or write(). Instead of these, graphical games use other functions which can be as low level as set\_pixel() to set the color of an individual pixel on the screen, to entire frameworks that allow you to draw three-dimensional models with lots of effects.

But the main idea is the same as for a simple math console application. You get input from the user, act according to it to modify some variables, and then print (or draw) some output. Games and other interactive programs perform 30, 60 or more of these input-calculation-output cycles happen every second. Of course, every part can be as complex as you want, but it all usually comes down to input-calculation-output. So don't worry, you're on the right path.

As for recommendations, I'd say you keep programming, as much as you can. If you're interested in focusing on game programming, and you only know console programming, try and make a small text based adventure or RPG. That way you'll practice a lot on how to manage your variables, use random numbers and organize your code.

After you get some experience with that, take on to the basics of a graphics library. If you're doing procedural programming, I'd recommend OpenGL, while if you're doing object oriented programming, I'd recommend XNA.

However, don't take too many things at once. It's very easy to get disappointed over learning a complicated tool, while you're learning how to manage a source tree, while you're learning how to iterate over an array, while you're learning how to get input and sound, all while you're designing your game.

There's a long way ahead, but remember that the fun is actually walking through it.

Keep up the good work!
> 4 votes

# Answer
A computer game is an endless loop of:

* Update: Advance the game state one tiny time slice (like 1/80 second).
* Paint the current game state.

There are variations of these. Some games have more updates between each paint, or it can vary them to make the game flow equally smooth on different machines. But that is technical details.

The update phase that occurs between 50 and 100 times each second (yes it's that often) does this:

* Update the games physics. Say that an actor have a velocity. The update should move him one tiny bit in the right direction. Also, if you use a physics engine, it should check for collisions with other actos or obstacles.
* Update the games rules. This is what makes it a game and not a physics experiment. Say that a bullet hit the player actor. The game rules tell the player to deduct X points of health and the bullet to disapear.
* AI updates. Sometimes the computer controlled actors should deside what to do. Go left or right? Find a path to a nice place to be. Fire a weapon.
* Input control. Update the player actor according the buttons pressed on the keyboard.
* Update scene graph. This can be advancing an animation one step, or updating the GUI to show that the player now has 10 points less health. It's only purpose is to make the game look and feel nice.

**Where do you start?**

The basic requirement for a graphical game is to program graphics. Make sure you can open a window, and draw a ball in it.

I assume you can make some kind of classes. Make a Ball class. It have the following members: x, y, deltaX, deltaY. All are integers and in pixel scales. Now, write this loop.

```
forever, do this {
  start measure time (in milliseconds)
  //physics part
  add deltaX to x
  add deltaY to y
  if x is bigger than the screen width, assign -deltaX to deltaX
  if y is bigger than the screen height, assign -deltaY to deltaY
  if x is less than 0, assign -deltaX to deltaX
  if y is less than 0, assign -deltaY to deltaY

  //paint
  paint the ball at x, y
  stop measuring time, assign this to workTime
  make the thread sleep for (25 - workTime) milliseconds
}

```

This will make the ball bounce of the windows boundaries. **It is not a game yet**, rather a physical simulation. If you write the balls physics update inside the ball class, it is easy to add several balls. Store them in a list and update and paint each one for each frame.

You can add a paddle (simulate physics for it and make it controllable with the mouse or keyboard) and a game objective such as stopping the ball from reaching the left wall. If the game adds more and more balls over time, the difficulty will increase. **You have a game.**

**Why sleep** for (25 - workTime) milliseconds? If you do it like this, the simulation will run at a contant pace of 40 updates and paints per second. It will be quite smooth. If you would skip the sleep part, the animation would be jerky, and take up 100% CPU. Also, the speed of the ball would depend on the speed of the machine running it. Now, the ball vertical speed is 40 * deltaY pixels per second.
> 4 votes

# Answer
Take your console program that does math, and then when you put in a correct answer make it shoot off some confetti... It has become a game (Anyone besides me play Math Blaster as a kid? :)).

As for how computers are made to create game environments, it can be a bit much to wrap your head around at times but it comes down to an application of human's understanding of the world around them. Games use the same math, physics and sciences to define themselves as we apply to the world around us to explain how it works.

The Sim games are a good example of real to virtual. Long while ago I read an interview with the guy behind the Sim games and almost all of them, with out exception, were born from reading about a topic trying to explain the world around us, then harnessed with mathmatical formulas and put into a virtual environment to represent it. SimCity for example, was stemmed from trying to simulate the basics of economies.

As for the specifics of how you make a 3D game environment, put physics in it, add in some audio, let a user start to interact with it.. Well that is what this site and many others are here for and would be impossible to sum up into a more specific answer.

At the end of the day I describe video games as very fast limited data-set databases. They are highly focused on relational data and high speed data access.. I mean if you are rendering a frame every 60th of a second, you are processing potentially large amounts of data very fast based on the relationship of where the player is in the game to all the other data tracked by the game :)
> 2 votes

# Answer
What you need to understand is matrices. They underpin games. Once you understand the power of matrices, you will see how games reduce to simple mathematics.

You take a vertex position in game space. You project it using a matrix on to the screen (find it's screen co-ordinates). You interpolate some pixels between it and it's neighbour vertices, and you're done. That is obviously an exceedingly large simplification, but the fundamentals of rasterization are not at all complex once you grok matrices.
> 1 votes

---
Tags: education
---


title: What's next to learn?

text:
# Question
Title: What's next to learn?
I am self-learning programming for video games. I have learned:

* Basics (variables, loops, branching, etc.)
* Object Oriented (classes, objects)
* Functions
* Dynamic Memory Allocation
* Operator Overloading
* Aggregation
* Inheritance and Polymorphism
* Swallow Copy And Deep Copy
* STL Libraries

and I am learning I/O Files. What is next? Thanks for the help.

# Answer
Developing games is a whole different story from learning programming languages. To make any `interactive applications`, you need to know (at least)

* how to handle user `input` (mouse, keyboard, joystick, etc)
* how to `draw` something on screen (this will be your first challenge unless you are making text-based-game)
* how to play `sound` (game without sound? no way! :)

Those three things are heavily related to OS you are developing on. You can use just plain OS API functions to do all the above things. Sometimes, they even offer better API functions specifically for multimedia applications like "a video game". Windows offer `DirectX`. Other OS (like iOS) supports `OpenGL`. There are even many other libraries or tools which enables you to draw complicated 3D model with an animation by writing a few lines of code (or even without writing any code). They are the `Game Engine` like XNA, Unity, Unreal, etc.

It is totally up to you what you use but you have to understand how the three things are working. Since you are now studying, I recommend that you study OS API functions especially for `multimedia related functions` without using those handy game engines, and `make a really simple game` like space invader or tetris. You will realize `the simple game` is `not simple at all` and you will know what things you need to figure out. Something like,

* how to manage game `objects` (monster, princess, candy, etc)
* how to handle their `states` (move, jump, fly, die, etc)
* how to let game objects `communicate` each other
* and much much more. and much more. and much... you know what I mean.

As you know more about game programming, the first three things will be getting less important and the later ones become `key` techniques for game development. That's why some people might say they are not very important or not even necessary to study. However, I still strongly suggest that you start with the first three things as it will give you strong basis for later game development life.

It will be a long journey but should be fun. Good luck! :)
> 3 votes

# Answer
You will want to start dealing with hardware soon. This takes the form of a few self contained areas that you can get into like Rendering technologies (Anything from Flash to Direct3D or OpenGL). User input from keyboards, mice and game controllers is another area of hardware to deal with. Audio programming. Networking.. All of these areas go together to make games along with basic programming knowledge mentioned above. I just recommend more than anything to take things one at a time.. People who are just starting out tend to try and go to recreate their favorite game, but games these days are very complicated pieces of software. Try and learn one thing at a time, user input, audio output, simple rendering or the like, but do them with very simple 'games' in mind if at all. Learning to program technologies and learning to program game logic and systems at the same time can become very cumbersome.
> 1 votes

# Answer
A lot would agree with me that being good at programming is more about practical experience, than theoretical knowledge.

If you're interested in making games, use what you've learned to make a game. If you don't know graphics libraries, you can make a text based adventure. You'll see that there are many more problems in programming than just learning a defined set of steps.

Once you have a game, or while you're making it, ask yourself "what would make this game better?" and you will mathemagically find that the answer to that question is the same answer to your original question.
> 1 votes

# Answer
You should learn OpenGL next, great way to render graphics.
> 0 votes

---
Tags: c++, software-engineering
---


# Question
Title: Manually invoke key callback in (free)glut
I have to watch the keyboard during rendering. So, is there a way to force glut to invoke the Keyboard callback immediately?

# Answer
> 2 votes
I'm unclear as to when exactly you think "immediately" is in this context, or what you're actually trying to do by "watching the keyboard during rendering."

But given that you must have known what function is actually being assigned to the keyboard callback (since you had to pass to the `glutKeyboardWhatever` function), couldn't you just directly invoke the function you passed yourself when you want to?

No flavor of GLUT that I'm aware of has the ability to manually invoke the callback indirectly.

# Answer
> 1 votes
> I have to watch the keyboard during rendering.

Fullstop here. Go over your code again and rethink how stuff works. Logic and rendering should be strictly seperated. There should no situation what-so-ever arise for you to need to check the input during the rendering calls. Rendering doesn't compute input. It just works with what's being given to it.

---
Tags: opengl, glut
---