-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cpp
More file actions
91 lines (88 loc) · 2.33 KB
/
Enemy.cpp
File metadata and controls
91 lines (88 loc) · 2.33 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Enemy.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hasmith <hasmith@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/27 00:33:43 by lhernand #+# #+# */
/* Updated: 2019/01/27 23:06:24 by hasmith ### ########.fr */
/* */
/* ************************************************************************** */
#include "Enemy.hpp"
#include <math.h>
Enemy::Enemy(void)
:
wait(0)
{
this->setN(0);
this->setX(-1);
this->setY(-1);
return ;
}
Enemy::~Enemy(void)
{
std::cout << "Enemy Destroyed" << std::endl;
}
Enemy::Enemy(Enemy const & src)
{
*this = src;
}
Enemy &Enemy::operator=(Enemy const & rhs)
{
if (this == &rhs)
return (*this);
this->x = rhs.getX();
this->y = rhs.getY();
this->N = rhs.getN();
return (*this);
}
void Enemy::clearEnemy(void)
{
mvaddch(getY(), getX(), ' ');
mvaddch(getY() - 1, getX() + 1, ' ');
mvaddch(getY() - 1, getX() - 1, ' ');
refresh();
}
void Enemy::killEnemy(void)
{
this->clearEnemy();
this->setN(0);
this->setX(-1);
this->setY(-1);
}
void Enemy::moveDown(void)
{
wait+=1;
if (wait % 6 == 0)
{
this->clearEnemy();
mvaddch(getY(), getX(), ' ');
mvaddch(getY() - 1, getX() + 1, ' ');
mvaddch(getY() - 1, getX() - 1, ' ');
this->setY(getY() + 1);
wait = 0;
}
}
void Enemy::drawEnemy(void)//game instance is passed to know the map size;
{
moveDown();
attron(COLOR_PAIR(2));
mvaddch(this->getY() - 1, getX() + 1, '#');
mvaddch(this->getY() - 1, getX() - 1, '#');
mvaddch(this->getY(), this->getX(), '#');
attroff(COLOR_PAIR(2));
box(stdscr, 0, 0);
refresh();
usleep(700); // creates small delay for the enemies as they move left to right and back.
}
int win(Enemy *enemies, Game *game, int number)
{
int i = 0;
while (i < number)
{
if (enemies[i++].getY() == game->getMapY() - 3)
return (1);
}
return (0);
}