supercasiobros/src/tuyau.c

78 lines
1.9 KiB
C
Raw Normal View History

2020-01-23 19:54:19 +01:00
#include <tuyau.h>
2020-01-24 12:08:40 +01:00
#include <mario.h>
#include <keyboard.h>
#include <world.h>
#include <framerate.h>
2020-01-29 14:34:47 +01:00
#include <camera.h>
2020-01-23 19:54:19 +01:00
#include <gint/std/string.h>
#include <base.h>
2020-03-10 19:34:09 +01:00
#include <ennemi.h>
2020-01-23 19:54:19 +01:00
static teleport_t teleporteurs[6]={0}; // 6 max
static int nombre_teleporteurs=0; // Nombre d'entités utilisés dans le niveau actuel
void teleportersSet(teleport_t const * const t, unsigned int const n)
2020-01-23 19:54:19 +01:00
{
if (t)
{
nombre_teleporteurs=min(n,6);
if (nombre_teleporteurs) memcpy(teleporteurs, t, sizeof(teleport_t)*nombre_teleporteurs);
2020-01-23 19:54:19 +01:00
}
else nombre_teleporteurs=0;
2020-01-24 12:08:40 +01:00
}
void teleportersActive()
2020-01-24 12:08:40 +01:00
{
for (int i=0; i<nombre_teleporteurs; i++)
{
teleport_t const t = teleporteurs[i];
if ((t.x==mario.p.x/8) && (t.y*8==mario.p.y || t.y*8==mario.p.y+mario.p.h))
2020-01-24 12:08:40 +01:00
{
if (!MKB_getKeyState(t.key)) continue;
/* Animation section */
if (t.key==MK_DOWN) while (mario.p.y+mario.p.h>=8*t.y)
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame(); // 20/2 = 10 fps
mario.p.y--;
}
if (t.key==MK_RIGHT) while (mario.p.x-mario.p.w<=8*t.x)
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x++;
}
if (t.key==MK_LEFT) while (mario.p.x+mario.p.w>=8*t.x)
2020-02-16 15:20:35 +01:00
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x--;
2020-02-16 15:20:35 +01:00
}
/* End of animated section */
2020-02-16 15:20:35 +01:00
2020-02-17 14:49:03 +01:00
marioResetJump();
2020-02-16 15:20:35 +01:00
mario.p.x=t.tx*8+4; mario.p.y=t.ty*8; // Move Mario
mario.p.vx=0; mario.p.vy=0; // Disables every move of mario
cameraAdjust();
2020-03-10 19:20:06 +01:00
2020-04-03 19:20:03 +02:00
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]);
2020-03-10 19:34:09 +01:00
const tuyau_t c = *((tuyau_t*)worldGetCell(mario.p.x, mario.p.y));
if (c.type==TUYAU && c.y==2) // animation de sortie
{
for (int j=0; j<8; j++)
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.y++;
}
}
2020-01-24 12:08:40 +01:00
}
}
}