-Treballant en les portes

This commit is contained in:
2023-06-02 12:15:39 +02:00
parent e710069aec
commit 234f6dc287
4 changed files with 52 additions and 17 deletions

View File

@@ -164,7 +164,7 @@ namespace actor
if ( input::keyDown(SDL_SCANCODE_LEFT) ) if ( input::keyDown(SDL_SCANCODE_LEFT) )
{ {
act->orient=PUSH_XN; 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; act->push |= PUSH_XN;
moving = true; moving = true;
@@ -173,7 +173,7 @@ namespace actor
if ( input::keyDown(SDL_SCANCODE_RIGHT) ) if ( input::keyDown(SDL_SCANCODE_RIGHT) )
{ {
act->orient=PUSH_XP; act->orient=PUSH_XP;
if (act->pos.x<max.x) if ( (act->pos.x<max.x && act->pos.y>=min.y && act->pos.y<=max.y) || ( (room::getDoors()&DOOR_XP) && (act->pos.y>=24) && (act->pos.y<=32) ) )
{ {
act->push |= PUSH_XP; act->push |= PUSH_XP;
moving = true; moving = true;
@@ -182,7 +182,7 @@ namespace actor
if ( input::keyDown(SDL_SCANCODE_UP) ) if ( input::keyDown(SDL_SCANCODE_UP) )
{ {
act->orient=PUSH_YN; 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; act->push |= PUSH_YN;
moving = true; moving = true;
@@ -191,7 +191,7 @@ namespace actor
if ( input::keyDown(SDL_SCANCODE_DOWN) ) if ( input::keyDown(SDL_SCANCODE_DOWN) )
{ {
act->orient=PUSH_YP; act->orient=PUSH_YP;
if (act->pos.y<max.y) if ( (act->pos.y<max.y && act->pos.x>=min.y && act->pos.x<=max.x) || ( (room::getDoors()&DOOR_YP) && (act->pos.x>=24) && (act->pos.x<=32) ) )
{ {
act->push |= PUSH_YP; act->push |= PUSH_YP;
moving = true; moving = true;
@@ -314,7 +314,7 @@ namespace actor
if (act->push & PUSH_XN) { if (act->push & PUSH_XN) {
act->pos.x--; act->pos.x--;
actor::actor_t *other = actor::get_collision(act); actor::actor_t *other = actor::get_collision(act);
if (act->pos.x<min.x || other) if (other || ( act->pos.x<min.x && ( !(room::getDoors()&DOOR_XN) || (act->pos.y!=28) ) ))
{ {
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XN; if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XN;
act->pos.x++; act->pos.x++;
@@ -332,6 +332,8 @@ namespace actor
act->above->push = 0; act->above->push = 0;
} }
} }
if (act->pos.x<min.x-4) act->pos.x = max.x;
actor::setDirty(act); actor::setDirty(act);
} }
} }
@@ -339,7 +341,7 @@ namespace actor
if (act->push & PUSH_XP) { if (act->push & PUSH_XP) {
act->pos.x++; act->pos.x++;
actor::actor_t *other = actor::get_collision(act); 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; if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XP;
act->pos.x--; act->pos.x--;
@@ -357,6 +359,8 @@ namespace actor
act->above->push = 0; act->above->push = 0;
} }
} }
if (act->pos.x>max.x+4) act->pos.x = min.x;
actor::setDirty(act); actor::setDirty(act);
} }
} }
@@ -364,7 +368,7 @@ namespace actor
if (act->push & PUSH_YN) { if (act->push & PUSH_YN) {
act->pos.y--; act->pos.y--;
actor::actor_t *other = actor::get_collision(act); actor::actor_t *other = actor::get_collision(act);
if (act->pos.y<min.y || other) if (other || ( act->pos.y<min.y && ( !(room::getDoors()&DOOR_YN) || (act->pos.x!=28) ) ))
{ {
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YN; if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YN;
act->pos.y++; act->pos.y++;
@@ -382,6 +386,8 @@ namespace actor
act->above->push = 0; act->above->push = 0;
} }
} }
if (act->pos.y<min.y-4) act->pos.y = max.y;
actor::setDirty(act); actor::setDirty(act);
} }
} }
@@ -389,7 +395,7 @@ namespace actor
if (act->push & PUSH_YP) { if (act->push & PUSH_YP) {
act->pos.y++; act->pos.y++;
actor::actor_t *other = actor::get_collision(act); 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; if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YP;
act->pos.y--; act->pos.y--;
@@ -407,6 +413,8 @@ namespace actor
act->above->push = 0; act->above->push = 0;
} }
} }
if (act->pos.y>max.y+4) act->pos.y = min.y;
actor::setDirty(act); actor::setDirty(act);
} }
} }
@@ -481,15 +489,20 @@ namespace actor
void print(int x, int y, int num) void print(int x, int y, int num)
{ {
int digits=0; int digits=0;
bool sign = num < 0;
num = SDL_abs(num);
int n = num; int n = num;
while (n>0) {n=n/10;digits++;} while (n>0) {n=n/10;digits++;}
if (sign) digits++;
x=x+digits*4; x=x+digits*4;
if (num==0) draw::draw(x+4,y,5,7,0,120);
while (num>0) while (num>0)
{ {
draw::draw(x,y,5,7,(num%10)*5,120); draw::draw(x,y,5,7,(num%10)*5,120);
num=num/10; num=num/10;
x=x-4; x=x-4;
} }
if (sign) draw::draw(x,y,5,7,50,120);
} }
//int order=0; //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; 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); 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,act->pos.x);
//print(x+5,y+6,act->pos.y); print(x+5,y+6,act->pos.y);
//print(x+5,y+12,order); //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); if (draw_all && act->next) draw(act->next);
} }

View File

@@ -16,7 +16,7 @@ void game::init()
draw::loadPalette("test.gif"); draw::loadPalette("test.gif");
game::setUpdateTicks(64); 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 = actor::create({16,16,0}, {8,8,4}, {64,0,32,24}, {0,24});
box->flags = FLAG_MOVING; box->flags = FLAG_MOVING;
@@ -48,6 +48,7 @@ bool game::loop()
draw::cls(8); draw::cls(8);
room::draw(); room::draw();
actor::draw(actor::getFirst()); actor::draw(actor::getFirst());
room::draw2();
//draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0); //draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0);
draw::render(); draw::render();

View File

@@ -9,7 +9,7 @@ namespace room
static vec3_t min = {0,0,0}; static vec3_t min = {0,0,0};
static vec3_t max = {56,56,56}; 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) 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 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 // 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+3*16-tmin.y*16,32+3*8+tmin.y*8,40,59,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,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) if (doors & DOOR_XN)
{ {
// Pintem els dos tiles baix de la porta 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-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(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) 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); draw::draw(148+4*16-(tmax.y+1)*16,76+4*8+(tmax.y+1)*8,32,15,0,1);
// Pintem la porta YP // 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+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+4*16-8-(tmax.y+1)*16,28+4*8+4+(tmax.y+1)*8,24,55,34,137);
} }
if (doors & DOOR_XP) 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() vec3_t getSize()
{ {
return size; return size;

View File

@@ -10,6 +10,7 @@ namespace room
{ {
void load(int x, int y); void load(int x, int y);
void draw(); void draw();
void draw2();
vec3_t getSize(); vec3_t getSize();
vec3_t getMin(); vec3_t getMin();