, battleSprite(0)
, meleeAnimation(0)
, attackAnimation(0)
-, spellAnimation(0)
-
-, mapSprite(0) {
+, spellAnimation(0) {
}
Hero h;
int animationId(TypeDescription::GetTypeId("Animation"));
+ int entityId(TypeDescription::GetTypeId("Entity"));
int numberId(TypeDescription::GetTypeId("Number"));
int spriteId(TypeDescription::GetTypeId("Sprite"));
int statsId(TypeDescription::GetTypeId("Stats"));
td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true));
td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true));
- td.AddField("mapSprite", FieldDescription(((char *)&h.mapSprite) - ((char *)&h), spriteId, true));
+ td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), entityId, false));
}
void Hero::Construct(void *data) {
#include "fwd.h"
#include "Stats.h"
#include "../graphics/fwd.h"
+#include "../map/Entity.h"
#include <vector>
graphics::Animation *AttackAnimation() { return attackAnimation; }
graphics::Animation *SpellAnimation() { return spellAnimation; }
- graphics::Sprite *MapSprite() { return mapSprite; }
+ map::Entity &MapEntity() { return mapEntity; }
+ const map::Entity &MapEntity() const { return mapEntity; }
static void CreateTypeDescription();
static void Construct(void *);
graphics::Animation *attackAnimation;
graphics::Animation *spellAnimation;
- graphics::Sprite *mapSprite;
+ map::Entity mapEntity;
};
Sprite::CreateTypeDescription();
Stats::CreateTypeDescription();
common::TargetingMode::CreateTypeDescription();
+ Entity::CreateTypeDescription();
Arguments args;
args.Read(argc, argv);
triggers2[0].map = &map1;
triggers2[0].target = Vector<int>(8, 3);
- SimpleAnimation mapMaximAnimation(gameState.heroes[0].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
- Entity mapMaxim;
- mapMaxim.SetAnimation(&mapMaximAnimation);
- mapMaxim.Position() = Vector<float>(64, 128);
- mapMaxim.SpriteOffset() = Vector<float>(0, -32);
-
- SimpleAnimation mapSelanAnimation(gameState.heroes[1].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
- Entity mapSelan;
- mapSelan.SetAnimation(&mapSelanAnimation);
- mapSelan.Position() = Vector<float>(64, 128);
- mapSelan.SpriteOffset() = Vector<float>(0, -32);
- mapSelan.SetFlags(Entity::FLAG_NONBLOCKING);
- mapMaxim.AddFollower(&mapSelan);
-
- SimpleAnimation mapGuyAnimation(gameState.heroes[2].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
- Entity mapGuy;
- mapGuy.SetAnimation(&mapGuyAnimation);
- mapGuy.Position() = Vector<float>(64, 128);
- mapGuy.SpriteOffset() = Vector<float>(0, -32);
- mapGuy.SetFlags(Entity::FLAG_NONBLOCKING);
- mapSelan.AddFollower(&mapGuy);
-
- SimpleAnimation mapDekarAnimation(gameState.heroes[3].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
- Entity mapDekar;
- mapDekar.SetAnimation(&mapDekarAnimation);
- mapDekar.Position() = Vector<float>(64, 128);
- mapDekar.SpriteOffset() = Vector<float>(0, -32);
- mapDekar.SetFlags(Entity::FLAG_NONBLOCKING);
- mapGuy.AddFollower(&mapDekar);
+ gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
+
+ gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
+ gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
+ gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
+
+ gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
+ gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
+ gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
+
+ gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
+ gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
+ gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
SDL_Surface *mapMonsterImg(IMG_Load("test-data/monster-map.png"));
Sprite mapMonsterSprite(mapMonsterImg, 32, 32);
} else {
MapState *mapState(new MapState(&map1));
- mapState->ControlEntity(&mapMaxim);
+ mapState->ControlEntity(&gameState.heroes[0].MapEntity());
mapState->SetWalkingSpeed(walkSpeed);
mapMonster.StartAnimation(*mapState);
#include "Entity.h"
+#include "../loader/TypeDescription.h"
+
using geometry::Vector;
+using loader::FieldDescription;
+using loader::TypeDescription;
namespace map {
}
}
+
+void Entity::CreateTypeDescription() {
+ Entity e;
+
+ int animationId(TypeDescription::GetTypeId("Animation"));
+ int vectorId(TypeDescription::GetTypeId("Vector"));
+
+ TypeDescription &td(TypeDescription::CreateOrGet("Entity"));
+ td.SetConstructor(&Construct);
+ td.SetLoader(&Load);
+ td.SetSize(sizeof(Entity));
+
+ td.AddField("animation", FieldDescription(((char *)&e.animation) - ((char *)&e), animationId, true));
+ td.AddField("spriteOffset", FieldDescription(((char *)&e.spriteOffset) - ((char *)&e), vectorId, false));
+}
+
+void Entity::Construct(void *data) {
+ new (data) Entity;
+}
+
+void Entity::Load(void *data) {
+ Entity *entity(reinterpret_cast<Entity *>(data));
+ entity->runner.ChangeAnimation(entity->animation);
+}
+
}
geometry::Vector<float> &Velocity() { return velocity; }
const geometry::Vector<float> &Velocity() const { return velocity; }
- geometry::Vector<float> &SpriteOffset() { return spriteOffset; }
- const geometry::Vector<float> &SpriteOffset() const { return spriteOffset; }
+ geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
+ const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
void SetAnimation(const graphics::Animation *a);
void StartAnimation(app::Application &ctrl);
void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
+ static void CreateTypeDescription();
+ static void Construct(void *);
+ static void Load(void *);
+
private:
void UpdateVelocity();
Entity *follower;
const graphics::Animation *animation;
graphics::AnimationRunner runner;
- geometry::Vector<float> spriteOffset;
+ geometry::Vector<int> spriteOffset;
geometry::Vector<float> position;
geometry::Vector<float> velocity;
Orientation orientation;
image: :"maxim.png",
size: <64,64>
}
-Sprite maximMapSprite {
- image: :"maxim-map.png",
- size: <32,64>
-}
export Hero maxim {
name: "Maxim",
level: 1,
battleSprite: maximSprite,
- mapSprite: maximMapSprite,
maxHealth: 33,
health: 33,
maxMana: 20,
},
frametime: twoFramesTime,
framecount: 4
+ },
+ mapEntity: Entity {
+ animation: SimpleAnimation{
+ sprite: Sprite {
+ image: :"maxim-map.png",
+ size: <32,64>
+ },
+ frametime: 120,
+ framecount: 2
+ },
+ spriteOffset: <0,-32>
}
}
image: :"selan.png",
size: <64,64>
}
-Sprite selanMapSprite {
- image: :"selan-map.png",
- size: <32,64>
-}
export Hero selan {
name: "Selan",
level: 1,
battleSprite: selanSprite,
- mapSprite: selanMapSprite,
maxHealth: 28,
health: 28,
maxMana: 23,
},
frametime: twoFramesTime,
framecount: 4
+ },
+ mapEntity: Entity {
+ animation: SimpleAnimation{
+ sprite: Sprite {
+ image: :"selan-map.png",
+ size: <32,64>
+ },
+ frametime: 120,
+ framecount: 2
+ },
+ spriteOffset: <0,-32>
}
}
image: :"guy.png",
size: <64,64>
}
-Sprite guyMapSprite {
- image: :"guy-map.png",
- size: <32,64>
-}
export Hero guy {
name: "Guy",
level: 1,
battleSprite: guySprite,
- mapSprite: guyMapSprite,
maxHealth: 38,
health: 38,
maxMana: 0,
},
frametime: fourFramesTime,
framecount: 4
+ },
+ mapEntity: Entity {
+ animation: SimpleAnimation{
+ sprite: Sprite {
+ image: :"guy-map.png",
+ size: <32,64>
+ },
+ frametime: 120,
+ framecount: 2
+ },
+ spriteOffset: <0,-32>
}
}
image: :"dekar.png",
size: <64,64>
}
-Sprite dekarMapSprite {
- image: :"dekar-map.png",
- size: <32,64>
-}
export Hero dekar {
name: "Dekar",
level: 1,
battleSprite: dekarSprite,
- mapSprite: dekarMapSprite,
maxHealth: 38,
health: 38,
maxMana: 0,
},
frametime: twoFramesTime,
framecount: 4
+ },
+ mapEntity: Entity {
+ animation: SimpleAnimation{
+ sprite: Sprite {
+ image: :"dekar-map.png",
+ size: <32,64>
+ },
+ frametime: 120,
+ framecount: 2
+ },
+ spriteOffset: <0,-32>
}
}