add game skeleton
This commit is contained in:
parent
26c94b6e66
commit
b282d432f5
55
src/duet.h
55
src/duet.h
|
@ -13,6 +13,7 @@
|
|||
// Data structures
|
||||
//---
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
typedef struct {
|
||||
float w, h; /* px */
|
||||
float x, y; /* px */
|
||||
|
@ -21,6 +22,8 @@ typedef struct {
|
|||
float vr; /* rad/s */
|
||||
} rect_t;
|
||||
|
||||
=======
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
//---
|
||||
// Level strucutres
|
||||
|
@ -28,16 +31,22 @@ typedef struct {
|
|||
|
||||
typedef enum {
|
||||
Shape_Square = 0,
|
||||
Shape_LongBar = 1,
|
||||
Shape_NormalBar = 2,
|
||||
Shape_BorderBar = 2,
|
||||
Shape_SmallBar = 2,
|
||||
Shape_MediumBar = 3,
|
||||
Shape_NormalBar = 4,
|
||||
Shape_LongBar = 5,
|
||||
Shape_HugeBar = 6,
|
||||
} shape_t;
|
||||
|
||||
typedef enum {
|
||||
Action_RotateLeft = 0,
|
||||
Action_RotateRight = 1,
|
||||
Action_Speed = 2,
|
||||
Action_FadeOut = 3,
|
||||
Action_Normal = 0,
|
||||
Action_RotateLeft = 1,
|
||||
Action_RotateRight = 2,
|
||||
Action_Speed = 3,
|
||||
Action_FadeOut = 4,
|
||||
Action_OuterRotateLeft = 5,
|
||||
Action_OuterRotateRIght = 6,
|
||||
Action_Slide = 7,
|
||||
} action_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -53,9 +62,33 @@ typedef struct {
|
|||
action_t action;
|
||||
} rectmeta_t;
|
||||
|
||||
//typedef struct {
|
||||
// rectmeta_t ;
|
||||
//} level_t;
|
||||
typedef struct {
|
||||
float tempo;
|
||||
rectmeta_t *blocks;
|
||||
} level_t;
|
||||
|
||||
//---
|
||||
// Game
|
||||
//---
|
||||
|
||||
typedef struct {
|
||||
float w, h; /* px */
|
||||
float x, y; /* px */
|
||||
float vx, vy; /* px/s */
|
||||
float vr; /* rad/s */
|
||||
} rect_t;
|
||||
|
||||
#define RECT_TABLE_SIZE 20
|
||||
|
||||
struct game {
|
||||
int dead;
|
||||
float time;
|
||||
level_t *level;
|
||||
|
||||
rect_t table[RECT_TABLE_SIZE];
|
||||
int cursor;
|
||||
float player_rota;
|
||||
};
|
||||
|
||||
//---
|
||||
// Rendering
|
||||
|
@ -65,4 +98,4 @@ void dcircle(int x, int y, int r, int color, bool fill);
|
|||
|
||||
void dtriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color);
|
||||
|
||||
void drectoid(rect_t const *r, int color);
|
||||
void drectoid(rect_t const *r, int color);
|
85
src/main.c
85
src/main.c
|
@ -1,28 +1,79 @@
|
|||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/timer.h>
|
||||
#include <gint/gint.h>
|
||||
#include <gint/cpu.h>
|
||||
|
||||
#include <fxlibc/printf.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "duet.h"
|
||||
|
||||
//rectmeta_t level1[] = {
|
||||
// {.time = 0, .shape = Shape_LongBar, .position = Position_Left}
|
||||
//};
|
||||
level_t level0 = {
|
||||
.tempo = 1.0,
|
||||
.blocks = (rectmeta_t []){
|
||||
{
|
||||
.time = 0,
|
||||
.shape = Shape_LongBar,
|
||||
.position = Position_Left,
|
||||
.action = Action_Normal
|
||||
},
|
||||
{
|
||||
.time = 1,
|
||||
.shape = Shape_LongBar,
|
||||
.position = Position_Middle,
|
||||
.action = Action_Normal
|
||||
},
|
||||
{
|
||||
.time = 3,
|
||||
.shape = Shape_LongBar,
|
||||
.position = Position_Left,
|
||||
.action = Action_Normal
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
dclear(C_WHITE);
|
||||
volatile int need_frame;
|
||||
struct game game;
|
||||
float dt = 0;
|
||||
int timer;
|
||||
|
||||
rect_t r = {
|
||||
.w = 80,
|
||||
.h = 20,
|
||||
.x = 200,
|
||||
.y = 150,
|
||||
.r = M_PI / 12,
|
||||
};
|
||||
__printf_enable_fp();
|
||||
|
||||
dcircle(100, 100, 20, C_RED, true);
|
||||
dtriangle(0, 0, 8, 20, 20, 0, C_BLACK);
|
||||
drectoid(&r, C_RED);
|
||||
dupdate();
|
||||
|
||||
getkey();
|
||||
return 1;
|
||||
memset(&game, 0x00, sizeof(struct game));
|
||||
game.level = &level0;
|
||||
|
||||
timer = timer_configure(TIMER_ANY, 33000, GINT_CALL_SET(&need_frame));
|
||||
timer_start(timer);
|
||||
while (1) {
|
||||
dt = (1.0 / 30) * level0.tempo;
|
||||
game.time += 1.0 / 30;
|
||||
|
||||
key_event_t e;
|
||||
while ((e = pollevent()).type != KEYEV_NONE) {
|
||||
if (e.type == KEYEV_DOWN && e.key == KEY_MENU)
|
||||
gint_osmenu();
|
||||
}
|
||||
if (keydown(KEY_7)) {
|
||||
game.player_rota += dt;
|
||||
}
|
||||
if (keydown(KEY_0)) {
|
||||
game.player_rota -= dt;
|
||||
}
|
||||
|
||||
//TODO: physix
|
||||
|
||||
dclear(C_BLACK);
|
||||
dprint(0, 0, C_WHITE, "game time: %.2fs", game.time);
|
||||
dprint(0, 11, C_WHITE, "player rota: %.2f rad", game.player_rota);
|
||||
dupdate();
|
||||
|
||||
while (need_frame == 0)
|
||||
sleep();
|
||||
need_frame = 0;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue