Entity Systems have fascinated me for a while, the idea of being able to effectively turn anything into anything else with a few removals and additions of components makes me happy. My knowledge on the Entity System and it’s pros and cons is somewhat limited. So if you want to find out more read these posts (from far more knowledgable others) :
This Guy Knows Lots
My intention is to experiment with the combination of ecs and pyglet to create a basic Asteroids type game, and I hope to document the process for others interested in following the same path.
PART 1: Small Beginnings – Introduces the Renderable and Transform components.
PART 2: Flying Around – Introduces the Physics and Player components.
PART 3: Crashing Into Things – Introduces the Bounds component.
I decided to enter the Ludum Dare game jam this december – it’s something I’ve been wanting to do for a while, but never quite managed to make the time. The winning theme was a real difficult challenge for me, because it wasn’t really a theme, it was a technical constraint (at best). I chose Unity as my development tool, I had only begun learning unity a few weeks before so I wasn’t going to achieve anything too exotic.
After two false starts and most of Saturday daytime wasted I decided to throw away everything I had so far and start again! This happened to be the best idea I’d had, My idea was to create a simple enough match-3 game in 3D. Matches can be made by switching your cube with neighbouring cubes, and the entire cube can be rotated to match cubes on other sides.
The feedback I received was incredibly useful and really helped to solidify the weak spots for me. I wasn’t expecting much from the voting results when I entered, however I managed to get into the top #100 in the Innovation category!
Ludum Dare Entry Page – Game and source code available.
I would like to take this further and give it better win/lose conditions, audio and visuals, as I feel the underlying game idea was fairly enjoyable.
Inspired by the transport tycoon type game, the complete specifics are still being debated, but effectively I’m aiming for managing a space company, with the possibility to focus on different avenues.
Pure trader – Move goods around, buy low, sell high. Don’t forget to factor in transport costs!
Research – fund new research into, mining, manufacturing and design. Then sell these technologies to other companies for royalties and/or lump sums!
Manufacturing – Take raw resources and manufacture them into different products, these products need researching so either research them yourself or buy from another company!
Reconnaissance – explore the unknown, send scout ships to map an area, or send the prospectors to find out what resources lie hidden on the planets. On behalf of your company or others; For a price!
- Generate a Section of a galaxy divided into sectors, each sector is then populated with solar systems and other objects.
- Procedurally craft a small section of a galaxy, down to the resources on a planet (albeit a little abstracted).
- Create an economic simulation that shifts causing supply and demand to change. The effects of competing companies.
I have mainly been working on the rendering and organisation of the differing levels, so far I have achieved:
- Animated Sprites, with customisable “tick” rate.
- Ability to pan.
- Parallax sprites – that when panning move in an offset fashion to normal sprites.
- Selection of objects with mouse.
- Randomly generated “solar systems” and “asteroid fields”, not procedurally done yet.
- Different levels of “view” Galaxy, Sector, Solar System and Planet(or other objects), that allow for more in depth information.
Some development pics
(yayy for programmer art and opengameart.org/):
Sector view, with solar systems and asteroid fields plus debug connections
debug boxes and houses as “planets” and a…. planet…. oh. Planet is my art, rest was opengamart.org acquired
So right now we can give entities images. However, they don’t do anything on screen other than stay very still in the location we put them. To change this we need to give the entities a Physics component this will allow for the entity to update its position.
def __init__(self, vx=0.0, vy=0.0, thrust=100.0, rotate_speed=100.0):
self.vx = vx #the velocity in the x axis
self.vy = vy #the velocity in the y axis
self.thrust = thrust #the amount of force we can apply
self.rotate_speed = rotate_speed #how quickly we can rotate.
We also need to build the accompanying PhysicsSystem, which will require the use of Physics component and the Transform component.
self.drag = 0.4
def update(self, dt):
for entity, phys_comp in self.entity_manager.pairs_for_type(Physics):
#we need our transform component to update the position of the entity
pos_comp= self.entity_manager.component_for_entity(entity, Transform)
#times it by the delta time to get frame rate independent movement.
pos_comp.x += phys_comp.vx * dt
pos_comp.y += phys_comp.vy * dt
#apply drag to velocity.
phys_comp.vx -= phys_comp.vx * self.drag *dt
phys_comp.vy -= phys_comp.vy * self.drag *dt
To get our player to start moving we need to update the entity factory create_player() method and add the system into our SystemsManager. To test the movement system is working we can give our player an initial velocity, it’s a one line addition after the other components
I have completed an MSc in Advanced Computer Science (awaiting results). I love throwing the “Advanced” bit in there all casual-like because I got “upgraded” and it made me feel special. I’m probably not quite worthy of the title, but I have learnt a lot and am enjoying myself so I’ll use it proudly 🙂
My dissertation topic was “AI- Based Crowd Simulation”, and it was an open ended project. The project(or corpus) was worked on by myself and three other students over the course of roughly three months.
I was developed the agent behaviours and the behaviour system that used them. It was written in Java, using the libGDX framework.
Some features of the finished product:
- Basic flocking rules (Reynolds)
- More complex set of behaviours – eg, Panic, Hunger.
- Multi Species
- Customisable behaviour for a species
- Evolution of behaviour from an Evolutionary Algorithm
- Initial simulation setup
- Ability to place new animals and objects once simulation has begun.
highlighted are the animals in the same family group, all are the same species in this image.
zoomed in view of a herd of wildebeest changing course to avoid a hyena
You can download a zip of the project here
This is my longest standing project – it’s a long term hobby!
The premise of this was to be a shopkeeper/adventurer, much along the likes of Recettear, however I wanted more of the permanent roguelike elements to make an appearance. So when you lose a fight, you die and that’s it! I also wanted this to cross over into other things, so if you were in debt for too long without making any payments, people would come and begin repossessing your things and even your take the shop. Ideally there would be a couple of routes out of a situation like that – sell up everything and be a full time adventurer?, sign a deal with the thieves and local thugs? Fight off all the guards who come to try and touch your stuff!
The current state of the game is not close to realising this yet, I got quite distracted with generating everything so never really made any progress on making the “game” part, plus it’s been on hiatus whilst working on my masters’ but I will come back around to it eventually.
- Controllable player character
- Dungeons that are visit-able
- Can pick up items
- Player has skills
- Can use some items
- Procedurally (almost) generated a world
- Traders go between cities
- Cities trade with each other and have a supply and demand
- Pathfinding – roads generated with it, and some dumb AI generate and follow paths between cities.
map generated with a few cities and dungeons, and some garish roads connecting some of the cities
The very beginning of dungeon generation. Currently just places rectangles with a chance of touching. Along with a single “connection” (diagonal corridor in this case)
The view of the moisture in the land – this will be used (eventually) for biome calculation
Current (or next) goals:
- Finish biome generation
- Finish dungeon generation
- City/Settlement generation
I am not going to go through the specifics of setting up Python/Pyglet/IDE’s and ecs, but here are the links to all the appropriate sources:
- Python (I’m using 2.7)
- ecs (I used pip to install it, here is an easy install for pip)
- Pyglet I am using the development version (pyglet 1.2 alpha1), and used pip on the command line to install as per instructions on the bottom of their download page.
QuickStart Guide for Pyglet: If you’ve never used Pyglet I would advise looking through this, just to get a feel for how Pyglet works. They can probably explain the basics better than I can!
The IDE I am (experimentally) using is PyCharm, though I have used Aptana Studio standalone, and both do a very good job.
This tutorial is based heavily upon this tutorial, but I have tried to go about extracting the game into components and systems.