new mario hit box => reduced width

This commit is contained in:
Milang 2020-02-16 12:51:27 +01:00
parent 4fb0254dba
commit 6d29add2da
6 changed files with 52 additions and 56 deletions

Binary file not shown.

View File

@ -21,7 +21,7 @@ typedef struct
} box_t;
void box_move(box_t * b);
int BoxContact(box_t const * b1, box_t const * b2);
void box_jump(box_t * b, int height);
#endif
#endif

View File

@ -36,7 +36,7 @@ void bonus_move() //+collision
box_move(&bonus.b);
if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR)
{
if (bonus.b.vx==0)
{
if (bonus.p1==0)
@ -44,7 +44,7 @@ void bonus_move() //+collision
bonus.b.vx=2;
bonus.p1=1;
}
else
else
{
bonus.p1*=-1;
bonus.b.vx=2*bonus.p1;
@ -54,9 +54,8 @@ void bonus_move() //+collision
bonus_set(BONUS_NONE,0,0);
}
bool x_collide= (mario.p.x<=bonus.b.x && bonus.b.x<mario.p.x+mario.p.w) || (mario.p.x<=bonus.b.x+bonus.b.w-1 && bonus.b.x+bonus.b.w<mario.p.x+mario.p.w);
bool y_collide= (mario.p.y<=bonus.b.y && bonus.b.y<mario.p.y+mario.p.h) || (mario.p.y<=bonus.b.y+bonus.b.h-1 && bonus.b.y+bonus.b.h<mario.p.y+mario.p.h);
if (x_collide&&y_collide)
int collide=BoxContact(&mario.p, &bonus.b);
if (collide)
{
if (bonus.type==BONUS_CHAMPI)
{
@ -98,4 +97,4 @@ void bonus_draw()
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &life_1up, 0,0);
if (bonus.type==BONUS_STAR)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &mario_starman, 0,0);
}
}

View File

