1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#ifndef TEENSY_H_
#define TEENSY_H_
#include <limits.h>
#include "teensy_common.h"
#include "teensy_list.h"
#define ty_vec2(x, y) ((struct ty_vec2){x, y})
#define ty_vec2i(x, y) ((struct ty_vec2i){x, y})
#define ty_color(R, G, B) ((struct ty_color){R, G, B})
#define ty_img_full(img) ((struct ty_recti){0, 0, (img).width, (img).height})
#define TY_COLOR_BLACK ty_color(0, 0, 0 )
#define TY_COLOR_RED ty_color(255, 0, 0 )
#define TY_COLOR_GREEN ty_color(0, 255, 0 )
#define TY_COLOR_YELLOW ty_color(255, 255, 0 )
#define TY_COLOR_BLUE ty_color(0, 0, 255)
#define TY_COLOR_MAGENTA ty_color(255, 0, 255)
#define TY_COLOR_CYAN ty_color(0, 255, 255)
#define TY_COLOR_WHITE ty_color(255, 255, 255)
// Virtual controller. Keyboard keys are also mapped to this.
enum ty_button {
TY_BTN_LEFT_UP, // D-pad #1 up
TY_BTN_LEFT_DOWN, // D-pad #1 down
TY_BTN_LEFT_LEFT, // D-pad #1 left
TY_BTN_LEFT_RIGHT, // D-pad #1 right
TY_BTN_RIGHT_UP, // D-pad #2 up
TY_BTN_RIGHT_DOWN, // D-pad #2 down
TY_BTN_RIGHT_LEFT, // D-pad #2 left
TY_BTN_RIGHT_RIGHT, // D-pad #2 right
TY_BTN_ACTION_1, // A
TY_BTN_ACTION_2, // B
TY_BTN_ACTION_3, // X
TY_BTN_ACTION_4, // Y
// for use in the editor
TY_BTN_DB_CTRL,
TY_BTN_DB_SHIFT,
TY_BTN_COUNT,
};
struct ty_hints {
int scr_width;
int scr_height;
const char *game_title;
int ticrate;
};
struct ty_color {
uint8_t r;
uint8_t g;
uint8_t b;
};
struct ty_vec2 {
float x;
float y;
};
struct ty_vec2i {
int x;
int y;
};
struct ty_rect {
float x;
float y;
float w;
float h;
};
struct ty_recti {
int x;
int y;
int w;
int h;
};
struct ty_image {
struct ty_color *data;
int width;
int height;
};
struct ty_font {
struct ty_image glyphs[CHAR_MAX];
};
struct ty_renderer {
struct ty_image screen;
};
void ty_init(struct ty_hints hints);
void ty_deinit(void);
// If the button is being held down
bool ty_button_down(enum ty_button btn);
// If the button was pressed just now
bool ty_button_pressed(enum ty_button btn);
// Whether or not the main loop should continue executing.
bool ty_is_game_running(void);
// Gets the real time that the game has been running.
double ty_get_time(void);
// Handle events, tick game logic, etc. Returns the amount of times you should
// tic.
int ty_tick(void);
struct ty_image ty_create_image(int w, int h, const struct ty_color* data);
void ty_free_image(struct ty_image img);
struct ty_color ty_img_get_pixel(struct ty_image img, struct ty_vec2i pos);
void ty_img_set_pixel(
struct ty_image img,
struct ty_vec2i pos,
struct ty_color color
);
void ty_font_add_glyph(struct ty_font *font, uint8_t c, struct ty_image img);
int ty_font_width(struct ty_font *font, const char *fmt, ...);
void ty_draw_clear(struct ty_color col);
void ty_draw_image(struct ty_image img, struct ty_vec2i pos);
void ty_draw_image_ex(
struct ty_image img,
struct ty_recti src,
struct ty_recti dst
);
void ty_draw_image_rot(
struct ty_image img,
struct ty_vec2i pos,
struct ty_vec2i offset,
double rot
);
void ty_draw_rect(struct ty_recti rect, struct ty_color color);
void ty_draw_line(
struct ty_vec2i start,
struct ty_vec2i end,
struct ty_color color
);
void ty_draw_text(struct ty_font *font, struct ty_vec2i pos, const char *text);
void ty_draw_text_fmt(
struct ty_font *font,
struct ty_vec2i pos,
const char *fmt,
...
);
void ty_draw_end(void);
void ty_sleep(uint64_t ms);
#endif // TEENSY_H_
|