Skip to content

Commit

Permalink
+ enemy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-str committed Mar 3, 2021
1 parent 840a9fe commit 770c090
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Enemy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Enemy.h"

Enemy::Enemy(Point center_pos, int _type) : type(_type), mov(center_pos)
Enemy::Enemy(Point center_pos, int _type) : type(_type), mov(center_pos + Point{.x = 0, .y = 5})
{
max_hp = get_hp(_type);
hp = max_hp;
Expand Down
5 changes: 4 additions & 1 deletion Enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ struct Enemy
static constexpr int get_hp(int type)
{
if (type == 0)return 20;
return 35;
if (type == 1)return 40;
return 30;
}
static constexpr Size get_sz(int type)
{
if (type == 0)return Size {.w = 41, .h = 34};
if (type == 1)return Size {.w = 28, .h = 38};
return Size {2,2};
}
static constexpr int get_speed(int type)
{
if (type == 0)return 160;
if (type == 1)return 80;
return 80;
}

Expand Down
6 changes: 3 additions & 3 deletions LiveObjSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ enum class E_LiveObjType
struct LiveObjSprite
{

LiveObjSprite(E_LiveObjType must_enemy, int type, int move_frames, int attack_frames, int take_hit_frames) : spr_states()
LiveObjSprite(E_LiveObjType must_enemy, int type, int move_frames, int attack_frames, int take_hit_frames, int ms_speed) : spr_states()
{
if (must_enemy != E_LiveObjType::Enemy)error("must enemy. for character use another constructor");
lo_type = must_enemy;
cur_dir = std::rand() % 2 ? E_Dir::LEFT : E_Dir::RIGHT;
std::string path_0 = "../resources/enemies/" + std::to_string(type) + "/";
spr_states.insert({E_LiveObjState::Idle, std::map<E_Dir, Sprite>{}}).first->second.insert({E_Dir::RIGHT, Sprite(path_0 + "move.png", move_frames)});
spr_states.insert({E_LiveObjState::Attack, std::map<E_Dir, Sprite>{}}).first->second.insert({E_Dir::RIGHT, Sprite(path_0 + "attack.png", attack_frames)});
spr_states.insert({E_LiveObjState::Idle, std::map<E_Dir, Sprite>{}}).first->second.insert({E_Dir::RIGHT, Sprite(path_0 + "move.png", move_frames, ms_speed)});
spr_states.insert({E_LiveObjState::Attack, std::map<E_Dir, Sprite>{}}).first->second.insert({E_Dir::RIGHT, Sprite(path_0 + "attack.png", attack_frames, ms_speed)});
spr_states.insert({E_LiveObjState::TakeHit, std::map<E_Dir, Sprite>{}}).first->second.insert({E_Dir::RIGHT, Sprite(path_0 + "take_hit.png", take_hit_frames)});
//SetCurSprite();
}
Expand Down
2 changes: 1 addition & 1 deletion Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private: static Player *player_getter;
{
Kill,
EmptyStay,
};
};

static Player &Get() { return *player_getter; }

Expand Down
15 changes: 13 additions & 2 deletions SpriteManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,33 @@ struct SpriteManager
static constexpr int e_get_move_frames(int type)
{
if (type == 0)return 8;
if (type == 1)return 8;
return 1;
}
static constexpr int e_get_attack_frames(int type)
{
if (type == 0)return 8;
if (type == 1)return 8;
return 1;
}
static constexpr int e_get_take_hit_frames(int type)
{
if (type == 0)return 4;
if (type == 1)return 4;
return 1;
}
static constexpr int e_get_spr_speed(int type)
{
if (type == 0)return 125;
if (type == 1)return 190;
return 1;
}
SpriteManager() : enemy_spr(), hp_imgs(), doors()
{
for (int _type = 0; _type < 1; _type++)
enemy_spr.emplace_back(E_LiveObjType::Enemy, _type, e_get_move_frames(_type), e_get_attack_frames(_type), e_get_take_hit_frames(_type));
for (int _type = 0; _type < 2; _type++)
enemy_spr.emplace_back(E_LiveObjType::Enemy, _type,
e_get_move_frames(_type), e_get_attack_frames(_type),
e_get_take_hit_frames(_type), e_get_spr_speed(_type));

int sz = HP_SZ;
Image hp_img {sz,sz,4};
Expand Down
4 changes: 2 additions & 2 deletions maps/F.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ O. ..E.....#.........#... .....O
###########O####################
z-

E: 0, 0, 0, 0, 0, 0, 0, 0
/1, 0, 1, 1, 1, 0, 0, 0
/E: 0, 0, 0, 0, 0, 0, 0, 0
E: 1, 0, 1, 1, 1, 0, 0, 0
I: 2, 1, 2, 3, 0, 0, 0, 1, 1

/I: - rarity of Items in the same order as they stay on map
Expand Down
Binary file added resources/enemies/1/attack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/enemies/1/move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/enemies/1/take_hit.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 770c090

Please sign in to comment.