Entities ahoy!

Filed under Game development by Jussi Lepistö

Entity system

Today I’ve continued work under the hood, on the entity system. Both components and entity types are now loaded using the plugin / entry point system of setuptools, which means custom components and units will be really easy to create and distribute. And much easier for me to load. :) I have a habit of making too many sweeping changes to code at once, and this is no exception. On the other hand, this does result in massive improvements to the entity system and especially creation of entity type files, so it’s all for the greater good.

No screenshots to show for my efforts, but see the end of the post for examples of what entity type files currently look like. This might change before these changes are completed.

Entity editor

I’ll probably have to start working on an entity editor at some point, since I recon unit and other entity creation will get quite complicated when multiple linked entities, collision shapes, etc. etc. get involved. I’m no big fan of GUI programming, especially since Python’s GUI libraries all seem kind of shoddy (though that seems to apply to other languages too, at least C# and Java). Anyway, I’ll probably use wxPython for it. Making it in-game would be cool, but too much effort at the moment.

Trac

I tried installing Trac (again) today since they just released version 0.11, and couldn’t get it working (again). After getting over a few hurdles, I was finally stumped when trac-admin hanged while trying to create the environment. Every time. I really want to like Trac, since it’s excellent when it works, but I’ve had nothing but problems trying to get it working myself. It seems I’ll have to let it go and find some other issue tracker when I really start needing one. I’d like it to integrate with Mylyn, but the (free) options there are a bit limited. We’ll see…

Entity types files

Here’s what a unit type file currently looks like. The interface for this is not fully implemented yet, but I hope I’ll get that finished during this weekend.

from artillerybrawl import component, entity
from artillerybrawl.entity import Entity
 
Unit = entity.get_class("unit")
 
class Howitzer(Unit):
    name = "howitzer"
 
    def __init__(self):
        Unit.__init__(self)
 
        self.mass = None
        self.material = None
        self.hitpoints = None
        self.resistances = None
 
        # Body
        self.body_width = None
        self.body_height = None
        self.body_texture = None
 
        self.collision_meshes = None
 
        # Turret
        self.turret_offset = None
 
        self.turret_width = None
        self.turret_height = None
        self.turret_texture = None
 
        self.turret_min_angle = None
        self.turret_max_angle = None
        self.turret_max_power = None
 
    def create(self):
        entity = Unit.create(self)
 
        # Body
        body_sprite = component.create("sprite", self.body_width,
                                       self.body_height, self.body_texture)
        body_physics = component.create("physics", self.mass,
                                         self.collision_meshes, self.material)
        body_damage = component.create("damage", self.hitpoints)
 
        body = Entity(self.name, (body_sprite, body_physics, body_damage))
 
        # Turret
        turret_transform = component.create("transform", parent=body)
        turret_sprite = component.create("sprite", self.turret_width,
                                  self.turret_height, self.turret_texture)
        turret_component = component.create("turret", self.turret_min_angle,
            self.turret_max_angle, self.turret_max_power)
 
        turret = Entity("%s_turret" % self.name,
                        (turret_transform, turret_sprite, turret_component))
 
        return body

And an actual unit base on the unit type above.

from artillerybrawl import entity
 
Howitzer = entity.get_class("howitzer")
 
class A1(Howitzer):
    name = "A1"
 
    def __init__(self):
        Howitzer.__init__(self)
 
        self.mass = 1000.0
        self.material = "metal"
 
        self.hitpoints = 100
        self.resistances = {
            "kinetic": 50.0,
        }
 
        # Body
        self.body_width = 5.0
        self.body_height = 2.5
        self.body_texture = "a1"
 
        self.collision_meshes = [
            [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0), (1.0, 0.0)],
            [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0), (1.0, 0.0)],
        ]
 
        # Turret
        self.turret_offset = (2.5, 2.5)
 
        self.turret_width = 5.0
        self.turret_height = 1.0
        self.turret_texture = "a1_turret"
 
        self.turret_min_angle = -5.0
        self.turret_max_angle = 85.0
        self.turret_max_power = 100.0

Comments Off

Comments are closed.