-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monster.cpp
100 lines (94 loc) · 2.06 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
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include "Monster.h"
#include "MapElement.h"
#include <math.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_primitives.h>
#include <iostream>
using namespace std;
enum DIRECTION{RIGHT, UP, LEFT, DOWN};
//Monster
Monster::Monster()
{
live = false;
xPos = 0;
yPos = 0;
slowed = 0;
direction = 4;
distanceTravelled = COORD_BOX_SIZE;
}
void Monster::PlaceMonster(MapElement startPath)
{
live = true;
xPos = (startPath.cell.GetXTop() + startPath.cell.GetXBot())/2;
yPos = (startPath.cell.GetYTop() + startPath.cell.GetYBot())/2;
}
void Monster::WalkMonster(MapElement grid[MAP_WIDTH/COORD_BOX_SIZE][MAP_HEIGHT/COORD_BOX_SIZE], Player &player)
{
if(live)
{
int i = xPos/COORD_BOX_SIZE;
int j = yPos/COORD_BOX_SIZE;
distanceTravelled += speed - slowed;
if(distanceTravelled >= COORD_BOX_SIZE)
{
if(grid[i + 1][j].pathElement.GetLive() && direction != LEFT)
{
direction = RIGHT;
}
else if(grid[i][j - 1].pathElement.GetLive() && direction != DOWN)
{
direction = UP;
}
else if(grid[i - 1][j].pathElement.GetLive() && direction != RIGHT)
{
direction = LEFT;
}
else if(grid[i][j + 1].pathElement.GetLive() && direction != UP)
{
direction = DOWN;
}
distanceTravelled = 0;
}
if(direction == RIGHT)
xPos += speed - slowed;
else if(direction == UP)
yPos -= speed - slowed;
else if(direction == LEFT)
xPos -= speed + slowed;
else if(direction == DOWN)
yPos += speed + slowed;
if(grid[i][j].pathElement.GetEnd() == true)
{
if(distanceTravelled >= COORD_BOX_SIZE*9/10)
{
live = false;
player.LoseLife();
}
}
}
}
void Monster::GotHit(float dmg, float slow)
{
if(live)
{
health -= dmg;
if(health <= 0)
live = false;
if(slowed < slow)
slowed = slow;
}
}
void Monster::DrawMonster()
{
if(live)
al_draw_filled_rectangle(xPos - 10, yPos - 10, xPos + 10, yPos + 10, al_map_rgb(health/maxHealth*200, health/maxHealth*200, health/maxHealth*200));
}
//EasyMonster
EasyMonster::EasyMonster()
{
live = false;
maxHealth = 50;
health = maxHealth;
speed = .7;
}