From 4986e76864a551fab4e4f818f60e58110b75c7d1 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Tue, 6 Jun 2023 18:05:42 +0200 Subject: [PATCH] - Les portes nomes deixen passar en la Z correcta - Les vores de les portes espenten cap a la porta --- source/actor.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------ source/main.cpp | 16 ++++++++------ source/room.cpp | 6 ++++++ source/room.h | 6 ++++++ 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index 09f5396..59edf3e 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -168,8 +168,16 @@ namespace actor act->orient=PUSH_XN; if ( (act->pos.x>min.x && act->pos.y>=min.y && act->pos.y<=max.y) || ( (room::getDoors()&DOOR_XN) && (act->pos.y>=24) && (act->pos.y<=32) ) ) { - act->push |= PUSH_XN; moving = true; + if ( (act->pos.x<=min.x) && (act->pos.z==room::getDoor(XN)*4) && (room::getDoors()&DOOR_XN) ) { + if (act->pos.y<28) + act->push |= PUSH_YP; + else if (act->pos.y>28) + act->push |= PUSH_YN; + else + act->push |= PUSH_XN; + } else + act->push |= PUSH_XN; } } if ( input::keyDown(SDL_SCANCODE_RIGHT) ) @@ -177,8 +185,16 @@ namespace actor act->orient=PUSH_XP; if ( (act->pos.xpos.y>=min.y && act->pos.y<=max.y) || ( (room::getDoors()&DOOR_XP) && (act->pos.y>=24) && (act->pos.y<=32) ) ) { - act->push |= PUSH_XP; moving = true; + if ( (act->pos.x>=max.x) && (act->pos.z==room::getDoor(XP)*4) && (room::getDoors()&DOOR_XP) ) { + if (act->pos.y<28) + act->push |= PUSH_YP; + else if (act->pos.y>28) + act->push |= PUSH_YN; + else + act->push |= PUSH_XP; + } else + act->push |= PUSH_XP; } } if ( input::keyDown(SDL_SCANCODE_UP) ) @@ -186,8 +202,16 @@ namespace actor act->orient=PUSH_YN; if ( (act->pos.y>min.y && act->pos.x>=min.x && act->pos.x<=max.x) || ( (room::getDoors()&DOOR_YN) && (act->pos.x>=24) && (act->pos.x<=32) ) ) { - act->push |= PUSH_YN; moving = true; + if ( (act->pos.y<=min.y) && (act->pos.z==room::getDoor(YN)*4) && (room::getDoors()&DOOR_YN) ) { + if (act->pos.x<28) + act->push |= PUSH_XP; + else if (act->pos.x>28) + act->push |= PUSH_XN; + else + act->push |= PUSH_YN; + } else + act->push |= PUSH_YN; } } if ( input::keyDown(SDL_SCANCODE_DOWN) ) @@ -195,8 +219,16 @@ namespace actor act->orient=PUSH_YP; if ( (act->pos.ypos.x>=min.x && act->pos.x<=max.x) || ( (room::getDoors()&DOOR_YP) && (act->pos.x>=24) && (act->pos.x<=32) ) ) { - act->push |= PUSH_YP; moving = true; + if ( (act->pos.y>=max.y) && (act->pos.z==room::getDoor(YP)*4) && (room::getDoors()&DOOR_YP) ) { + if (act->pos.x<28) + act->push |= PUSH_XP; + else if (act->pos.x>28) + act->push |= PUSH_XN; + else + act->push |= PUSH_YP; + } else + act->push |= PUSH_YP; } } if ( input::keyDown(SDL_SCANCODE_SPACE) && act->pos.y<=max.y && act->pos.y>=min.y && act->pos.x<=max.x && act->pos.x>=min.x && act->react_mask==0 && (act->pos.z==0 || act->below)) @@ -215,6 +247,8 @@ namespace actor if (act->react_mask) { + if (act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.yreact_push=8; + if (act->react_push<8) { act->pos.z++; @@ -294,6 +328,9 @@ namespace actor vec3_t min = room::getMin(); vec3_t max = room::getMax(); + //if ((act->flags&FLAG_HERO) && (act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.ypush & PUSH_ZP) { if (act->pos.z>=max.z) { @@ -316,7 +353,7 @@ namespace actor if (act->push & PUSH_XN) { act->pos.x--; actor::actor_t *other = actor::get_collision(act); - if (other || ( act->pos.xpos.y!=28) || !(act->flags&FLAG_HERO) ) )) + if (other || ( act->pos.xpos.y!=28) || (act->pos.z!=room::getDoor(XN)*4) || !(act->flags&FLAG_HERO) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XN; act->pos.x++; @@ -370,7 +407,7 @@ namespace actor if (act->push & PUSH_YN) { act->pos.y--; actor::actor_t *other = actor::get_collision(act); - if (other || ( act->pos.ypos.x!=28) || !(act->flags&FLAG_HERO) ) )) + if (other || ( act->pos.ypos.x!=28) || (act->pos.z!=room::getDoor(XN)*4) || !(act->flags&FLAG_HERO) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YN; act->pos.y++; @@ -424,7 +461,7 @@ namespace actor if (act->push & PUSH_ZN) { act->pos.z--; actor::actor_t *other = actor::get_collision(act); - if (act->pos.z<0 || other) + if (other || act->pos.z<0 || act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.yflags & FLAG_PUSHABLE) other->push |= PUSH_ZN; act->pos.z++; @@ -469,6 +506,10 @@ namespace actor below->above = act; return; } + vec3_t min = room::getMin(); + vec3_t max = room::getMax(); + + if (act->flags&FLAG_HERO && (act->pos.x>max.x || act->pos.xpos.y>max.y || act->pos.ypos.z--; } diff --git a/source/main.cpp b/source/main.cpp index 23371fc..e88bf5d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,23 +8,25 @@ draw::surface *surf; actor::actor_t *box; -int room_w = 0; -int room_h = 0; -int room_xp = 0; -int room_xn = 0; -int room_yp = 0; -int room_yn = 0; +int room_w = 2; +int room_h = 2; +int room_xp = -1; +int room_xn = -1; +int room_yp = -1; +int room_yn = -1; void restart() { actor::clear(); room::load(room_w, room_h, room_xp, room_xn, room_yp, room_yn); + /* box = actor::create("ASCENSOR",{16,32,0}, {8,8,4}, {64,0,32,24}, {0,24}); box->flags = FLAG_MOVING; box->movement = MOV_Z; box->mov_push = PUSH_ZP; actor::setDirty(box, true); + */ box = actor::create("BOX", {32,32,16}, {8,8,8}, {32,0,32,32}, {0,32}); box->flags = FLAG_PUSHABLE | FLAG_GRAVITY; @@ -75,7 +77,7 @@ void btn(const char* label, const int x, const int y, int &var, int min, int max { char buffer[100]; int result=0; - draw::print("ROOM WIDTH:", x, y+3, 15, 0); + draw::print(label, x, y+3, 15, 0); result=ui::button(SDL_itoa(var, buffer, 10), x+50, y, 28, 11); if (result) { diff --git a/source/room.cpp b/source/room.cpp index 11c6d2a..01108c2 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -162,4 +162,10 @@ namespace room { return doors; } + + uint8_t getDoor(const int d) + { + return door_height[d]; + } + } diff --git a/source/room.h b/source/room.h index c94a806..e57f36f 100644 --- a/source/room.h +++ b/source/room.h @@ -6,6 +6,11 @@ #define DOOR_YP 4 #define DOOR_YN 8 +#define XP 0 +#define XN 1 +#define YP 2 +#define YN 3 + namespace room { void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn); @@ -16,4 +21,5 @@ namespace room vec3_t getMin(); vec3_t getMax(); uint8_t getDoors(); + uint8_t getDoor(const int d); }