Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Jan 2010
Offline Last Active Jun 02 2013 03:06 PM

Topics I've Started

Separation of concerns in game architecture

19 May 2013 - 10:02 AM

I'm looking at writing a simple iOS game. I'm a .NET developer by trade but have only ever dabbled in writing games before. The game I'm writing is a relatively straightforward tile-based puzzle game. Since I have little experience of videogame architectures, I've done some Googling around for similar open source games and tutorials, to find out what the common design patterns are. I am looking, in particular, for the way the relationship between the physical, visual entities and their abstract, logical counterparts is managed. What I tend to see is something like this (pseudocode):


class Tile
    public int PosX;
    public int PosY;
    public string Value;
    public SpriteClass Sprite;


Now, when I see this, my architectural brain tells me that something smells bad. Tile is, in this instance, a logical representation of the individual Tile on a board. Its X and Y coordinates are graph coordinates, rather than physical screen coordinates. Its "physical" counterpart is its Sprite property.


I can't help but feel that Sprite should not - in fact - be managed by Tile at all, but that Tile should be exposed to some kind of independent manager that interprets the Tile object's position and creates the appropriate Sprite object, removing this tight coupling and making the Tile and the Sprite completely ignorant of each other.


Are my concerns unfounded? Is the above common practice in well-architected games? If not, can anyone provide any insight, tutorials or examples of a better way of managing the relationship between the physical and the logical?


"Mouse Tail" Geometry

26 August 2011 - 08:42 AM

I have a simple sprite to represent a mouse and behind the mouse are a chain of overlapping circles to represent the mouse's tail. I currently have the following update method for the mouse and its tail:

public void Update()
            Velocity.X = (float)Speed * (float)Math.Cos(Angle);
            Velocity.Y = (float)Speed * (float)Math.Sin(Angle);
            if ((Position.Y + Velocity.Y < StageHeight - 24) && Position.Y + Velocity.Y > 0)
                Position.Y += Velocity.Y;
            if ((Position.X + Velocity.X < StageWidth - 24) && Position.X + Velocity.X > 0)
                Position.X += Velocity.X;

            // Update tail positions
                Tail[0].Position.X = 8 + Position.X - 12 * (float)Math.Cos(Angle);
                Tail[0].Position.Y = 8 + Position.Y - 12 * (float)Math.Sin(Angle);

                for (int i = 1; i < Tail.Count; i++)
                    Tail[i].Position.X = Tail[i - 1].Position.X - 4 * (float)Math.Cos(Tail[i - 1].Angle);
                    Tail[i].Position.Y = Tail[i - 1].Position.Y - 4 * (float)Math.Sin(Tail[i - 1].Angle);

                Tail[0].Angle = Angle;
                for (int i = Tail.Count - 1; i > 0; i--)
                    Tail[i].Angle = Tail[i - 1].Angle;

Tail is an ArrayList of TailSegment objects, which are basically just simple sprites. This has the effect of curling the tail nicely as the mouse moves and turns, but it has a couple of problems. Particularly when the mouse is moving slowly or is stationary, turning causes the tail to whip around and end perfectly straight as this code results in the tail being lined up behind a mouse after Tail.Count frames. I'd like the tail to move a little more realistically with respect to the movement of the mouse, so turning on the spot or stopping while turning will leave the tail curved, the tail will straighten up more gently if the mouse is moving slowly etc., but as I think about it it starts to sound a little more complex than I initially thought. Can anyone help point me in the right direction when it comes to modelling something like this?


A question on design philosophy.

18 August 2010 - 05:49 AM

I've found that one of the biggest stumbling blocks for me so far in application development - particularly games - has been class architecture. I have a structure in mind and I begin to work on my game but before long something throws me a curveball that I have to work around and eventually I become unhappy with the structure of my code, how my classes are interfacing, how modular and independent sections of my project are etcetera. Once or twice this has frustrated me to the point where I scrap the lot and start again with a plan on how to do it better, which means that I learn plenty but it also means that I have difficulty getting things finished.

So what's the best approach to this kind of problem? Is it to have a very neat, well-planned structure to begin with? To progress and rework messy bits as you go along? Or is it just to stop being such a fussy git, accept that there will always be flaws in my game architecture and not worry about it until it becomes an actual practical problem?

The other thing that ties into this is concerning myself with my code being generic. If I'm developing a hex-based TBS, for example, should I focus on ensuring that the tilemap engine is as generic and reusable as possible or should I just concentrate on making sure it works in the current context?

[C] Parsing a string with optional tokens

11 August 2010 - 10:18 PM

I've got a string, which is an XML xsd:duration element, in the format PnYnMnDTnHnMnS, where P is mandatory, T represents that the rest of the string represents a duration in time (rather than days/years) and, for example, "nS" represents number of seconds. This needs to be split up into a struct tm (or similar format), so that I can work with it locally.

The problem is that everything except the P is optional. So, for example, you could have any of the following:

- P5Y
- PT30S
- P3M5DT12H

So far, I've split the nHnMnS from nYnMnD, albeit not very elegantly:

	// Separate time and date
if(strstr(string, "PT")) //i.e. string contains ONLY time (H, M, S) values
date = "";
time = strtok(string, "PT");
date = strtok(string, "PT");
time = strtok(NULL, "");
if (!time) time = "";

I'm having trouble thinking of a tidy way of parsing this. My initial thought was to use repeated calls to strtok, but if any of the tokens were missing it would give me the rest of the string (instead of none of it). I thought of using a repeated "if (strstr(...)) {x = strtok(...) ...}" method but if strstr returns NULL then it will throw the pointer out of whack for strtok. So it's looking like I might have to do it all "manually" instead.

Anyone have any thoughts (or knowledge of an existing library that can do this)?

2D Drawing and Animation - Where to Start?

10 July 2010 - 05:08 AM

Hi guys.

Basically, I have been doing some game dev for a while now, throwing together bits and bobs of engines and such. I'm a Comp Sci student and a reasonably competent programmer with a particular interest in games and I've also always had a bit of a creative streak. So I can come up with concepts for small game dev projects, I can create stories for them and program them with reasonable efficiency. I'm also a musician with a fair amount of experience in composition and arrangement, so there's no problem there, either. Trouble is, no matter how creative my vision, when it comes to drawing and animation, I'm completely hopeless.

Does anyone have any advice on how to begin, with a view to being able to produce things like backdrops and sprites from scratch? I've Googled around but I'm struggling to find anything to get me on the right track. How do you deal with the aspects of your game development projects that you lack proficiency in? Do you find things in the public domain? Find someone to help you? I'm just thinking it would be nice to work on a project where absolutely everything - from the game engine to the artwork - is of my own creation.

Any advice appreciated.