fix minor hitbox bug when conflict with platform & blocs
This commit is contained in:
parent
7138dd442c
commit
27a22209e3
|
@ -2,7 +2,7 @@
|
|||
|
||||
[_1]
|
||||
Type=5
|
||||
Order=0
|
||||
Order=1
|
||||
Top=15
|
||||
Left=2235
|
||||
Height=4740
|
||||
|
@ -13,7 +13,7 @@ OptionA=0
|
|||
|
||||
[_2]
|
||||
Type=1
|
||||
Order=1
|
||||
Order=0
|
||||
Top=15
|
||||
Left=7800
|
||||
Height=4740
|
||||
|
|
BIN
SuperCbr.g1a
BIN
SuperCbr.g1a
Binary file not shown.
59
src/box.c
59
src/box.c
|
@ -13,11 +13,7 @@ int check_collision(box_t *b)
|
|||
|
||||
bool boxContact(box_t const * b1, box_t const * b2)
|
||||
{
|
||||
if (b1==b2) return 0;/*
|
||||
bool x_collide= (mario.p.x<=e->b.x && e->b.x<=mario.p.x+mario.p.w-1) || (mario.p.x<=e->b.x+e->b.w-1 && e->b.x+e->b.w-1<=mario.p.x+mario.p.w-1);
|
||||
bool y_collide= (mario.p.y<=e->b.y && e->b.y<=mario.p.y+mario.p.h-1) || (mario.p.y<=e->b.y+e->b.h-1 && e->b.y+e->b.h-1<=mario.p.y+mario.p.h-1);*/
|
||||
|
||||
|
||||
if (b1==b2) return 0;
|
||||
int x_collide= (b2->x >= b1->x && b2->x < b1->x+b1->w) || (b1->x >= b2->x && b1->x < b2->x + b2->w);
|
||||
int y_collide= (b2->y >= b1->y && b2->y < b1->y+b1->h) || (b1->y >= b2->y && b1->y < b2->y + b2->h);
|
||||
if (x_collide&&y_collide) return 1;
|
||||
|
@ -33,11 +29,9 @@ static void move_x(box_t * b)
|
|||
int t_vx=((sgn_vx*b->vx+time_id%2)/2)*sgn_vx; // si n impair, alterne entre n+1 n-1
|
||||
sgn_vx=sgn(t_vx);
|
||||
|
||||
int coef=1;//1;
|
||||
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
|
||||
coef=2;//ralentir dans l'eau
|
||||
if (frame_id%coef)
|
||||
return;
|
||||
int coef=1;// move each frame
|
||||
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER) coef=2; //slow down in water
|
||||
if (frame_id%coef) return; // move 1 frame of 2 when in water ~to be improved
|
||||
|
||||
if (sgn_vx)
|
||||
{
|
||||
|
@ -92,19 +86,40 @@ static void move_y(box_t * b)
|
|||
if (b->vy>0)
|
||||
{
|
||||
int old=b->x;
|
||||
if (worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
if (worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
if (worldGetCellCategory(b->x, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
|
||||
if (worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
if (worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
if (worldGetCellCategory(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
{ // contournement du coin si seul le coin touche
|
||||
box_t temp_hitbox=*b;
|
||||
|
||||
int sgn_vx=0;
|
||||
|
||||
if (worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
sgn_vx++;
|
||||
if (worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
sgn_vx++;
|
||||
if (worldGetCellCategory(b->x, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
sgn_vx++;
|
||||
|
||||
if (worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
sgn_vx--;
|
||||
if (worldGetCellCategory(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
sgn_vx--;
|
||||
|
||||
int fail=0;
|
||||
for (int i=0; i<abs(sgn_vx); i++)
|
||||
{
|
||||
for (int j=0; j<b->h; j++) // test de validité
|
||||
{
|
||||
int typetemp;
|
||||
if (sgn_vx>0) typetemp=worldGetCellCategory(temp_hitbox.x+temp_hitbox.w-1+i*sgn_vx,temp_hitbox.y+j);
|
||||
else typetemp=worldGetCellCategory(temp_hitbox.x+i*sgn_vx,temp_hitbox.y+j);
|
||||
|
||||
if (typetemp==CTG_SOIL) fail=1;
|
||||
}
|
||||
temp_hitbox.x+=sgn(sgn_vx);
|
||||
}
|
||||
if (!fail) *b=temp_hitbox;
|
||||
}
|
||||
|
||||
if (old==b->x)
|
||||
{
|
||||
b->y+=(i-1)*sgn_vy;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "mario.h"
|
||||
#include <mario.h>
|
||||
|
||||
#include "tile.h"
|
||||
#include "world.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -219,12 +220,12 @@ void marioMove()
|
|||
brick_t *c=(brick_t*)t;
|
||||
if (c->time_hit_id==0 && mario.p.last_vy>0)
|
||||
{
|
||||
//mario.p.vy=0;
|
||||
if (c->content==0 || c->number)
|
||||
{
|
||||
c->time_hit_id=1;
|
||||
mario.p.last_vy=0;
|
||||
}
|
||||
|
||||
if (c->content==1 && c->number)
|
||||
{
|
||||
c->number--;
|
||||
|
|
Loading…
Reference in New Issue