]> git.localhorst.tv Git - l2e.git/commitdiff
store complete entity in hero
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 7 Oct 2012 19:02:25 +0000 (21:02 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 7 Oct 2012 19:02:25 +0000 (21:02 +0200)
src/common/Hero.cpp
src/common/Hero.h
src/main.cpp
src/map/Entity.cpp
src/map/Entity.h
test-data/test.l2s

index 98b92ca2fdafbbef48bad6fa86216060b380bc75..1d276e5117aa1e230200607230c9cbb60d0cfccd 100644 (file)
@@ -35,9 +35,7 @@ Hero::Hero()
 , battleSprite(0)
 , meleeAnimation(0)
 , attackAnimation(0)
-, spellAnimation(0)
-
-, mapSprite(0) {
+, spellAnimation(0) {
 
 }
 
@@ -61,6 +59,7 @@ void Hero::CreateTypeDescription() {
        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"));
@@ -87,7 +86,7 @@ void Hero::CreateTypeDescription() {
        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) {
index d78d14958f37344de310847c8be5f3145cb073e9..caa8f4dba2a5e71c1074c0be28021c6f1a3d3aea 100644 (file)
@@ -11,6 +11,7 @@
 #include "fwd.h"
 #include "Stats.h"
 #include "../graphics/fwd.h"
+#include "../map/Entity.h"
 
 #include <vector>
 
@@ -72,7 +73,8 @@ public:
        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 *);
@@ -114,7 +116,7 @@ private:
        graphics::Animation *attackAnimation;
        graphics::Animation *spellAnimation;
 
-       graphics::Sprite *mapSprite;
+       map::Entity mapEntity;
 
 };
 
index ff49b66bb578b11a9536fb476abcb7b868d6b75d..5be8305346ab493da8d7abba6d1af8e6e7336f29 100644 (file)
@@ -127,6 +127,7 @@ int main(int argc, char **argv) {
                Sprite::CreateTypeDescription();
                Stats::CreateTypeDescription();
                common::TargetingMode::CreateTypeDescription();
+               Entity::CreateTypeDescription();
 
                Arguments args;
                args.Read(argc, argv);
@@ -509,35 +510,19 @@ int main(int argc, char **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);
@@ -566,7 +551,7 @@ int main(int argc, char **argv) {
                } else {
                        MapState *mapState(new MapState(&map1));
 
-                       mapState->ControlEntity(&mapMaxim);
+                       mapState->ControlEntity(&gameState.heroes[0].MapEntity());
                        mapState->SetWalkingSpeed(walkSpeed);
                        mapMonster.StartAnimation(*mapState);
 
index 610e58551510a556db8c6045db23ae9de81ddc15..e1f970bea644103be655e27a094ffa478c4a3169 100644 (file)
@@ -7,7 +7,11 @@
 
 #include "Entity.h"
 
+#include "../loader/TypeDescription.h"
+
 using geometry::Vector;
+using loader::FieldDescription;
+using loader::TypeDescription;
 
 namespace map {
 
@@ -109,4 +113,29 @@ void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
        }
 }
 
+
+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);
+}
+
 }
index 872ad0c92ed739ea1e714da24b132d1870223e3d..3ddc9ccef49f5340680882be332ae216cbb1c259 100644 (file)
@@ -41,8 +41,8 @@ public:
        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);
@@ -72,6 +72,10 @@ public:
 
        void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
 
+       static void CreateTypeDescription();
+       static void Construct(void *);
+       static void Load(void *);
+
 private:
        void UpdateVelocity();
 
@@ -79,7 +83,7 @@ private:
        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;
index 2576b3cfb57383d62a16c82c1ea9ba52080a94ac..4a4bb059b16dc9de5e1d57922bad2d2224354121 100644 (file)
@@ -70,15 +70,10 @@ Sprite maximSprite {
        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,
@@ -146,6 +141,17 @@ export Hero maxim {
                },
                frametime: twoFramesTime,
                framecount: 4
+       },
+       mapEntity: Entity {
+               animation: SimpleAnimation{
+                       sprite: Sprite {
+                               image: :"maxim-map.png",
+                               size: <32,64>
+                       },
+                       frametime: 120,
+                       framecount: 2
+               },
+               spriteOffset: <0,-32>
        }
 }
 
@@ -153,15 +159,10 @@ Sprite selanSprite {
        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,
@@ -223,6 +224,17 @@ export Hero selan {
                },
                frametime: twoFramesTime,
                framecount: 4
+       },
+       mapEntity: Entity {
+               animation: SimpleAnimation{
+                       sprite: Sprite {
+                               image: :"selan-map.png",
+                               size: <32,64>
+                       },
+                       frametime: 120,
+                       framecount: 2
+               },
+               spriteOffset: <0,-32>
        }
 }
 
@@ -230,15 +242,10 @@ Sprite guySprite {
        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,
@@ -282,6 +289,17 @@ export Hero guy {
                },
                frametime: fourFramesTime,
                framecount: 4
+       },
+       mapEntity: Entity {
+               animation: SimpleAnimation{
+                       sprite: Sprite {
+                               image: :"guy-map.png",
+                               size: <32,64>
+                       },
+                       frametime: 120,
+                       framecount: 2
+               },
+               spriteOffset: <0,-32>
        }
 }
 
@@ -289,15 +307,10 @@ Sprite dekarSprite {
        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,
@@ -360,6 +373,17 @@ export Hero dekar {
                },
                frametime: twoFramesTime,
                framecount: 4
+       },
+       mapEntity: Entity {
+               animation: SimpleAnimation{
+                       sprite: Sprite {
+                               image: :"dekar-map.png",
+                               size: <32,64>
+                       },
+                       frametime: 120,
+                       framecount: 2
+               },
+               spriteOffset: <0,-32>
        }
 }