Sprint 3 just ended for our FYPs (Final Year Project) so I figured I’d talk a little about my main focus for this sprint. Main Menu Img

My initial goal was to have all my Scene objects loading from xml files. While I didn’t get to fully complete this goal before the deadline, I did get pretty close: close enough to complete it before Sprint 4 starts. As it stands, I have the SceneProxy written to allow lazy loading of the Scenes themselves from xml files, but the class can’t be used with my SceneManager until I have Menu scenes loading from xml (currently I only have Level scenes loading from xml).

Level One Img

I have 3 layers of xml loading in my game now. Layers might not be a great word for it but it helps to explain how it works. The first layer is the Level constructor; It takes a tinyXML2::XMLElement*, “<Level>” surprise surprise, and initializes its members from the tag’s body. It’s simple and straightforward until you get to the <Units> tag, whose body is filled with <Unit type="xyz"> tags. Each <Unit> tag denotes a single Pawn (Minion or Hero) to populate the level with. A UnitFactory takes the type attribute and returns the created Pawn.

The UnitFactory is where the second layer becomes involved. The type attribute of each <Unit> denotes the file name for the unit definitions (minus the extension). The factory opens the corresponding file and passes the first xml element to the Minion or Hero constructor. Within the root element are is the <Pawn> element, and inside that is the <Actor> element, which in turn contains the <Collidable> element. Each of these are passed to the corresponding constructor, which initializes its member variables and passes the base class tag to base constructor.

<!-- filename: levelOne.lvl -->
<Level id="1">
  <Lives>3</Lives>
	<Background>./res/img/bg.png</Background>
	<TerrainData>./res/img/terrain.bmp</TerrainData>
  <Music volume="50">./res/mus/level.ogg</Music>
  <StartingMoney>300</StartingMoney>
  <NextLevel>LevelTwo</NextLevel>
  <Path>	<!-- nodes that enemies will follow through level -->
		<Node>
			<X>51</X>
			<Y>140</Y>
			<Radius>50</Radius>
		</Node>
         .
         .
         .
    </Path>

    <Units>	<!-- every unit in the level, including PC -->
        .
        .
        .
       <!-- type attribute gets picked up by UnitFactory -->
        <Unit type="basic_enemy">
          <X>100</X>
          <Y>300</Y>
        </Unit>
        <Unit type="fast_enemy">
          <X>50</X>
          <Y>50</Y>
        </Unit>
	    <Unit type="hero">
          <X>500</X>
          <Y>400</Y>
	    </Unit>
    </Units>

The third layer comes into play in the Actor class. The <Actor> xml tag contains none or more <Animation> tags. I have written a specialized template for my ResourceManager to work with thor::FrameAnimations, so the ResourceManager can load each unique animation once and each Actor can hold references to the ones it needs (inside its thor::Animator).

<!-- filename: hero.def -->
<Hero name="hero">
  <HealthRegen rate="100">1</HealthRegen>
  <Pawn>
    <Faction>PLAYER</Faction>
    <Health>100</Health>
    <Armour>0.50</Armour>
    <MagicResist>0.25</MagicResist>
    <DamageType>PHYSICAL</DamageType>
    <AttackRange>60</AttackRange>
    <AttackDamage>10</AttackDamage>
    <AttacksPerSecond>1.5</AttacksPerSecond>
    <MovementSpeed>150</MovementSpeed>


    <Actor>
      <!-- Texture path, this will be the texture's key in the ResourceManager -->
      <Texture>././res/img/hero.png</Texture>
      <Animation path="././res/xml/hero_run.anim">
        <!-- Friendly name, local to each Actor -->
        <Name>walk</Name>
        <!-- Duration of animation in seconds -->
        <Duration>0.6f</Duration>
      </Animation>
      .
      .
      .

      <Origin x="25.f" y="50.f"/>

      <!--
      Used to check for collisions.
      Options for type are "Circle" and "Convex";
      Circle requires a radius, whereas Convex requires the x, y and index of each point.
      -->
      <Collidable pointCount="6" type="Circle">
        <Offset x="-2.5f" y="-5.f"/>
        <Radius>25.f</Radius>
      </Collidable>
    </Actor>
  </Pawn>
</Hero>

Level One Img