Browse Source

add spikes (25%)

master
Milang 2 years ago
parent
commit
2a85f98b93
  1. BIN
      SuperCbr.g1a
  2. BIN
      assets-fx/img/spikes.png
  3. 3
      include/ennemi.h
  4. 2
      include/tile.h
  5. 1
      include/world.h
  6. 2
      src/box.c
  7. 2
      src/bullet.c
  8. 56
      src/ennemi.c
  9. 3
      src/tile.c
  10. 2
      src/tuyau.c
  11. 8
      src/world.c

BIN
SuperCbr.g1a

Binary file not shown.

BIN
assets-fx/img/spikes.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

3
include/ennemi.h

@ -43,7 +43,8 @@ typedef struct
void ennemiDisplay(ennemi_t const * e);
extern ennemi_t * ennemis_global;
extern int ennemis_global_size;
int ennemiesNumber();
void ennemiesDisplay();
void ennemiMove(ennemi_t * e);

2
include/tile.h

@ -25,7 +25,7 @@ extern const tileset_t buisson;
extern const tileset_t colline;
extern const tileset_t castle;
extern const tileset_t end_level;
extern const tileset_t spikes;
extern const tileset_t champi;
extern const tileset_t fleur;
extern const tileset_t life_1up;

1
include/world.h

@ -19,6 +19,7 @@ typedef enum
ARBRE,
GIFT,
COIN,
SPIKES,
NUAGE,
BUISSON,
COLLINE,

2
src/box.c

@ -7,7 +7,7 @@
int check_collision(box_t *b)
{
for (int i=0; i<ennemis_global_size; i++) if (boxContact(&ennemis_global[i].b,b)) return 1;
for (int i=0; i<ennemiesNumber(); i++) if (boxContact(&ennemis_global[i].b,b)) return 1;
return 0;
}

2
src/bullet.c

@ -53,7 +53,7 @@ void bulletsMove()
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+127) bullets[i].type=0; // delete a bullet if it is out of the screen
// contact with ennemies
for (int a=0; a<ennemis_global_size; a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
for (int a=0; a<ennemiesNumber(); a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
{
ennemis_global[a].life=DEAD;
bullets[i].type=0;

56
src/ennemi.c

@ -12,18 +12,38 @@
#include <stdbool.h>
/** properties **/
const int ennemi_widths [NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8 , 8, 8};
//const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 12, 9, 12, 9, 8};
const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8, 8, 8};
/** ram storage **/
ennemi_t * ennemis_global=0;
static int ennemis_global_size=0;
int ennemiesNumber() { return ennemis_global_size; }
void ennemiesInit(ennemi_t * table, int s)
{
if (ennemis_global) freeProf(ennemis_global);
ennemis_global_size = ennemis_global = 0; // reset
if (s==0) return;
int const size = sizeof(ennemi_t) * s;
if ((ennemis_global = mallocProf(size)) == 0) mallocError();
ennemis_global_size = s;
memcpy(ennemis_global, table, size);
}
void ennemiDisplay(ennemi_t const * e)
{
if (e->type==NONE) return;
if (e->b.x<=cameraX(0)-e->b.w || e->b.x>=cameraX(0)+127) return; // do not draw if out of the screen
if (e->type == NONE) return;
if (e->b.x <= cameraX(0) - e->b.w || e->b.x >= cameraX(0) + 127) return; // do not draw if out of the screen
{// draw
int tx=0, ty=0, dsx=0, dsy=0;
tileset_t t={0,ennemi_widths[e->type], ennemi_heights[e->type],1};
tileset_t t={0, ennemi_widths[e->type], ennemi_heights[e->type], 1};
switch (e->type)
{
case GOOMBA_ID:
@ -86,16 +106,15 @@ void plante_tour(ennemi_t *e)
{
e->p1++;
e->p1%=PLANTE_NLAPS;
if (0<=e->p1 && e->p1<35) // (plante en bas, en attente)
{
if (abs(mario.p.x-e->b.x)<15) e->p1=0;
}
// En attente
if (0<=e->p1 && e->p1<35) if (abs(mario.p.x-e->b.x)<15) e->p1=0;
if (35<=e->p1 && e->p1<58)
{
if ((e->p1+1)%3==0) e->b.y++;
}
if (58<=e->p1 && e->p1<75){} // plante en attente en haut
if (75<=e->p1 && e->p1<98)
if (58 <= e->p1 && e->p1 < 75){} // plante en attente en haut
if (75 <= e->p1 && e->p1 < 98)
{
if (e->p1%3==0) e->b.y--;
}
@ -332,24 +351,9 @@ void ennemiMove(ennemi_t *e)
}
}
// Global variables for ennemies
ennemi_t * ennemis_global=0;
int ennemis_global_size=0;
void ennemiesDisplay()
{
for (int i=0; i<ennemis_global_size; i++) ennemiDisplay(&ennemis_global[i]);
}
void ennemiesInit(ennemi_t * table, int s)
{
if (ennemis_global)
freeProf(ennemis_global);
ennemis_global_size=ennemis_global=0;
if (!s) return;
int size=sizeof(ennemi_t)*s;
if ((ennemis_global=mallocProf(size))==0) mallocError();
ennemis_global_size=s;
memcpy(ennemis_global, table, size);
}

3
src/tile.c

@ -22,6 +22,9 @@ const tileset_t gift={&img_gift, TILE_W, TILE_H, 1};
extern image_t img_coin;
const tileset_t coin={&img_coin, TILE_W, TILE_H, 1};
extern image_t img_spikes;
const tileset_t spikes={&img_spikes, TILE_W, TILE_H, 1};
extern image_t img_nuage;
const tileset_t nuage={&img_nuage, TILE_W, TILE_H, 0};
extern image_t img_buisson;

2
src/tuyau.c

@ -57,7 +57,7 @@ void teleportersActive()
mario.p.vx=0; mario.p.vy=0; // Disables every move of mario
cameraAdjust();
for (int j=0; j<ennemis_global_size; j++) if (ennemis_global[j].type==PLANTE_ID) for (int k=0; k<99; k++) plante_tour(&ennemis_global[j]);
for (int j=0; j<ennemiesNumber(); j++) if (ennemis_global[j].type==PLANTE_ID) for (int k=0; k<99; k++) plante_tour(&ennemis_global[j]);
const tuyau_t c = *((tuyau_t*)worldGetCell(mario.p.x, mario.p.y));

8
src/world.c

@ -7,8 +7,6 @@
#include <camera.h>
#include <mario.h>
#include <ennemi.h>
#include <bonus.h>
#include <ennemi.h>
#include <plateforme.h>
@ -65,6 +63,10 @@ void cellDraw(int cx, int cy, int sx, int sy, int plan)
tileDraw(sx, sy, &bloc, 0, 0);
break;
case SPIKES:
tileDraw(sx, sy, &spikes, 0, 0);
break;
case BRICK:
if (((brick_t*)cell)->time_hit_id) // calculate collision animation
{
@ -177,7 +179,7 @@ void worldDraw()
void worldMove()
{
MKB_update();
for (int i=0; i<ennemis_global_size; i++) ennemiMove(&ennemis_global[i]);
for (int i=0; i<ennemiesNumber(); i++) ennemiMove(&ennemis_global[i]);
bonusMove();
bulletsMove();
platformsMove();

Loading…
Cancel
Save