enum i_button_state buttons[I_CURSOR_BUTTONS];
};
+enum i_arrow_keys {
+ I_ARROW_UP = 0,
+ I_ARROW_DOWN,
+ I_ARROW_LEFT,
+ I_ARROW_RIGHT,
+ I_ARROW_LEN
+};
+
+#define I_FKEYS_LEN 12
+
struct i_keyboard {
+ enum i_button_state esc;
enum i_button_state shift;
enum i_button_state ctrl;
enum i_button_state alt;
enum i_button_state space;
enum i_button_state backspace;
+ enum i_button_state arrow[I_ARROW_LEN];
+
+ enum i_button_state del;
+ enum i_button_state home;
+ enum i_button_state end;
+ enum i_button_state pgup;
+ enum i_button_state pgdown;
+ enum i_button_state insert;
+
+ enum i_button_state tab;
+
+ enum i_button_state print;
+ enum i_button_state pause;
+
+ enum i_button_state fkey[I_FKEYS_LEN];
+
/* ascii table for all other keys */
enum i_button_state keys[I_KEYBOARD_KEYS];
};
#include "r_render.h"
#include "r_assets.h"
#include "i_input.h"
+#include "t_camera.h"
+#include "t_map.h"
struct lrts_config lrts_global_cfg;
}
void lrts_init(void) {
+ struct u_vec2 res = lrts_get_render_res();
+
/* init the fallback tile mask */
r_asset_init_fallback_tile();
i_input_init();
+
+
+
+ t_main_camera = t_camera_init(res.x, res.y);
+ t_map = t_map_init();
}
int lrts_main(int argc, char **argv) {
#ifndef R_ASSETS_H__
#define R_ASSETS_H__
-#define R_TILE_W 64
-#define R_TILE_H 32
+#define R_TILE_W 96
+#define R_TILE_H 48
/**
* This module contains asset descriptions
}
void r_render_frame() {
- int i, j;
- struct t_tile t;
-
p_draw_begin();
- /* draw test tile */
- t.type = T_TILE_TYPE_GRASS;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j++) {
- r_draw_tile(&t, i, j);
- }
- }
+ t_map_draw(&t_map);
p_draw_end();
p_draw_present();
#include "t_camera.h"
+struct t_camera t_main_camera;
+
struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y) {
struct t_camera c;
c.x = 0;
U_CLAMP(c->x, 0, c->viewport_x);
U_CLAMP(c->y, 0, c->viewport_y);
}
+
i32 viewport_y;
};
+extern struct t_camera t_main_camera;
+
struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y);
void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y);
#include "t_map.h"
+#include "u_mem.h"
+
+struct t_map t_map;
+
+struct t_map t_map_init(void) {
+ u32 i, j;
+
+ struct t_map m;
+ u_memset(&m, 0, sizeof(m));
+
+ m.width = T_MAP_MAX_W;
+ m.height = T_MAP_MAX_H;
+
+ for (i = 0; i < m.width; i++) {
+ for (j = 0; j < m.height; j++) {
+ m.tiles[j * m.width + i].type = T_TILE_TYPE_GRASS;
+ }
+ }
+
+ return m;
+}
+
+void t_map_draw(struct t_map *m) {
+ u32 i, j;
+
+ /* TODO: only draw visible tiles */
+ for (i = 0; i < m->width; i++) {
+ for (j = 0; j < m->height; j++) {
+ r_draw_tile(&m->tiles[j * m->width + i], i, j);
+ }
+ }
+}
struct t_tile tiles[T_MAP_MAX_W * T_MAP_MAX_H];
};
+extern struct t_map t_map;
+
+/**
+ * Inits a default map of max size
+ * and grass tiles
+ */
+struct t_map t_map_init(void);
+
+void t_map_draw(struct t_map *m);
+
#endif