From b0dd34b5dffa35cfce0f5129f6ffeddfcd5d78d3 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 30 Jul 2024 13:01:33 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20Per=20a=20crear=20noves=20habitacio?= =?UTF-8?q?ns=20descartar=20clicks=20fora=20del=20canvas=20-=20[FIX]=20Nom?= =?UTF-8?q?es=20crear=20nova=20habitaci=C3=B3=20si=20s'est=C3=A0=20pulsant?= =?UTF-8?q?=20LCTRL=20-=20[NEW]=20Minimapa=20en=20l'editor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/gifs.txt | 1 + data/mapa.gif | Bin 0 -> 614 bytes data/rooms/00.txt | 62 +++++++++++------------ data/rooms/02.txt | 4 +- data/rooms/03.txt | 4 +- data/rooms/04.txt | 4 +- data/rooms/05.txt | 4 +- data/rooms/06.txt | 9 ---- source/m_editor_map.cpp | 109 ++++++++++++++++++++++++++++++++++++++++ source/m_editor_map.h | 10 ++++ source/m_game.cpp | 37 +++++++++++--- source/m_game.h | 1 + source/main.cpp | 10 ++++ 13 files changed, 199 insertions(+), 56 deletions(-) create mode 100644 data/mapa.gif delete mode 100644 data/rooms/06.txt create mode 100644 source/m_editor_map.cpp create mode 100644 source/m_editor_map.h 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 0000000000000000000000000000000000000000..9995cb90eb166dd69682bd75083d70c86960c979 GIT binary patch literal 614 zcmV-s0-60sNk%v~VSoUD0Du4h00030|NkNR1PKZN001li0001h0Du4h0{?`MsmtvT zqnxzbi?iOm`wxcVNS0<6q`}E<>gv8~+r6AT$GB+g@{NOOf9$;4C*GI(XlvPDoDCV%p z6?WxF;rKH_87MJmacPLhImyZRpt)5T`Dq!t*?C%twAf17hNoZn<*I*Jvy}t>wM`k9U;pd&K%k-oh_(}U7o1Gj!yk7UQPbq zX>VJ9?XDirevYr*f^VRkqPNAB859J*sxaiAxwQec?M+YlO{ij$&MCr8nmg! ziU^6mGYU1TMtDM9LY11;DpIjKw_aTrP%I*?H-}RFNp%<3i*w)FM8mS?)PinF8pykp ztzQxpl@9i{BJtS6A7D6U+~P4H$Sj^Lri?kW=FOZtd;SbMwCK^KOPfB8I<@N62U!bs z?GLu>*|clhzKuJ#?%lk5`~IEkoa`!3wJ3Hid64AQjuBo4t@zXP&-j=-J)PC?;3aVP zYPQjQTlDFeiI4YVp0#;cAh$1W{}+%X^2LZ_Z7CmY*=5P6EIrpN7)jw(^PYAYoi`tH z_E>imcG=PA7kBD-ml=3}5hx#g&>bgBde&uViiW5mxC4ZtjdR<6>KO +#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) {