-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1996547
commit 9dcdb2a
Showing
4 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#include "Enemy.h" | ||
|
||
Enemy::Enemy(Point center_pos, int _type) : spr(E_LiveObjType::Enemy, _type, get_move_frames(_type), get_attack_frames(_type)), mov(center_pos) | ||
Enemy::Enemy(Point center_pos, int _type) : type(_type), mov(center_pos) | ||
{ | ||
hp = get_hp(_type); | ||
sz = get_sz(_type); | ||
speed = get_speed(_type); | ||
cur_dir = std::rand() % 2 ? E_Dir::LEFT : E_Dir::RIGHT; | ||
} | ||
|
||
void Enemy::Draw(Image &canvas) | ||
{ | ||
auto p = mov.Pos(); | ||
spr.Draw(canvas, {.x = p.x - sz.w / 2, .y = p.y - sz.h / 2}); | ||
SpriteManager::Get().enemy_spr[type].Draw(canvas, {.x = p.x - sz.w / 2, .y = p.y - sz.h / 2}, cur_dir); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef MAIN_SPMz_ENE_H | ||
#define MAIN_SPMz_ENE_H | ||
|
||
#include "LiveObjSprite.h" | ||
|
||
struct SpriteManager | ||
{ | ||
static SpriteManager &Get() { static SpriteManager spr {}; return spr; } | ||
|
||
std::vector<LiveObjSprite> enemy_spr; | ||
|
||
private: | ||
static constexpr int e_get_move_frames(int type) | ||
{ | ||
if (type == 0)return 8; | ||
return 1; | ||
} | ||
static constexpr int e_get_attack_frames(int type) | ||
{ | ||
if (type == 0)return 8; | ||
return 1; | ||
} | ||
SpriteManager() : enemy_spr() | ||
{ | ||
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)); | ||
} | ||
|
||
}; | ||
|
||
#endif |