supercasiobros/src/tuyau.c

61 lines
1.5 KiB
C

#include <tuyau.h>
#include <mario.h>
#include <keyboard.h>
#include <world.h>
#include <framerate.h>
#include <camera.h>
#include <gint/std/string.h>
#include <base.h>
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)
{
if (t)
{
nombre_teleporteurs=min(n,6);
if (nombre_teleporteurs) memcpy(teleporteurs, t, sizeof(teleport_t)*nombre_teleporteurs);
}
else nombre_teleporteurs=0;
}
void teleportersActive()
{
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))
{
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)
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x--;
}
/* End of animated section */
marioResetJump();
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();
}
}
}