-
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
da84e12
commit 1996547
Showing
14 changed files
with
195 additions
and
69 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#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) | ||
{ | ||
hp = get_hp(_type); | ||
sz = get_sz(_type); | ||
speed = get_speed(_type); | ||
} | ||
|
||
void Enemy::Draw(Image &canvas) | ||
{ | ||
auto p = mov.Pos(); | ||
spr.Draw(canvas, {.x = p.x - sz.w / 2, .y = p.y - sz.h / 2}); | ||
} |
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,47 @@ | ||
#ifndef MAIN_I3z_ENE_H | ||
#define MAIN_I3z_ENE_H | ||
|
||
#include "LiveObjSprite.h" | ||
#include "Movement.h" | ||
|
||
struct Enemy | ||
{ | ||
private: | ||
static constexpr int get_move_frames(int type) | ||
{ | ||
if (type == 0)return 8; | ||
return 1; | ||
} | ||
static constexpr int get_attack_frames(int type) | ||
{ | ||
if (type == 0)return 8; | ||
return 1; | ||
} | ||
static constexpr int get_hp(int type) | ||
{ | ||
if (type == 0)return 20; | ||
return 35; | ||
} | ||
static constexpr Size get_sz(int type) | ||
{ | ||
if (type == 0)return Size {.w = 41, .h = 34}; | ||
return Size {2,2}; | ||
} | ||
static constexpr int get_speed(int type) | ||
{ | ||
if (type == 0)return 160; | ||
return 80; | ||
} | ||
public: | ||
Enemy(Point center_pos, int _type); | ||
|
||
void Draw(Image &canvas); | ||
|
||
Size sz {.w = 0,.h = 0}; | ||
int hp; | ||
Movement mov; | ||
LiveObjSprite spr; | ||
int speed = 50; | ||
|
||
}; | ||
#endif |
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
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,65 @@ | ||
#include "GameMap.h" | ||
#include "Movement.h" | ||
|
||
void Movement:: Move(int dx, int dy, int speed) | ||
{ | ||
double now_t = GameTime::Now().GetTime(); | ||
|
||
if (dx || dy) { | ||
double dt = now_t - last_time; | ||
if (obj_size.IsEmpty()) { | ||
x += dt * dx * speed; | ||
y += dt * dy * speed; | ||
last_moved_time = now_t; | ||
moved = true; | ||
} else { | ||
|
||
bool move_x = false; | ||
if (dx) { | ||
double x_back = x; | ||
double x_temp = x + dt * dx * speed; | ||
|
||
for (; (dx > 0) ? (x_temp > x_back) : (x_temp < x_back); x_temp += (dx > 0) ? -1 : 1) { | ||
bool can_stay = GameMap::GetCur()->CanStay( | ||
(dx > 0) ? GameMap::E_CanStayType::Right : GameMap::E_CanStayType::Left, | ||
Point {.x = (int)x_temp, .y = (int)y}, obj_size, can_stay_on_empty | ||
); | ||
if (can_stay) { | ||
move_x = true; | ||
break; | ||
} | ||
} | ||
|
||
if (move_x)x = x_temp; | ||
} | ||
|
||
bool move_y = false; | ||
if (dy) { | ||
double y_back = y; | ||
double y_temp = y + dt * dy * speed; | ||
|
||
for (; (dy > 0) ? (y_temp > y_back) : (y_temp < y_back); y_temp += (dy > 0) ? -1 : 1) { | ||
bool can_stay = GameMap::GetCur()->CanStay( | ||
(dy > 0) ? GameMap::E_CanStayType::Up : GameMap::E_CanStayType::Down, | ||
Point {.x = (int)x, .y = (int)y_temp}, obj_size, can_stay_on_empty | ||
); | ||
if (can_stay) { | ||
move_y = true; | ||
break; | ||
} | ||
} | ||
|
||
if (move_y)y = y_temp; | ||
} | ||
|
||
if (move_x || move_y) { | ||
last_moved_time = now_t; | ||
moved = true; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
last_time = now_t; | ||
} |
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
Oops, something went wrong.