level changes

currently adding plants (part 1)
This commit is contained in:
Milang 2020-03-07 15:22:39 +01:00
parent 35c1214270
commit 9476c81e50
7 changed files with 57 additions and 19 deletions

Binary file not shown.

Binary file not shown.

View File

@ -24,7 +24,7 @@ extern const int ennemi_heights[NOMBRE_ENNEMIS];
#define KOOPA_R(x,y,dir) {KOOPA_R_ID,{x,y,ennemi_widths[KOOPA_R_ID],ennemi_heights[KOOPA_R_ID],dir,0,0,1},ALIVE,0,dir}
#define PLANTE(x,y) {PLANTE_ID,{x,y,ennemi_widths[PLANTE_ID],ennemi_heights[PLANTE_ID],0,0,0,0},ALIVE,0,0}
// pour plante ID, ymin est associé à p1=0
// Dimensions pr les boites

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -23,7 +23,7 @@ mario_start = (108, 81, 47)
nuage = (127, 127, 127)
arbre_tronc = (74,35,18)
arbre_feuilles = (0,86,0)
plante = (102,0,127)
def color_compare(color1, color2):
if color1[0] == color2[0] and color1[1] == color2[1] and color1[2] == color2[2]:
@ -54,19 +54,19 @@ pixels = img.load()
for x in range(0,img.size[0]):
for i in range(0, img.size[1]):
y=img.size[1]-i-1
if color_compare(pixels[x,y],empty):
code += write_char(0)
elif color_compare(pixels[x,y], pierre):
code += write_char(1)
elif color_compare(pixels[x,y], piece):
code += write_char(2)
elif color_compare(pixels[x,y], brique):
code += write_char(3)
elif color_compare(pixels[x,y],brique_piece):
code += write_char(4)
@ -75,7 +75,7 @@ for x in range(0,img.size[0]):
elif color_compare(pixels[x,y],boite_champi):
code += write_char(6)
elif color_compare(pixels[x,y],beton):
code += write_char(7)
@ -109,8 +109,12 @@ for x in range(0,img.size[0]):
elif color_compare(pixels[x,y], arbre_feuilles):
code += write_char(17)
elif color_compare(pixels[x,y], plante):
code += write_char(18)
else:
code += write_char(0)
print("Warning: unknown type at", x, y, "with pixel color: ", pixels[x,y])
f = open("../assets-fx/bin/lvl_"+filename, 'wb')

View File

