diff options
author | quou <quou@disroot.org> | 2024-07-27 15:44:45 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-07-27 15:49:46 +1000 |
commit | 4cacaad9e392bf5fe63a90019411f21a72db0e7a (patch) | |
tree | 34e3cd4d576c8cbafca6f8f4d5ef381dece3a325 /3de.c | |
parent | b8b18d982af8cc8e10372f90c6c7bff4f0b58f69 (diff) |
WIP raycasting
Diffstat (limited to '3de.c')
-rw-r--r-- | 3de.c | 52 |
1 files changed, 40 insertions, 12 deletions
@@ -1,5 +1,6 @@ #include "asset.h" #include "config.h" +#include "map.h" #include "maths.h" #include "memory.h" #include "plat.h" @@ -21,9 +22,9 @@ void draw_spinny(Renderer* r, Colour c) { void draw_gun(Renderer* r) { static int a = 0; - const Mesh* m = get_mesh(asset_id_gun_mesh); + const Mesh* m = get_mesh(asset_id_monkey); const Texture* tex = get_texture(asset_id_gun_texture); - int p[] = { 0, 0, 0, f1 }; + int p[] = { f1 * 7, 0, f1 * 5, f1 }; mtx_push_trans(p); /*mtx_push_rot_x(a); mtx_push_rot_y(a); @@ -44,11 +45,39 @@ void draw_tri(Renderer* r, int x, int y) { } void draw_line(Renderer* r, int x, int y) { - int s[] = { 100, 100 }; - int e[] = { x, y }; + int s[] = { 100, 100 }, e[2]; + e[0] = x; + e[1] = y; ren_line(r, make_red(), s, e); } +void draw_map(Renderer* r, Player* p) { + int data[512] = { + 16, 16, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }; + int pos[2]; + Map* m = (Map*)data; + pos[0] = p->p[0]; + pos[1] = p->p[2]; + ren_map(r, m, pos, p->f, p->l); +} + int entrypoint(int argc, const char** argv, Arena* a) { App* app; Renderer r = { 0 }; @@ -89,24 +118,23 @@ int entrypoint(int argc, const char** argv, Arena* a) { while (app->o) { fps_begin(&f); while (f.now >= f.next) { - Rect clip = { 30, 80, 400, 800 }; app_begin(app); update_player(&p, &s); ren_begin(&r, app->fb, depth, app->w, app->h); - ren_clip(&r, &clip); - ren_clearc(&r, make_blue()); + ren_clear(&r); ren_cleard(&r, f1 * 300); +/* draw_line(&r, app->mx, app->my);*/ + push_player_cam(&p); + draw_gun(&r); + draw_map(&r, &p); + pop_player_cam(); + /*draw_tri(&r, app->mx, app->my);*/ sprintf(buf, "FPS: %d", app->fps); ren_texts(&r, blue, 3, 3, buf); sprintf(buf, "CAP: %d", f.fps); ren_texts(&r, blue, 3, 8, buf); sprintf(buf, "MOUSE: %d, %d", app->mx, app->my); ren_texts(&r, blue, 3, 13, buf); - draw_line(&r, app->mx, app->my); - push_player_cam(&p); - draw_gun(&r); - pop_player_cam(); - draw_tri(&r, app->mx, app->my); ren_end(&r); app_end(app); fps_update(&f); |