From 234f6dc2877d2d773da9b5fbd6453152861fadb3 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 2 Jun 2023 12:15:39 +0200 Subject: [PATCH] -Treballant en les portes --- source/actor.cpp | 35 ++++++++++++++++++++++++----------- source/main.cpp | 3 ++- source/room.cpp | 30 +++++++++++++++++++++++++----- source/room.h | 1 + 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index 72b61e1..964d24e 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -164,7 +164,7 @@ namespace actor if ( input::keyDown(SDL_SCANCODE_LEFT) ) { act->orient=PUSH_XN; - if (act->pos.x>min.x) + 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; @@ -173,7 +173,7 @@ namespace actor if ( input::keyDown(SDL_SCANCODE_RIGHT) ) { act->orient=PUSH_XP; - if (act->pos.xpos.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; @@ -182,7 +182,7 @@ namespace actor if ( input::keyDown(SDL_SCANCODE_UP) ) { act->orient=PUSH_YN; - if (act->pos.y>min.y) + if ( (act->pos.y>min.y && act->pos.x>=min.y && act->pos.x<=max.x) || ( (room::getDoors()&DOOR_YN) && (act->pos.x>=24) && (act->pos.x<=32) ) ) { act->push |= PUSH_YN; moving = true; @@ -191,7 +191,7 @@ namespace actor if ( input::keyDown(SDL_SCANCODE_DOWN) ) { act->orient=PUSH_YP; - if (act->pos.ypos.ypos.x>=min.y && act->pos.x<=max.x) || ( (room::getDoors()&DOOR_YP) && (act->pos.x>=24) && (act->pos.x<=32) ) ) { act->push |= PUSH_YP; moving = true; @@ -314,7 +314,7 @@ namespace actor if (act->push & PUSH_XN) { act->pos.x--; actor::actor_t *other = actor::get_collision(act); - if (act->pos.xpos.xpos.y!=28) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XN; act->pos.x++; @@ -332,6 +332,8 @@ namespace actor act->above->push = 0; } } + if (act->pos.xpos.x = max.x; + actor::setDirty(act); } } @@ -339,7 +341,7 @@ namespace actor if (act->push & PUSH_XP) { act->pos.x++; actor::actor_t *other = actor::get_collision(act); - if (act->pos.x>max.x || other) + if (other || (act->pos.x>max.x && ( !(room::getDoors()&DOOR_XP) || (act->pos.y!=28) || !(act->flags&FLAG_HERO) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XP; act->pos.x--; @@ -357,6 +359,8 @@ namespace actor act->above->push = 0; } } + if (act->pos.x>max.x+4) act->pos.x = min.x; + actor::setDirty(act); } } @@ -364,7 +368,7 @@ namespace actor if (act->push & PUSH_YN) { act->pos.y--; actor::actor_t *other = actor::get_collision(act); - if (act->pos.ypos.ypos.x!=28) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YN; act->pos.y++; @@ -382,6 +386,8 @@ namespace actor act->above->push = 0; } } + if (act->pos.ypos.y = max.y; + actor::setDirty(act); } } @@ -389,7 +395,7 @@ namespace actor if (act->push & PUSH_YP) { act->pos.y++; actor::actor_t *other = actor::get_collision(act); - if (act->pos.y>max.y ||other) + if (other || ( act->pos.y>max.y && ( !(room::getDoors()&DOOR_YP) || (act->pos.x!=28) ) )) { if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YP; act->pos.y--; @@ -407,6 +413,8 @@ namespace actor act->above->push = 0; } } + if (act->pos.y>max.y+4) act->pos.y = min.y; + actor::setDirty(act); } } @@ -481,15 +489,20 @@ namespace actor void print(int x, int y, int num) { int digits=0; + bool sign = num < 0; + num = SDL_abs(num); int n = num; while (n>0) {n=n/10;digits++;} + if (sign) digits++; x=x+digits*4; + if (num==0) draw::draw(x+4,y,5,7,0,120); while (num>0) { draw::draw(x,y,5,7,(num%10)*5,120); num=num/10; x=x-4; } + if (sign) draw::draw(x,y,5,7,50,120); } //int order=0; @@ -507,10 +520,10 @@ namespace actor const int ao = (act->flags & FLAG_ANIMATED) ? anims[act->anim_cycle][anim_frame]*act->bmp_rect.w : 0; draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip); - //print(x+5,y,act->pos.x); - //print(x+5,y+6,act->pos.y); + print(x+5,y,act->pos.x); + print(x+5,y+6,act->pos.y); //print(x+5,y+12,order); - print(x+5,y,act->flags); + //print(x+5,y,act->flags); if (draw_all && act->next) draw(act->next); } diff --git a/source/main.cpp b/source/main.cpp index eb58b6b..5164d62 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -16,7 +16,7 @@ void game::init() draw::loadPalette("test.gif"); game::setUpdateTicks(64); - room::load(0,3); + room::load(1,3); box = actor::create({16,16,0}, {8,8,4}, {64,0,32,24}, {0,24}); box->flags = FLAG_MOVING; @@ -48,6 +48,7 @@ bool game::loop() draw::cls(8); room::draw(); actor::draw(actor::getFirst()); + room::draw2(); //draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0); draw::render(); diff --git a/source/room.cpp b/source/room.cpp index 83b8b4c..29f9b69 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -9,7 +9,7 @@ namespace room static vec3_t min = {0,0,0}; static vec3_t max = {56,56,56}; - static uint8_t doors = DOOR_YN; //15 ; + static uint8_t doors = 15 ; void load(int x, int y) { @@ -30,14 +30,17 @@ namespace room draw::draw(148+4*16-(tmin.y-1)*16, 76+4*8+(tmin.y-1)*8, 32, 15, 0, 1); // Tile de Piso // Pintem la porta YN - draw::draw(164+3*16-tmin.y*16,32+3*8+tmin.y*8,16,47,18,133); // Porta Y esq - draw::draw(164+4*16-tmin.y*16,28+4*8+tmin.y*8,24,55,34,137); // Porta Y dret + draw::draw(164+3*16-tmin.y*16,32+3*8+tmin.y*8,40,59,18,133); // Porta Y esq + //draw::draw(164+3*16-tmin.y*16,32+3*8+tmin.y*8,16,47,18,133); // Porta Y esq + //draw::draw(164+4*16-tmin.y*16,28+4*8+tmin.y*8,24,55,34,137); // Porta Y dret } if (doors & DOOR_XN) { // Pintem els dos tiles baix de la porta XN draw::draw(148+(tmin.x-1)*16-3*16,76+(tmin.x-1)*8+3*8,32,15,0,1); // Tile de Piso draw::draw(148+(tmin.x-1)*16-4*16,76+(tmin.x-1)*8+4*8,32,15,0,1); // Tile de Piso + + draw::draw( 164+tmin.x*16-4*16-16, 32+3*8+4+tmin.x*8, 40,59, 64,133); } for (int x=tmin.x;x<=tmax.x;++x) @@ -76,8 +79,8 @@ namespace room draw::draw(148+4*16-(tmax.y+1)*16,76+4*8+(tmax.y+1)*8,32,15,0,1); // Pintem la porta YP - 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); + //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) { @@ -93,6 +96,23 @@ namespace room } + void draw2() + { + if (doors & DOOR_YP) + { + // Pintem la porta YP + draw::draw(164+3*16-8-(tmax.y+1)*16,32+3*8+4+(tmax.y+1)*8,40,59,18,133); + //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) + { + // Pintem la porta XP + draw::draw( 164+(tmax.x+1)*16-4*16-16, 32+3*8+4+(tmax.x+1)*8, 40,59, 64,133); + } + + } + vec3_t getSize() { return size; diff --git a/source/room.h b/source/room.h index d06c266..5e23479 100644 --- a/source/room.h +++ b/source/room.h @@ -10,6 +10,7 @@ namespace room { void load(int x, int y); void draw(); + void draw2(); vec3_t getSize(); vec3_t getMin();