Commit 67302cb3 authored by Chris's avatar Chris
Browse files

dice animation base logic

parent c2351738
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#include "graphics.h"
#include <unistd.h> // sleep()
#include <stdlib.h> // malloc()
#include <time.h> // timespec struct

// yaht.c
// Copyright (c) 2025
@@ -30,6 +31,7 @@ FILE *get_urandom();
unsigned int roll_single_die(FILE *urandom_file);
void roll_multiple_dice(game_context *ctx, unsigned int *out_dice_values, int save_in_game_state);
int set_die_held(game_context *ctx, unsigned int index, unsigned int held);
void sleep_ms(unsigned int ms);

int main() {
	 game_context ctx;
@@ -62,6 +64,14 @@ int main() {
	roll_multiple_dice(&ctx, next_roll, 1);
	print_multiple_dice(next_roll, NUM_DICE, 0);

	// do a little dice animation
	for (int i = 0; i < 30; i++) {	
		roll_multiple_dice(&ctx, next_roll, 0);
		print_multiple_dice(next_roll, NUM_DICE, 0);
		sleep_ms(100);
		if (i < 30 - 1) clear_dice();
	}

	fclose(ctx.random_device_fd);
	return 0;
}
@@ -106,3 +116,10 @@ int set_die_held(game_context *ctx, unsigned int index, unsigned int held) {

	return error;
}

void sleep_ms(unsigned int ms) {
	struct timespec ts;
	ts.tv_sec = ms / 1000;
	ts.tv_nsec = (ms % 1000) * 1000000;
	nanosleep(&ts, NULL);
}
+56 B (17.1 KiB)

File changed.

No diff preview for this file type.