@ -72,13 +72,35 @@ void ennemiDisplay(ennemi_t const * e)
{
extern image_t img_plante;
t.sheet=&img_plante;
// TODO tx ty tsx,tsy
dsx=-4;
}
}
tileDraw(e->b.x-cameraX(0)+dsx, e->b.y-cameraY(mario.p.y)+dsy, &t, tx, ty);
}
}
static void plante_tour(ennemi_t *e)
{
if (e->type==PLANTE_ID)
{
e->p1++;
e->p1%=93;
if (0<=e->p1 && e->p1<35) // (plante en bas, en attente)
{
if (abs(mario.p.x-e->b.x)<15) e->p1=0;
}
if (35<=e->p1 && e->p1<52)
{
if ((e->p1+1)%3==0) e->b.y++;
}
if (52<=e->p1 && e->p1<75){} // plante en attente en haut
if (75<=e->p1 && e->p1<92)
{
if (e->p1%3==0) e->b.y--;
}
}
}
bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p)); }
void hurtMario()
@ -92,11 +114,11 @@ void ennemiMove(ennemi_t *e)
{
if (!(e->b.x<=cameraX(0)-e->b.w || e->b.x>=cameraX(0)+127)) e->discovered=1; // for security, tag as discover all drawed ennemies
if (e->life==0 && e->type!=NONE)
if (e->life==DEAD && e->type!=NONE) // dying animation
{
if (e->p1==0)
{
e->b.vx=-2*sgn(e->b.vx);
e->b.vx=2*sgn(e->b.vx);
e->b.vy=5;
}
e->p1++;
@ -127,7 +149,7 @@ void ennemiMove(ennemi_t *e)
return;
}
for (int i=0; i<ennemis_global_size; i++)
for (int i=0; i<ennemis_global_size; i++) // physique des carapaces (collisions avec les autres)
{
ennemi_t* t=&ennemis_global[i];
if (t->type!=NONE)
@ -159,17 +181,17 @@ void ennemiMove(ennemi_t *e)
}
}
}
int previous_case=-5;
for (int j=0; j<e->b.h; j++)
{
if ((e->b.x+j)/8!=previous_case)
{
previous_case=(e->b.x+j)/8;
gift_t * c=(gift_t*)worldGetCell(e->b.x+j ,e->b.y-1);
gift_t * c=(gift_t *)worldGetCell(e->b.x+j, e->b.y-1);
if ((c->type==GIFT || c->type==BRICK) && (c->time_hit_id || c->state) && e->life!=DEAD)
{
e->life=DEAD;
e->p1=0;
e->life=e->p1=DEAD;
scoreAdd(KILL_ENNEMI);
break;
}
@ -179,10 +201,10 @@ void ennemiMove(ennemi_t *e)
if (e->b.y<0) e->type=NONE;
const bool mario_fatal_hit = (mario.p.last_vy<=-2 || mario.p.vy<=-2);
boxMove(&e->b);
switch (e->type) // move
{
case KOOPA_R_ID:
boxMove(&e->b);
if (e->b.vx)
{ // demi tour si au dessus du vide
int s=-1;
@ -194,6 +216,7 @@ void ennemiMove(ennemi_t *e)
// fall through
case GOOMBA_ID:
case KOOPA_V_ID:
if (e->type!=KOOPA_R_ID) boxMove(&e->b);
if (e->b.vx==0) // demi tour si mur
{
if (e->p1==0) e->b.vx=e->p1=-1;
@ -203,6 +226,7 @@ void ennemiMove(ennemi_t *e)
case CARAPACE_VERTE:
case CARAPACE_ROUGE:
boxMove(&e->b);
if (e->b.vx==0)
{
if (e->p1<2)
@ -221,6 +245,9 @@ void ennemiMove(ennemi_t *e)
}
}
break;
case PLANTE_ID:
plante_tour(e);
}
if (e_hitMario && mario_fatal_hit) switch (e->type) // mario attacks
@ -252,9 +279,9 @@ void ennemiMove(ennemi_t *e)
if (mario.p.x<=e->b.x) e->p1=1;
e->b.vx=6*e->p1;
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE];
boxMove(&e->b);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE];
boxMove(&e->b);
}
else
@ -310,7 +337,7 @@ void ennemiesDisplay()
void ennemiesInit(ennemi_t * table, int s)
{
if (ennemis_global)
freeProf(ennemis_global);
freeProf(ennemis_global);
ennemis_global_size=ennemis_global=0;
if (!s) return;
int size=sizeof(ennemi_t)*s;

View File

@ -34,6 +34,7 @@
#define PACKED_NUAGE 15
#define PACKED_ARBRE_TRONC 16
#define PACKED_ARBRE_FEUILLES 17
#define PACKED_PLANTE 18
void mallocError()
{
@ -85,7 +86,7 @@ static void unpackLevel(packed_level_t * p)
int sx=0, sy=p->height; // Mario start coords
ennemi_t ennemis[20]={0};
ennemi_t ennemis[30]={0};
int nombre_ennemis=0;
@ -318,6 +319,12 @@ static void unpackLevel(packed_level_t * p)
ennemis[nombre_ennemis]=e;
nombre_ennemis++;
}
else if (contents==PACKED_PLANTE)
{
ennemi_t e=PLANTE(8*x+4,8*y/*-8*/);
ennemis[nombre_ennemis]=e;
nombre_ennemis++;
}
if (contents==PACKED_MARIO_START)
{