-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnnemi.cpp
More file actions
58 lines (46 loc) · 1.37 KB
/
Copy pathEnnemi.cpp
File metadata and controls
58 lines (46 loc) · 1.37 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
// CPE - 4ETI - Maj.Image - Programmation en C++ - 09/03/2018
// CARNEIRO ESTEVES, Sophie
// FOLETTO PIMENTA, Pedro
// TP 2
//includes
#include "Ennemi.hpp"
#define WINDOW_WIDTH 821
#define WINDOW_HEIGHT 541
#define TAILLE_ENNEMI_X 80
#define TAILLE_ENNEMI_Y 60
Ennemi::Ennemi()
{
//std::cout<<"Constructor of Ennemi is called"<<std::endl;//debug
pixmap->load("images/alien.png");
// prendre un nombre aleatoire
std::random_device r;
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(1, 30);
int rand_int = uniform_dist(e1);
float rand_float = ((float)rand_int)/35;
setPosition(14*WINDOW_WIDTH/15, rand_float*(WINDOW_HEIGHT-TAILLE_ENNEMI_Y-10));
int speed_y = 1 + (rand_int%3); // entre 1 et 3
if (rand_int % 2 == 0) //50% de chance de aller par au dessus
{
speed_y = -speed_y;
}
setSpeed(-1, speed_y);
}
Ennemi::~Ennemi()
{
//std::cout<<"Destructor of Ennemi is called"<<std::endl;//debug
}
void Ennemi::move(){
vec2 pos = this->getPosition();
vec2 speed = this->getSpeed();
int x = pos.x;
int y = pos.y;
// quand il arrive aux bords verticaux, changer de sense
if((y+TAILLE_ENNEMI_Y) >= (WINDOW_HEIGHT) || y <= 0){
setSpeed(getSpeed().x,-getSpeed().y);
}
speed = this->getSpeed();
x = (int) pos.x+speed.x;
y = (int) pos.y+speed.y;
this->setPosition(x, y);
}