2024-05-07 22:10:15 +00:00
|
|
|
#include "fumotris.h"
|
2024-05-02 22:17:37 +00:00
|
|
|
|
|
|
|
|
2024-05-08 12:47:46 +00:00
|
|
|
struct Fumotris {
|
2024-05-14 04:20:20 +00:00
|
|
|
struct Tetra board;
|
|
|
|
struct Tetra piece;
|
|
|
|
nsec timer;
|
|
|
|
bool is_ground;
|
2024-05-08 12:47:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-05-14 04:20:20 +00:00
|
|
|
void FumotrisStart(struct FumoInstance *inst, struct Fumotris *fumo)
|
2024-05-02 22:17:37 +00:00
|
|
|
{
|
2024-05-10 07:38:08 +00:00
|
|
|
ControllerBindMulti(&inst->ctrl, BINDS_N, controls_g, codes_g, types_g);
|
2024-05-08 12:47:46 +00:00
|
|
|
|
2024-05-14 04:20:20 +00:00
|
|
|
CreateTetra(&fumo->board, 10, 10);
|
|
|
|
SetTetra(&fumo->piece, T, 3, 3, 0, 0);
|
|
|
|
fumo->timer = 0;
|
|
|
|
fumo->is_ground = false;
|
2024-05-07 22:10:15 +00:00
|
|
|
}
|
2024-05-07 03:29:10 +00:00
|
|
|
|
2024-05-14 04:20:20 +00:00
|
|
|
void FumotrisUpdate(struct FumoInstance *inst, struct Fumotris *fumo)
|
2024-05-07 22:10:15 +00:00
|
|
|
{
|
2024-05-14 04:20:20 +00:00
|
|
|
i16 horizontal = 0;
|
2024-05-10 07:38:08 +00:00
|
|
|
if (inst->ctrl.axes[LEFT].is_down)
|
2024-05-14 04:20:20 +00:00
|
|
|
horizontal -= 1;
|
2024-05-10 07:38:08 +00:00
|
|
|
if (inst->ctrl.axes[RIGHT].is_down)
|
2024-05-14 04:20:20 +00:00
|
|
|
horizontal += 1;
|
|
|
|
TetraMove(&fumo->piece, &fumo->board, horizontal, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (inst->ctrl.axes[SOFT_DROP].is_down)
|
|
|
|
TetraMove(&fumo->piece, &fumo->board, 0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (inst->ctrl.axes[HARD_DROP].is_down) {
|
|
|
|
while (TetraMove(&fumo->piece, &fumo->board, 0, 1));
|
|
|
|
|
|
|
|
fumo->timer = 0;
|
|
|
|
TetraOverlay(&fumo->piece, &fumo->board);
|
|
|
|
SetTetra(&fumo->piece, I, 4, 4, 0, 0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fumo->timer += inst->frametime;
|
|
|
|
while (fumo->timer > 5e8) {
|
|
|
|
fumo->timer -= 5e8;
|
|
|
|
|
|
|
|
if (!TetraMove(&fumo->piece, &fumo->board, 0, 1)) {
|
|
|
|
if (!fumo->is_ground) {
|
|
|
|
fumo->is_ground = true;
|
|
|
|
} else {
|
|
|
|
TetraOverlay(&fumo->piece, &fumo->board);
|
|
|
|
SetTetra(&fumo->piece, I, 4, 4, 0, 0);
|
2024-05-06 05:52:30 +00:00
|
|
|
|
2024-05-14 04:20:20 +00:00
|
|
|
fumo->is_ground = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FumotrisDraw(struct FumoInstance *inst, struct Fumotris *fumo)
|
|
|
|
{
|
|
|
|
TetraTerminalClear(&fumo->board, &inst->term);
|
|
|
|
TetraTerminalDraw(&fumo->board, &inst->term);
|
|
|
|
TetraTerminalDraw(&fumo->piece, &inst->term);
|
2024-05-02 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2024-05-08 12:47:46 +00:00
|
|
|
struct FumoInstance inst;
|
|
|
|
CreateFumoInstance(&inst);
|
2024-05-02 22:17:37 +00:00
|
|
|
|
2024-05-07 22:10:15 +00:00
|
|
|
struct Fumotris game;
|
2024-05-08 12:47:46 +00:00
|
|
|
EventAdd(&inst.on_start, FumotrisStart, &game);
|
|
|
|
EventAdd(&inst.on_update, FumotrisUpdate, &game);
|
2024-05-02 22:17:37 +00:00
|
|
|
|
2024-05-08 12:47:46 +00:00
|
|
|
FumoInstanceRun(&inst);
|
2024-05-02 22:17:37 +00:00
|
|
|
|
2024-05-07 22:10:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|