@ -7,17 +7,20 @@
int check_collision(box_t *b)
{
for (int i=0; i<ennemis_global_size; i++)
{
box_t* t=&ennemis_global[i].b;
if (t!=b)
{
int x_collide= (t->x<=b->x && b->x<t->x+t->w) || (t->x<=b->x+b->w-1 && b->x+b->w<t->x+t->w);
int y_collide= (t->y<=b->y && b->y<t->y+t->h) || (t->y<=b->y+b->h-1 && b->y+b->h<t->y+t->h);
if (x_collide&&y_collide)
return 1;
}
}
for (int i=0; i<ennemis_global_size; i++) if (BoxContact(&ennemis_global[i].b,b)) return 1;
return 0;
}
int 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);*/
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;
return 0;
}
@ -32,9 +35,9 @@ static void move_x(box_t * b)
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;//ralentir dans l'eau
coef=2;//ralentir dans l'eau
if (frame_id%coef)
return;
return;
if (sgn_vx)
{
@ -44,9 +47,9 @@ static void move_x(box_t * b)
{
int typetemp;
if (sgn_vx>0)
typetemp=world_get_ctg(b->x+b->w-1+i*sgn_vx,b->y+j);
typetemp=world_get_ctg(b->x+b->w-1+i*sgn_vx,b->y+j);
else
typetemp=world_get_ctg(b->x+i*sgn_vx,b->y+j);
typetemp=world_get_ctg(b->x+i*sgn_vx,b->y+j);
if (typetemp==CTG_SOIL)
{
b->x+=(i-1)*sgn_vx;
@ -66,12 +69,12 @@ static void move_y(box_t * b)
{
b->last_vy=b->vy;
int sgn_vy=sgn(b->vy);
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;// 0.5
coef=2;// 0.5
if (frame_id%coef)
return;
return;
if (sgn_vy)
{
@ -81,27 +84,27 @@ static void move_y(box_t * b)
{
int typetemp;
if (sgn_vy>0)
typetemp=world_get_ctg(b->x+j ,b->y+b->h-1+i);
typetemp=world_get_ctg(b->x+j ,b->y+b->h-1+i);
else
typetemp=world_get_ctg(b->x+j ,b->y-i);
typetemp=world_get_ctg(b->x+j ,b->y-i);
if (typetemp==CTG_SOIL)
{
if (b->vy>0)
{
int old=b->x;
if (world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
b->x++;
if (world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
b->x++;
if (world_get_ctg(b->x, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
b->x++;
if (world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
b->x--;
if (world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
b->x--;
if (world_get_ctg(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
b->x--;
if (old==b->x)
{
b->y+=(i-1)*sgn_vy;
@ -121,14 +124,14 @@ static void move_y(box_t * b)
}
b->y+=b->vy;
}
//if (b->vy>=-6)
//if (b->vy>=-6)
b->vy-=b->gravity;
}
void box_move(box_t * b)
{
//velx
//velx
move_x(b);
move_y(b);
}
@ -143,13 +146,13 @@ void box_jump(box_t * b, int height)
{
int typetemp=world_get_ctg(b->x+j ,b->y+sgn_vy);
if (typetemp==CTG_SOIL)
sol++;
sol++;
if (typetemp==CTG_WATER)
eau++;
eau++;
}
if (sol)
b->vy=height;
b->vy=height;
else if (eau)
b->vy+=height/2;
b->vy+=height/2;
}
}
}

View File

@ -75,11 +75,7 @@ void display_ennemi(ennemi_t * e)
}
bool ennemi_check_collision(ennemi_t *e)
{ 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);
return (x_collide&&y_collide);
}
bool ennemi_check_collision(ennemi_t *e) { return (BoxContact(&e->b, &mario.p)); }
void hurt_mario()
{ if (mario.size==M_SMALL && mario_immunity==0)
@ -114,14 +110,13 @@ void move_ennemi(ennemi_t *e)
for (int i=0; i<ennemis_global_size; i++)
{
ennemi_t* t=&ennemis_global[i];
if (t!=e && t->discovered && t->type!=NONE)
if (t->type!=NONE)
{
bool x_collide= (t->b.x<=e->b.x+e->b.vx && e->b.x+e->b.vx<t->b.x+t->b.w) || (t->b.x<=e->b.x+e->b.w-1+e->b.vx && e->b.x+e->b.w+e->b.vx<t->b.x+t->b.w);
bool y_collide= (t->b.y<=e->b.y+e->b.vy && e->b.y+e->b.vy<t->b.y+t->b.h) || (t->b.y<=e->b.y+e->b.h-1+e->b.vy && e->b.y+e->b.h+e->b.vy<t->b.y+t->b.h);
if (x_collide&&y_collide && t->life!=DEAD)
e->b.x+=sgn(e->b.vx)*(abs(e->b.vx)+(time_id%2))/2;
const int contact=BoxContact(&e->b, &t->b);
e->b.x-=sgn(e->b.vx)*(abs(e->b.vx)+(time_id%2))/2;
if (contact && t->life!=DEAD)
{
if (e->type!=CARAPACE_VERTE && e->type!=CARAPACE_ROUGE)
{
@ -141,7 +136,6 @@ void move_ennemi(ennemi_t *e)
t->p1=0;
score_add(200);
}
}
}
}
@ -385,4 +379,4 @@ void init_ennemi(ennemi_t * table, int s)
malloc_error();
ennemis_global_size=s;
memcpy(ennemis_global, table, size);
}
}

View File

@ -14,7 +14,7 @@ int id_frame=0;
pnj mario=
{
{26,17,8,8,0,0,0,1},
{26,17,6,8,0,0,0,1},
M_SMALL,
M_RIGHT1, M_WALK,
0
@ -52,7 +52,7 @@ void mario_draw()
{
if ( (mario_immunity==0 || (mario_immunity/7)%2==0) && (mario_star_mode/2)%2==0)
{
const int mx=mario.p.x-camera_x(mario.p.x);
const int mx=mario.p.x-camera_x(mario.p.x)-1;
const int my=mario.p.y-camera_y(mario.p.y);
if (mario.size==M_SMALL)
{