60 FPS cap (WIP)
This commit is contained in:
parent
10eb356b1d
commit
73a58e7241
BIN
platform.g3a
BIN
platform.g3a
Binary file not shown.
20
src/main.c
20
src/main.c
|
@ -1,4 +1,6 @@
|
|||
#include <gint/keyboard.h>
|
||||
#include <gint/timer.h>
|
||||
#include <gint/clock.h>
|
||||
#include "draw.h"
|
||||
#include "collide.h"
|
||||
#include "levels.h"
|
||||
|
@ -6,12 +8,21 @@
|
|||
void jump_test(char *jump_pressed, char *jump_buffer); //test if jump pressed
|
||||
char sgn(int number); //return the sign of input double
|
||||
|
||||
int callback(volatile void *arg)
|
||||
{
|
||||
volatile int *has_ticked = arg;
|
||||
*has_ticked = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
volatile int has_ticked = 1; //fps cap
|
||||
char level[14*25];
|
||||
unsigned char level_id = 0;
|
||||
char jump_pressed = 0; //avoid holding jump
|
||||
char jump_buffer = 0; //jump buffer, last 3 frames
|
||||
unsigned int jump_hold = 0; //number of consecutive frames jump has been held
|
||||
double vspd = 0; //player vertical speed
|
||||
char hspd = 0; //player horizontal speed
|
||||
char on_ground = 6; //remember if player is on solid
|
||||
|
@ -26,7 +37,12 @@ int main(void)
|
|||
draw_level(level, &player_x, &player_y);
|
||||
old_x = player_x + 1; //offset to draw it on first cycle
|
||||
old_y = player_y;
|
||||
//fps cap timer
|
||||
timer_setup(0, timer_delay(0, 16667), 0, callback, &has_ticked);
|
||||
timer_start(0);
|
||||
while (1) {
|
||||
while(!has_ticked) sleep();
|
||||
has_ticked = 0;
|
||||
draw_player(old_x, old_y, player_x, player_y);
|
||||
dupdate();
|
||||
old_x = player_x;
|
||||
|
@ -76,10 +92,11 @@ int main(void)
|
|||
}
|
||||
}
|
||||
|
||||
void jump_test(char *jump_pressed, char *jump_buffer)
|
||||
void jump_test(char *jump_pressed, char *jump_buffer, unsigned int *jump_hold)
|
||||
{
|
||||
if (keydown(KEY_SHIFT))
|
||||
{
|
||||
*jump_hold++;
|
||||
if (!*jump_pressed)
|
||||
{
|
||||
*jump_pressed = 1;
|
||||
|
@ -87,6 +104,7 @@ void jump_test(char *jump_pressed, char *jump_buffer)
|
|||
}
|
||||
}
|
||||
else {
|
||||
*jump_hold = 0;
|
||||
*jump_pressed = 0;
|
||||
}
|
||||
if (*jump_buffer) *jump_buffer -= 1;
|
||||
|
|
Loading…
Reference in New Issue