diff --git a/data/gifs.txt b/data/gifs.txt index 09e29dc..f2f9eef 100644 --- a/data/gifs.txt +++ b/data/gifs.txt @@ -8,6 +8,7 @@ font2.gif gat.gif gat2.gif jailgames.gif +mapa.gif objectes.gif obrer.gif roomaux.gif diff --git a/data/mapa.gif b/data/mapa.gif new file mode 100644 index 0000000..9995cb9 Binary files /dev/null and b/data/mapa.gif differ diff --git a/data/rooms/00.txt b/data/rooms/00.txt index 4ca872d..60400b2 100644 --- a/data/rooms/00.txt +++ b/data/rooms/00.txt @@ -1,14 +1,12 @@ width: 3 height: 1 door-height-xp: 0 -door-height-xn: 0 color: CYAN floor-texture: 0 wall-texture: 2 door-texture: 0 under-door-texture: 0 exit-xp: 1 -exit-xn: 4 actor{ name: MESITA @@ -20,36 +18,6 @@ actor{ movement: CW } -actor{ - name: LLIT - bmp: altres.gif - bmp-rect: 48 0 57 47 - bmp-offset: 11 32 - pos: 8 16 0 - size: 16 16 4 - movement: CW -} - -actor{ - name: MESITA01 - bmp: caixes.gif - bmp-rect: 0 64 32 32 - bmp-offset: 0 32 - pos: 24 16 0 - size: 8 8 4 - movement: CW -} - -actor{ - name: MANCUERNA - bmp: altres.gif - bmp-rect: 106 33 17 14 - bmp-offset: -6 20 - pos: 24 25 0 - size: 6 4 2 - movement: CW -} - actor{ name: FINESTRA01 bmp: altres.gif @@ -79,3 +47,33 @@ actor{ size: 6 6 16 movement: CW } + +actor{ + name: LLIT + bmp: altres.gif + bmp-rect: 48 0 57 47 + bmp-offset: 11 32 + pos: 8 16 0 + size: 16 16 4 + movement: CW +} + +actor{ + name: MESITA01 + bmp: caixes.gif + bmp-rect: 0 64 32 32 + bmp-offset: 0 32 + pos: 24 16 0 + size: 8 8 4 + movement: CW +} + +actor{ + name: MANCUERNA + bmp: altres.gif + bmp-rect: 106 33 17 14 + bmp-offset: -6 20 + pos: 24 25 0 + size: 6 4 2 + movement: CW +} diff --git a/data/rooms/02.txt b/data/rooms/02.txt index 6d3d080..a9e356f 100644 --- a/data/rooms/02.txt +++ b/data/rooms/02.txt @@ -1,8 +1,8 @@ -width: 2 +width: 3 height: 2 door-height-xn: 0 door-height-yn: 0 -color: CYAN +color: GREEN floor-texture: 0 wall-texture: 0 door-texture: 0 diff --git a/data/rooms/03.txt b/data/rooms/03.txt index eec73ab..02c9969 100644 --- a/data/rooms/03.txt +++ b/data/rooms/03.txt @@ -1,5 +1,5 @@ width: 2 -height: 2 +height: 3 door-height-xn: 0 door-height-yp: 0 color: CYAN @@ -7,5 +7,5 @@ floor-texture: 0 wall-texture: 0 door-texture: 0 under-door-texture: 0 -exit-xn: 5 +exit-xn: 4 exit-yp: 2 diff --git a/data/rooms/04.txt b/data/rooms/04.txt index 3cddf12..42f03ea 100644 --- a/data/rooms/04.txt +++ b/data/rooms/04.txt @@ -1,9 +1,11 @@ width: 2 height: 2 door-height-xp: 0 +door-height-xn: 0 color: CYAN floor-texture: 0 wall-texture: 0 door-texture: 0 under-door-texture: 0 -exit-xp: 0 +exit-xp: 3 +exit-xn: 5 diff --git a/data/rooms/05.txt b/data/rooms/05.txt index 228b08b..ebd42e5 100644 --- a/data/rooms/05.txt +++ b/data/rooms/05.txt @@ -1,11 +1,9 @@ width: 2 height: 2 door-height-xp: 0 -door-height-xn: 0 color: CYAN floor-texture: 0 wall-texture: 0 door-texture: 0 under-door-texture: 0 -exit-xp: 3 -exit-xn: 6 +exit-xp: 4 diff --git a/data/rooms/06.txt b/data/rooms/06.txt deleted file mode 100644 index 53f96e1..0000000 --- a/data/rooms/06.txt +++ /dev/null @@ -1,9 +0,0 @@ -width: 2 -height: 2 -door-height-xp: 0 -color: CYAN -floor-texture: 0 -wall-texture: 0 -door-texture: 0 -under-door-texture: 0 -exit-xp: 5 diff --git a/source/m_editor_map.cpp b/source/m_editor_map.cpp new file mode 100644 index 0000000..0a7fd4f --- /dev/null +++ b/source/m_editor_map.cpp @@ -0,0 +1,109 @@ +#include "m_editor_map.h" +#include "jdraw.h" +#include "jinput.h" +#include "misc.h" +#include +#include "room.h" + +namespace modules +{ + namespace editor_map + { + draw::surface *surf; + vec2_t scroll {0,0}; + bool drawn[64]; + int current_room; + + struct miniroom_t + { + uint8_t w; + uint8_t h; + uint8_t color; + uint8_t exits[6]; + }; + miniroom_t minirooms[64]; + + void loadMiniRoom() + { + const int room = room::getCurrent(); + if (drawn[room]) return; + drawn[room] = true; + + minirooms[room].color = room::getColor(0); + minirooms[room].w = (room::getSize().x >> 1)-1; + minirooms[room].h = (room::getSize().y >> 1)-1; + for (int i=0; i= 0) && (next_room <= 64) && (!drawn[next_room]) ) { + room::load(next_room); + loadMiniRoom(); + } + } + } + + void init() + { + surf = draw::getSurface("mapa.gif"); + scroll = {260,120}; + draw::resetViewport(); + for (int i=0;i<64;++i) drawn[i]=false; + + current_room = room::getCurrent(); + loadMiniRoom(); + room::load(current_room); + } + + void drawRoom(const int room, const int x, const int y) + { + if (drawn[room]) return; + drawn[room] = true; + if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) ) + { + draw::stencil::set(room); + draw::swapcol(1, minirooms[room].color); + draw::draw(x-16, y-8, 32, 16, minirooms[room].w*32, minirooms[room].h*16); + + draw::swapcol(1, RED); + if (minirooms[room].exits[XN] != 255) draw::draw(x-4-(minirooms[room].w*2), y-5-(minirooms[room].w),4,5,0,64); + if (minirooms[room].exits[YN] != 255) draw::draw(x+(minirooms[room].h*2), y-5-(minirooms[room].h),4,5,3,64); + if (minirooms[room].exits[XP] != 255) draw::draw(x+(minirooms[room].w*2), y-3+(minirooms[room].w),4,5,0,64); + if (minirooms[room].exits[YP] != 255) draw::draw(x-4-(minirooms[room].h*2), y-3+(minirooms[room].h),4,5,3,64); + + char num[] = "00"; num[0] = 48+(room/10); num[1] = 48+(room%10); + draw::print(num, x-4, y-3, LIGHT+(room==current_room?YELLOW:WHITE), BLACK); + } + if (minirooms[room].exits[XN] != 255) drawRoom(minirooms[room].exits[XN], x-24, y-12); + if (minirooms[room].exits[XP] != 255) drawRoom(minirooms[room].exits[XP], x+24, y+12); + if (minirooms[room].exits[YN] != 255) drawRoom(minirooms[room].exits[YN], x+24, y-12); + if (minirooms[room].exits[YP] != 255) drawRoom(minirooms[room].exits[YP], x-24, y+12); + } + + bool loop() + { + for (int i=0;i<64;++i) drawn[i]=false; + + if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false; + + draw::cls(2); + draw::setSource(surf); + + draw::stencil::enable(); + draw::stencil::clear(255); + + drawRoom(room::getCurrent(), scroll.x, scroll.y); + draw::render(); + + if (input::mouseClk(1)) { + const int clicked = draw::stencil::query(input::mouseX(), input::mouseY()); + if (clicked!=255) { + room::load(clicked); + return false; + } + } + + return true; + } + } +} diff --git a/source/m_editor_map.h b/source/m_editor_map.h new file mode 100644 index 0000000..ee9ad0c --- /dev/null +++ b/source/m_editor_map.h @@ -0,0 +1,10 @@ +#pragma once + +namespace modules +{ + namespace editor_map + { + void init(); + bool loop(); + } +} diff --git a/source/m_game.cpp b/source/m_game.cpp index 75b4ad1..1bb9a5a 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -265,16 +265,19 @@ namespace modules else return GAME_MENU; } - if (input::keyPressed(SDL_SCANCODE_TAB) || input::keyPressed(SDL_SCANCODE_GRAVE) ) console::toggle(); // WHILE EDITING... if (editor::isEditing()) { + if (input::keyPressed(SDL_SCANCODE_TAB)) return GAME_EDITOR_MAP; + editor_move_selected(); actor::updateEditor(actor::getFirst()); } else { + if (input::keyPressed(SDL_SCANCODE_TAB) || input::keyPressed(SDL_SCANCODE_GRAVE) ) console::toggle(); + if (!console::update()) { actor::update(actor::getFirst()); @@ -387,12 +390,32 @@ namespace modules if (input::mouseClk(1)) { const int mx = draw::getLocalX(input::mouseX()); const int my = draw::getLocalY(input::mouseY()); - if (mx<32 && my<24) room::load(room::editor::refExit(XN), XP); - if (mx>288 && my<24) room::load(room::editor::refExit(YN), YP); - if (mx>288 && my>216) room::load(room::editor::refExit(XP), XN); - if (mx<32 && my>216) room::load(room::editor::refExit(YP), YN); - if (mx>144 && mx<176 && my<24) room::load(room::editor::refExit(ZP), ZN); - if (mx>144 && mx<176 && my>216) room::load(room::editor::refExit(ZN), ZP); + if (mx>=0 && my>=0 && mx<320 && my<240) { + if (mx<32 && my<24) { + int room = room::editor::refExit(XN); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, XP); + } + if (mx>288 && my<24) { + int room = room::editor::refExit(YN); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, YP); + } + if (mx>288 && my>216) { + int room = room::editor::refExit(XP); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, XN); + } + if (mx<32 && my>216) { + int room = room::editor::refExit(YP); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, YN); + } + if (mx>144 && mx<176 && my<24) { + int room = room::editor::refExit(ZP); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, ZN); + } + if (mx>144 && mx<176 && my>216) { + int room = room::editor::refExit(ZN); + if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, ZP); + } + } } ui::start(); diff --git a/source/m_game.h b/source/m_game.h index ac12af0..e84a977 100644 --- a/source/m_game.h +++ b/source/m_game.h @@ -7,6 +7,7 @@ namespace modules #define GAME_NONE -1 #define GAME_MENU 0 #define GAME_DEAD 1 + #define GAME_EDITOR_MAP 2 void init(); int loop(); diff --git a/source/main.cpp b/source/main.cpp index 58d4383..ad5a217 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -19,6 +19,7 @@ #include "m_catslife.h" #include "m_menu_tecles.h" #include "m_menu_audio.h" +#include "m_editor_map.h" #define M_LOGO 0 #define M_MENU 1 @@ -28,6 +29,8 @@ #define M_CATSLIFE 5 #define M_MENU_TECLES 6 #define M_MENU_AUDIO 7 +#define M_EDITOR_MAP 8 +#define M_EDITOR_TEMPLATES 9 int current_module = M_LOGO; int zoom = 3; @@ -134,9 +137,16 @@ bool game::loop() } else { modules::gameover::init(); current_module = M_GAMEOVER; } + } else if (option==GAME_EDITOR_MAP) { + modules::editor_map::init(); current_module = M_EDITOR_MAP; } } break; + case M_EDITOR_MAP: + if (!modules::editor_map::loop()) { + current_module = M_GAME; + } + break; case M_INGAME: option = modules::ingame::loop(); if (option != INGAME_NONE) {