Skip to content

Commit

Permalink
add grave when die
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-str committed Mar 3, 2021
1 parent 5b07916 commit 840a9fe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
6 changes: 4 additions & 2 deletions Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -37,6 +37,8 @@ struct Sprite

double time_start_prev_frame = -1;
std::vector<Image> imgs;

bool loop = true;
};

#endif
Binary file added resources/grave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 840a9fe

Please sign in to comment.