Duet/src/duet.h

164 lines
3.4 KiB
C
Raw Normal View History

2021-08-21 11:48:06 +02:00
#pragma once
#include <gint/defs/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <gint/display.h>
#define __BSD_VISIBLE 1
2021-08-21 11:48:06 +02:00
#include <math.h>
2021-08-21 12:11:24 +02:00
//---
// Level structures
2021-08-21 12:11:24 +02:00
//---
typedef enum {
Shape_Square = 0,
Shape_SmallBar = 2,
Shape_MediumBar = 3,
Shape_NormalBar = 4,
Shape_LongBar = 5,
Shape_HugeBar = 6,
Shape_LongVertical = 7,
2021-08-21 12:11:24 +02:00
} shape_t;
typedef enum {
2021-08-21 14:00:35 +02:00
Action_Normal = 0,
Action_RotateLeft = 1,
Action_RotateRight = 2,
2021-08-21 22:52:08 +02:00
Action_Speed1 = 3,
2021-08-21 14:00:35 +02:00
Action_FadeOut = 4,
Action_OuterRotateLeft = 5,
2021-08-21 22:09:32 +02:00
Action_OuterRotateRight = 6,
2021-08-21 14:00:35 +02:00
Action_Slide = 7,
2021-08-21 22:52:08 +02:00
Action_Speed2 = 8,
Action_Speed3 = 9,
2021-08-21 12:11:24 +02:00
} action_t;
typedef enum {
Position_Left = 0,
Position_Right = 1,
Position_Middle = 2
} position_t;
typedef struct {
int time;
shape_t shape;
position_t position;
action_t action;
} rectmeta_t;
2021-08-21 14:00:35 +02:00
typedef struct {
float tempo;
const char *message;
int block_count;
2021-08-21 14:00:35 +02:00
rectmeta_t *blocks;
} level_t;
2021-08-21 23:46:47 +02:00
typedef struct {
char const *name;
int level_count;
level_t **levels;
} episode_t;
2021-08-21 14:00:35 +02:00
//---
// Game
//---
#define PLAYER_X 60
#define PLAYER_R 40
#define PLAYER_SIZE 8
#define CORRIDOR_SIZE 150
#define RECT_SPEED 50 /* px/tempo */
2021-08-21 14:49:01 +02:00
2021-08-21 14:00:35 +02:00
typedef struct {
float w, h; /* px */
float x, y; /* px */
2021-08-21 14:08:53 +02:00
float r; /* rad */
rectmeta_t const *meta;
2021-08-21 14:00:35 +02:00
} rect_t;
#define RECT_TABLE_SIZE 20
2021-08-21 14:49:01 +02:00
typedef struct game {
2021-08-21 21:48:47 +02:00
/* Current level */
level_t const *level;
2021-08-21 21:48:47 +02:00
/* List of rectangles (same amount as lv->block_count) */
2021-08-21 20:57:56 +02:00
rect_t *rects;
int rect_count;
2021-08-21 21:48:47 +02:00
/* Current player rotation */
2021-08-21 14:00:35 +02:00
float player_rota;
2021-08-21 21:48:47 +02:00
/* Current level time (determines the position of all objects) */
float time;
/* Time spent during the death freeze animation */
float time_dead;
/* Time spent during level transition */
float time_transition;
2021-08-22 00:41:42 +02:00
/* Time spent during episode transition */
float time_episode_transition;
2021-08-21 21:48:47 +02:00
/* Forced rotation speed for level transitions and death rewind */
2021-08-21 21:28:14 +02:00
float forced_player_rota;
2021-08-21 14:49:01 +02:00
} game_t;
2021-08-21 12:11:24 +02:00
2021-08-21 11:48:06 +02:00
//---
// Rendering
//---
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);
2021-08-22 00:51:48 +02:00
void drectoid(rect_t const *r, float extra_size, int color);
2021-08-21 14:49:01 +02:00
2021-08-21 22:32:22 +02:00
void render_player(int x, int y, float angle);
2021-08-21 14:49:01 +02:00
//---
// Duet Text
//---
/* (x,y) is screen as usual, but align is relative to rotated text */
void duet_text_opt(int x, int y, int fg, int bg, int halign, int valign,
char const *str, int size);
2021-08-21 14:49:01 +02:00
//---
// Physics
//---
void player_position(float angle,
float *x1, float *y1, float *x2, float *y2);
bool player_collision(game_t const *game);
2021-08-21 14:49:01 +02:00
bool rect_circle_collide(rect_t const *r, int cx, int cy, int cr);
void rect_load(rect_t *r, rectmeta_t const *meta);
void rect_physics(rect_t *r, rectmeta_t const *meta, float time);
//---
// Levels
//---
2021-08-21 23:12:08 +02:00
extern level_t level1, level2, level3, level4;
extern level_t level5, level6, level7, level8;
extern level_t level9, level10, level11, level12;
extern level_t level13, level14, level15, level16;
2021-08-21 23:31:55 +02:00
extern level_t level17, level18, level19, level20;
extern level_t level21, level22, level23, level24;
extern level_t level25, level26, level27, level28;
2021-08-21 22:32:22 +02:00
2021-08-21 23:46:47 +02:00
extern episode_t episodes[];
extern int episode_count;
2021-08-21 22:32:22 +02:00
//---
// Menu
//---
2021-08-21 23:46:47 +02:00
/* Main menu, sets selected level */
int main_menu(int *episode, int *level);