BitBlt

RSS

Game Objects or Entity Systems

To start, I intentionally left out “component” from Entity Systems. They add an extra layer of indirection which will probably make this post more bias towards Entity Systems. While I like the fact that components allow you to abstract objects more easily and to allow you to customize entities without needing to open up a code editor, I dislike not having a concrete class that I can play with.

One of the biggest problems I face is that I have to have my tools work for me and not against me. This often leads to times where I completely refactor my game engine for what seems to be no apparent reason other than I didn’t like the way something worked. Generally these issues would appear minor to most people, but for me they are huge.

This almost always leads to sideways progression instead of forward progression. An example of this recently is that my current engine uses a sort of Unity GameObject system. All game objects can have children and scripts attached to them and has the same style event system unity has (all though mine is almost as fast as a straight function call, we’ll save that for another day). While this approach works, I don’t like creating manager classes that you attach to the root game object and then have to pull them out in scripts with something like “var bulletManager = rootObject.getScript<BulletManager>()”.

Just relying on GameObjects and scripts seems clunky to me and this is where I feel Entity Systems shine (and why I added it to my current game engine). My MC clone actually uses this for both client and server. I really liked the way things are split up in to units of work (but kept together). On one hand I like to define an entity’s structure (data) in a single class and have systems interact with that data. On the other hand, its nice to just be able to attach a script to a single object and watch it work.

Both of these examples work in my game engine today. I wonder which one people would prefer…


Entity System

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
	public interface IPositionable
	{
		Vector2 position { get; set; }
	}

	public interface IVelocity
	{
		Vector2 velocity { get; set; }
	}

	public class MovableEntity : IPositionable, IVelocity
	{
		public position { get;set; }
		public velocity { get;set; }	
	}

	public class VelocitySystem : System
	{
		public void init()
		{
			require<IPositionable, IVelocity>( (pc, vc) => 
			{
				pc.value += vc.value; 
			});
		}

		public void update()
		{
			//call the helper function from require on each entity
			base.processEntities(); 
		}
	}


	//init game

	Root.instance.addSystem(new VelocitySystem());
	Root.instance.createEntity(new MoveableEntity());


GameObjects and Scripts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

	public class TrasnformScript : Script
	{
		public Vector2 value;
	}

	public class VelocityScript : Script
	{
		public Vector2 value;
	}

	public MovementScript : Script
	{
		private TransformScript transform;
		private VelocityScript velocity;

		private void init()
		{
			transform = gameObject.getScript<TrasnformScript>();
			velocity = gameObject.getScript<VelocityScript>();
		}	

		private void fixedupdate()
		{
			transform.value += velocity.value;	
		}	
	}


	//init game
	var go = rootObject.createChild("movableEntity");
	go.createScript<TransformScript>();
	go.createScript<VelocityScript>();
	go.createScript<MovementScript>();
Nov 7

Worked a lot on the random generation system along with making parallax scripts and sprite quad trees. Currently the sectors are small but I may increase their size by a good bit.

This checks off 2 things on my list and there is a bonus minimap feature!

Nov 4

So here is a short update with whats been accomplished. I tried to spend some time making the overall game look better.

  • Scrolling Text
  • Lasers
  • Planet Spawner
  • Sun
  • Engine Particles

Here is what I want to work on next.

  • Add more parallax layers
  • Add shields, armor and hull systems
  • Allow asteroids to be destroyed
  • More space debris
  • Turret guns with their own tracking

Live Coding

Live game coding on twitch tonight at 6PM EST. Please let people know!

I plan to incorporate enemy spawning, AI and possibly an experience/level system to the player. You can ask me any questions during the broadcast and I will try to answer them all. I will also listen to any ideas you may have and add them in to the game if they fit.

Simple demonstration of the particle emitter. I should put together a small clip of me abusing the emitter.

Particle Emitter

Well YouTube decided it needs over an hour to process my 30 second video. I was going to make this all one post, but I decided to just through out the code snippet that goes with it.

The original particle effect code just created new game objects per particle and added scripts to each one to control its velocity and duration. This inevitably will cause serious performance issues along with a ton of GC overhead.

The solution is to write a script (my game engine sorta mimics unity3d) to manage all the particles. Each object can now have a particle emitter attached to it and has a decent amount of configuration options.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    public class Enemy : Script
    {
        private int health = 150;
        private int maxHealth = 150;
        private ParticleEmitter particles;

        private void init()
        {
            particles = gameObject.
                createScript<ParticleEmitter>();

            particles.MinEnergy = 0.25f;
            particles.MaxEnergy = 0.5f;
            particles.MaxSize = 1f;
            particles.MinSize = 0.5f;
            particles.EndSizeScale = 0.5f; 
            particles.MinRotationSpeed = 0.1f;
            particles.MaxRotationSpeed = 0.2f;
            particles.StartColor = Color.Red;
            particles.EndColor = Color.Yellow;
            particles.RandomVelocity = 1f;
            particles.Velocity = 1;

            var file = "content/textures/streak.png";
            var material = resources.
                createMaterialFromTexture(file);

            material.SetBlendState(BlendState.Additive);

            particles.material = material;

        }

        private void render()
        {
            //draw the health bar
            var g = Root.instance.graphics;
            var p = transform.DerivedPosition;
            var s = new Vector2(p.X - 50, p.Y);
            var e = new Vector2(p.X + 50, p.Y);
            var l = (float)health / (float)maxHealth;

            var bg = AxisAlignedBox.
                FromRect(s.X, s.Y - 3, 50, 4);
            var fg = AxisAlignedBox.
                FromRect(s.X, s.Y - 3, 50 * l, 4);

            g.Draw(null, bg, Color.White);
            g.Draw(null, fg, Color.Red);

        }
     
        private void takedamage()
        {
            health--;

            if (health <= 0)
            {
                gameObject.destroy();
                //add explosion effect back in
            }
            else
            {
                particles.emitParticles(20, 50, 0.1f);
            }
        }
    }

Space shooter prototype, I will probably host a live code session on this at some point in the week.

Who am I?

This blog is here to follow my progress of day to day life as a wanna-be indie game developer. Please follow me in my journey to success or failure!

I started programming around the age of 15, or maybe even younger. QBasic was probably my first language, and I moved in to VB6 not long after that. I continued with VB6 all the way until .NET 2.0 (skipped 1.X) and transitioned in to VB.NET. During this time I played with things like ASM (z80), x86 (NASM), and PCBs.

After some time, I became discouraged with the countless examples in C# and the fact that VB developers never seemed to use option explicit and strict. One day I sat down and said it was time to move to C# and I believe it was even game related. I remember specifically looking over someones Vector3.cs class (perhaps Axiom3d?) and looking at how much cleaner the code was to read than VB (personal preference, don’t hate me).

Some of the countless projects I have messed with range from z80 controllers, to MajorMud editors, a MineCraft clone, GameEngines sitting on Axiom3d and one also running on MonoGame and several game projects that will almost assuredly never see the light of day. One of my biggest problems is that I like to tinker and to see how game mechanics were implemented (see MineCraft clone). I also have a bad habit of just getting an idea in my head and wanting to code it for awhile to see where it takes me.

This has all inevitably lead up to this blog. I’m ready to take the next step. I want to become a serious Indie Game Developer. I’d like to specifically thank Vlambeer for motivating me to take this first step. They have some great videos up on youtube from conferences that they have done and some of them showcase their inner workings and thought processes.