From c6156f6b3dc88a97a78694a2652dfbc874fcc8e4 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 19 Aug 2012 21:51:56 +0200 Subject: [PATCH] added monster's attack animation --- src/battle/Monster.h | 21 ++++++++++++++++++--- src/main.cpp | 9 +++++++-- test-data/monster.png | Bin 971 -> 1671 bytes 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/battle/Monster.h b/src/battle/Monster.h index 50a1807..e4d787e 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -12,7 +12,11 @@ #include -namespace graphics { class Sprite; } +namespace common { class Item; } +namespace graphics { + class Animation; + class Sprite; +} namespace battle { @@ -42,12 +46,17 @@ public: Uint16 ExpReward() const { return expReward; } Uint16 GoldReward() const { return goldReward; } - const /* Item */ void *DropItem() const { return dropItem; } + const common::Item *DropItem() const { return dropItem; } Uint8 DropChance() const { return dropChance; } const /* Script */ void *AttackScript() { return attackScript; } const /* Script */ void *DefenseScript() { return defenseScript; } + graphics::Animation *AttackAnimation() { return attackAnimation; } + const graphics::Animation *AttackAnimation() const { return attackAnimation; } + graphics::Animation *SpellAnimation() { return spellAnimation; } + const graphics::Animation *SpellAnimation() const { return spellAnimation; } + // temporary setters until loader is implemented public: void SetName(const char *n) { name = n; } @@ -60,13 +69,19 @@ public: void SetStats(const Stats &s) { stats = s; } void SetReward(Uint16 exp, Uint16 gold) { expReward = exp; goldReward = gold; } + void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; } + void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; } + private: const char *name; graphics::Sprite *sprite; - /* Item */ void *dropItem; + common::Item *dropItem; /* Script */ void *attackScript; /* Script */ void *defenseScript; + graphics::Animation *attackAnimation; + graphics::Animation *spellAnimation; + Uint16 maxHealth, health; Uint16 maxMana, mana; diff --git a/src/main.cpp b/src/main.cpp index 987a985..1781e5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,15 +89,20 @@ int main(int argc, char **argv) { heroesLayout.AddPosition(Point(160, 152)); SDL_Surface *monsterImg(IMG_Load("test-data/monster.png")); - Sprite dummySprite(monsterImg, 64, 64); + Sprite monsterSprite(monsterImg, 64, 64); Monster monster; monster.SetName("Lizard"); - monster.SetSprite(&dummySprite); + monster.SetSprite(&monsterSprite); monster.SetLevel(1); monster.SetMaxHealth(8); monster.SetHealth(8); monster.SetStats(Stats(14, 6, 6, 6, 6, 6, 6)); monster.SetReward(3, 5); + ComplexAnimation monsterAttackAnimation(&monsterSprite, 120); + monsterAttackAnimation.AddFrame(0, 1, Vector(16, 0)); + monsterAttackAnimation.AddFrame(0, 0, Vector(16, 0)); + monsterAttackAnimation.AddFrame(0, 1, Vector(16, 0)); + monster.SetAttackAnimation(&monsterAttackAnimation); SDL_Surface *maximImg(IMG_Load("test-data/maxim.png")); Sprite maximSprite(maximImg, 64, 64); diff --git a/test-data/monster.png b/test-data/monster.png index 94391020a60216841857d4717f52f5d9a430c643..0484303f5f679c6db4832756f5d52474a94d8bff 100644 GIT binary patch delta 1667 zcmV-}27LL;2Zs%i7k_{V1^@s6yMb?N000I~Nkl`YdH4)*9wZl|O`fI2`Hw?p7gwU?wF(`KnVCFsy*2@nMc&~}PE#bY!Ss5Dgp3Rt5u z7RXR<>_9$I-D?Uwz}}5b0KnSn8USGUdI$h`^!qCSK=(nXQYIJ!7L9!C`UU{t<&*mWfX7EM!r$L~ z>}>q)^IZVIW~&VV`0SIfD`CQgXTbZ5KEc{*%XvSAd_#O5O*6rwz_KuaMsH7qiMX_W z|372EQZnGxsDBRt*xiox0G`J$hd&$x08R%Z0KoB4udIS>7z56O4q!BBw=X;KK8+S@ znLa}@NcxH?5Zk*)3m%Vo)`7@k`XyRp=AieijHr~s;U(M>8S8~4`894St31dJ2 z19GdfyyktiKAGKd`{8R8isuJOJl|QrRO$zIp8f4GwELhFO-BP`K(i1_0p8ghL(LeVA^+oc9Cr_n;%jp6&K>|@|C<<*UN1)A*6mvWfRnc`bCK7w zG9o=udWrG8vW7_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