From: Daniel Karbach Date: Sat, 29 Sep 2012 19:02:34 +0000 (+0200) Subject: added test tileset, area and map X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=6786f73930b6a0406ddefa792763157ac41298ee;p=l2e.git added test tileset, area and map --- diff --git a/src/main.cpp b/src/main.cpp index a2cdae9..0a6882a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,10 @@ #include "loader/ParsedSource.h" #include "loader/Parser.h" #include "loader/TypeDescription.h" +#include "map/Area.h" +#include "map/Map.h" +#include "map/MapState.h" +#include "map/Tile.h" #include "sdl/InitImage.h" #include "sdl/InitScreen.h" #include "sdl/InitSDL.h" @@ -69,6 +73,10 @@ using loader::Interpreter; using loader::ParsedSource; using loader::Parser; using loader::TypeDescription; +using map::Area; +using map::Map; +using map::MapState; +using map::Tile; using sdl::InitImage; using sdl::InitScreen; using sdl::InitSDL; @@ -224,8 +232,96 @@ int main(int argc, char **argv) { dekar.SetRing(caster.GetItem("rocketRingItem")); dekar.SetJewel(caster.GetItem("krakenRockItem")); + Tile tiles[64]; + + tiles[ 0].SetOffset(Vector(2, 1)); + tiles[ 1].SetOffset(Vector(4, 0)); + tiles[ 2].SetOffset(Vector(3, 0)); + tiles[ 3].SetOffset(Vector(3, 0)); + tiles[ 4].SetOffset(Vector(0, 1)); + tiles[ 5].SetOffset(Vector(2, 0)); + tiles[ 6].SetOffset(Vector(2, 0)); + tiles[ 7].SetOffset(Vector(2, 0)); + + tiles[ 8].SetOffset(Vector(2, 1)); + tiles[ 9].SetOffset(Vector(4, 0)); + tiles[10].SetOffset(Vector(3, 0)); + tiles[11].SetOffset(Vector(3, 0)); + tiles[12].SetOffset(Vector(0, 2)); + tiles[13].SetOffset(Vector(1, 2)); + tiles[14].SetOffset(Vector(1, 2)); + tiles[15].SetOffset(Vector(1, 2)); + + tiles[16].SetOffset(Vector(2, 1)); + tiles[17].SetOffset(Vector(4, 0)); + tiles[18].SetOffset(Vector(3, 0)); + tiles[19].SetOffset(Vector(3, 0)); + tiles[20].SetOffset(Vector(0, 3)); + tiles[21].SetOffset(Vector(1, 3)); + tiles[22].SetOffset(Vector(1, 3)); + tiles[23].SetOffset(Vector(2, 3)); + + tiles[24].SetOffset(Vector(2, 1)); + tiles[25].SetOffset(Vector(4, 0)); + tiles[26].SetOffset(Vector(3, 0)); + tiles[27].SetOffset(Vector(3, 0)); + tiles[28].SetOffset(Vector(0, 4)); + tiles[29].SetOffset(Vector(1, 4)); + tiles[30].SetOffset(Vector(1, 4)); + tiles[31].SetOffset(Vector(2, 4)); + + tiles[32].SetOffset(Vector(2, 1)); + tiles[33].SetOffset(Vector(4, 0)); + tiles[34].SetOffset(Vector(3, 0)); + tiles[35].SetOffset(Vector(3, 0)); + tiles[36].SetOffset(Vector(3, 0)); + tiles[37].SetOffset(Vector(3, 0)); + tiles[38].SetOffset(Vector(3, 0)); + tiles[39].SetOffset(Vector(3, 0)); + + tiles[40].SetOffset(Vector(2, 1)); + tiles[41].SetOffset(Vector(4, 0)); + tiles[42].SetOffset(Vector(3, 0)); + tiles[43].SetOffset(Vector(3, 0)); + tiles[44].SetOffset(Vector(3, 0)); + tiles[45].SetOffset(Vector(4, 0)); + tiles[46].SetOffset(Vector(4, 0)); + tiles[47].SetOffset(Vector(4, 0)); + + tiles[48].SetOffset(Vector(2, 1)); + tiles[49].SetOffset(Vector(4, 0)); + tiles[50].SetOffset(Vector(3, 0)); + tiles[51].SetOffset(Vector(3, 0)); + tiles[52].SetOffset(Vector(0, 0)); + tiles[53].SetOffset(Vector(1, 0)); + tiles[54].SetOffset(Vector(1, 0)); + tiles[55].SetOffset(Vector(1, 0)); + + tiles[56].SetOffset(Vector(2, 1)); + tiles[57].SetOffset(Vector(4, 0)); + tiles[58].SetOffset(Vector(3, 0)); + tiles[59].SetOffset(Vector(3, 0)); + tiles[60].SetOffset(Vector(0, 1)); + tiles[61].SetOffset(Vector(1, 1)); + tiles[62].SetOffset(Vector(1, 1)); + tiles[63].SetOffset(Vector(1, 1)); + + Area area; + area.SetTiles(tiles, 64); + area.SetWidth(8); + + SDL_Surface *tilesetImg(IMG_Load("test-data/tileset.png")); + Sprite tileset(tilesetImg, 32, 32); + + Map map; + map.SetAreas(&area, 1); + map.SetTileset(&tileset); + map.SetWidth(1); + InitScreen screen(width, height); + app::State *state(0); + if (battle) { BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes)); battleState->AddMonster(monster); @@ -236,24 +332,27 @@ int main(int argc, char **argv) { battleState->AddHero(selan); battleState->AddHero(guy); battleState->AddHero(dekar); - Application app(&screen, battleState); - app.Buttons().MapKey(SDLK_w, Input::PAD_UP); - app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT); - app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN); - app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT); - app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A); - app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B); - app.Buttons().MapKey(SDLK_UP, Input::ACTION_X); - app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y); - app.Buttons().MapKey(SDLK_RETURN, Input::START); - app.Buttons().MapKey(SDLK_SPACE, Input::SELECT); - app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT); - app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT); - app.Run(); + state = battleState; } else { - + MapState *mapState(new MapState(&map)); + state = mapState; } + Application app(&screen, state); + app.Buttons().MapKey(SDLK_w, Input::PAD_UP); + app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT); + app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN); + app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT); + app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A); + app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B); + app.Buttons().MapKey(SDLK_UP, Input::ACTION_X); + app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y); + app.Buttons().MapKey(SDLK_RETURN, Input::START); + app.Buttons().MapKey(SDLK_SPACE, Input::SELECT); + app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT); + app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT); + app.Run(); + return 0; } catch (Parser::Error &e) { cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl; diff --git a/test-data/tileset.png b/test-data/tileset.png new file mode 100644 index 0000000..299f94f Binary files /dev/null and b/test-data/tileset.png differ