aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'player.c')
-rw-r--r--player.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/player.c b/player.c
index a99f40b..77d0b01 100644
--- a/player.c
+++ b/player.c
@@ -6,6 +6,7 @@
#include "physics.h"
#include "plat.h"
#include "render.h"
+#include "world.h"
void init_player(Player* p) {
p->anim = asset_id_guy_run_right_anm;
@@ -18,6 +19,7 @@ void init_player(Player* p) {
p->headbutted = 0;
p->on_ramp = 0;
p->jumping = 0;
+ p->cooldown = 0;
p->face = face_right;
}
@@ -46,12 +48,13 @@ void update_player_phys(Player* p, const Map* map) {
);
}
-void update_player_move(Player* p, const App* a) {
+void update_player_move(Player* p, const App* a, World* w) {
int grounded = p->grounded < 3;
int mf = player_move_force;
int nanim, moving, t;
int jumping = p->jumping;
Face* face = &p->face;
+ p->cooldown--;
if (!grounded) {
mf = player_air_move_force;
}
@@ -89,6 +92,21 @@ void update_player_move(Player* p, const App* a) {
p->jumping = 1;
play_sound(500);
}
+ if (p->cooldown <= 0 && btn_just_pressed(a, btn_shoot)) {
+ int sx, sy;
+ int anim;
+ if (p->face == face_left) {
+ anim = asset_id_slash_left_anm;
+ sx = (p->x >> fbits) - 45;
+ sy = (p->y >> fbits);
+ } else {
+ anim = asset_id_slash_right_anm;
+ sx = (p->x >> fbits) + 16;
+ sy = (p->y >> fbits);
+ }
+ inst_particle(w, sx, sy, anim, asset_id_arms_img);
+ p->cooldown = 10;
+ }
jumping = p->jumping;
nanim = p->anim;
switch (p->face) {
@@ -120,13 +138,18 @@ void update_player_move(Player* p, const App* a) {
}
}
-void update_player(Player* p, App* app, const Map* map) {
- update_player_move(p, app);
+void update_player(
+ Player* p,
+ World* w,
+ const App* app,
+ const Map* map
+) {
+ update_player_move(p, app, w);
update_player_phys(p, map);
update_player_anim(p);
}
-void ren_player(Player* p, struct Renderer* r) {
+void ren_player(const Player* p, struct Renderer* r) {
const Bitmap* b = get_bitmap(asset_id_guy_img);
ren_map(r, p->x >> fbits, p->y >> fbits, &p->rect, b);
}