add plateforms as complete physical objects
there are no max coordinates any longer, but now thay can fall, and there is a better support with mario (not complete yet)
BIN
SuperCbr.g1a
After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 616 B After Width: | Height: | Size: 616 B |
|
@ -5,16 +5,13 @@
|
|||
#define P_MOVING_H 1
|
||||
#define P_MOVING_V 2
|
||||
|
||||
|
||||
#include <box.h>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned type;
|
||||
int xinit, yinit;
|
||||
int x, y;
|
||||
int width; // height fixed to 3
|
||||
int v, vinit;
|
||||
|
||||
union
|
||||
{
|
||||
|
@ -27,13 +24,14 @@ typedef struct
|
|||
int ymax;
|
||||
};
|
||||
int counter;
|
||||
box_t b;
|
||||
} plateforme_t;
|
||||
|
||||
#define PLATEFORME_HEIGHT 3
|
||||
|
||||
#define PLATEFORME_FALLING(x,y,w) {P_FALLING,x,y,x,y,w,0,0,.xmin=0,.xmax=0,0}
|
||||
#define PLATEFORME_MOVING_H(x,y,w,v,x0,x1) {P_MOVING_H,x,y,x,y,w,0,v,.xmin=x0,.xmax=x1,0}
|
||||
#define PLATEFORME_MOVING_V(x,y,w,v,y0,y1) {P_MOVING_V,x,y,x,y,w,0,v,.ymin=y0,.ymax=y1,0}
|
||||
#define PLATEFORME_FALLING(x,y,w) {P_FALLING,x,y,.xmin=0,.xmax=0,0, {x,y,w,3, 0,0, 0,0}}
|
||||
#define PLATEFORME_MOVING_H(x,y,w,v,x0,x1) {P_MOVING_H,x,y,.xmin=x0,.xmax=x1,0, {x,y,w,3, v,0, 0,0}}
|
||||
#define PLATEFORME_MOVING_V(x,y,w,v,y0,y1) {P_MOVING_V,x,y,.ymin=y0,.ymax=y1,0, {x,y,w,3, 0,v, 0,0}}
|
||||
|
||||
//void reset_plateforme(plateforme_t* p);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ typedef struct
|
|||
} tileset_t;
|
||||
|
||||
extern const tileset_t tuyau;
|
||||
extern const tileset_t arbre;
|
||||
extern const tileset_t brick;
|
||||
extern const tileset_t earth;
|
||||
extern const tileset_t gift;
|
||||
|
|
|
@ -8,10 +8,23 @@
|
|||
#define W_SIZE_X 160
|
||||
#define W_SIZE_Y 16
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EMPTY=0,
|
||||
EARTH,
|
||||
BRICK,
|
||||
BLOC,
|
||||
END_LEVEL,
|
||||
TUYAU,
|
||||
ARBRE,
|
||||
GIFT,
|
||||
COIN,
|
||||
NUAGE,
|
||||
BUISSON,
|
||||
COLLINE,
|
||||
CASTLE,
|
||||
} cell_id;
|
||||
|
||||
#define EMPTY 0
|
||||
|
||||
#define EARTH 1 // X, Y, _ (XY tileset)
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -20,7 +33,6 @@ typedef struct
|
|||
unsigned y :4;
|
||||
} earth_t;
|
||||
|
||||
#define BRICK 2
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -31,14 +43,12 @@ typedef struct
|
|||
unsigned number :4;
|
||||
} brick_t;
|
||||
|
||||
#define BLOC 3
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
unsigned data :24; // raw binary format
|
||||
} bloc_t;
|
||||
|
||||
#define END_LEVEL 4
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -50,7 +60,6 @@ typedef struct
|
|||
|
||||
} end_level_t;
|
||||
|
||||
#define TUYAU 5 // X, Y, _ (XY tileset)
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -59,7 +68,15 @@ typedef struct
|
|||
unsigned y :4;
|
||||
} tuyau_t;
|
||||
|
||||
#define GIFT 6 // s, t, n (state[hit time], type[vide=0, piece=1, ...], qté)
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
unsigned empty :16;
|
||||
unsigned x :4;
|
||||
unsigned y :4;
|
||||
} arbre_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -70,7 +87,6 @@ typedef struct
|
|||
unsigned number :4;
|
||||
} gift_t;
|
||||
|
||||
#define COIN 7 // s, _, _ (state)
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -78,10 +94,6 @@ typedef struct
|
|||
unsigned taken :4;
|
||||
} coin_t;
|
||||
|
||||
#define NUAGE 8 // X, Y, _ (XY tileset)
|
||||
#define BUISSON 9 // X, Y, _ (XY tileset)
|
||||
#define COLLINE 10 // X, Y, _ (XY tileset)
|
||||
#define CASTLE 11
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
@ -90,7 +102,7 @@ typedef struct
|
|||
unsigned y :4;
|
||||
} deco_t;
|
||||
|
||||
// Generic container
|
||||
// Generic container 32 bits
|
||||
typedef struct
|
||||
{
|
||||
unsigned type :8;
|
||||
|
|
After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 872 B |
After Width: | Height: | Size: 860 B |
|
@ -16,14 +16,14 @@ beton = (84, 84, 84)
|
|||
tuyau_milieu = (0, 255, 102)
|
||||
tuyau_bout = (50, 255, 0)
|
||||
drapeau = (0, 255, 216)
|
||||
|
||||
goomba = (127, 76, 0)
|
||||
koopa_vert = (25, 127, 0)
|
||||
koopa_rouge = (127, 0, 0)
|
||||
|
||||
mario_start = (108, 81, 47)
|
||||
|
||||
nuage = (127, 127, 127)
|
||||
arbre_tronc = (74,35,18)
|
||||
arbre_feuilles = (0,86,0)
|
||||
|
||||
|
||||
def color_compare(color1, color2):
|
||||
if color1[0] == color2[0] and color1[1] == color2[1] and color1[2] == color2[2]:
|
||||
|
@ -103,6 +103,12 @@ for x in range(0,img.size[0]):
|
|||
elif color_compare(pixels[x,y], nuage):
|
||||
code += write_char(15)
|
||||
|
||||
elif color_compare(pixels[x,y], arbre_tronc):
|
||||
code += write_char(16)
|
||||
|
||||
elif color_compare(pixels[x,y], arbre_feuilles):
|
||||
code += write_char(17)
|
||||
|
||||
else:
|
||||
code += write_char(0)
|
||||
|
||||
|
|
|
@ -27,18 +27,18 @@ static void move_x(box_t * b)
|
|||
{
|
||||
int sgn_vx=sgn(b->vx);
|
||||
|
||||
int t_vx=((sgn_vx*b->vx+time_id%2)/2)*sgn_vx;
|
||||
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 (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
|
||||
coef=2;
|
||||
coef=2;//ralentir dans l'eau
|
||||
if (frame_id%coef)
|
||||
return;
|
||||
|
||||
if (sgn_vx)
|
||||
{
|
||||
for (int i=sgn_vx; i<=sgn_vx*t_vx; i++)
|
||||
for (int i=1; i<=sgn_vx*t_vx; i++)
|
||||
{
|
||||
for (int j=0; j<b->h; j++)
|
||||
{
|
||||
|
|
29
src/level.c
|
@ -14,6 +14,7 @@
|
|||
#include <gint/std/string.h>
|
||||
#include <gint/std/stdio.h>
|
||||
#include <liblog.h>
|
||||
#include <base.h>
|
||||
|
||||
#define PACKED_EMPTY 0
|
||||
#define PACKED_STONE 1
|
||||
|
@ -31,6 +32,8 @@
|
|||
#define PACKED_KOOPA_ROUGE 13
|
||||
#define PACKED_MARIO_START 14
|
||||
#define PACKED_NUAGE 15
|
||||
#define PACKED_ARBRE_TRONC 16
|
||||
#define PACKED_ARBRE_FEUILLES 17
|
||||
|
||||
void malloc_error()
|
||||
{
|
||||
|
@ -279,6 +282,26 @@ static void unpack_level(packed_level_t * p)
|
|||
cell_t t={NUAGE,16*px+py};
|
||||
cell = t;
|
||||
}
|
||||
else if (contents==PACKED_ARBRE_TRONC)
|
||||
{
|
||||
cell_t t={ARBRE,0x11};
|
||||
cell = t;
|
||||
}
|
||||
else if (contents==PACKED_ARBRE_FEUILLES)
|
||||
{
|
||||
int px=0;
|
||||
if (pack_access(p,x+1,y)==PACKED_ARBRE_FEUILLES)
|
||||
{
|
||||
if (pack_access(p,x-1,y)==PACKED_ARBRE_FEUILLES)
|
||||
px=1;
|
||||
else
|
||||
px=0;
|
||||
}
|
||||
else
|
||||
px=2;
|
||||
cell_t t={ARBRE,16*px};
|
||||
cell = t;
|
||||
}
|
||||
|
||||
cell_set(c,w,h,x,y,cell);
|
||||
|
||||
|
@ -361,6 +384,12 @@ void set_level(int w, int l)
|
|||
};
|
||||
init_plateformes(plateforme0,sizeof(plateforme0)/sizeof(plateforme_t));
|
||||
}
|
||||
|
||||
if (w+1==1 && l+1==3) // 1-2
|
||||
{
|
||||
extern packed_level_t bin_lvl_1_3;
|
||||
unpack_level(&bin_lvl_1_3);
|
||||
}
|
||||
}
|
||||
|
||||
void get_lvl_id(int w, int l, char * str)
|
||||
|
|
|
@ -15,72 +15,45 @@ plateforme_t* plateformes=0;
|
|||
|
||||
void reset_plateforme(plateforme_t* p)
|
||||
{
|
||||
p->x=p->xinit;
|
||||
p->y=p->yinit;
|
||||
p->v=p->vinit;
|
||||
p->b.x=p->xinit;
|
||||
p->b.y=p->yinit;
|
||||
}
|
||||
|
||||
void move_plateforme(plateforme_t* p)
|
||||
{/*
|
||||
if (p->x+p->width-world_get_real_x0()<-50)
|
||||
return;
|
||||
if (p->x-world_get_real_x0()-128>50)
|
||||
return;
|
||||
|
||||
|
||||
if (p->y-world_get_real_y0()-64>50)
|
||||
return;
|
||||
if (p->y+3-world_get_real_y0()<-50)
|
||||
return;
|
||||
*/
|
||||
|
||||
int xc = (mario.p.x<p->x+p->width && mario.p.x>=p->x) || (mario.p.x+mario.p.w<p->x+p->width && mario.p.x+mario.p.w>=p->x);
|
||||
int yc = (mario.p.y-3==p->y);
|
||||
|
||||
if (p->type==P_FALLING)
|
||||
{
|
||||
if (p->v)
|
||||
p->v++;
|
||||
p->y+=p->v/2;
|
||||
}
|
||||
|
||||
if (p->type==P_MOVING_H)
|
||||
{
|
||||
int s=sgn(p->v);
|
||||
int t_v=((s*p->v+time_id%2)/2)*s;
|
||||
if (p->v==0)
|
||||
p->v=p->vinit;
|
||||
p->x+=t_v;
|
||||
int xc = (mario.p.x<p->b.x+p->b.w && mario.p.x>=p->b.x) || (mario.p.x+mario.p.w<p->b.x+p->b.w && mario.p.x+mario.p.w>=p->b.x);
|
||||
int yc = (mario.p.y-3==p->b.y);
|
||||
|
||||
/*if (p->type==P_FALLING)
|
||||
{
|
||||
if (p->v)
|
||||
p->v++;
|
||||
p->b.y+=p->v/2;
|
||||
}*/
|
||||
box_t temp=p->b;
|
||||
|
||||
box_move(&p->b);
|
||||
|
||||
// Si mario est sur la plateforme, il bouge avec
|
||||
if (xc&&yc)
|
||||
mario.p.x+=t_v;
|
||||
if (p->x+p->width > p->xmax && p->v>0)
|
||||
p->v *= -1;
|
||||
if (p->x < p->xmin && p->v<0)
|
||||
p->v *= -1;
|
||||
}
|
||||
{
|
||||
box_t mario_clone=mario.p;
|
||||
mario_clone.vx=temp.vx;
|
||||
mario_clone.vy=temp.vy;
|
||||
box_move(&mario_clone);
|
||||
mario.p.x=mario_clone.x;
|
||||
mario.p.y=mario_clone.y;
|
||||
}
|
||||
|
||||
if (p->type==P_MOVING_V)
|
||||
{
|
||||
int s=sgn(p->v);
|
||||
int t_v=((s*p->v+time_id%2)/2)*s;
|
||||
if (p->v==0)
|
||||
p->v=p->vinit;
|
||||
p->y+=t_v;
|
||||
if (p->y > p->ymax || p->y+3 < p->ymin)
|
||||
p->v *= -1;
|
||||
}
|
||||
|
||||
if (xc&&yc)
|
||||
{
|
||||
int s=sgn(p->v);
|
||||
int t_v=((s*p->v+time_id%2)/2)*s;
|
||||
if (p->type==P_FALLING)
|
||||
mario.p.y+=p->v/2;
|
||||
if (p->type==P_MOVING_V)
|
||||
mario.p.y+=t_v;
|
||||
if (p->type==P_MOVING_H)
|
||||
mario.p.x+=t_v/2;
|
||||
}
|
||||
|
||||
if (p->b.vx==0)
|
||||
{
|
||||
p->b.vx=-temp.vx;
|
||||
//p->b.x -= sgn(p->b.vx);
|
||||
}
|
||||
if (p->b.vy==0)
|
||||
p->b.vy=-temp.vy;
|
||||
}
|
||||
|
||||
void display_plateformes()
|
||||
|
@ -91,9 +64,9 @@ void display_plateformes()
|
|||
for (int i=0; i<plateforme_table_size; i++)
|
||||
{
|
||||
p=&plateformes[i];
|
||||
for (int j=p->x; j < p->x+p->width; j+=3)
|
||||
draw_tile(j-camera_x(),p->y-camera_y(), &tplateforme, 0,0);
|
||||
//drect(p->x-world_get_real_x0(),64-(p->y-world_get_real_y0()),p->x-world_get_real_x0()+p->width,64-(p->y-world_get_real_y0()-3), C_BLACK);
|
||||
for (int j=p->b.x; j < p->b.x+p->b.w; j+=3)
|
||||
draw_tile(j-camera_x(),p->b.y-camera_y(), &tplateforme, 0,0);
|
||||
//drect(p->b.x-world_get_real_x0(),64-(p->b.y-world_get_real_y0()),p->b.x-world_get_real_x0()+p->b.w,64-(p->b.y-world_get_real_y0()-3), C_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +89,7 @@ int plateforme_check_collide(int x, int y)
|
|||
for (int i=0; i<plateforme_table_size; i++)
|
||||
{
|
||||
plateforme_t * p=&plateformes[i];
|
||||
if (p->x<=x && p->x+p->width>x && p->y<=y && p->y+3>y)
|
||||
if (p->b.x<=x && p->b.x+p->b.w>x && p->b.y<=y && p->b.y+3>y)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -7,6 +7,8 @@ int dark_theme=0;
|
|||
|
||||
extern image_t img_tuyau;
|
||||
const tileset_t tuyau={&img_tuyau, TILE_W, TILE_H, 1};
|
||||
extern image_t img_arbre;
|
||||
const tileset_t arbre={&img_arbre, TILE_W, TILE_H, 0};
|
||||
|
||||
extern image_t img_brick;
|
||||
const tileset_t brick={&img_brick, TILE_W, TILE_H, 1};
|
||||
|
|
18
src/world.c
|
@ -51,6 +51,13 @@ void display_cell(int cx, int cy, int sx, int sy, int plan)
|
|||
draw_tile(sx, sy, &tuyau, i->x, i->y);
|
||||
}
|
||||
|
||||
if (cell->type==ARBRE)
|
||||
{
|
||||
arbre_t* i=(arbre_t*)cell;
|
||||
draw_tile(sx, sy, &arbre, i->x, i->y);
|
||||
}
|
||||
|
||||
|
||||
if (cell->type==EARTH)
|
||||
{
|
||||
earth_t* i=(earth_t*)cell;
|
||||
|
@ -144,6 +151,12 @@ int world_get_ctg(int x, int y)
|
|||
}
|
||||
if (plateforme_check_collide(x,y))
|
||||
return CTG_SOIL;
|
||||
if (c->type==ARBRE)
|
||||
{
|
||||
arbre_t* a=(arbre_t*)c;
|
||||
if (a->x==1&&a->y==1)
|
||||
return CTG_EMPTY;
|
||||
}
|
||||
switch (c->type)
|
||||
{
|
||||
case TUYAU:
|
||||
|
@ -151,6 +164,7 @@ int world_get_ctg(int x, int y)
|
|||
case BRICK:
|
||||
case EARTH:
|
||||
case BLOC:
|
||||
case ARBRE:
|
||||
return CTG_SOIL;
|
||||
default:
|
||||
return CTG_EMPTY;
|
||||
|
@ -159,8 +173,8 @@ int world_get_ctg(int x, int y)
|
|||
|
||||
void world_draw()
|
||||
{
|
||||
//camera_move(0);
|
||||
camera_adjust();
|
||||
camera_move(0);
|
||||
//camera_adjust();
|
||||
int mx0=camera_x();
|
||||
int my0=camera_y();
|
||||
int sx0=mx0%8;
|
||||
|
|