From 5a089b3333698a09e16c4118aa72836d11357e52 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 10 Mar 2023 18:57:04 +0100 Subject: [PATCH] - Treballant en les portes --- source/actor.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ source/room.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ source/room.h | 5 +++++ 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index ab21f56..72b61e1 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -161,15 +161,49 @@ namespace actor vec3_t max = room::getMax(); bool moving = false; - if (input::keyDown(SDL_SCANCODE_LEFT) && act->pos.x>min.x) { act->push |= PUSH_XN; act->orient=PUSH_XN; moving = true; } - if (input::keyDown(SDL_SCANCODE_RIGHT) && act->pos.xpush |= PUSH_XP; act->orient=PUSH_XP; moving = true; } - if (input::keyDown(SDL_SCANCODE_UP) && act->pos.y>min.y) { act->push |= PUSH_YN; act->orient=PUSH_YN; moving = true; } - if (input::keyDown(SDL_SCANCODE_DOWN) && act->pos.ypush |= PUSH_YP; act->orient=PUSH_YP; moving = true; } - if (input::keyDown(SDL_SCANCODE_SPACE) && act->react_mask==0 && (act->pos.z==0 || act->below)) { + if ( input::keyDown(SDL_SCANCODE_LEFT) ) + { + act->orient=PUSH_XN; + if (act->pos.x>min.x) + { + act->push |= PUSH_XN; + moving = true; + } + } + if ( input::keyDown(SDL_SCANCODE_RIGHT) ) + { + act->orient=PUSH_XP; + if (act->pos.xpush |= PUSH_XP; + moving = true; + } + } + if ( input::keyDown(SDL_SCANCODE_UP) ) + { + act->orient=PUSH_YN; + if (act->pos.y>min.y) + { + act->push |= PUSH_YN; + moving = true; + } + } + if ( input::keyDown(SDL_SCANCODE_DOWN) ) + { + act->orient=PUSH_YP; + if (act->pos.ypush |= PUSH_YP; + moving = true; + } + } + if ( input::keyDown(SDL_SCANCODE_SPACE) && act->react_mask==0 && (act->pos.z==0 || act->below)) + { act->react_mask=1; act->react_push=0; act->flags &= uint8_t(~FLAG_GRAVITY); - if (act->below) { + if (act->below) + { act->below->above = nullptr; act->below = nullptr; } diff --git a/source/room.cpp b/source/room.cpp index 973807b..3a65aa2 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -9,6 +9,8 @@ namespace room static vec3_t min = {0,0,0}; static vec3_t max = {56,56,56}; + static uint8_t doors = DOOR_YP; + void load(int x, int y) { size = {(x+1)*2,(y+1)*2,3}; @@ -20,13 +22,56 @@ namespace room void draw() { + if (doors & DOOR_YN) + { + draw::draw(164+4*16-(tmin.y-1)*16,84+4*8+(tmin.y-1)*8,16,15,144,49); + draw::draw(148+3*16-(tmin.y-1)*16,76+3*8+(tmin.y-1)*8,32,15,0,1); + draw::draw(148+4*16-(tmin.y-1)*16,76+4*8+(tmin.y-1)*8,32,15,0,1); + + draw::draw(164+3*16-tmin.y*16,32+3*8+tmin.y*8,16,47,18,133); + draw::draw(164+4*16-tmin.y*16,28+4*8+tmin.y*8,24,55,34,137); + } + if (doors & DOOR_XN) + { + draw::draw(148+(tmin.x-1)*16-3*16,76+(tmin.x-1)*8+3*8,32,15,0,1); + draw::draw(148+(tmin.x-1)*16-4*16,76+(tmin.x-1)*8+4*8,32,15,0,1); + } + + for (int x=tmin.x;x<=tmax.x;++x) + { + if ( !(doors & DOOR_YP) || (x!=3 && x!=4) ) draw::draw(148+x*16-tmax.y*16,84+x*8+tmax.y*8,16,15,128,49); + if ( !(doors & DOOR_YN) || (x!=3 && x!=4) ) draw::draw(164+x*16-tmin.y*16,36+x*8+tmin.y*8,16,48,128,16); + } for (int y=tmin.y;y<=tmax.y;++y) { + if ( !(doors & DOOR_XP) || (y!=3 && y!=4) ) draw::draw(164+tmax.x*16-y*16,84+tmax.x*8+y*8,16,15,144,49); + if ( !(doors & DOOR_XN) || (y!=3 && y!=4) ) draw::draw(148+tmin.x*16-y*16,36+tmin.x*8+y*8,16,48,144,16); for (int x=tmin.x;x<=tmax.x;++x) { draw::draw(148+x*16-y*16,76+x*8+y*8,32,15,0,1); } } + if (doors & DOOR_YP) + { + draw::draw(164+4*16-(tmax.y+1)*16,84+4*8+(tmax.y+1)*8,16,15,144,49); + draw::draw(148+3*16-(tmax.y+1)*16,84+3*8+(tmax.y+1)*8,16,15,128,49); + draw::draw(148+4*16-(tmax.y+1)*16,84+4*8+(tmax.y+1)*8,16,15,128,49); + draw::draw(148+3*16-(tmax.y+1)*16,76+3*8+(tmax.y+1)*8,32,15,0,1); + draw::draw(148+4*16-(tmax.y+1)*16,76+4*8+(tmax.y+1)*8,32,15,0,1); + + draw::draw(164+3*16-8-(tmax.y+1)*16,32+3*8+4+(tmax.y+1)*8,16,47,18,133); + draw::draw(164+4*16-8-(tmax.y+1)*16,28+4*8+4+(tmax.y+1)*8,24,55,34,137); + } + if (doors & DOOR_XP) + { + draw::draw(148+(tmax.x+1)*16-4*16,84+(tmax.x+1)*8+4*8,16,15,128,49); + draw::draw(164+(tmax.x+1)*16-3*16,84+(tmax.x+1)*8+3*8,16,15,144,49); + draw::draw(164+(tmax.x+1)*16-4*16,84+(tmax.x+1)*8+4*8,16,15,144,49); + + draw::draw(148+(tmax.x+1)*16-3*16,76+(tmax.x+1)*8+3*8,32,15,0,1); + draw::draw(148+(tmax.x+1)*16-4*16,76+(tmax.x+1)*8+4*8,32,15,0,1); + } + } vec3_t getSize() diff --git a/source/room.h b/source/room.h index beef806..8883c78 100644 --- a/source/room.h +++ b/source/room.h @@ -1,6 +1,11 @@ #pragma once #include "misc.h" +#define DOOR_XP 1 +#define DOOR_XN 2 +#define DOOR_YP 4 +#define DOOR_YN 8 + namespace room { void load(int x, int y);