<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Game Entities and Representing Objects in a Game</title>
	<atom:link href="http://cheezeworld.com/game-entities/feed/" rel="self" type="application/rss+xml" />
	<link>http://cheezeworld.com/game-entities/</link>
	<description>The Cheeze to Your Macaroni - Games, Open Source Programming, and Other Odd Ramblings.</description>
	<lastBuildDate>Sun, 27 Feb 2011 05:06:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Sidar</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-4616</link>
		<dc:creator>Sidar</dc:creator>
		<pubDate>Wed, 29 Jul 2009 00:24:13 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-4616</guid>
		<description>Hi,

When i open the example from googleCode. I see actually brackets with codes.
However here they are left out.

Im typing all this stuff over for learning purposes, so I&#039;m confused right now.

I did i missed something i should have read?

greetings,
Sidar</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>When i open the example from googleCode. I see actually brackets with codes.<br />
However here they are left out.</p>
<p>Im typing all this stuff over for learning purposes, so I&#8217;m confused right now.</p>
<p>I did i missed something i should have read?</p>
<p>greetings,<br />
Sidar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Visual Harmonics &#187; Post Topic &#187; Composition over Inheritance in Game Entities</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-481</link>
		<dc:creator>Visual Harmonics &#187; Post Topic &#187; Composition over Inheritance in Game Entities</dc:creator>
		<pubDate>Wed, 11 Feb 2009 17:33:54 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-481</guid>
		<description>[...] just answered a question on another blog, which I thought was worth reposting on it&#8217;s own [...]</description>
		<content:encoded><![CDATA[<p>[...] just answered a question on another blog, which I thought was worth reposting on it&#8217;s own [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Wiggill</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-480</link>
		<dc:creator>Nick Wiggill</dc:creator>
		<pubDate>Wed, 11 Feb 2009 17:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-480</guid>
		<description>Hmm, incomplete edit on that last post, where I said:

&quot;So say you have two different methods of collision detection. One is for objects moving along a straight path, and one is for objects moving along a sinusoid.&quot;

...I had meant to say:

&quot;So say you have two different methods of collision detection. One is for circular objects, and one is for concave polygon objects.&quot;</description>
		<content:encoded><![CDATA[<p>Hmm, incomplete edit on that last post, where I said:</p>
<p>&#8220;So say you have two different methods of collision detection. One is for objects moving along a straight path, and one is for objects moving along a sinusoid.&#8221;</p>
<p>&#8230;I had meant to say:</p>
<p>&#8220;So say you have two different methods of collision detection. One is for circular objects, and one is for concave polygon objects.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Wiggill</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-479</link>
		<dc:creator>Nick Wiggill</dc:creator>
		<pubDate>Wed, 11 Feb 2009 17:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-479</guid>
		<description>Iain,

Very good question. In response:

1. &quot;Favour composition over inheritance.&quot;
2. &quot;Build to interfaces, not implementations.&quot;

1. We make use of the &quot;Single Responsibility Principle&quot;: A class (and thus it&#039;s instances) has one and only one responsibility. So you create a class Collidable that deals solely with collision detection, and you create a class Living that contains functionality solely pertinent to measuring life remaining. Now you create a third class which is the Entity, and at runtime it instantiates Collidable and Living, and holds references to them. It calls them at the appropriate times to deal with the appropriate logic. So you can see that we are *composing* the object, rather than deriving it&#039;s functionality through inheritance.

2. Interfaces describe the *services which a class provides*, rather than how you implement those services. So say you have two different methods of collision detection. One is for objects moving along a straight path, and one is for objects moving along a sinusoid.
So, let&#039;s say you implement an interface ICollidable (from which your class Collidable will extend) which accurately describes the services a &quot;collision-detectable object&quot; would expose, eg. &quot;checkMyCollisionWith(someOtherObject)&quot;. You can now split your Collidable implementation into two: One that manages collisions for object which need only simple collision detection, and another for objects which require more advanced collision detection (eg. for concave polygons). 

This is useful because it means that, at runtime, you can dynamically decide how to compose your object... rather than using inheritance, because inheritance leads to an inflexible hierarchy, as you have realised. This is particularly true in ActionScript, because multiple inheritance is not supported. So you can use the same skeleton, Entity, for all your entities, but you can dynamically decide how to create each individual one according to it&#039;s type, eg. player, AI-controlled, static objects, etc.

DISCLAIMER: The Gang of Four (Gamma, Helm, Johnson, Vlissides) claimed that one should always &quot;Favour composition over inheritance&quot;, but this is not quite true, and they later admitted as much. There are many cases (this article is a perfect example) where it is 100% the best way to go. But in many cases, inheritance is a lot more logical. Example: I&#039;ve recently built a pseudo-3D rendering engine. At each step down the inheritance chain I have extended the functionality a little bit more. So I start out with an abstract renderer, I extend it to a 2d (flat) renderer, and then extend it further to my pseudo3D (perspective-based) renderer. This works because there is no branching of the inheritance chain -- just three different classes, each of which does a little more than it&#039;s parent class.

Best regards,

-Nick</description>
		<content:encoded><![CDATA[<p>Iain,</p>
<p>Very good question. In response:</p>
<p>1. &#8220;Favour composition over inheritance.&#8221;<br />
2. &#8220;Build to interfaces, not implementations.&#8221;</p>
<p>1. We make use of the &#8220;Single Responsibility Principle&#8221;: A class (and thus it&#8217;s instances) has one and only one responsibility. So you create a class Collidable that deals solely with collision detection, and you create a class Living that contains functionality solely pertinent to measuring life remaining. Now you create a third class which is the Entity, and at runtime it instantiates Collidable and Living, and holds references to them. It calls them at the appropriate times to deal with the appropriate logic. So you can see that we are *composing* the object, rather than deriving it&#8217;s functionality through inheritance.</p>
<p>2. Interfaces describe the *services which a class provides*, rather than how you implement those services. So say you have two different methods of collision detection. One is for objects moving along a straight path, and one is for objects moving along a sinusoid.<br />
So, let&#8217;s say you implement an interface ICollidable (from which your class Collidable will extend) which accurately describes the services a &#8220;collision-detectable object&#8221; would expose, eg. &#8220;checkMyCollisionWith(someOtherObject)&#8221;. You can now split your Collidable implementation into two: One that manages collisions for object which need only simple collision detection, and another for objects which require more advanced collision detection (eg. for concave polygons). </p>
<p>This is useful because it means that, at runtime, you can dynamically decide how to compose your object&#8230; rather than using inheritance, because inheritance leads to an inflexible hierarchy, as you have realised. This is particularly true in ActionScript, because multiple inheritance is not supported. So you can use the same skeleton, Entity, for all your entities, but you can dynamically decide how to create each individual one according to it&#8217;s type, eg. player, AI-controlled, static objects, etc.</p>
<p>DISCLAIMER: The Gang of Four (Gamma, Helm, Johnson, Vlissides) claimed that one should always &#8220;Favour composition over inheritance&#8221;, but this is not quite true, and they later admitted as much. There are many cases (this article is a perfect example) where it is 100% the best way to go. But in many cases, inheritance is a lot more logical. Example: I&#8217;ve recently built a pseudo-3D rendering engine. At each step down the inheritance chain I have extended the functionality a little bit more. So I start out with an abstract renderer, I extend it to a 2d (flat) renderer, and then extend it further to my pseudo3D (perspective-based) renderer. This works because there is no branching of the inheritance chain &#8212; just three different classes, each of which does a little more than it&#8217;s parent class.</p>
<p>Best regards,</p>
<p>-Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colby Cheeze</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-439</link>
		<dc:creator>Colby Cheeze</dc:creator>
		<pubDate>Thu, 29 Jan 2009 15:48:16 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-439</guid>
		<description>Well, if you are creating some sort of unit that will have health and other properties...and will need the behaviors of the MovingEntity then you simply extend the MovingEntity. So here is a short example of a Unit that might be used in an adventure or RPG type game, ( and btw, I&#039;ll be getting around to a post about this stuff soon in any case. )


public class Unit extends MovingEntity
{
    public var maxHealth:Number;
    public var health:Number;
    public var maxMana:Number;
    public var mana:Number;
    public var attackPower:Number;    
    
    public function Unit( a_params:UnitParams ) : void
    {
         health = maxHealth = a_params.maxHealth;
        _mana = maxMana = a_params.maxMana;
         attackPower = a_params.attackPower;
         m_armorType = a_params.armorType;
         m_armorTable = a_params.armorTable;
    }
    public function doDamage( a_value:Number ) : void
    {
        health -= a_value * m_armorTable[ armorType ];
    }

    private var m_armorType:String;
    private var m_armorTable:Dictionary;
}


So now you can use the health properties etc of Unit, and still do the movement of it such as unit.x += SOME_NUMBER;</description>
		<content:encoded><![CDATA[<p>Well, if you are creating some sort of unit that will have health and other properties&#8230;and will need the behaviors of the MovingEntity then you simply extend the MovingEntity. So here is a short example of a Unit that might be used in an adventure or RPG type game, ( and btw, I&#8217;ll be getting around to a post about this stuff soon in any case. )</p>
<p>public class Unit extends MovingEntity<br />
{<br />
    public var maxHealth:Number;<br />
    public var health:Number;<br />
    public var maxMana:Number;<br />
    public var mana:Number;<br />
    public var attackPower:Number;    </p>
<p>    public function Unit( a_params:UnitParams ) : void<br />
    {<br />
         health = maxHealth = a_params.maxHealth;<br />
        _mana = maxMana = a_params.maxMana;<br />
         attackPower = a_params.attackPower;<br />
         m_armorType = a_params.armorType;<br />
         m_armorTable = a_params.armorTable;<br />
    }<br />
    public function doDamage( a_value:Number ) : void<br />
    {<br />
        health -= a_value * m_armorTable[ armorType ];<br />
    }</p>
<p>    private var m_armorType:String;<br />
    private var m_armorTable:Dictionary;<br />
}</p>
<p>So now you can use the health properties etc of Unit, and still do the movement of it such as unit.x += SOME_NUMBER;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iain</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-438</link>
		<dc:creator>Iain</dc:creator>
		<pubDate>Thu, 29 Jan 2009 14:33:31 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-438</guid>
		<description>How do you get around the fact that an object might be, say, both a &quot;moving object&quot; with speed and position and a &quot;killable object&quot; with health and armour, without having one extend the other, so that they can be used separately? Just an example of course, in practice you&#039;d never really want something killable that can&#039;t move. Flash doesn&#039;t have multiple inheritance, so I&#039;ve thought about making a &quot;movable&quot; behaviour object that is owned by an entity and is responsible for the entity&#039;s position, and a &quot;killable&quot; behaviour object that controls health etc. Any thoughts?</description>
		<content:encoded><![CDATA[<p>How do you get around the fact that an object might be, say, both a &#8220;moving object&#8221; with speed and position and a &#8220;killable object&#8221; with health and armour, without having one extend the other, so that they can be used separately? Just an example of course, in practice you&#8217;d never really want something killable that can&#8217;t move. Flash doesn&#8217;t have multiple inheritance, so I&#8217;ve thought about making a &#8220;movable&#8221; behaviour object that is owned by an entity and is responsible for the entity&#8217;s position, and a &#8220;killable&#8221; behaviour object that controls health etc. Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colby Cheeze</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-386</link>
		<dc:creator>Colby Cheeze</dc:creator>
		<pubDate>Fri, 02 Jan 2009 12:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-386</guid>
		<description>If you have questions, send them my way.</description>
		<content:encoded><![CDATA[<p>If you have questions, send them my way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: poze nunti</title>
		<link>http://cheezeworld.com/game-entities/comment-page-1/#comment-385</link>
		<dc:creator>poze nunti</dc:creator>
		<pubDate>Fri, 02 Jan 2009 12:14:20 +0000</pubDate>
		<guid isPermaLink="false">http://cheezeworld.com/?p=108#comment-385</guid>
		<description>Funny blue ball..
I might need some help in the future, are you available for some work ?</description>
		<content:encoded><![CDATA[<p>Funny blue ball..<br />
I might need some help in the future, are you available for some work ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

