Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Oct 2005
Offline Last Active Sep 16 2014 07:36 AM

Topics I've Started

Platformer movement (Flashback / Prince of Persia style)

17 September 2013 - 07:50 AM

I'm programming a pretty basic tile based platformer in Javascript and I'm struggling to figure out how to code the movement of entities correctly.


Originally the entities were directly influenced by key presses ie. pressing left would make the entity move one tile width to the left (Pressing SHIFT would make the entity sprint instead of walk) but this caused problems with the entity's animation and position if the entity began to sprint half way through moving.


I remember games like Flashback and Prince of Persia had a very distinct movement style where the entity would only begin to sprint when it reached the next tile. I tried to implement a system where the player would actually move onto the next tile instantly but the sprite would have an offset that would catch up to the entity eventually (and the entity would not process key presses until the sprite had caught up). This gave the right effect when moving left and right but it all started to fall apart when jumping / crouching / getting knocked back. Also I liked the way that (in Flashback) it was possible to press a button to draw your gun mid-step and the character would remember to do that when they reached the next tile.


Could anyone suggest a simpler way of achieving this kind of movement or point me to an existing example?

Efficiently calculating increase in money over a period of time

06 May 2013 - 01:49 AM

I'm currently working on the server side logic of a real-time online browser game build using NodeJS. Currently the logic works like this...


1. Receive an event from a player (queue something for production)

2. Calculate when the next event will happen in the game (look at when the next production will complete or when the next research project will finish)

3. Set a timeout so that the server effectively sleeps until the next event happens (unless interrupted by a player sending another event)


This seems to work very well so far. When the server wakes up from the timeout it updates the game with the amount of time passed and all production and research etc. is updated by the ellapsed time.


The problem I'm having at the moment is that the amount of money generated for a player is based on how many workers they have. Worker numbers slowly increase over time until they reach a population cap. Given the following facts...


- The player has 1 worker

- The player has no money

- A new working is created every minute

- A worker produces 100 credits per minute


How many credits does the user have after an hour? I have no idea how to predict the number of credits produced as the number of workers increases over time


I hope that makes sense!

Sorting by depth

21 August 2010 - 04:10 PM

I currently have a tree of nodes in my game. The screen shot below shows this tree rendered. The larger girls are top level nodes, with no parents. The boy is also a top level node, the small girl is a child node of the boy.

When each node is queued with the renderer it applies its own transformations to the current matrix and then stores a copy of it. When the screen is finally drawn I keep replacing the current matrix with the one stored inside each node.

This positions everything correctly within my scene but I get the following problem...

Uploaded with ImageShack.us

As you can see from this screen shot the boy is being rendered correctly on top of the other parent nodes however the child node is being obscured because it is drawn after its parent.

How can I sort my scene to correct this problem? The only positioning information I have at the time the image is rendered is a matrix defining where on the scene it should be rendered. Can I extract a Z position from this matrix?


Game engine design help!

09 August 2010 - 01:32 PM

I keep coming back to game development and keep falling at the same hurdle so it's time I solved this once and for all! Please excuse the wall of text.

I am building a game engine. So far my code goes like this...

Engine creates a game state
game state creates an actor
actor creates triangles
triangles have 3 vertices
vertices have 3 points

The engine also creates a renderer.

The actor has a position x,y,z.
Triangles have no position, their position is defined by the actors position plus the position of their 3 vertices

Actors can also contain other actors (child actors)

The game engine calls render on the state, the state calls render on all its actors and the actors loop over their triangles and queue them inside the renderer object.
Inside the renderer object the triangles are stored inside a vector.

Once all actors have queued their triangles, the game engine then tells the renderer to draw the whole scene.

From this point on I am lost.

Just outputting the triangles to the screen draws them all in the center, since I'm not using the actors position for anything. Even if I add the position of the actor to the triangles position, it doesn't take into account that the actor may have rotated and doesn't help me render child actors which will be relative to the parent actor.

What I *think* I need to do is when render is called on the actor, translate and rotate to the actors position, then multiply each of the triangles vectors by the current model/view matrix. Is it possible to retrieve the resulting x,y and z positions from this multiplication?

for example...

if an actor is at 10.0f, 0.0f, 0.0f
and the first vertex of the actors first triangle is at 2.0f, 0.0f, 0.0f

is it possible to use glTranslatef( 10.0f, 0.0f, 0.0f );
then multiply the position of the vertex by this matrix and retrieve the "global" space coordinates of the vertex as if I hadn't translated?

Please, please, please help. I've been stuck on this for so long and I really would like to move forward,

Stuck building a game engine...

11 October 2009 - 03:43 AM

I'm trying to build a (simple) game engine using c++, SDL and OpenGL but I can't seem to figure out the next step. This is what I have so far... An engine object which controls the main game loop A scene renderer which will render the scene A stack of game states that can be pushed and popped Each state has a collection of actors and each actor has a collection of triangles. The scene renderer successfully sets up the view projection matrix I'm not sure if the problem I am having relates to how to store an actors position or how to create a rendering queue. I have read that it is efficient to create a rendering queue that will draw opaque polygons front to back and then draw transparent polygons from back to front. Because of this my actors make calls to the "queueTriangle" method of the scene renderer object. The scene renderer object then stores a pointer to each of the actors triangles, then sorts them based on their position and then renders them. The problem I am facing is that for this to happen the triangle needs to know its position in world coordinates, but if I'm using glTranslatef and glRoatetef I don't know these coordinates! Could someone please, please, please offer me a solution or perhaps link me to a (simple) guide on how to solve this. Thankyou!