-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissile.cpp
More file actions
88 lines (85 loc) · 2.42 KB
/
Missile.cpp
File metadata and controls
88 lines (85 loc) · 2.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Missile.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hasmith <hasmith@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/27 00:33:43 by lhernand #+# #+# */
/* Updated: 2019/01/27 22:48:09 by hasmith ### ########.fr */
/* */
/* ************************************************************************** */
#include "Missile.hpp"
Missile::Missile(void)
{
this->setX(-1);
this->setY(-1);
return ;
}
Missile::~Missile(void)
{
std::cout << "Missile Destroyed" << std::endl;
}
Missile::Missile(Missile const & src)
{
*this = src;
}
Missile &Missile::operator=(Missile const & rhs)
{
if (this == &rhs)
return (*this);
this->x = rhs.getX();
this->y = rhs.getY();
this->N = rhs.getN();
return (*this);
}
void Missile::clearMissile(void)
{
mvaddch(this->getY(), this->getX(), ' ');
// usleep(100);
refresh();
}
void Missile::killMissile(void)
{
this->clearMissile();
this->setN(0);
this->setX(0);
this->setY(0);
}
void Missile::moveUp(void)
{
mvaddch(this->getY(), this->getX(), ' ');
this->setY(this->getY() - 1);
}
void Missile::drawMissile(Game *game)
{
if (this->getN() > 0 && (this->getY() > 0 && this->getY() < game->getMapY() - 1))
{
this->moveUp();
attron(COLOR_PAIR(3));
mvaddch(this->getY(), this->getX(), '0');
attroff(COLOR_PAIR(3));
box(stdscr, 0, 0);
refresh();
}
else
this->N = 0;
}
int Missile::missileCollision(int nx, int ny)
{
if ((this->getY() == ny && this->getX() == nx)
||
(this->getY() == ny && this->getX() == nx+1) ||
(this->getY() == ny && this->getX() == nx-1) ||
(this->getY() == ny-1 && this->getX() == nx) ||
(this->getY() == ny-1 && this->getX() == nx-1) ||
(this->getY() == ny-1 && this->getX() == nx+1) ||
(this->getY() == ny && this->getX() == nx+1) ||
(this->getY() == ny && this->getX() == nx-1) ||
(this->getY() == ny && this->getX() == nx))
{
this->killMissile();
return 1;
}
return 0;
}