2019-11-24 14:28:04 +01:00
|
|
|
#include "level.h"
|
|
|
|
#include "world.h"
|
2019-11-25 19:12:25 +01:00
|
|
|
#include "mario.h"
|
2019-11-30 13:57:18 +01:00
|
|
|
#include "score.h"
|
2019-12-03 19:53:30 +01:00
|
|
|
#include "ennemi.h"
|
2020-01-06 18:43:36 +01:00
|
|
|
#include "keyboard.h"
|
2020-01-11 15:19:53 +01:00
|
|
|
#include <plateforme.h>
|
2020-01-23 21:03:58 +01:00
|
|
|
#include <tuyau.h>
|
2020-01-11 15:19:53 +01:00
|
|
|
|
2019-11-24 14:28:04 +01:00
|
|
|
#include <gint/display.h>
|
2019-11-30 13:57:18 +01:00
|
|
|
#include <gint/std/stdlib.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <gint/std/string.h>
|
2020-01-23 21:03:58 +01:00
|
|
|
#include <gint/std/stdio.h>
|
2020-01-11 15:19:53 +01:00
|
|
|
|
2020-02-01 16:39:34 +01:00
|
|
|
#define PACKED_EMPTY 0
|
|
|
|
#define PACKED_STONE 1
|
|
|
|
#define PACKED_COIN 2
|
|
|
|
#define PACKED_BRICK 3
|
|
|
|
#define PACKED_BRICK_COIN 4
|
|
|
|
#define PACKED_BOX_COIN 5
|
|
|
|
#define PACKED_BOX_CHAMPI 6
|
|
|
|
#define PACKED_BETON 7
|
|
|
|
|
|
|
|
#define PACKED_TUYAU_BOUT 8
|
|
|
|
#define PACKED_TUYAU_MIDDLE 9
|
|
|
|
|
2019-11-30 13:57:18 +01:00
|
|
|
void malloc_error()
|
2019-11-24 14:28:04 +01:00
|
|
|
{
|
2019-11-30 13:57:18 +01:00
|
|
|
extern image_t img_ram;
|
|
|
|
timer_stop(0);
|
|
|
|
dimage(0,0,&img_ram);
|
|
|
|
dupdate();
|
|
|
|
while (1)
|
2020-01-30 21:09:18 +01:00
|
|
|
mkb_getkey();
|
2019-11-30 13:57:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 16:39:34 +01:00
|
|
|
static uint8_t pack_access(packed_level_t const * const p, int x, int y)
|
|
|
|
{
|
|
|
|
if (0<=x && x<w && 0<=y && y<h)
|
|
|
|
return p->data[x*p->height+y];
|
|
|
|
else
|
|
|
|
return PACKED_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cell_set(cell_t *const array, int w, int h, int x, int y, cell_t const cell)
|
|
|
|
{
|
|
|
|
if (0<=x && x<w && 0<=y && y<h)
|
|
|
|
array[x*w+y] = cell;
|
|
|
|
}
|
|
|
|
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-01 16:39:34 +01:00
|
|
|
void unpack_level(packed_level_t const * const p)
|
2020-01-11 15:19:53 +01:00
|
|
|
{
|
2020-02-01 16:39:34 +01:00
|
|
|
const unsigned int w = p->width;
|
|
|
|
const unsigned int h = p->height;
|
|
|
|
|
|
|
|
cell_t * c = (cell_t *) malloc(sizeof(cell_t) * w * h);
|
|
|
|
if (c==0)
|
2020-01-11 15:19:53 +01:00
|
|
|
malloc_error();
|
2020-02-01 16:39:34 +01:00
|
|
|
|
|
|
|
int sx=0, sy=p->height; // Mario start coords
|
|
|
|
|
|
|
|
for (int x=0; x<w; x++)
|
2020-01-13 20:26:37 +01:00
|
|
|
{
|
2020-02-01 16:39:34 +01:00
|
|
|
for (int y=0; y<h; y++)
|
|
|
|
{
|
|
|
|
int contents = pack_access(p,x,y);
|
|
|
|
cell_t cell = {0,0};
|
|
|
|
if (contents==PACKED_EMPTY)
|
|
|
|
{
|
|
|
|
cell_t t={0,0};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_STONE)
|
|
|
|
{
|
|
|
|
int props=0;
|
|
|
|
{ // determiner x
|
|
|
|
int px=1;
|
|
|
|
if (pack_access(p,x-1,y)!=PACKED_STONE)
|
|
|
|
px=0;
|
|
|
|
if (pack_access(p,x+1,y)!=PACKED_STONE)
|
|
|
|
px=2;
|
|
|
|
props+=16*px;
|
|
|
|
}
|
|
|
|
{ // determiner y
|
|
|
|
int py=1;
|
|
|
|
if (pack_access(p,x,y+1)!=PACKED_STONE)
|
|
|
|
py=0;
|
|
|
|
props+=py;
|
|
|
|
}
|
|
|
|
cell_t t={EARTH,props};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_COIN)
|
|
|
|
{
|
|
|
|
cell_t t={COIN,0};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_BRICK)
|
|
|
|
{
|
|
|
|
cell_t t={BRICK,0};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_BRICK_COIN)
|
|
|
|
{
|
|
|
|
cell_t t={BRICK,0x15};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_BOX_COIN)
|
|
|
|
{
|
|
|
|
cell_t t={GIFT,0x11};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_BOX_CHAMPI)
|
|
|
|
{
|
|
|
|
cell_t t={GIFT,0x21};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_BETON)
|
|
|
|
{
|
|
|
|
cell_t t={BLOC,0};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
else if (contents==PACKED_TUYAU_BOUT)
|
|
|
|
{
|
|
|
|
int x=0, y=0;
|
|
|
|
int props=0;
|
2020-01-28 14:32:39 +01:00
|
|
|
|
2020-02-01 16:39:34 +01:00
|
|
|
{ // haut du tuyau horizontal
|
|
|
|
if (pack_access(p,x-1,y)==PACKED_TUYAU_BOUT)
|
|
|
|
{
|
|
|
|
x=1;
|
|
|
|
if (pack_access(p,x,y-1)==PACKED_TUYAU_MIDDLE)
|
|
|
|
y=2;
|
|
|
|
if (pack_access(p,x,y+1)==PACKED_TUYAU_MIDDLE)
|
|
|
|
y=4;
|
|
|
|
}
|
|
|
|
if (pack_access(p,x+1,y)==PACKED_TUYAU_BOUT)
|
|
|
|
{
|
|
|
|
x=0;
|
|
|
|
if (pack_access(p,x,y-1)==PACKED_TUYAU_MIDDLE)
|
|
|
|
y=2;
|
|
|
|
if (pack_access(p,x,y+1)==PACKED_TUYAU_MIDDLE)
|
|
|
|
y=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // bout de tuyau vertical
|
|
|
|
if (pack_access(p,x,y-1)==PACKED_TUYAU_BOUT)
|
|
|
|
{
|
|
|
|
y=0;
|
|
|
|
if (pack_access(p,x+1,y)==PACKED_TUYAU_MIDDLE)
|
|
|
|
x=0;
|
|
|
|
if (pack_access(p,x-1,y)==PACKED_TUYAU_MIDDLE)
|
|
|
|
x=2;
|
|
|
|
}
|
|
|
|
if (pack_access(p,x,y+1)==PACKED_TUYAU_BOUT)
|
|
|
|
{
|
|
|
|
y=1;
|
|
|
|
if (pack_access(p,x+1,y)==PACKED_TUYAU_MIDDLE)
|
|
|
|
x=0;
|
|
|
|
if (pack_access(p,x-1,y)==PACKED_TUYAU_MIDDLE)
|
|
|
|
x=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
props=16*x+y;
|
|
|
|
cell_t t={TUYAU,props};
|
|
|
|
cell = t;
|
|
|
|
}
|
|
|
|
cell_set(c,w,h,x,y,cell);
|
|
|
|
}
|
|
|
|
}
|
2020-02-01 14:39:08 +01:00
|
|
|
}
|