From c9f41c9635e5e1275b47199ba9c721d258b04e5a Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 11 Jul 2024 09:55:22 +0200 Subject: [PATCH] - [NEW] Nou flag per als actors: FLAG_INERTIA - [NEW] Nou moviment per als actors: RANDV - [NEW] HUNT implementat - [NEW] Mentres es prova en l'editor ara es poden donar i llevar skills fent click damutn del seu dibuixet. - [NEW] en l'editor, els skills i powerups nomes es veuen al estar provant --- data/rooms/09.txt | 119 +++++++++++++++++++++++++--------------------- source/actor.cpp | 77 +++++++++++++++++++++--------- source/actor.h | 6 ++- source/m_game.cpp | 63 ++++++++++++++++-------- 4 files changed, 168 insertions(+), 97 deletions(-) diff --git a/data/rooms/09.txt b/data/rooms/09.txt index d537fea..fc98b0b 100644 --- a/data/rooms/09.txt +++ b/data/rooms/09.txt @@ -7,7 +7,7 @@ door-texture: 0 under-door-texture: 0 actor{ - name: BOX + name: TAULETA bmp: caixes.gif bmp-rect: 0 64 32 32 bmp-offset: 0 32 @@ -26,6 +26,26 @@ actor{ movement: CW } +actor{ + name: KALLAX-A + bmp: altres.gif + bmp-rect: 0 48 24 27 + bmp-offset: 0 31 + pos: 0 8 0 + size: 4 8 8 + movement: CW +} + +actor{ + name: KALLAX-A03 + bmp: altres.gif + bmp-rect: 72 48 24 27 + bmp-offset: 0 31 + pos: 0 16 0 + size: 4 8 8 + movement: CW +} + actor{ name: KALLAX-A04 bmp: altres.gif @@ -60,6 +80,16 @@ actor{ movement: CW } +actor{ + name: BOX01 + bmp: caixes.gif + bmp-rect: 128 32 32 32 + bmp-offset: 0 32 + pos: 16 24 0 + size: 8 8 8 + movement: CW +} + actor{ name: KALLAX-A07 bmp: altres.gif @@ -73,14 +103,13 @@ actor{ } actor{ - name: KALLAX-A06 - bmp: altres.gif - bmp-rect: 72 48 24 27 - bmp-offset: -8 31 - pos: 24 0 8 - size: 8 4 8 - orient: YP - flags: ORIENTABLE + name: BOX02 + bmp: caixes.gif + bmp-rect: 160 32 32 32 + bmp-offset: 0 32 + pos: 24 24 0 + size: 8 8 8 + react-push: XP movement: CW } @@ -97,24 +126,13 @@ actor{ } actor{ - name: KALLAX-A09 - bmp: altres.gif - bmp-rect: 0 48 24 27 - bmp-offset: -8 31 - pos: 32 0 8 - size: 8 4 8 - orient: YP - flags: ORIENTABLE - movement: CW -} - -actor{ - name: KALLAX-A - bmp: altres.gif - bmp-rect: 0 48 24 27 - bmp-offset: 0 31 - pos: 0 8 0 - size: 4 8 8 + name: BOX + bmp: test.gif + bmp-rect: 32 0 32 32 + bmp-offset: 0 32 + pos: 32 32 0 + size: 8 8 8 + flags: PUSHABLE INERTIA movement: CW } @@ -128,16 +146,6 @@ actor{ movement: CW } -actor{ - name: KALLAX-A03 - bmp: altres.gif - bmp-rect: 72 48 24 27 - bmp-offset: 0 31 - pos: 0 16 0 - size: 4 8 8 - movement: CW -} - actor{ name: KALLAX-A02 bmp: altres.gif @@ -148,16 +156,6 @@ actor{ movement: CW } -actor{ - name: BOX01 - bmp: caixes.gif - bmp-rect: 128 32 32 32 - bmp-offset: 0 32 - pos: 16 24 0 - size: 8 8 8 - movement: CW -} - actor{ name: BOX03 bmp: caixes.gif @@ -170,13 +168,14 @@ actor{ } actor{ - name: BOX02 - bmp: caixes.gif - bmp-rect: 160 32 32 32 - bmp-offset: 0 32 - pos: 24 24 0 - size: 8 8 8 - react-push: XP + name: KALLAX-A06 + bmp: altres.gif + bmp-rect: 72 48 24 27 + bmp-offset: -8 31 + pos: 24 0 8 + size: 8 4 8 + orient: YP + flags: ORIENTABLE movement: CW } @@ -192,3 +191,15 @@ actor{ react-push: XP movement: CW } + +actor{ + name: KALLAX-A09 + bmp: altres.gif + bmp-rect: 0 48 24 27 + bmp-offset: -8 31 + pos: 32 0 8 + size: 8 4 8 + orient: YP + flags: ORIENTABLE + movement: CW +} diff --git a/source/actor.cpp b/source/actor.cpp index dbc169b..1804c51 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -140,7 +140,7 @@ namespace actor } else if (util::strcomp(key, "orient:")) { t->orient = util::stringToInt(file::readString(buffer), {"none", "xp", "xn", "yp", "yn", "zp", "zn"}, {0, 1, 2, 4, 8, 16, 32}); } else if (util::strcomp(key, "movement:")) { - t->movement = util::stringToInt(file::readString(buffer), {"none", "x", "y", "z", "cw", "ccw", "rand", "hunt"},{MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_HUNT}); + t->movement = util::stringToInt(file::readString(buffer), {"none", "x", "y", "z", "cw", "ccw", "rand", "randv", "hunt"},{MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_RANDV, MOV_HUNT}); } else if (util::strcomp(key, "anim-cycle:")) { t->anim_cycle = util::stringToInt(file::readString(buffer), {"walk", "seq", "min"},{0, 1, 2}); } else if (util::strcomp(key, "anim-wait:")) { @@ -150,7 +150,7 @@ namespace actor int value = 0; while (str) { - value |= util::stringToInt(str, { "none", "hero", "pushable", "reactive", "moving", "animated", "orientable", "deadly", "gravity", "pickable", "special", "noeditor" },{ FLAG_NONE, FLAG_HERO, FLAG_PUSHABLE, FLAG_REACTIVE, FLAG_MOVING, FLAG_ANIMATED, FLAG_ORIENTABLE, FLAG_DEADLY, FLAG_GRAVITY, FLAG_PICKABLE, FLAG_SPECIAL, FLAG_NOEDITOR }); + value |= util::stringToInt(str, { "none", "hero", "pushable", "reactive", "moving", "animated", "orientable", "deadly", "gravity", "pickable", "special", "noeditor", "inertia" },{ FLAG_NONE, FLAG_HERO, FLAG_PUSHABLE, FLAG_REACTIVE, FLAG_MOVING, FLAG_ANIMATED, FLAG_ORIENTABLE, FLAG_DEADLY, FLAG_GRAVITY, FLAG_PICKABLE, FLAG_SPECIAL, FLAG_NOEDITOR, FLAG_INERTIA }); str = file::readString(buffer, true); } t->flags = value; @@ -234,15 +234,16 @@ namespace actor { tmp[0]=0; if (value==0) return "NONE"; - if (value&256) strcat(tmp, "PICKABLE "); - if (value&2) strcat(tmp, "PUSHABLE "); - if (value&4) strcat(tmp, "REACTIVE "); - if (value&8) strcat(tmp, "MOVING "); - if (value&16) strcat(tmp, "ANIMATED "); - if (value&32) strcat(tmp, "ORIENTABLE "); - if (value&64) strcat(tmp, "DEADLY "); - if (value&128) strcat(tmp, "GRAVITY "); - if (value&512) strcat(tmp, "SPECIAL "); + if (value & FLAG_PICKABLE) strcat(tmp, "PICKABLE "); + if (value & FLAG_PUSHABLE) strcat(tmp, "PUSHABLE "); + if (value & FLAG_REACTIVE) strcat(tmp, "REACTIVE "); + if (value & FLAG_MOVING) strcat(tmp, "MOVING "); + if (value & FLAG_ANIMATED) strcat(tmp, "ANIMATED "); + if (value & FLAG_ORIENTABLE) strcat(tmp, "ORIENTABLE "); + if (value & FLAG_DEADLY) strcat(tmp, "DEADLY "); + if (value & FLAG_GRAVITY) strcat(tmp, "GRAVITY "); + if (value & FLAG_SPECIAL) strcat(tmp, "SPECIAL "); + if (value & FLAG_INERTIA) strcat(tmp, "INERTIA "); return tmp; } @@ -255,7 +256,8 @@ namespace actor if (value==4) return "CW"; if (value==5) return "CCW"; if (value==6) return "RAND"; - if (value==7) return "HUNT"; + if (value==7) return "RANDV"; + if (value==8) return "HUNT"; return "NONE"; } @@ -663,8 +665,25 @@ namespace actor case 3: act->mov_push=PUSH_XP; break; } break; + case MOV_RANDV: + switch (rand()%8) + { + case 0: act->mov_push=PUSH_YP; break; + case 1: act->mov_push=PUSH_XN; break; + case 2: act->mov_push=PUSH_YN; break; + case 3: act->mov_push=PUSH_XP; break; + case 4: act->mov_push=PUSH_YP; act->mov_push=PUSH_XN; break; + case 5: act->mov_push=PUSH_XN; act->mov_push=PUSH_YN; break; + case 6: act->mov_push=PUSH_YN; act->mov_push=PUSH_XP; break; + case 7: act->mov_push=PUSH_XP; act->mov_push=PUSH_YP; break; + } + break; case MOV_HUNT: - // TODO + actor_t *heroi = find("HERO"); + if (heroi->pos.x < act->pos.x) act->mov_push=PUSH_XN; + if (heroi->pos.x > act->pos.x) act->mov_push=PUSH_XP; + if (heroi->pos.y < act->pos.y) act->mov_push=PUSH_YN; + if (heroi->pos.y > act->pos.y) act->mov_push=PUSH_YP; break; } if (act->flags & FLAG_ORIENTABLE) act->orient = act->mov_push; @@ -732,6 +751,7 @@ namespace actor if (other) act->push |= push(act, other, PUSH_XN); act->pos.x+=vel; if (act->flags & FLAG_MOVING) changeMoving(act); + if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; } else { @@ -750,7 +770,7 @@ namespace actor actor::setDirty(act); } - act->push &= ~PUSH_XN; + if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_XN; } if (act->push & PUSH_XP) { @@ -761,6 +781,7 @@ namespace actor if (other) act->push |= push(act, other, PUSH_XP); act->pos.x-=vel; if (act->flags & FLAG_MOVING) changeMoving(act); + if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; } else { @@ -777,7 +798,7 @@ namespace actor actor::setDirty(act); } - act->push &= ~PUSH_XP; + if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_XP; } if (act->push & PUSH_YN) { @@ -788,6 +809,7 @@ namespace actor if (other) act->push |= push(act, other, PUSH_YN); act->pos.y+=vel; if (act->flags & FLAG_MOVING) changeMoving(act); + if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; } else { @@ -804,7 +826,7 @@ namespace actor actor::setDirty(act); } - act->push &= ~PUSH_YN; + if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_YN; } if (act->push & PUSH_YP) { @@ -815,6 +837,7 @@ namespace actor if (other) act->push |= push(act, other, PUSH_YP); act->pos.y-=vel; if (act->flags & FLAG_MOVING) changeMoving(act); + if (act->flags & FLAG_INERTIA) act->push = PUSH_NONE; } else { @@ -831,7 +854,7 @@ namespace actor actor::setDirty(act); } - act->push &= ~PUSH_YP; + if ( !(act->flags & FLAG_INERTIA) ) act->push &= ~PUSH_YP; } if (act->push & PUSH_ZN) { @@ -1369,18 +1392,26 @@ namespace actor return 0; } + bool giveSkill(int skill) + { + skills |= skill; + return skill!=0; + } + bool giveSkill(char *skill) { - const int value = getSkillFromString(skill); - skills |= value; - return value!=0; + return giveSkill(getSkillFromString(skill)); + } + + bool dropSkill(int skill) + { + skills &= ~skill; + return skill!=0; } bool dropSkill(char *skill) { - const int value = getSkillFromString(skill); - skills &= ~value; - return value!=0; + return dropSkill(getSkillFromString(skill)); } bool wasSkillCollected(char *skill) diff --git a/source/actor.h b/source/actor.h index 1105737..98fce30 100644 --- a/source/actor.h +++ b/source/actor.h @@ -18,6 +18,7 @@ #define FLAG_PICKABLE 256 // Es pot agafar #define FLAG_SPECIAL 512 // Especial (habilitats, poders temporals i parts de l'excavadora) #define FLAG_NOEDITOR 1024 // No es seleccionable a l'editor (son les portes) +#define FLAG_INERTIA 2048 // Al rebre una espenta, continua fins tropesar en algo #define FLAG_SENSIBLE 6 // PUSHABLE or REACTIVE #define FLAG_IGNORE 1025 // HERO or NOEDITOR @@ -40,7 +41,8 @@ #define MOV_CW 4 // Es mou en sentit de les agulles del rellotge #define MOV_CCW 5 // Es mou en sentit contrari a les agulles del rellotge #define MOV_RAND 6 // Es mou en direcció aleatòria -#define MOV_HUNT 7 // Persegueix al heroi +#define MOV_RANDV 7 // Es mou en direcció aleatòria, diagonals incloses +#define MOV_HUNT 8 // Persegueix al heroi // Boosters #define BOOST_NONE 0 @@ -187,7 +189,9 @@ namespace actor void useBoostRun(); void useBoostJump(); + bool giveSkill(int skill); bool giveSkill(char *skill); + bool dropSkill(int skill); bool dropSkill(char *skill); bool wasSkillCollected(char *skill); int getSkills(); diff --git a/source/m_game.cpp b/source/m_game.cpp index 157be4e..4a6f104 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -307,26 +307,50 @@ namespace modules } } - const int col1 = room::getColor(1); - const int col2 = room::getColor(2); - const int col3 = room::getColor(3); - draw::print2("a", 4, 26, col1, FONT_ZOOM_NONE); - draw::print2("b", 7, 26, col2, FONT_ZOOM_NONE); - draw::print2("c", 10, 26, col3, FONT_ZOOM_NONE); - - draw::print2(actor::hero::getBoostJump(), 2, 3, 27, col3, FONT_ZOOM_NONE); - draw::print2(actor::hero::getBoostGod()/2, 2, 6, 27, col1, FONT_ZOOM_NONE); - draw::print2(actor::hero::getBoostRun()/2, 2, 9, 27, col2, FONT_ZOOM_NONE); + if (!editor::isEditing()) + { + const int col1 = room::getColor(1); + const int col2 = room::getColor(2); + const int col3 = room::getColor(3); + draw::print2("a", 4, 26, col1, FONT_ZOOM_NONE); + draw::print2("b", 7, 26, col2, FONT_ZOOM_NONE); + draw::print2("c", 10, 26, col3, FONT_ZOOM_NONE); + + draw::print2(actor::hero::getBoostJump(), 2, 3, 27, col3, FONT_ZOOM_NONE); + draw::print2(actor::hero::getBoostGod()/2, 2, 6, 27, col1, FONT_ZOOM_NONE); + draw::print2(actor::hero::getBoostRun()/2, 2, 9, 27, col2, FONT_ZOOM_NONE); - draw::setSource(draw::getSurface("objectes.gif")); - draw::swapcol(1, actor::hero::getSkills()&SKILL_SHOES ? col1 : col3); - draw::draw(276,166, 28, 22, 162, 0); - draw::swapcol(1, actor::hero::getSkills()&SKILL_PANTS ? col1 : col3); - draw::draw(250,183, 18, 23, 167, 22); - draw::swapcol(1, actor::hero::getSkills()&SKILL_GLOVES ? col1 : col3); - draw::draw(222,200, 21, 22, 165, 45); - draw::swapcol(1, actor::hero::getSkills()&SKILL_BAG ? col1 : col3); - draw::draw(279,200, 20, 25, 145, 41); + draw::stencil::enable(); + draw::stencil::clear(255); + + draw::setSource(draw::getSurface("objectes.gif")); + draw::stencil::set(SKILL_SHOES); + draw::swapcol(1, actor::hero::getSkills()&SKILL_SHOES ? col1 : col3); + draw::draw(276,166, 28, 22, 162, 0); + draw::stencil::set(SKILL_PANTS); + draw::swapcol(1, actor::hero::getSkills()&SKILL_PANTS ? col1 : col3); + draw::draw(250,183, 18, 23, 167, 22); + draw::stencil::set(SKILL_GLOVES); + draw::swapcol(1, actor::hero::getSkills()&SKILL_GLOVES ? col1 : col3); + draw::draw(222,200, 21, 22, 165, 45); + draw::stencil::set(SKILL_BAG); + draw::swapcol(1, actor::hero::getSkills()&SKILL_BAG ? col1 : col3); + draw::draw(279,200, 20, 25, 145, 41); + + draw::stencil::disable(); + + if (editor::isDevMode() && input::mouseClk(1)) + { + const uint8_t val = draw::stencil::query(input::mouseX(), input::mouseY()); + if (val != 255) + { + if (actor::hero::getSkills() & val) + actor::hero::dropSkill(val); + else + actor::hero::giveSkill(val); + } + } + } /* print(0,0,input::mouseX()); print(0,20,input::mouseY()); @@ -618,6 +642,7 @@ namespace modules line+=10; ui::label("FLAGS", 2, line, 96, 11, GRAY); + changed |= btn_check(50, line, "INER", act->flags, FLAG_INERTIA); changed |= btn_check(74, line, "SPEC", act->flags, FLAG_SPECIAL); line+=10;