#include "common/Inventory.h"
#include "common/Item.h"
#include "common/Spell.h"
-#include "geometry/Point.h"
#include "geometry/Vector.h"
#include "graphics/ComplexAnimation.h"
#include "graphics/Font.h"
#include "graphics/Menu.h"
#include "graphics/SimpleAnimation.h"
#include "graphics/Sprite.h"
+#include "loader/Interpreter.h"
+#include "loader/ParsedSource.h"
+#include "loader/Parser.h"
#include "sdl/InitImage.h"
#include "sdl/InitScreen.h"
#include "sdl/InitSDL.h"
+#include <cstdlib>
+#include <ctime>
#include <exception>
#include <iostream>
#include <SDL.h>
using common::Inventory;
using common::Item;
using common::Spell;
-using geometry::Point;
using geometry::Vector;
using graphics::ComplexAnimation;
using graphics::Font;
using graphics::Menu;
using graphics::SimpleAnimation;
using graphics::Sprite;
+using loader::Interpreter;
+using loader::ParsedSource;
+using loader::Parser;
using sdl::InitImage;
using sdl::InitScreen;
using sdl::InitSDL;
const int framerate = 33;
+// std::srand(std::time(0));
+
try {
InitSDL sdl;
InitImage image(IMG_INIT_PNG);
+
+ ParsedSource source;
+ Parser parser("test-data/test.l2s", source);
+ parser.Parse();
+ cout << source;
+ Interpreter intp(source);
+ intp.ReadSource();
+
InitScreen screen(width, height);
// temporary test data
SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
PartyLayout monstersLayout;
- monstersLayout.AddPosition(Point<Uint8>(88, 88));
- monstersLayout.AddPosition(Point<Uint8>(128, 88));
- monstersLayout.AddPosition(Point<Uint8>(168, 88));
- monstersLayout.AddPosition(Point<Uint8>(208, 88));
+ monstersLayout.AddPosition(Vector<Uint8>(88, 88));
+ monstersLayout.AddPosition(Vector<Uint8>(128, 88));
+ monstersLayout.AddPosition(Vector<Uint8>(168, 88));
+ monstersLayout.AddPosition(Vector<Uint8>(208, 88));
PartyLayout heroesLayout;
- heroesLayout.AddPosition(Point<Uint8>(48, 136));
- heroesLayout.AddPosition(Point<Uint8>(128, 136));
- heroesLayout.AddPosition(Point<Uint8>(80, 152));
- heroesLayout.AddPosition(Point<Uint8>(160, 152));
-
- SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
- Sprite monsterSprite(monsterImg, 64, 64);
- Monster monster;
- monster.SetName("Lizard");
- 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, 4 * framerate);
- monsterAttackAnimation.AddFrame(0, 1, Vector<int>(16, 0));
- monsterAttackAnimation.AddFrame(0, 0, Vector<int>(16, 0));
- monsterAttackAnimation.AddFrame(0, 1, Vector<int>(16, 0));
- monster.SetAttackAnimation(&monsterAttackAnimation);
- SDL_Surface *monsterMeleeImg(IMG_Load("test-data/attack-monster.png"));
- Sprite monsterMeleeSprite(monsterMeleeImg, 96, 64);
- SimpleAnimation monsterMeleeAnimation(&monsterMeleeSprite, framerate, 14);
- monster.SetMeleeAnimation(&monsterMeleeAnimation);
-
- SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
- Sprite maximSprite(maximImg, 64, 64);
- Hero maxim;
- maxim.SetName("Maxim");
- maxim.SetLevel(1);
- maxim.SetSprite(&maximSprite);
- maxim.SetMaxHealth(33);
- maxim.SetHealth(33);
- maxim.SetMaxMana(20);
- maxim.SetMana(20);
- maxim.SetIP(0);
- maxim.SetStats(Stats(28, 22, 28, 17, 14, 100, 10));
- ComplexAnimation maximAttackAnimation(&maximSprite, framerate);
- // TODO: cross check double frames; could be related to differences in framerates
- maximAttackAnimation.AddFrames(1, 0, Vector<int>(0, 0), 7); // TODO: maybe this could also be a pause before the battle animation
- maximAttackAnimation.AddFrames(1, 0, Vector<int>(4, -1), 2);
- maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, -2), 2);
- maximAttackAnimation.AddFrames(2, 0, Vector<int>(6, -2), 2);
- maximAttackAnimation.AddFrames(2, 1, Vector<int>(6, -1), 1);
- maximAttackAnimation.AddFrames(2, 1, Vector<int>(3, -1), 2);
- maximAttackAnimation.AddFrames(2, 1, Vector<int>(0, 0), 1);
- maximAttackAnimation.AddFrames(2, 2, Vector<int>(0, 0), 2);
- maximAttackAnimation.AddFrames(2, 2, Vector<int>(2, 0), 1);
- maximAttackAnimation.AddFrames(1, 0, Vector<int>(0, 0), 7); // TODO: maybe this could also be a pause between two animations
- maxim.SetAttackAnimation(&maximAttackAnimation);
- ComplexAnimation maximSpellAnimation(&maximSprite, 5 * framerate);
- maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
- maximSpellAnimation.AddFrame(3, 1);
- maxim.SetSpellAnimation(&maximSpellAnimation);
- SDL_Surface *maximMeleeImg(IMG_Load("test-data/melee-maxim.png"));
- Sprite maximMeleeSprite(maximMeleeImg, 96, 96);
- SimpleAnimation maximMeleeAnimation(&maximMeleeSprite, 2 * framerate, 4);
- maxim.SetMeleeAnimation(&maximMeleeAnimation);
+ heroesLayout.AddPosition(Vector<Uint8>(48, 136));
+ heroesLayout.AddPosition(Vector<Uint8>(128, 136));
+ heroesLayout.AddPosition(Vector<Uint8>(80, 152));
+ heroesLayout.AddPosition(Vector<Uint8>(160, 152));
+
+ Monster monster(*intp.GetMonster("lizard"));
+ Hero maxim(*intp.GetHero("maxim"));
SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
Sprite selanSprite(selanImg, 64, 64);
Item zircoSword;
zircoSword.SetName("Zirco sword");
zircoSword.SetMenuIcon(&swordIcon);
+ zircoSword.GetTargetingMode().TargetSingleEnemy();
Ikari firestorm;
firestorm.SetName("Firestorm");
firestorm.SetCost(224);
Ikari lightGuard;
lightGuard.SetName("Light guard");
lightGuard.SetCost(128);
- lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+ lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
lightGuard.SetMagical();
holyShield.SetIkari(&lightGuard);
maxim.SetShield(&holyShield);
Ikari boomerang;
boomerang.SetName("Boomerang");
boomerang.SetCost(164);
- boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+ boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
boomerang.SetMagical();
legendHelm.SetIkari(&boomerang);
maxim.SetHelmet(&legendHelm);
Item zircoWhip;
zircoWhip.SetName("Zirco whip");
zircoWhip.SetMenuIcon(&rodIcon);
+ zircoWhip.GetTargetingMode().TargetSingleEnemy();
Ikari thundershriek;
thundershriek.SetName("Thundershriek");
thundershriek.SetCost(224);
Item zircoAx;
zircoAx.SetName("Zirco ax");
zircoAx.SetMenuIcon(&axIcon);
+ zircoAx.GetTargetingMode().TargetSingleEnemy();
Ikari torrent;
torrent.SetName("Torrent");
torrent.SetCost(224);
Ikari ironBarrier;
ironBarrier.SetName("Iron barrier");
ironBarrier.SetCost(255);
- ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+ ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
ironBarrier.SetMagical();
megaShield.SetIkari(&ironBarrier);
guy.SetShield(&megaShield);
Item lizardBlow;
lizardBlow.SetName("Lizard blow");
lizardBlow.SetMenuIcon(&swordIcon);
+ lizardBlow.GetTargetingMode().TargetSingleEnemy();
Ikari dragonRush;
dragonRush.SetName("Dragon rush");
dragonRush.SetCost(164);
app.Run();
return 0;
+ } catch (Parser::Error &e) {
+ cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
+ return 1;
} catch (exception &e) {
cerr << "exception in main(): " << e.what() << endl;
return 1;