diff options
author | quou <quou@disroot.org> | 2024-08-10 19:21:55 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-08-10 19:37:58 +1000 |
commit | cfc86e984f965285094fca91fee7d9098423b4cb (patch) | |
tree | 2bec7b29e35ae56d9061931ec984d25d4f7b75ba | |
parent | db26f27bbeea7de759c8f5a30fa79789bed066a2 (diff) |
draw the gun
-rw-r--r-- | 3de.c | 21 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | player.c | 27 | ||||
-rw-r--r-- | player.h | 3 |
4 files changed, 35 insertions, 21 deletions
@@ -41,21 +41,6 @@ void draw_spinny(Renderer* r, Colour c) { a += 20; } -void draw_gun(Renderer* r) { - static int a = 0; - const Mesh* m = get_mesh(asset_id_monkey); - const Texture* tex = get_texture(asset_id_gun_texture); - int p[] = { f1 * 7, 0, f1 * 5, f1 }; - mtx_push_trans(p); - mtx_push_scale(0xff); - /*mtx_push_rot_x(a); - mtx_push_rot_y(a); - mtx_push_rot_z(a);*/ - ren_mesh(r, m, tex); - mtx_popn(2); - a++; -} - void draw_tri(Renderer* r, int x, int y) { const Texture* tex = get_texture(asset_id_gun_texture); int v0[] = { 100, 100, 0, 0, 0, f1, f1, f1 }; @@ -158,10 +143,8 @@ int entrypoint(int argc, const char** argv, Arena* a) { if (editing) { edit_map(&e, &g, map); } else { - push_player_cam(&p); - draw_map(&r, &p, map); - draw_gun(&r); - pop_player_cam(); + draw_map(&r, &p, map); + draw_player_world(&r, &p); } /*draw_tri(&r, app->mx, app->my);*/ gui_end(&g, &r); @@ -35,10 +35,11 @@ mesh_sources = \ $(int_dir)/monkey.obj texture_sources = \ - $(int_dir)/gun.bmp \ + $(int_dir)/brick.bmp \ $(int_dir)/floorboards.bmp \ $(int_dir)/floorboardsbot.bmp \ - $(int_dir)/brick.bmp + $(int_dir)/gun.bmp \ + $(int_dir)/guy.bmp meshes = $(mesh_sources:$(int_dir)/%.obj=$(data_dir)/%.msh) textures = $(texture_sources:$(int_dir)/%.bmp=$(data_dir)/%.bc1) @@ -1,6 +1,8 @@ +#include "asset.h" #include "maths.h" #include "plat.h" #include "player.h" +#include "render.h" #include "services.h" void init_player(Player* p) { @@ -8,6 +10,7 @@ void init_player(Player* p) { vec_cpy(p->p, ip, 3); p->r[0] = 0; p->r[1] = 0; + p->anim = 0; } void update_player(Player* p, struct Services* s) { @@ -32,6 +35,10 @@ void update_player(Player* p, struct Services* s) { p->f[1] = dir[1]; p->l[0] = dir[2]; p->l[1] = dir[3]; + if (a->mbtn_states[mbtn_left] & key_state_just_pressed && p->anim < 16) + p->anim = 0xff; + if (p->anim > 16) + p->anim -= 16; } void push_player_cam(const Player* p) { @@ -47,3 +54,23 @@ void push_player_cam(const Player* p) { void pop_player_cam(void) { mtx_popn(3); } + +void draw_gun(Renderer* r, const Player* p) { + const Mesh* m = get_mesh(asset_id_gun_mesh); + const Texture* tex = get_texture(asset_id_gun_texture); + int pos[3]; + pos[0] = 0; + pos[1] = -f1; + pos[2] = cos_table[p->anim]; + mtx_push_trans(pos); + mtx_push_scale(f1/4); + mtx_push_rot_y(-64); + ren_mesh(r, m, tex); + mtx_popn(3); +} + + +void draw_player_world(Renderer* r, const Player* p) { + ren_cleard(r, f1 * 300); + draw_gun(r, p); +} @@ -2,16 +2,19 @@ #define player_h struct Services; +struct Renderer; typedef struct { int p[3]; int r[2]; int f[2], l[2]; + int anim; } Player; void init_player(Player* p); void update_player(Player* p, struct Services* s); void push_player_cam(const Player* p); void pop_player_cam(void); +void draw_player_world(struct Renderer* r, const Player* p); #endif |