From 840a9feb2c23d39830d034d56c1ea6db4a804b7c Mon Sep 17 00:00:00 2001 From: name Date: Wed, 3 Mar 2021 05:33:57 +0300 Subject: [PATCH] add grave when die --- Player.cpp | 2 ++ Player.h | 11 ++++++----- Sprite.cpp | 11 ++++++++--- Sprite.h | 6 ++++-- resources/grave.png | Bin 0 -> 863 bytes 5 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 resources/grave.png diff --git a/Player.cpp b/Player.cpp index a00a55d..2162929 100644 --- a/Player.cpp +++ b/Player.cpp @@ -73,6 +73,8 @@ void Player::DieDraw(Image &canvas, double proc) if (die_type == E_DieType::EmptyStay) { SetPosY(-30 + -50 + (50 + die_pos.y) * (1 - proc)); spr.GetImage(E_LiveObjState::Idle, 0).Draw(canvas, coords, false); + } else { + grave.Draw(canvas, coords, true); } //for kill draw grave } diff --git a/Player.h b/Player.h index b2d9f53..901ad66 100644 --- a/Player.h +++ b/Player.h @@ -20,7 +20,7 @@ private: static Player *player_getter; static Player &Get() { return *player_getter; } - explicit Player(Point pos, LiveObjSprite &sprite) : position(pos), coords(pos), old_coords(pos), spr(sprite) + explicit Player(Point pos, LiveObjSprite &sprite) : position(pos), coords(pos), old_coords(pos), spr(sprite), grave("../resources/grave.png", 4, 150, 1, false) { position.SetSize(Size {.w = 29, .h = 29}); position.SetCanStay(true); @@ -87,7 +87,7 @@ private: static Player *player_getter; void GetDamage(int dmg) { hp -= dmg; - if (hp < 0) { + if (hp <= 0) { die_pos = coords; died = true; die_type = E_DieType::Kill; @@ -143,7 +143,7 @@ private: static Player *player_getter; void Use() { - Player::Get().GetDamage(1);//TODO:DEL + Player::Get().GetDamage(5);//TODO:DEL if (inv_pos < 0)return; if (inv_item.size() <= inv_pos)return; if (!inv_item[inv_pos].can_be_used)return; @@ -221,13 +221,14 @@ private: static Player *player_getter; int move_speed_ctrl = 40; LiveObjSprite &spr; + Sprite grave; bool now_attack = false; double blocked_to_time = -0.0; bool died = false; - Point die_pos; - E_DieType die_type; + Point die_pos {-1, -1}; + E_DieType die_type = E_DieType::EmptyStay; int hp = 40; int max_hp = 40; diff --git a/Sprite.cpp b/Sprite.cpp index 4f2b27e..7aece95 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -32,12 +32,12 @@ void Sprite::SpriteFromImg(Image &img0, int p_frames, int ms_on_frame, int scale } } -Sprite::Sprite(const std::string &path, int p_frames, int ms_on_frame, int scale) : imgs() +Sprite::Sprite(const std::string &path, int p_frames, int ms_on_frame, int scale, bool _loop) : imgs(), loop(_loop) { SpriteFromImg(Image {path, scale}, p_frames, ms_on_frame, scale); } -Sprite::Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame, int scale) : imgs() +Sprite::Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame, int scale, bool _loop) : imgs(), loop(_loop) { auto img0 = Image {path, scale}; if (frame_sz.width == 0)std::abort(); @@ -64,7 +64,12 @@ void Sprite::Draw(Image &canvas, const Point p, bool flip_OX, bool flip_OY) time_start_prev_frame += add_frame * s_per_frame; } - frame_now = (frame_now + add_frame) % frames; + if (loop) { + frame_now = (frame_now + add_frame) % frames; + } else { + frame_now = frame_now + add_frame; + if (frame_now >= frames) frame_now = frames - 1; + } imgs[frame_now].Draw(canvas, p, flip_OX, flip_OY); } \ No newline at end of file diff --git a/Sprite.h b/Sprite.h index 6f9e0a7..c538086 100644 --- a/Sprite.h +++ b/Sprite.h @@ -15,8 +15,8 @@ struct SpritePixSz struct Sprite { Sprite() {}; - Sprite(const std::string &path, int p_frames, int ms_on_frame = 125, int scale = 1); - Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame = 125, int scale = 1); + Sprite(const std::string &path, int p_frames, int ms_on_frame = 125, int scale = 1, bool _loop = true); + Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame = 125, int scale = 1, bool _loop = true); void Draw(Image &canvas, const Point p, bool flip_OX = false, bool flip_OY = false); @@ -37,6 +37,8 @@ struct Sprite double time_start_prev_frame = -1; std::vector imgs; + + bool loop = true; }; #endif \ No newline at end of file diff --git a/resources/grave.png b/resources/grave.png new file mode 100644 index 0000000000000000000000000000000000000000..433d292bdce290d0baa22a8d78707b3344a1d85e GIT binary patch literal 863 zcmV-l1EBngP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0`y5lK~#8N?U_+- z6G0F}bBIJBMZq6I0*M3i!38(~65pKExIl%*HPt=6_BvkU`FM)AXQykryRur#5BvRo za>v-nBnGV-@9_kUsqV?zJj|Yiky`zgs z4;rb1P_)r4*snP=@C0!hfP;0zCE2=rIvrh1jzJ^cAX;3b739&}5s?8n*l4(5bk8)v z0?qOr$asslaDW`H0fYr8M@l;|+TiM3RVCZho$A8=YET1RfxQ>FnLqJt18t%gZH>KQZYbQx64_D=Tkk$+GoggZ7@3ka3UkB z#b5G2uwnoZ)$ejvsn$=j8MyoznYImP;=qZFs5W34;4j$>T>gwqy9;E(zzI~j_FMS> zVgTSYBC@)>z$Fb(8Njvm!4?bva9(!~;50HK{XTFAtqsKAzuT3XpnKO~i9XQ%=R$qe psi3(|A=B>yll#I3C-=hs;Wwv0u$>n({SyEH002ovPDHLkV1leghHU@< literal 0 HcmV?d00001