-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.cpp
87 lines (71 loc) · 1.39 KB
/
Monster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Player.h"
#include "World.h"
#include "Engine.h" // keycode 갖고 오기 위햐
#include "Goal.h"
#include "Monster.h"
#include "SDL.h"
#include "Actor.h"
AMonster::AMonster()
: AActor()
{
R = 0;
G = 255;
B = 255;
LoadBMP("Data/slime.bmp");
}
AMonster::AMonster(int NewX, int NewY, char NewShape, bool bNewCollision, int NewSortOrder)
: AActor(NewX, NewY, NewShape, bNewCollision, NewSortOrder)
{
srand((unsigned int)time(NULL));
R = 0;
G = 255;
B = 255;
LoadBMP("Data/slime.bmp");
}
AMonster::~AMonster()
{
}
void AMonster::Tick()
{
ElapsedTimeM += GEngine->GetWorldDeltaSeconds();
if (ElapsedTimeM >= ProcessTimeM)
{
int MonsterIndex = rand() % 4;
switch (MonsterIndex)
{
case 0:
Y = PredictCollision(X, Y - 1) == false ? Y - 1 : Y;
break;
case 1:
Y = PredictCollision(X, Y + 1) == false ? Y + 1 : Y;
break;
case 2:
X = PredictCollision(X - 1, Y) == false ? X - 1 : X;
break;
case 3:
X = PredictCollision(X + 1, Y) == false ? X + 1 : X;
break;
}
ElapsedTimeM = 0;
}
if (IsPlayer())
{
SDL_Log("Game Over");
GEngine->QuitGame();
}
}
bool AMonster::IsPlayer()
{
for (auto Actor : GEngine->GetWorld()->MyActors)
{
if (Actor->X == X && Actor->Y == Y)
{
APlayer* Player = dynamic_cast<APlayer*>(Actor); //dynamic cast는 무조건 포인터로 사용해야 한다.
if (Player != nullptr)
{
return true;
}
}
}
return false;
}