# Question
Title: Faster way to scale images than gluScaleImage?
I'm porting a C++ game to Android using the NDK and there's one bottleneck that's really slowing down the code: gluScaleImage().

Does anyone know of a faster way to scale image textures?

# Answer
Scaling images is computationally expensive (even when you're using heavily optimized code/functions). If you're doing this a lot during runtime, you should probably rethink your design.

If this is just about displaying images with various sizes, why not create a textured quad and scale it to the requested size? The texture could always be the same size then.
> 3 votes

# Answer
Not familiar with the android's hardware scaling abilities, but if `gluScaleImage()` doesn't utilize hardware, you should find something that does. Be aware that your performance will then be hardware-dependent as well as CPU speed-dependent (try to find a friend with an older, slower android device to test). If this doesn't help you may want to cache the rotated graphics. When learning SDL I was surprised to find that the planes in this game have a long sprite sheet with ~16 rotations in an image for each of the two colors of plane.
> 0 votes

---
Tags: android, opengl-es, porting
---


title: AI: Learning vs. Strategizing

text:
# Question
Title: AI: Learning vs. Strategizing
I have a theory on AI that I would like to write a "whitepaper" about. The distinction I want to explore in AI is **learning vs. strategizing.** My question is, **where can I read other material about this subject?**

Let me give a chess example. Let's look at a chess AI as a max-tree, where capturing an enemy unit adds that unit's value to the "move score" for that decision (and likewise losing a piece subtracts that value to the score). Capturing a pawn might net 1 point, a knight 4 points, a rook 5 points, etc.

*Strategizing* would be AI to apply these points and determine the next move; eg. given ten possible moves, pick the best (max score) at the end of three moves.

*Learning* would be applying statistical observation to determine those values. If you play 100 games, the AI might decide that capturing a pawn is 2 points, and a knight is worth 7 points, while a rook is only worth 3 points (based on 100 gameplays).

Does this distinction already exist in literature, and if so, *where can I read about it*?

**Edit:** Does anyone know a Chess game (with source-code preferably) that utilizes this approach? Maybe Chess960@Home?

# Answer
> 15 votes
What you call strategizing is usually called search in the AI community. It encompasses simple algorithms like A\* and DFS, and methods for heuristic design for informed searches like A\*.

What you call learning is called machine learning, traditionally split into supervised learning, unsupervised learning, and reinforcement learning. Probably the most important areas to games are genetic programming, neural networks and support vector machines, and Bayesian networks. But machine learning is an enormous field and this is only a small set of the tools it studies.

If you are really interested in the different types of AI approaches, I recommend getting a real textbook, like *AI: A Modern Approach* rather than reading Wikipedia.

# Answer
> 1 votes
You should definitely read AI a modern approach. The book is a bit expensive but you can't have a serious discussion about AI until you've got some ground work. Also the 2nd edition is as good as the 3rd, so if you're able to find a cheaper 2nd edition take it.

If you really want to get into machine learning, Dr. Mitchell's book has much move indepth information.

It's unfortunate that there is such a large barrier of entry into AI academics. But it wont help you or anyone else if you publish a white paper that uses unique (wrong) vocabulary and discusses techniques already well known in academia.

The field of learning you opponent's behavior to improve your own has several notable entries. Good spam filters do just this. You should look into Paper Rock Scissors AI. What makes PRS unique is that that it's simple and there is no search involved (AKA strategizing). The only way the AI can beat a human is to learn his preferences and exploit them.

Check out this PRS AI bot built by the NYTimes.

---
Tags: ai, chess
---


# Question
Title: Turn-Based RPG Battle Instance Layout For Larger Groups
What a title, eh?

I'm currently designing a videogame; a turn-based RPG like Final Fantasy (because everybody knows Final Fantasy). It's a 2D sprite game.

These are my ideas for combat:

* The player has a group of 15 members (main character included)
* During battle, five of the group are designated as active, and appear in the battle.
* These five may be switched out at leisure, or when one of the five die.
* At any time, the Waiting members can cast buffs, be healed by the active members, or perform special attacks.
* Battles should contain 10+ monsters at least. I'm aiming for 20, but I'm not sure if that's possible yet.
* Battles should feel larger than normal due to the interaction of Waiting members, active members and the increased amount of monsters per battle.
* The player has two rows in which to put the Active members: front and back.
* Depending on the implementation, I might allow comboing of player attacks and skills.

These are just design ideas, so beware! I have not been able to test this out yet- I have no idea yet if any of these ideas bunched together will make for a compelling game. What sounds good on paper doesn't necessarily have to be good in practice!

What I'm asking now is how to create the layout for this. My starting point are the battles in Final Fantasy VI, with up to 5-6 monsters on the left and the characters on the right- monsters on both sides if it's a pincer attack.

However, this view would not work feasible with my goal of 20 monsters and 5 characters. All the monsters on the left would appear cluttered unless I scale them far far back. If I create a pincer-like map, then there would be no real pincer-attack possible. If I space the monsters out, I force the player to scroll the screen- a game mechanic I've come across and not enjoyed.

**Does anybody have any layouts or guides for designing battle maps in turn-based RPGs, especially with a larger number of enemies taken into consideration? How should it look?**

I am not asking for specific combat mechanics, just the layout for the moment.

# Answer
It might not work for the "look and feel" that you're going for, but one thing to consider might be a top-down or more isometric view for your battle map, similar to how e.g. Warcraft or Civilization represents the world. These styles of maps lend less size to show the fine detail of your sprites, of course, but they tend to give you a lot more room to show sprites and to move around. You might also consider some sort of "intelligent zoom", where as folks on either side start dropping the view could automatically zoom in a little closer as it needs less room to show off the scale of the battle, meaning that as you whittle down the opposing force your players go from a very broad view to a much more detailed view -- not unlike what your characters would experience as they transition from smashing a massive army to mopping up the remaining stragglers.
> 2 votes

# Answer
My first thought is to switch the view from FF-standard side-on to looking from behind and above the player characters. That way, you can render arbitrary numbers of monsters, with more distant ones scaled down, and instead of falling off the left side of the screen, the ones farther away are just partially or completely obscured by the nearer ones. This should give a good sense of the size of the group facing the players and of its thinning out as the battle progresses.

The downside is that it's a bit harder to have your PCs standing there looking epic if you're staring at their backs, but I think it would work to show them as facing somewhat sideways.
> 1 votes

# Answer
Try looking at turn-based strategy games like the old Might&Magic or Civilization games, which can display a large number of armies on tiles.

Note that in the early Final Fantasy games, the only reason there were only a few enemies is that the enemy sprites were drawn so much larger than the player sprites. Reduce the size of the enemies and it's easier to cram them all in there (at the expense of having them be less recognizable, so your artist would have to put in extra work to make them really distinctive).

Another alternative, if a typical monster group contains many copies of an individual type (so when you say "20 enemies" really you mean "10 rats + 5 bats + 5 wolves"), you could just limit it to, say, 6 enemy types and then put a number next to each enemy sprite to denote how many of that type there are.
> 1 votes

# Answer
If you want to keep the side view, you could have the monsters function in a method similar to how you imagine the player's characters to be situated. The enemies would have a "front rank" of sorts with the other monsters on standby. Give them the ability to support the ones in front with their attacks or perhaps sometimes have different weaker (or stronger) attacks that are only launched while not in front.

This would add consistency between the player and the enemies, and limit your on-screen resources to reasonable levels. It could also add some strategy depending on how the monsters are arrayed (probably have some way to see their full group, either via text or a quick pan), how they fill forward as the front line falls, and how different monsters react to their position.
> 1 votes

# Answer
Try having your camera move dynamically.

Center on the front rank of players, and the front-most monsters, and then switch views or move the camera to show the rest of the enemies when they are being attacked, attacking, or being selected by the player for an attack.

This would also make your battles more engaging, I bet.
> 1 votes

---
Tags: game-mechanics, rpg, turn-based
---


# Question
Title: Which game portals support Silverlight games?
I have been looking for strong game portals that support Silverlight. Which ones are currently available?

# Answer
http://www.mashooo.com has quite a few Silverlight games.
> 1 votes

# Answer
GameJolt is pretty awesome!
> 1 votes

# Answer
http://www.silverarcade.com/ is dedicated to Silverlight only, that's the only one I'm aware of.
> 1 votes

# Answer
http://www.vectorlight.net/games.aspx has Silverlight and HTML5 games you can submit to.
> 0 votes

---
Tags: silverlight, support
---


title: Shadow map artifacts

text:
# Question
Title: Shadow map artifacts
I want to try adding shadows to a 3D XNA game. I've set up some testing environment with one light and one camera. However, I'm running into artifacts with my approach.

I'm using the shader code from http://pastebin.com/zXi0hmsU to render the final result and http://pastebin.com/rY4Gcj9N to create the shadow maps. The code is pretty straight forward and involves production of the depthmap from the light point of view, then projecting it into the camera space and checking for occlusions.

However, from most angles I am getting pretty ugly results

The scene consists of some simple cubes (constructed by hand, facing outside, backface is culled), one light (shadow map shown in top left corner - looks okay) and one camera.

My RenderTarget for the shadow maps is initialized by

```
int shadowMapSize = 512;
RenderTarget2D shadowMap = new RenderTarget2D(GraphicsDevice, shadowMapSize,
    shadowMapSize, true, GraphicsDevice.PresentationParameters.BackBufferFormat,
    DepthFormat.Depth24Stencil8);
GraphicsDevice.SetRenderTarget(shadowMap);
GraphicsDevice.Clear(Color.White);
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

```

Afterwards, the `CreateShadowMap` effect is applied, followed by the LambertWithShadows effect. Finally, the shadow map is drawn using a `SpriteBatch`.

Rest of the code consists of simply providing the correct values to the shaders. If necessary, I can provide it at well.

# Answer
This is typical problem called *shadow map acne*. It is caused because of the projected pixel of the shadow map(depth) is bigger than pixel on the screen (eq. cannot represent depth correctly).

There are plenty of solutions to this. First most easy is bias (i see it in your code, so that is not the problem). And second easy solution is shadow map in bigger resolution, it is really more than typical to have shadowmaps in resolution 2048x2048 on current hw. *(EDIT: thats not true, i've wrote that when i was working on movie rendering. In game development, you want to keep you shadow map as small as possible)*

Some resources to study more advanced techniques.

---

edit:
> 19 votes

---
Tags: xna, c#, shaders, shadows, shadow-mapping
---


title: RTS game engine for iOS/iPhone

text:
# Question
Title: RTS game engine for iOS/iPhone
Anyone know any free or non-free RTS engine that can be used for iOS game development?

# Answer
> 2 votes
I don't know of an engine dedicated to RTS, but there's always Unity3D. Runs on both iOS and win. If you plan on iPhone/Pad development it's going to cost quite a bit though. That being said, Unity is quite awesome!

# Answer
> 1 votes
Glest uses OpenGL. You could port it to the iPhone.

---
Tags: iphone, ios, ipad, rts
---


title: Texture animation/coordinates in VBOs

text:
# Question
Title: Texture animation/coordinates in VBOs
# Situation

I've got a large map divided into 16\*16 parts (comparable to Minecraft) for x and z. For every part a VBO is generated and stored using GL\_STATIC\_DRAW.

# Problem

The technique described above works fine and with good performance, however it restricts (due to the nature of GL\_STATIC\_DRAW) modifications that *may* happen frequently, especially texture animations (that is incrementing texture coordinates to select another sub rectangle in the texture).

Now I'm asking myself how to solve that problem. Switching to GL\_DYNAMIC\_DRAW seems like an overkill to me, since most of the geometry *is* static, thus better placed in GPU's memory.

Generating a separate VBO (or even a vertex array?) is an option that came into my mind, however this would greatly increase complexity. Any ideas?

# Answer
Well, if you have access to VBO's, you have access to some version of the GLSL shading lang. A vertex shader for manipulating texture coordinates would do what you are asking with minimal performance impact, but it might require a significant change in your rendering system if you are currently using the fixed-function pipeline.

I would go with c0d3rguy's suggestion and try using the VBO that might be updated as a GL\_STREAM\_DRAW or GL\_DYNAMIC\_DRAW and see what the performance impact is. It might prove to work just fine
> 1 votes

---
Tags: c++, opengl
---


title: Billboard draws fine on PC, not on XBOX

text:
# Question
Title: Billboard draws fine on PC, not on XBOX
The moon is drawn with two draw calls, but both draw wrong on the xbox so I'm just displaying one draw for simplicity.

---

This is how the moon should look on the PC:

How it looks on the XBOX:

The texture flickers, disappears, looks like a gradient from bottom to top, lines run through it, and so on as the camera moves around. For example after moving the camera slightly it looks like this: http://olhovsky.com/xna/xbox\_moon2.png

```
public void Draw(Camera cam)
{
    GraphicsDevice gd = Game3.GDM.GraphicsDevice;

    Vector3 position = Position + cam.Position;
    Matrix world = Matrix.CreateScale(2.0f);
    world *= Matrix.CreateConstrainedBillboard(
    position, cam.Position, Vector3.Down, cam.Forward, null);

    _moonEffect2.Parameters["World"].SetValue(world);
    _moonEffect2.Parameters["View"].SetValue(cam.View);
    _moonEffect2.Parameters["Projection"].SetValue(cam.Projection);

    // Draw blended part of moon only.
    _moonEffect2.Parameters["AlphaTestDirection"].SetValue(-1);
    gd.BlendState = BlendState.AlphaBlend;
    gd.RasterizerState = RasterizerState.CullNone;
    gd.DepthStencilState = DepthStencilState.DepthRead;
    ScreenQuadDraw.DrawQuad(_moonQuad, _moonEffect2);
}

```

Here is the shader used, nothing complicated here: http://www.olhovsky.com/xna/Moon.fx

Does anyone know why the texture is not being displayed properly on the xbox? Is there another state I should be setting perhaps?

# Answer
> 4 votes
The solution was to remove the unused color input from the shader.

Old pixel shader:

```
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0, float4 color : COLOR0) : COLOR0
{
    color = tex2D(TextureSampler, texCoord);

    // Apply the alpha test.
    clip((color.a - AlphaTestThreshold) * AlphaTestDirection);

    return color;
}

```

New pixel shader:

```
float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
{
    float4 color = tex2D(TextureSampler, texCoord);

    // Apply the alpha test.
    clip((color.a - AlphaTestThreshold) * AlphaTestDirection);

    return color;
}

```

---
Tags: xna, c#
---


# Question
Title: How to implement a never-rebooting test world?
Am looking for ideas on how to do the following: I want to write a simple "world" in Java. One which I could start and then add new objects later at a later date to simulate/observe different behaviours between existing objects. The plan is then to code up newer objects after watching the old ones for a while and then load/drop them into the existing world. The problem is that I don't want to ever stop or restart the world once it's started, I want it to run for a few weeks but I do need the ability to drop in objects and redo/rewrite/delete/create/mutate them over time without needing a reboot. The world could be as simple as a 100 x 100 array of X/Y locations, with a possible tiled-map GUI to visually represent the world. I know I need some kind of ticktimer process to monitor objects and give each one a 'chance to act' (if they wanted to? (and if it was their turn to act?)).

Example: I code up World.java on Monday and leave it running. Then on Tuesday I write a new class called Rock.java (that doesn't move). I then load/drop it (somehow?) into this already running world (which just drops it someplace random in the world array and never moves). Then on Wednesday I create a new class called Cat.java and drop that into the world, again placed randomly, but this new object can move around the world (over some unit of time), then on Thursday i write a class called Dog.java which also moves around but can 'act' on another object if it's in the neighbour location and vice versa.

Here's the thing. I don't know what kinda of structure/design I would need to code the actual world class to know how to detect/load/track future (and currently non-existing) objects.

Any ideas on how you would do something like this using Java?

# Answer
What you are basically looking for is a hot-pluggable system. You run a main application and then add plug-ins at runtime that get integrated in the event loop. First, start off thinking about what your world expects from a game entity. For example (based on your description):

```
interface Entity {
   void init(World world);
   // Called when loaded for the first time in the world and adds itself
   // to the world (correct position in the array, scheduler for updates)

   void update(World world);
   // Called when scheduler fires (allows the entity to think about its
   // next move)

   Image getImage();
   // Called by the GUI when it is time to draw the entity on the screen
}

```

Of course, you can add other methods you deem necessary. Note the World parameter with the two relevant methods. This allows your new entity to consider the world when setting up or updating. In your Dog class, for example, you can ask the world for all cats in the neighborhood. Next, you create your world that works with this interface and a system for dynamically compiling and loading Java code. An example of this can be found here.

```
void injectEntity(String filename, World world) {
    // Load the class as described in the mentioned link
    Entity e = (Entity) loadClass(filename);
    e.init(world);
}

```

Call this method from the World GUI to add new entities. Depending on your World implementation, an Entity init function can look like this:

```
void init(World world) {
   // Register entity with world for easy access
   world.register(this, "RockImpl A");

   // Place the entity on the world map
   Point initialLocation = Point(10,5);
   world.place(this, initialLocation);

   // Schedule its update method for every 5 seconds
   world.schedule(this, 5);
}

```
> 5 votes

# Answer
We did something like that in Stendhal for raids.

We did not aim for completely avoiding restarts. So changes to our core infrastructure services such as client/server communication do need a restart. But adding entities, creatures and NPCs, and modifying existing objects does work. (Oh, and sometimes live bug fixing, reflection can be used to manipulate even private fields).

Since we do not only want new object based on **new data** (like another skin), but want to add new behaviour, the world program needs to be able to **load new class files**. We call them "scripts", but they are real compiled Java classes. Those classes implement the Script.java interface.

Maria.java is a simple example. She is a new NPC that sells drinks and food to players. We can define very complex objects in there, too.

A new class is loaded this way:

```
// create a new class loader, with the script folder as classpath.
final File file = new File("./data/script");
final ClassLoader loader = new URLClassLoader(new URL[]{file.toURI().toURL()});

// load class through new loader
final Class< ? > aClass = loader.loadClass(classname);
script = (Script) aClass.newInstance();

```

If you can ensure unique names and never want to unload classes, you are done with the low level stuff.

**Unloading**, however, seems pretty important. In order to achieve that, you have to instantiate a new class loader whenever you want to inject new code. So that the GC can do its work after the last reference to that code is cleared.

We have a **/unload command** that invokes an unload method in our interface so that scripts can do cleanup. The real unloading is done automatically by the GC.

We often create lots of **temporary objects** during raids. And we want all of them to be removed after the raid ends. For example the Gnomes Raid, which spawns a number of gnomes near the invisible admin, we use this code: GnomeRaid.java extends CreateRaid.java.

The script could access the world directly (as the first example shows) and do its own clean up in the unload() method. But Java coders are not used to do clean up, and it is annoying. So we created a **sandbox** that scripts may use. On unload all objects added to the world through the Sandbox class are removed.
> 16 votes

# Answer
Save the world (no pun intended) and all its state (positions, velocities, all variables).

* Close the program.
* Implement changes (ensuring backward compatibility with saves).
* Recompile program.
* Restart program.
* Load world and state.
* Repeat

This is a general solution though, I don't Java specifics to know if you can dynamically implement code blocks and classes like you hope...

**Option 2**, is to bind a scripting language that can be loaded on the fly.
> 3 votes

# Answer
For Java, all you need is an OSGi platform. With that it's trivial to hot-swap modules or applications, and even do remote management or partial upgrades.
> 1 votes

---
Tags: architecture, java, world-design
---


# Question
Title: Game server for an android/iOS turn-based board-game
I am currently programming an iPhone game and I would like to create an online multiplayer mode. In the future, this app will be port to Android devices, so I was wondering how to create the game-server?

First at all, which language should I choose? How to make a server able to communicate both with programs written in objective-c and Java?

Then, how to effectively do it? Is it good if I open a socket by client (there'll be 2)? What kind of information should I send to the server? to the clients?

# Answer
> 7 votes
I don't mean to start a holy war here, but most of the internet services (flickr, twitter, facebook and such) have been dropping SOAP in favor of RESTful webservices and JSON as the serialized format. Although essentially the same, REST services rely on the url and http method to define what should be done, for example

```
GET /articles - list all articles
POST /articles - add a new article
PUT /articles/123 - update article 123 with new data

```

JSON - described in json.org - is also simpler than XML, and altough maybe irrelevant, will save you a few bytes per request. Following the previous example, here's how an article would be described in JSON notation:

```
{
 "id": 123,
 "author": "Cyril",
 "content": "Hello, this is an article",
 "tags": [ "gamedev", "webservices", "multiplayer" ]
}

```

For the IOS there's this nice article http://petermcintyre.wordpress.com/2010/11/04/consume-json-rest-in-ios/ which mentions http://code.google.com/p/json-framework/ for parsing and generating the data.

Being turn-based, you can rely on http sessions on the server to maintain state, so there's no need to keep a persistent socket connection to the server. Any server-side language supports this (php, python, java, etc).

This architecture allows you to scale horizontally (adding more servers) in a transparent way.

# Answer
> 4 votes
Since your game is going to be turn based, real-time updates are not super important. The easiest way to do this is to use an already built server, I would go with a web server. Any platform worth porting your game to should facilitate accessing web services located on a web server.

In order to provide updates in near real-time, I recommend you look into long polling. The code at that link, provides the most basic implementation of long polling from the server side. But the bottom line is that once a request is made to a resource, the server executes a blocking call until the data requested becomes available. Then you repeat the process again, and again.

In terms of what data should you send back, always treat the client as hostile. The client should send whatever its "turn-state" is, the server validates it, and then if everything checks out, it sends the new "game-state" back to all connected clients.

--

SOAP web services is probably the best place to start (link), they are easy to get started, and most web frameworks provide a method for exposing them. You might also want to look into RESTful services, but they typically leave a bit more of the serialization process up to the consumer.

For consuming SOAP web services on Android, I'd look here.

# Answer
> 2 votes
I think using SOAP or even HTTP is overkill. Just define your own protocol over vanilla TCP-connections. For example, interpret each line of text sent as a command. Define what commands/responses the client and the server is allowed to send.

FICS works that way and it has been serving thousands of chess players for many years. IRC works that way too (see RFC 1459).

---
Tags: iphone, android, server, client-server, turn-based
---


title: game story event programming

text:
# Question
Title: game story event programming
I have developed a game engine in c/c++ and DirectX.

I have a tile engine for the maps, animated player/npc sprites, talking to the npc, menus, and level changing but there is no game, it just feels empty.

I have looked around and keep hearing buzzword answers but I want to know how to implement a story in my game.

Some people have said a save file that holds flags governing every possible action/state available in the game but this sounds ludicrous.

It is a bit ambitious but I am aiming to get a game like the older Pokemon/Final Fantasy games.

Does any one know how these games work or the theory used?

I have been looking for a while and would really appreciate any input people have.

# Answer
> 19 votes
Your game's story should probably be in the form of a finite state automaton (or some kind of extended FSA). When certain events happen, you should move to a new state. This way you only ever have to store the current state and whatever information is needed to know where to move next in the FSA (along with player details like position, health, etc.).

For example, if we absolutely oversimplify the Pokemon games, the gym badges form the main branch of the FSA. You start in state 0 where you have no badges and as you beat the gym leaders you move through the states, to state 1, to state 2, etc. To get your game entities to update to the current state, you only need to get them to look at the current state. For example, an NPC outside the 3rd gym would check which state you are in, see you are in the state corresponding to having 3 badges, and respond accordingly (perhaps with a "Well done!").

You don't need to store the state of everything in the world; just the state of the story. The entities themselves know how to react depending on the current state.

# Answer
> 7 votes
You could use a set of possible states your game is in. Your NPCs and your world would be aware of those states and react/display accordingly. You might also want to define a set of triggers that would be activated by some actions/events.

For example, beating a certain opponent would activate trigger A, which would add state S to your world and in state S your character gets electrocuted when it walks out of its opponents lair. Or it's raining outside. Or you find a rare candy. You get the point.

With those two simple additions to your game, you could make it be a lot more "alive".

Make sure you also create a rich background for your world, characters and storyline and make sure the game is consistent to that background. Plan your story first.

Also try Gamedev

# Answer
> 2 votes
As sftrabbit mentioned, this is a perfect application for a state machine.

Essentially, you have a sort of tree structure. Each leaf/node contains information about the current state, and rules for progressing to the next state. Each node may contain multiple exits, depending on how complex you need your plot/play flow to be.

A good, very loose analog to this is a Choose Your Own Adventure book. Each page contains some text describing part of the story, and decisions that the player can make. Each decision leads to another page. Some pages may link back to previously-visited pages, etc.

The old text-based adventure games like Zork and Leather Goddesses of Phobos, and the infamous Sierra \*Quest games (SpaceQuest starring Roger Wilco the space janitor is one of my favorites) used a very simple version of this type of system. Each room in a map was a state, with exits that linked to other states or rooms. Acquiring an item set a flag in a global state object. Each room would check those flags to determine which characters or items were available in each room.

So, your states may be implemented as a class or struct, each with properties for:

Asset list - list of pointers to background graphics and anything else that you need to display the room/state/level.

Entry conditions - achievements that must already have been reached to enter a level

Exits - links to each possible "next" exit. North,South,East and West are some examples of this, but you may also include Door1, Teleport, etc. When attempting to exit a room, or determining of an exit/door is "open", your game could check the next state to see if its entry conditions have been met, and alter the way the exit is displayed on the screen, or just not allow the player to move in that direction.

If you want to get fancy, you could include a different version of a state with different entry conditions, which would alter the way that the room is presented to the player, or the actions that are available in that room.

Your start screen, death/game over screen, etc could all be states within the system, similar to the way in which you might navigate between menu screens. In fact, if you have such a menu system in place, you could use it for this. Instead of up/down arrows and "enter" to navigate a menu, you would look for specific events within the game play area, such as stepping on a teleport pad, walking off of the right side of the screen, etc.

From an admin point of view, consider whether or not you could benefit from creating an admin tool that would allow you to create the state machine. Add rooms to a map, create links between them, assign assets like background images, etc. This is probably overkill for your first attempt; it's too easy to get absorbed in building admin tools, and never actually finish the game. Remember - you're not writing middleware, but a game.

Hope this helps.

# Answer
> 0 votes
I used to use this game engine called VERGE. Play around with that and see how it handles events, I really like it. It's open source too, so you can see how they implement it, here. Here's a brief description.

Each map has a variety of layers. The graphical layers, of which there may be several. The obstruction layer. And then there is the zone layer. The zone layer is what's important here.\*

Each tile has a number to indicate which zone it is part of. Each zone can be activated in one two basic ways. Either the zone is activated upon the player entering it, or it has what's called adjacent activation. Adjacent activation means that when the player is standing adjacent to one of the zone's tiles and presses some key specified as the activation key, the zone is activated.

What happens when a zone is activated is it calls a function from a script. So you need to embed some kind of scripting language. VERGE has it's own language called VergeC, and it also allows lua. I myself prefer to use python.

Once you've gotten over this hurdle, you now have tremendous power in your event scripting. You have a full fledged programming language in which you can store and act on data like player stats, story flags, etc...

\*There is also an Entity layer. Entities act like mobile adjacent activated zones.

---
Tags: c++, directx
---


# Question
Title: What was the game project that felt like "YOUR" game?
This question might seem a bit vague but it is hard to formulate properly. I will try as best as I can. So here goes...

For many years I have been trying to create games but I haven't managed to finish even a single one. The main reason, among others, was that the game creation process lacked focus. There never was a concrete vision of what I was trying to create.

Now I realize that I would usually want to create a game that was similar to some other that I recently played and liked. It seems like there are many games I would like to make but there is none that I would see as THE game I want to make (or one of THE games).

I really want to create something that I (and hopefully, others too) like and can be proud of. But I'm having a hard time discovering what it is. It doesn't have to be big, graphically awesome or anything like that. It should simply be something I really enjoy and am motivated to create.

So, has anyone else here had the same or similar problem? Have you found a way to overcome it? Have you discovered "YOUR" game?

If so, what was different about it from other games you tried creating?

EDIT:

Thanks for all your answers. Just want to clarify some things a bit...

Before asking this question I already read through various older questions about things like prototyping, having deadlines, to-do lists, participating in competitions with short deadlines, etc.

What I wanted to know more by asking this question was not how to create a game in general but how to discover a project that feels like what you really want to do.

For example, I play racing games very rarely, but sometimes I might play some game that is quite fun for a while and get an idea about creating some racing game of my own. But that idea won't stay for long and I will soon get bored with it because in general I am not the kind of guy who is really "into" racing games.

It would be nice if someone here could tell how they discovered what their game was. And I would appreciate if you could tell your story with more details, especially about the things that made the difference between "it would be nice to make this game for myself" and "I want to make this game really badly".

# Answer
> 20 votes
It took me dozens of failed projects before I started actually managing to finish and release games. This is my two cents on how to finish a game:

* Draft then polish. Instead of trying to make a game from "start to finish", start by developing a complete game that is a very rough representation of the final product. Use as much stand-in stuff as possible. Then polish it over and over until it feels done. This is analogous to a painter drawing a sketch, and painting over it later.
* Further to the previous point, the most important thing is for the game to become "fun" as soon as possible. If a game isn't going to be fun, it's better that you discover that sooner than later.
* Talk about your project with others often. Stick to a strict blogging schedule, perhaps one per week with a screenshot demonstrating something new.
* Do short release schedules ("Milestones") perhaps every other month or so, to gather feedback to guide development of the game.
* Keep a to-do list for the project that has as many items as possible, split up by milestone. A to-do list isn't really complete unless it lists everything that needs to be done for the game to be complete. Deal with bugs first to keep the source code from deteriorating.

As for the vision, that's a difficult one to answer. I think any vision for a game project is fine as long as it's something that the developer would play if someone else made it.

# Answer
> 8 votes
I personally give up easily on projects, so I found out something that keeps me interested throughout the whole development process.

I start out really small, like drawing a character to the screen. Then, I try to make it a little more interactive by accepting input to move that character. After that, I just add small functionalities that, in the long run, really makes you feel like you're making progress.

As for making "YOUR" game, I'd say start out by making "clones" of classic games(like Pong or whatever) and adding a little something that makes it different(why not 4 players Free For All Pong? :) ). The more "clones" you'll make, the better you'll get. Eventually you'll just get a really good feel of what game you want to make, and that game will be YOUR game.

For more tips on staying motivated, see this question: " How can I effectively manage a hobby game project? "

# Answer
> 6 votes
There's nothing wrong with making a variant on someone else's game, but I think there's a difference between making a variant and "fixing" it. If you play the game and think "I like this, but I wonder whether XYZ would improve it" then you're driven only by curiosity - which can be a powerful motivator, but not for everyone. If you play the game and think "I like this, but XYZ would make it far better" then I think that's a much better motivator. So try looking for games which have one obvious flaw which has somehow escaped the developer.

The simple solution to keeping your motivation going is to start with a short deadline. There are a number of game development contests which take place over a single weekend or a single week. At the end of that you won't have a polished game, but you can have something which is finished for some value of finished. You'll either be burnt out or have the momentum to keep polishing. Ludum Dare is one such contest I know of, but there are others. (Found a list while Googling).

# Answer
> 6 votes
In reply to your edited post, and not directly at prototyping a game

*what was different about it from other games you tried creating?*

I couldn't stop playing it! And when I talked/showed my friends they loved the idea/gameplay.

I generally make games that I like to play, and my friends like to play. I keep them updating and that keeps me excited in creating my game.

Edit: Most of my earlier games I would create for the sake of creating them and getting better at game programming. Once I started creating games not for learning or for making money is when the games starting to be better and more enjoyable.

# Answer
> 2 votes
I have been in the exact same position.

What I did was playing a lot of games and thinking about what elements made the game fun. This eventually lead to my current project which basically takes it main elements from three different games I've played earlier.

EDIT: Sorry, this answer was a little short. Anyway, earlier games I've attempted either a) was an exact clone of an existing game, which resulted in that as soon as I had completed the core functionality I would drop it as I already knew what the game was going to be like, or b) had no real plan at all, which made the code hard to overlook as different ideas was trying to get their way into the game.

What I did was that I, as I said, looked not at whole games as a template but at elements, and mixed them together. I made up a clear idea of what the core functionality and content was going to be like (with a little space for some changes of course). Then I worked actively towards that goal, always checking my mental checklist (this part, done, that part done, etc.)

Also, I never sat too long each programming session. Before I sat down and coded I already knew what part I was going to get done and stop and do something else.

I hope this is of some more use than my original answer.

---
Tags: motivation
---


# Question
Title: Took one major now want to be in different industryssT
How different is Programmer Analyst from Game Programmer? I took the first one as my major but want to go with game development industry. Is it possible to transition from one to another?

EDIT: There is a single class about game development in this major

# Answer
> 1 votes
Unfortunately, job titles vary from company to company, so a "programmer/analyst" at one place might just be a fancy term for "programmer" while at another place it might involve the creation of software specs and design docs, and in another it might involve budgeting and scheduling. So "Programmer analyst" is vague - you really need to list your skill set.

That said, can one transition from "programming" to "game programming"? Sure. Game programming can be thought of as a superset of programming: it's standard programming stuff plus the game-specific stuff (realtime input, graphics, networking, etc.). So, you've already got a foundation.

Keep in mind:

The game industry is insanely competitive. About half of the people in your class probably got into programming in the first place because of an interest in video games. Finding someone to pay you to make games is going to be an uphill battle. Especially if you have no field experience as a programmer, just a degree. (Real-world experience counts for a lot.)

There's no rule that says you can't be a programmer by day and make games on your own time at night, as a hobby.

In either case, take the time to learn how to do game programming (i.e. make some games on your own to teach yourself these skills). If you don't want to because it's too intimidating or just not fun for you, what do you think it'll be like when you have to do this stuff every day because it's your job?

If you are determined to find a game programming job, there are a few paths from here:

* Seek entry-level positions directly, right now. In the mean time, while you're waiting to hear back, bring yourself up to speed on game programming as best you can, and keep learning. If you are an outstanding, superstar programmer you might be able to pull this off; if not, realize you are competing against people who are, so it might take awhile.
* Seek an entry-level position at a non-game software company. Get some experience. When you feel ready to leave, start looking for game industry work.
* You can split the difference here: there are a fair number of "serious games" companies, gamification sites and similar companies that aren't "entertainment games" but are kinda sorta on the periphery and might be "close enough"... and the jobs there are usually less competitive.)
* Find a new school that offers a game-programming-specific degree, either as a graduate degree or a second bachelor's. This will probably be expensive and is certainly no guarantee, but if you learn best in a classroom environment this might be a way to push yourself in that direction. Some of these programs also offer part-time classes so that you can go there while also keeping a day job to support yourself. WARNING: there are some good schools out there and a lot of bad ones, and mistakes are very costly in time and money here, so make sure you're getting the value you want before you start if you go this route.

---
Tags: game-industry
---


title: How to build a bones animation engine?

text:
# Question
Title: How to build a bones animation engine?
I want to develop a flash game. It would draw a stick man, and edit his pose.

I think what I need to learn are **bones animation** and **physics engine**.

Can anyone introduce some good resources to learn both?

# Answer
> 7 votes
Here is another such tutorial, which might help you.

It's very thorough, and I even used it once to produce an animation engine. The theory is very good and it should be easily understood for you to use it in AS3.

# Answer
> 4 votes
I'd look into a physics engine like Box2D or Nape. These engines come with several different joints you can use to animate lots of different stuff. Here's an example of the different joints/constraints possible.

On the Box2D (for Flash) homepage you'll also find a Ragdoll example which probably comes really close to what you're trying to achieve. Maybe you could take the ragdoll-example code as a starting point for your own modifications?

# Answer
> 1 votes
Check out the skeleton animation tutorial over at Rookscape. It's VB based but the theory should be sound. Also take a look at some of the other tutorials if need be...

HTH

# Answer
> 1 votes
I would definitely take a look at some of the underlying principals in skeletal movements.

General background: http://en.wikipedia.org/wiki/Inverse\_kinematics

Good pictures here: http://freespace.virgin.net/hugo.elias/models/m\_ik.htm

This guy was doing 2D stick figures: http://www.chrishecker.com/Inverse\_Kinematics

---
Tags: flash, physics, actionscript-3, physics-engine
---


# Question
Title: How detailed and/or complete is/are your game design documents before starting a project?
What I'm wondering is how complete your design documents typically are before beginning the implementation of a project? I'm talking about medium to very small projects with a very small team here where even fully fleshed out the entire document may only be a few dozen pages.

Do you start with a rough framework and start fleshing out the details at the same time implementation is starting?

Do you completely flesh out every section completely before any implementation is even started? If so, what percentage change have you seen after implementation starts?

If you have experience with one of the two scenarios I outlined, I'd love to hear your opinion on what issues going that particular route caused and what obstacles you feel it helped you avoid.

# Answer
If the game idea is heavily based on some **unusual gameplay concept**, I prototype that **right away** from scratch, using a previous project as a template. 95% of the time this leads to realizing that it's not as fun as I imagined, and to make it fun would require more resources than it's worth.

If I'm working on another project in the meantime, I take my time, make a doodle to get an idea of what the **prototype** should look like (try not to get distracted by sketch art). Then I share it with friends, partly to see if they have any input, but mostly to make myself think of things that are **not obvious** right away (there are always tonnes of things, even for the smartest people thinking out the simplest ideas). After a couple hours like this, I'll jot down some key concepts that have to be in the architecture, literally ~20 words. Then I can build a prototype when I have time.
> 7 votes

# Answer
Currently my game designs have been adequately detailed before starting.

I'll flesh out most of the important classes, draw some mock-ups(drawings are usually horrible), do a description of the game.

Though this is mainly due to having a long commute to work, and nothing else to do. I would rather spend less time doing this, and more time programming, as fleshing out classes that are most likely going to change seems like overkill.
> 6 votes

# Answer
Working on small teams across small games (one-man teams on small casual games), I moved from "heavy design" to "quick design." I find iterative development (two weeks focused on a single goal, eg. core gameplay) helps flesh out the design, and **gives you something to play,** which means that you won't change your mind and invalidate 90% of what you designed which looked good "on paper" but not in-game.

Having said that, I do spend most of my design time on the core gameplay and mechanics (how the main game will function), and that rarely changes much -- it gets tweaks and sometimes I pick up new ideas or drop old ideas; but nothing goes without a working prototype.

On the technical side, anything should get at least a few minutes of thought before making the code real. But, you can always refactor later.
> 4 votes

# Answer
Design documentation has an upkeep cost; as things change you have to go back and re-read and update any existing docs. As such, it should be a production goal to minimize the amount of maintainable documentation because that will maximize time spent actually building the game.

From there, it follows that you don't want to design everything down to the tiniest detail in advance, because you know full well that half of it will change, and then you'll be dealing with a lot of wasted time. Do the minimum design needed to start making the core game. When that's done, iterate as needed, then repeat the process for each new feature.
> 2 votes

---
Tags: game-design, design-document
---


# Question
Title: Do you think it's Possible to go from C++ Straight to 3D (skipping 2D)
Do you think it's possible to go straight from Experienced C++ programming (5 or so years) straight into learning DirectX 3d?

I mean....i'd be starting with the basics, im more interested in setting up Demos (like getting a good water demo and such) than actually doing a full fledged game.

Do you think this is possible?

# Answer
Absolutely it's possible. A great starting point Introduction to 3D Game Programming with DirectX 10 by Frank D. Luna. It is very easy to read, allows you to quickly implement a lot of common functions, and serves as a great base to learn more about DirectX and game programming.
> 16 votes

# Answer
Of course, though I recommend starting with a very, very simple 2D app since the initial learning curve (just getting a DX app running can be a chore) can be quite steep, and it's helpful to know whether the problems you're seeing are 3D-specific, or if you're just missing something very basic.

Implement Pong - you'll learn basics such as getting a DX app up and running, input processing, basic collision detection and, most importantly, how to draw stuff on the screen.

If it's your first app, it should take you less than a week to get that running. At that point, you should understand the basics of the DX framework, and be ready to start another project where you can focus on the 3D aspects - transformation matrices, object/state management, culling, lighting, etc. Maybe implement 3D pong, or racquetball.
> 2 votes

# Answer
Of course it's possible. It's also possible to learn C++ as your first programming language. But it's probably not the fastest way to get there.

Going from "programming" to "game programming" requires learning a few things regardless of graphics: game loops, realtime input, and so on. Those are MUCH easier to learn if you don't have to deal with learning a new graphics library at the same time. Learn one thing at a time and you'll probably have a much easier time of it. (And if you're an experienced programmer, learning the 2D stuff should really not take that long anyway.)
> 0 votes

# Answer
What does 2D have in common with 3D? Not much. 2D is either a flat world or a faked 3D that, while having a visual appearance somewhat resembling 3D, has very different code from true 3D.

Even for the stuff that they have in common, such as collision detection, how hard is it to extend the code into 3D? Pretty easy.

Simply put, learning 2D won't help you as much as you might think in your journey to learn 3D game or engine design. They have little in common, and for what they do have in common, 2D isn't really an easy "stepping stone" to get you up to 3D.

As David Lively suggested, you might want to start out with a very basic 2D game such as Pong, but don't think that you'll have to recreate Final Fantasy, Super Mario Brothers, Zelda, etc. before you can move on to tackling 3D. Even introductory work such as this is not for the purpose of acquiring lots of 2D experience, but rather for the purpose of making everything as simple as possible so that you can see basic concepts & methods (collision detection, getting the graphics library initialized, etc.,) which have as much to do with 3D as they do with 2D, as quickly as possible so that you can move on to the next step. The next step might be creating a "New/Save/Load/Exit" menu, which you'll once again make as simple as possible, and then you just keep adding stuff (+1 dimension to movement, models, and collision detection, then jumping, anti-aliasing, mipmapping, shadows, reflections, particles, liquids, etc.) until there's nothing more to add, and then you go back and make it fancy, filling it with content.

Let's just put it this way, though. After learning some theory in a college course about game design, we were tasked with making a 3D engine. I made it in about a week. It drew 3D objects, cast shadows, drew textures, did mipmapping, detected collisions, allowed you to jump, and brought up a menu if you right-clicked or hit {ENTER} or {ESC}.

The time-consuming part is making it fancy... whether it be fine-tuning the engine or making models/textures/animations, game content, etc.
> 0 votes

# Answer
Yes. Since you already know C++, now you just have to learn an API and theory. The main hurdle in learning 3D specifically is probably the math involved. While 2D math is pretty easy to understand at a minimum level, 3D requires a more complex understanding. There's also a ton of stuff like shaders that are definitely more relevant to 3D as opposed to 2D. If you do plan on making a game though, I would take a quick 2D route just to get the feel for making a game from start to finish (and maybe get a working GUI system that you can port over!) before going into 3D.
> 0 votes

---
Tags: 3d, directx, game-mechanics
---


# Question
Title: glClear-like operation that respects the stencil buffer
For the background render in my code I need to perform an operation that essentially acts like calling **glClear(GL\_DEPTH\_BUFFER\_BIT)** except that it needs to use the current stencil buffer to mask out parts of the screen. The other requirement is that it has to work on fixed function pipeline systems, preferably back to OpenGL 1.3. Any suggestions on how to best do this?

# Answer
You have to do this manually:

* Disable depth testing.
* Enable depth writing.
* Set up an orthographic projection.
* Enable stencil testing.
* Draw a quad that covers the entire screen and whose Z is near your far plane.
> 7 votes

---
Tags: opengl
---


# Question
Title: How to implement large scrolling background image without tiles?
I know that its just the background that scrolls and the player pretty much stays centered. What I am wondering what technique is more correct when I am implementing a large side scrolling map (I am not using tiles like some other questions I have found).

using a very large map 16000 pixels map, and scrolling that. and create an image list, with maybe 4 4000 pixel maps?

also, lets say I want a box at a certain point in my map. Right now I am just counting the pixels that I am scrolling and once I get to pixel 2000 I insert the box, and scroll it with the background. Does that seem correct? or is there a better way to do all of this?

# Answer
> 4 votes
If you are using SpriteBatch:

* Draw everything (`SpriteBatch.Draw`) in its "world space"
* Pass a translation matrix to `SpriteBatch.Begin` to translate your world space to the correct position (think of this like a camera).
* The maximum texture size in XNA is 2048x2048 on the Reach profile, 4096x4096 for HiDef (details). If your background texture is bigger, you will have to split it up and draw it in parts.
* You may want to consider adding some culling ***if*** you hit performance issues.

You should do all your movement calculations and so on in that "world space". So that box would have a position of something like `new Vector2(2000, 0)`.

Your player would also have a `Vector2 position;` and probably also something like a `Vector2 velocity`. You would then `Draw` the player sprite at that position. And also use that position to create your camera matrix.

For *really* huge worlds, or for physics engines that require precision, you may need to mess about rebasing your world space to maintain precision (details). I imagine that this probably *doesn't* apply to your situation.

# Answer
> 0 votes
Use an image list. (Is more memory friendly - although pay attention to the garbage collector)

Counting pixels can be good or bad. Depends on the complexity of your game. Pro: - it's pretty WYSIWYG. \- it is simple to understand what's happening

Con: - Your smallest step-size is one pixel \- maybe you want to be able to be more precise with your controls

My suggestion: If your game is reasonably simple use pixels. Otherwise calculate everything in a continuous space.

---
Tags: 2d, xna, sprites, side-scroller
---


title: Method of terrain in a 3d RPG

text:
# Question
Title: Method of terrain in a 3d RPG
I am working on a RPG using the JMonkey engine. While I was conceptualizing the map, I realized I would have a problem with the terrain.

My problem is this: I want to have a click to move interface, and have the player move in increments of 1 world unit (wu). This is actually rather reminiscent of a tile based engine, but in 3d. While making the world map, do I need to make an object made of the world geometries, and load the one object, or would it be better to build a map out of the necessary tiles, using a file to tell the engine how to build the map (similar to 2d tile games)?

I might also add, the game isn't going to use heavy collision detection or real time physics, which is why I thought a tile based "pass-abilty" system might work.

Would loading that many objects for a tile be too much as far as memory goes? What if I make a single object, constructed of tiles by a definition file, and just make the player move in 1 wu increments, giving the illusion of "tile-based"?

I'm assuming that a combination of any of these might work, it's just that I don't have any prior experience making a system like this and would like some opinions on the most efficient method of doing what I'm trying to do.

# Answer
> 1 votes
Not sure about JMonkey, but for most 3D engines having lots of different objects has a negative impact on performance (not memory). That's because every object requires a separate call to draw it. If that's the case with JMonkey too, you'd be better off having one, or few, bigger objects. You might even build them from tiles on-the-fly.

---
Tags: 3d, java, tiles, rpg, jmonkeyengine
---


# Question
Title: How should I manage events in XNA on the Windows Phone 7 without impacting performance?
It's best-practice to **not** to create lots of short-lived temporary objects the heap as it'll eventually force a garbage collection during game-play.

It is best to create short lived value objects.

Where does this leave us with event handlers? My game object fires events quite frequently, so I don't want to create new `MyThingDidSomethingEventArgs` every time.

What's the alternative. What do you use?

# Answer
> 6 votes
See this document: How to: Publish Events that Conform to .NET Framework Guidelines (C# Programming Guide).

**Ignore it.**

There is no compelling reason to follow those guidelines when you are making a game. Make your own delegate type that takes appropriate types (either existing object references or value types):

```
public delegate void DidSomethingHandler(MyThing what, Vector2 where);
public event DidSomethingHandler DidSomething;

```

Or, if you want to be especially lazy (*protip: you want to be especially lazy*), you can even just do this:

```
public event Action<MyThing, Vector2> DidSomething;

```

(If creating your own delegate provides better documentation or will be used in many places, do that, otherwise just use an `Action`.)

---

Footnote: When *are* those event guidelines applicable? When someone else will be consuming your code - especially in versioning situations. See also: What are the benefits of having events conforming to Net guidelines?.

# Answer
> 3 votes
You could let MyThingDidSomethingEventArgs be a struct, these are generally (not always) created on the stack instead of on the heap. However this is only viable if you include only value-types in the struct.

However more important is: what is 'quite frequently', if it's not dozens times per frame than its not going to be an issue so you shouldn't be worrying about this too soon. I understand you want to keep to best practices, but this isn't a best practice more of a optimization hint that should only be applied after you've measured that performance is impacted because of frequent garbage collection.

---
Tags: xna, performance, events, windows-phone-7
---


# Question
Title: Data Structure to Represent Connections Between Countries on a Map
In a game I'm developing for a client a key game concept involves moving around on a map. In this case the sizes and shapes and such of the various countries are irrelevant: moving from one country to an adjacent country counts as a single step.

I'm trying to figure out the best data structure for internally representing the connections between the countries. For a given country the game needs to know which countries are adjacent, both to know which ways the players can move as well as for allowing the game's AI to plot out routes, determining possible paths from one country to another. The AI also needs to evaluate how well-connected a country is, not just to its immediately-adjacent neighbors but to the neighbors of those countries, etc.

I've figured out a couple of possibilities but they seem ungainly and inefficient. Because the AI will need to calculate a bunch of possible routes in order to make good decisions about its movement, "inefficient" is highly problematic.

I suspect that this is a somewhat common CS puzzle and that there's a common solution, but I've not been able to find much by searching. Any suggestions are welcome.

# Answer
Sound like a Graph and a Shortest path Algorithm
> 13 votes

# Answer
Definitly a Graph. Check it out here Graph Theory, basically you got nodes and edges. A node may contain 0 or more edges to other nodes.

There are lots of algorithms to calculate the shortest path (hops or distance) , check for cicles (more than one way to reach one self), etc.

Now, to be able to implement efficient solutions, that's a little more complex, but as always, there are ways.
> 6 votes

# Answer
As already mentioned you would need a graph representing all possible connections between countries. Each connections would also hold the distance between two countries.

Then a path-finding algorithm like A\* can be used to determine the shortest path between two countries.

There are also some good books about game ai: Game AI by example by Mat Buckland http://www.ai-junkie.com/books/toc\_pgaibe.html

or the AI Game Programming Wisdom series. http://www.aiwisdom.com/ The first book has several chapters about pathfinding.
> 2 votes

---
Tags: maps, efficiency
---


title: Speech synthesis book?

text:
# Question
Title: Speech synthesis book?
When I was a kid, everything had a speech synthesizer in it, more or less. A couple years back I started to wonder where the technology is going after all these years, and after some research found that it's going nowhere. Storage has increased, making concatenative synthesis more life-like, but little else has improved.

Text to speech seems to be the primary research field. Most books I've found of the subject of speech synthesis skim on the actual voice generation and then spend hundreds of pages on text to speech.

**I'm not interested in text to speech as such, but more on the voice generation.** Yet, I haven't found a single book with good, practical explanation of this. Concatenative synthesis is simple to grasp, but formant is the one I'd like more information about. (The third method, physical modelling, would be a plus, but not all that interesting).

What makes this game specific is that I'd love to make a tool that lets low budget/downloadable games have speech, without having to go out to get actual voice actors and having to store hundreds of megs of oggs with the game. Since the author is in complete control of the voice editing before release, text to speech is less important; what's more important is the voice synthesis.

So, anyone know any good books about this?

# Answer
> 1 votes
Have a look at HTS. This is a HMM-based Speech Synthesis System that uses hidden Markov models to learn and generate speech. This book has a chapter on HMM based synthesis as well as a complete description of other TTS technologies.

# Answer
> 2 votes
I can't recommend any specific books on speech, but you might want to look at Festvox, CMU's open source speech synthesis library, as a starting point.

Awesome idea though, if you can produce voices near the same quality as Nuance or A Capella and be indie-friendly, that would be a huge opportunity for you and a great benefit to indie devs.

# Answer
> 1 votes
So far this has been the best resource I've found:

http://liceu.uab.es/~joaquim/speech\_technology/tecnol\_parla/synthesis/refs\_sintesi.html#Speech\_synthesis\_formants

Most specifically: http://www.ling.ohio-state.edu/courses/materials/825/klsyn-dos/klsynman.pdf

Still, haven't found The Book.

# Answer
> 0 votes
I don't know of a book, but Vocaloid music is becoming very popular right now. You add in lyrics and melody and it can synthesize a singer. This is how it's possible:

> It uses synthesizing technology with specially recorded vocals of voice actors or singers.

Pure synthesis of a voice may not be a reality yet, but reassembling recorded sounds with manipulation is a possibility.

---
Tags: tools, audio, books, sound, voice
---


# Question
Title: XNA: Why use Xact when I can use Content.Load?
I have to add sound to a game and I found that you can use xact. That's fine, however why not just use Content.Load?

Besides the tweaking of the sound, are there any other advantages to using Xact?

# Answer
> 10 votes
There's a little more to game audio than just playing back and fading in/out sound files.

XACT is primarily useful when you're working with a sound designer who either has no coding experience, or no desire to work in code.

Omnion's answer covers the essentials:

* Grouping sounds for selecting a sound to randomly play back
* Grouping sounds for organizational purposes (maybe have multiple sounds with the same name but in different groups, so you just need to keep track of which group you're in
* Easier control of realtime effects

Among the few (all small or indie) developers I've worked with, there's a bad habit when thinking about game audio to describe your audio needs exclusively in terms of asset lists. While you do need to eventually keep track of all the different sound files you need for a game, it's not useful at all in describing how multiple sound assets work together to create an overall sound event.

XACT and other tools like FMOD and Wwise create an interface between sound designer and programmer. The sound designer creates a Sound Cue, Event, or Sync (terminology depends on the tool being used) that can be referred to either by name (`const *char` or `string`) or by a GUI in a header or config file. This sound event contains multiple sound files that play back in a specific way that are controlled by parameters, which are usually variables associated with a sound event that control playback.

Here's Microsoft's article about parameters in XACT: http://msdn.microsoft.com/en-us/library/ee416028(v=vs.85).aspx

So the breakdown is this:

### Sound Designer:

* Creates sound files using whatever their workflow is
* Creates an XACT project that includes all these files
* Creates SoundCues and Real-time parameter controls that affect sound playback, and communicates to the programmer what each real-time parameter represents (could be

### Programmer

* Takes the built XACT project, loads it into the game
* Plays the appropriate SoundCues at the appropriate times
* Modifies the real-time parameters as he and the sound designer have agreed upon

The classic example is a car engine. Here's a video someone made of their car engine model in FMOD. In this example the programmer would need to do the following:

1. Grab an instance of the CarEngine SoundCue
2. Optionally adjust the RPM Smooth, Load Smooth, and Scale Smooth parameters (sound designer can specify defaults).
3. Trigger the SoundCue
4. Update the RPM parameter as the player accelerates.

### More than Cars

I'm using FMOD on a project to control the movement of robots.

* If the programmer wants the robot to start moving: they play the RobotStartMove event, which triggers an initial start-from-idle sound, while fading in a looping whirring sound. The whirring sound starts at a slightly lower pitch than the loop and gradually pitches up.
* If the programmer wants the robot to suddenly change directions, they set a parameter called "time" to 0.05 (it's a generic parameter that interpolates between values at 1 unit per second, so this name made the most sense).
* If the programmer wants the robot to stop moving, they "keyoff" the time parameter (`timeParam->keyOff();`). Which basically just advances the time parameter to its end, as it does so, the whirring loop pitches down slightly while fading out to give the impression of the robot's motors slowing down.

XACT, FMOD, and Wwise are also really useful for footsteps, you can create a "Footstep" sound cue, which has a bank of different footsteps. It will select one at random, adjust its pitch randomly (within a limit).

The bottom line with these tools, is that your sound designer probably knows what sounds better than you do, so let them define the behavior in an abstract way, so then you only have to adjust some predefined parameters to get the desired effect.

# Answer
> 5 votes
Xact is a bit harder to use than the Content Pipeline method. It was originally the only way to play sounds, but the team added the Content Pipeline method for an easier way.

Xact lets you do stuff like:

1. Group sounds so you could mute or do something to a select group of sounds (like mute menu sounds)
2. You can have Xact change or choose from multiple sounds to play one sound (so your game engine doesn't play the same repetitive shooting sound over and over)
3. You can apply effects and other stuff and it really gives you some cool features and abilities. It's also pretty nice for working with sound editors because they don't have to work with code, just the Xact editor (which isn't easy, but it's more direct in purpose).
4. I'm not an expert, so there are probably other features that I haven't named, but I think this gives the gist of it at least.

Anyway, learning Xact can be a pain. Only do it if you really think your going to need it. Perhaps you could set up an abstraction in your game so you could switch to Xact a bit easier? If your going to have a lot of sounds and your going to want some of the above features, Xact might be the way to go. Personally, since your kind of new, I would just use the Content Pipeline method and switch to Xact if you really found the need for it later.

---
Tags: xna, sound
---


title: Silverlight scrolling with camera

text:
# Question
Title: Silverlight scrolling with camera
I'm trying to get my head around scrolling a 2D map that uses a physics engine. If I was to launch a projectile, would I actually be applying the physics to the background images rather than the projectile itself? I'd like to keep the projectile at the center of the 'camera', but I'm not sure how to do this in Silverlight. I thought of using a translate transform to constantly scroll the parent canvas's position, but is this the best way of doing this in Silverlight?

Edit - I'm using Farseer Physics with the Physics Helper library.

**Edit 2 - Solution **

It turns out the MSI installer of the Physics Helper installs an older version that had a broken camera. I downloaded and recompiled the latest source version and it now works!

# Answer
> 0 votes
Whoops! Turns out the MSI installer installs an older version that had a broken camera. I downloaded and recompiled the latest source version and it now works!

# Answer
> 1 votes
I would suggest you go with a 2D engine that can help you do this. I use FlatRedBall personally, and initially it did have the capability to focus the camera on a single object regardless of that object's velocity or acceleration. (I believe it still does, but I haven't tried this recently.)

Applying forces to all background sprites is **not** a good idea; you should mimic the natural approach, which is to apply physics on the bullet.

I'm also making a 2D map game in Silverlight, but I haven't reached this point yet due to other constraints. It shouldn't be hard, given a good engine. FRB is good because it handles both graphics and physics simultaneously.

---
Tags: c#, physics, camera, silverlight, side-scroller
---


# Question
Title: Unreal Development Kit - What is a good method for accessing a relational database file?
I'd like to use a SQL Express file or something similar for a UDK demo.

Is there a standard method for accessing data in a local relational database file?

I understand that the best method may involve creating a class library and using the DLLBind feature, but I'm still a bit unclear on how to pass data to controls in the UI (I'd like to populate dropdowns and such with records from the database).

# Answer
I know nothing of UDK, but Google turns up http://forums.epicgames.com/showthread.php?t=726137 as an example. (and yes, you should use SQLite for this)
> 1 votes

---
Tags: udk, unreal
---


# Question
Title: Correct order of operations in a platformer game loop
I've run into an issue with my Mega Man engine, and the structure of my game loop is making it very difficult to fix. With Rush Jet, or any falling platform, Mega Man needs to stay attached to the platform as it falls. Right now the best I can do (without resorting to workarounds like magic forcefields that pull him down) has it so that he falls for a single frame when the platform first starts falling. But even this requires the falling platform to pull him down during the collision check. Without this extra step, he constantly "jitters" in falling as the platform descends.

The order of events in my game loop is making this happen. It goes like this:

1. Mega Man and Rush Jet are flying horizontally for a while.
2. Thinking phase: Player presses down - the platform decides to set its velocity to downward.
3. Action phase: Platform moves down, player has no awareness of this.
4. Reaction phase: The two are not colliding, so no "binding force" check can occur.
5. Next frame, Mega Man falls. A frame later, gravity catches up and he lands on the platform again, resetting his y velocity to 0.

You can see there the basic order of my loop:

1. Thinking phase, where you analyze collisions from the previous frame, and any other variables, to decide on state transitions and other adjustments.
2. Action phase - everyone moves according to their velocity.
3. Reaction phase - collision checks, adjust positions to fix them. This also handles effects like moving platforms, eg. push the player by some amount. The changes to his velocity are applied in the next frame, during the action phase.

I've tried reordering these steps and various other changes, but they all make the whole thing much worse, with all sorts of bugs. If I need to make sweeping changes to my engine to get these things right, I'd rather know what the "proper" way is before wasting any time.

I know one possible solution would be for the movement step to look at who was touching the platform in the previous frame and pull him then, so they actually move together. That seems too complex though, reaching between components like that. My engine code already feels way more complicated than the original game could have been, suggesting that I'm doing something wrong.

So is there a proper sequence of events? There's another question on here about moving things along with a platform, but that doesn't address the order of events issue which causes my problem. Also, if anyone actually knows the way the classic Mega Man games did it, that would obviously be a huge help.

Find as much of my code as you want at https://github.com/Tesserex/C--MegaMan-Engine/tree/master/Mega%20Man. The CollisionComponent and MovementComponent may be the most useful.

# Answer
I know this answer doesn't fit with the title of this question, but I think it could solve your problem.

I looked at your code base and you have an aggregative component design for composing game entities. I'm guessing the rush jet has it's own game entity and list of components ("rush jet" is what I'll be calling this moving platform, yes I know nothing about mega man games). If this is the case, you should try to pass the rush jet a player game entity and set up some kind of bridge (not the best term to use).

For this "bridge", I would have the rush jet not take input from the keyboard. Instead, the player would take input and in your message system (the one for the game components in an entity) you could have another game component tied to the rush jet that would also intercept the movement message. Thus, the player and the platform would both be moved together. Once the rush jet is gone, the game component that serves as a bridge between the rush jet and player would be disposed of and removed.

I think this is a plausible alternative. The movement occurs in your game loop and then the collision checks occur to make sure the rush jet and the player are within bounds. I also believe it is perfectly fine for the rush jet to be dependent upon the player in this way. It's not the most sublime solution, but it'll probably work.

PS: I like your code base. The code isn't the best, but it's nice.
> 2 votes

# Answer
Okay so in its most basic form a game loop looks like this:

```
while game is running
    act upon user input
    update all game objects
    re-draw everything to the screen

```

In your case, what should happen is:

1. Loop begins.
2. You update all of the objects based on the key presses that have taken place. Platform moves down.
3. You then update all of the objects based on their velocities, inside that step should be a collision check to not go the full distance or change their velocities to zero when they hit (go through) walls and put them in the right places.
4. Now draw it all to the screen, the user has never seen any error states so everything looks great; no jitters ever.

And that is how most of the games I write make it work.

Update: If you need more information on how to write a good game loop then look now further than this good guide.
> 0 votes

---
Tags: collision-detection, game-loop, moving-platforms
---


# Question
Title: Do game programming just let all the objects in the program to interact with themselves and what about preventing infinite loop?
Does game programming use the method of

1) using time as the main controller to let objects interact with each other, so each step, let 1 object send messages to `N` objects, and the second object to any number of objects, and 3rd, 4th, until all objects done, and that's it, and display the results on screen (or think of it as just a loop that always repeat, with each iteration considered "a tick in time") (so object 1 call object 2's method, and object 2 cannot call other object's method immediately? otherwise, there can be infinite loop like (2) below. but how do you implement: "cannot call other objects until next time?" )

Or,

2) let the objects freely call other objects' methods (send messages to them), with no "Time" concept like the above

Are they both feasible solutions? But what if in (2), you have stones in a circular tube, and stone 1 pushes stone 2, and 2 pushes 3, and so forth, until stone N pushes stone 1 again, then the program will go into infinite loop and not able to do anything else (say if the program is a single process, single thread)

# Answer
Usually you have some separate class that does things like collision detection (collision-solver). So instead of *Object A sending a "collide" message to Object B*, you have a class that holds a list of all Objects. In one step (or update), the class checks collision for all objects in that list and stops when all objects have been checked.

With this setup it can still happen that if you move an object out of the way due to a collision, it will still collide with another object. To resolve this issue you can iterate the collision-solver several times within one update loop. As long as you have a specialized class that does this, the number of iterations can easily be controlled and infinite loops can be avoided.
> 7 votes

---
Tags: game-loop, objects
---


title: Efficiency of the SpriteBatch

text:
# Question
Title: Efficiency of the SpriteBatch
Does SpriteBatch in XNA draw to the screen only when a sprite would appear on the screen?

Say I have 5 identical sprites placed exactly on top of each other, is SpriteBatch able to determine that it only needs to draw one?

Also, say I have a large map that I've tiled off the screen in every direction. Does SpriteBatch handle that it does not need to draw these sprites that are off the screen.

(Note: Yes my code should handle this, I am just curious)

# Answer
> 4 votes
> Say I have 5 identical sprites placed exactly on top of each other, is SpriteBatch able to determine that it only needs to draw one?

Is it *able* to? Sure -- it has all the information that would allow it to make that determination. However, it *won't* do so, because such a computation is non-trivial in general and would actually drastically degrade the performance of the `SpriteBatch` interface.

If enabled, the depth test will kill off fragments that shouldn't be seen or overdraw will hide them, but in both cases the sprite vertices will have been transformed completely through the pipeline already.

> Also, say I have a large map that I've tiled off the screen in every direction. Does SpriteBatch handle that it does not need to draw these sprites that are off the screen.

It won't attempt to cull enqueued sprites against the view at all, either. They'll be clipped out entirely during the transformation stage like any other geometry, but it's vastly less expensive to simply never enqueue a sprite you know will not be drawn because it is out of view.

`SpriteBatch` is really just a wrapper around a dynamic vertex buffer that may or may not do some sorting for you to minimize texture stage changes and such. If your curious you can use Reflector to poke around at the internals and see that it does very little besides manage the buffer for you.

# Answer
> 1 votes
No, sprite batch does not handle the first instance (drawing sprites over one another). Anyway, this isn't always the desired result. Sometimes you'd want the images to merge because of transparency with alpha blending.

I'm pretty sure sprite batch doesn't clip images that aren't in the view port. I'm not sure if they are actually drawn, but you shouldn't batch them up in the sprite batch. It takes more time and from your question I can tell you've got some kind of tile engine.

If you told sprite batch to draw every tile on the map instead of the ones on the screen, your game would run a lot slower (major frame rate hit) just because of the sheer amount of tiles there could be.

It's not a good idea to tell the sprite batch to draw things that won't be displayed. However, I wouldn't really differentiate between if a sprite is completely covered by other sprites, especially if your using transparency and alpha blending. I think it's just a tad over kill.

---
Tags: xna, xna-4.0
---


# Question
Title: Is Xbox Live suitable for a multiplayer FPS?
I'm working on a basic first person shooter. I would eventually also like to publish it on Xbox Live.

If I do this, will I still have access to parties (invite and chat)? Does Microsoft provide servers for multiplayer, or do I have to provide my own? Am I free to connect my own server IP from the Xbox system within game? Can I charge people on a web page outside of Xbox for things like microtransactions or to maintain the cost of the servers?

# Answer
> 7 votes
Yes.

The typical model for multiplayer FPS in AAA titles these days is peer-to-peer multiplayer (where one player is chosen to be the server, and all others are peers relying on that player for synchronized updates). You can use this model in an XNA game for the XBOX 360.

You can get started at the networking architecture for XBOX XNA samples.

There are numerous examples including this one that demonstrates the type of network architecture used in AAA FPS titles like Halo and Call of Duty (where there is no dedicated server, except for the server(s) that handle the matchmaking).

One thing that you will be missing is the ability to query a dedicated server when matchmaking players. However, if you get to a point where you have so many players that you would benefit significantly from having a dedicated server for a matchmaking lobby, it's not unreasonable to go to microsoft to get a Live Arcade agreement, in which case you will have access to the microsoft storage servers and potentially access to your own server. Until you get that kind of (pretty large) userbase, peer-to-peer matchmaking will suit your purposes just fine.

# Answer
> 5 votes
XNA games cannot talk to a server, or anything other than other copies of the game in a peer-to-peer manner. It is possible to build an FPS like this, though latency might be an issue if you are trying to send a lot of data. As far as I know XBLIG are not permitted the use of the Marketplace, and any billing done outside the XBox "system" will land you with a nice lawsuit.

---
Tags: xna, multiplayer, xbox360, first-person-shooter, xbox-live
---


# Question
Title: Is XNA good for professional development for the Xbox 360?
I want to start off developing for my Xbox 360, and I've heard of the XNA framework that can target both the PC and Xbox. This sounds like an attractive option since my clients can use the game/app on normal computers as well.

However I'm very new to the Xbox scene. Is XNA only for hobbyist development, and is it not recommended for semi-professional or corporate application development? Does XNA lack the capabilities of a C++ developed solution, or dos it badly reduce performance of a game/app running on the Xbox?

Is it possible to target the Xbox using C#, and without XNA? What are the advantages?

Low-level programming would be in C++ directly working with DirectX. What are the advantages?

# Answer
The short answer: **Yes**.

XNA is just a tool. It is suitable for all but the most processor- and graphically-intensive games. If you are considering XNA for an Xbox 360 game, here's what you will miss out on:

* Access to the SIMD/Vector unit for doing really, *really* fast CPU floating point maths
* Ability to use native language code that will probably be a little bit faster than C#
* Ability to be a *little* bit lazier with how you allocate memory
* XBLIG games have access to only 4 of the 6 cores (but we still get all 3 CPUs, and they're not full cores either, so we don't miss out on much) - not sure if this applies to non-XBLIG XNA games
* Full DirectX access for doing really obscure graphical trickery

There might be more - this is off the top of my head.

(Speculation: if you *are* a professional developer (as in: have a devkit), I *think* that you can use XNA with native code, same as P/Invoke on Windows. Best of both worlds. You'd have to ask Microsoft. See also XDK.)

The bottom line is that an XNA game is *almost* as fast as a native game and can do *almost* as much stuff. I'd suggest you use it unless you find a compelling reason not to.

I do not know if there is any kind of managed DirectX for the 360. Perhaps SlimDX is a good place to start.
> 15 votes

# Answer
Unless you are willing to pay $10,000 for an XBOX or Playstation devkit, then the only console you can develop for is the XBOX 360, and the only way you can do it is with XNA.

For professional development, unless you really need to get 100% of the processing power of the XBOX (which most games, especially 2D games do not need), then XNA in my opinion is actually much better for development.

Some mistakes that other answerers have made:

The XBOX has only 3 cores. You get access to all of them with XNA.

Each core has hyperthreading and support for 2 hyperthreads. You only get access to 4/6 threads. One of those threads is for XNA. The other is a thread that no game developers get access to, as it is used by the XBOX OS.

C# on the XBOX is much slower than C# on Windows. The XBOX uses the .NET compact CLR, which is very lightweight and lacks many of the desktop CLR's optmizations. The XBOX security features prevent programs from modifying their own source code. This makes it very difficult to even allow .NET code to run, much less to run *fast*. Part of what makes managed code competitive in performance with C++ native code, is that the CLR can modify it's own code to optimize cache coherency. The XNA dev team has to jump through some pretty big hoops just to get C# to run on the XBOX at all, and there is an associated performance cost with these hoops.

You don't get to be TOO lazy with memory allocation. XNA on Windows greatly simplifies memory allocation, as you'd expect from a managed environment. However, on the XBOX, the .NET compact CLR uses a sweep & compact approach to garbage collection, and the typical approach to preventing stuttering in your game due to collections, is to avoid collections altogether. This requires using object pools for your classes, and using structs for smaller objects, where you'd normally uses classes in the Windows environment. Object pooling generally requires an allocate/free model of object management, which is no worse (and maybe a little bit better) than C++ memory management.

That said, development in C#/XNA is still many times faster and easier than development in C++ without a DirectX API (which XNA is).

Here's the status of a game I'm making in XNA, after 4 weeks of work:

That should give you a sense of how incredibly fast development with the XNA library/API is in combination with C#.

That screenshot is rendered by the XBOX at about 65FPS.

If you're a hobbyist game developer, and you want to make games for a console, not only is XNA+XBOX your only realisitic option, it's also a pretty amazing option, a fun development environment, and many XBOX Live Arcade games have been made with XNA, and made hundreds of thousands of dollars doing it. (Limbo for example.)
> 12 votes

# Answer
XNA is a double-edged blade; it's relatively easy to use, but very extensible and customizable. The problem is, being based on a managed language and having a so-so Compact Framework implementation, squeezing some performance from a complex game can be very painful and frustrating.

You can only deploy to your Xbox via C#/XNA, or via C++/DirectX, but the second option requires qualifying for a XBLA license and paying for the devkit, which can be very expensive (~10000$).

And remember that the Xbox is a closed system. Forget any direct TCP/IP interaction, you can only communicate with other consoles present in the Xbox Live! network, and you can't do raw HTTP connections.

So, if you are thinking of a game, give XNA a try and move to a devkit if you need more raw power (and you have the money). If you are thinking of an application... just target for another platform.
> 4 votes

---
Tags: xna, xbox360
---


# Question
Title: Is it true that to test a game on the iPhone or iPad, we either need to pay $99 to join Apple Developer program, or jailbreak the iPad?
To test a program for iPhone or iPad, seems like the only way is to join the Apple Developer program and pay $99 per year? Can you also jailbreak the iPhone or iPad and be able to test it?

# Answer
> 3 votes
You can use a jailbreaked iOS device for testing, but you won't be able to sell your App on the Appstore. And you won't be able to test the app on other (non-jailbreaked) devices. To do that you'll need the developer license.

The reason why this is so, is that every app needs to be signed (with the certificate you get from Apple when joining the developer program) to be run on iOS devices. Non-signed code will run on a jailbroken device, but not on any other device. Also a non-signed app cannot be sold in the Appstore.

# Answer
> 2 votes
Why all the talk about jailbreaking?

The iOS developers I know use ad-hoc distribution for testing. It's like when you sign your own SSL certificate on a home server. You'll have to add your own signature to the list of allowed signers on your device (butchering the terminology here, sorry), and then you can test to your heart's content.

Google turned up this:

http://www.readwriteweb.com/mobile/2010/12/apple-best-kept-secret-how-to-do-ad-hoc-installs.php

---
Tags: iphone, ios, ipad
---


title: Developing internet sweepstake games

text:
# Question
Title: Developing internet sweepstake games
I have absolutely no idea about game developing but want to know following things about internet sweepstake games: Click on demo and play any of the game.

1. What technology (programming language) is used to develop these games. e.g. Flash, Silverlight, etc.
2. If I wish to develop such game(s) what is the best technology to use, how much time it might take to learn and develop a simple commercial product.
3. Is the algorithm/code behind the scene re-usable while changing the front graphics. I mean a scalable/adjustible game.
4. In case I wish to hire a game programmer what would be the approximate cost or per/hr charge for such developer.
5. Any good books or online tutorial/videos to learn/see this in action?

Or any other ideas or suggestions? Sorry if these are lot of questions but this is the only good place I see asking such questions. I will more than happy to post them as separate questions if that is necessary.

# Answer
Separate and, more importantly, straightforward (answerable) questions work best on this site. That said, here's an answer to each of your sub-questions:

1. Any web technology could be used. The particular one you linked to is Flash (as you can tell if you right-click the game).
2. The best technology to use is generally the one you know best, or if you don't know any of them, maybe just choose the most popular one (or the one that best fits your needs, but in this case your needs can be met by any of the interactive web technologies). Flash is most popular by far for interactive web things; Silverlight is a good choice too, but fewer of your customers will come to your site with it installed. Java is another option; it probably has more coverage than Silverlight, but it is (in my opinion) more complicated to create things in, especially to a beginner or non-programmer. We are slowly moving towards HTML5 and JavaScript, so if you want to be ahead of the curve then look into that (it has the advantage of not requiring plugins and thus generally being lighter-weight, but on the other hand the user needs a recent browser).
3. Of course, you can make anything you want. If you plan it to be so, then make it so. If you are interested in the details from the programming perspective, you could browse through our architecture tag, and do searches (here and on your search engine) for the MVC or MVP pattern. This would get you started on a game engine which has a completely separated model and view, which would be the most "clean" way of doing this. For simplicity's sake you might just want to put conditional statements on the image loading and/or algorithm pieces of code and load them from a file or something. Again, this is very feasible, you would just need to plan it out and then make it.
4. This varies widely, depending on the quality of the programmer/team, country, and so on. It might be a good question for the Programmers Stack Exchange, but then again you will likely get the same answer from them. You'll need to do your research on this, maybe look at websites like vWorker if that's the kind of place you want to hire from. If you are looking to hire a local programmer, look up local companies' average salaries for software developers.
5. Sort of. We have a number of questions on books and tutorials (search for those keywords using the box in the top right corner) but they are about game development in general. Look for books and information on serious games, as that's what I believe this would be classified under, but I don't think you will specifically find a tutorial on creating "internet sweepstakes games".
> 3 votes

---
Tags: game-design, flash, game-mechanics, silverlight
---