-
Notifications
You must be signed in to change notification settings - Fork 1
/
point.cpp
78 lines (62 loc) · 1.33 KB
/
point.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
#include "point.h"
Point::Point(){
this->posx = 0;
this->posy = 0;
this->img = NULL;
this->point = 5;
}
Point::Point(string name){
srand(time(NULL));
int px = rand() % 40; // da 0 a 39
int py = rand() % 30; // da 0 a 29
this->posx = px * 16;
this->posy = py * 16;
this->point = 5;
this->setImg(name);
}
Point::Point(float px, float py, string name){
this->posx = px;
this->posy = py;
this->point = 5;
this->setImg(name);
}
Point::~Point(){
SDL_FreeSurface(this->img);
this->img = NULL;
}
float Point::getPosX() const{
return this->posx;
}
float Point::getPosY() const{
return this->posy;
}
int Point::getPoint() const {
return this->point;
}
void Point::setPosX(float px){
this->posx = px;
}
void Point::setPosY(float py){
this->posy = py;
}
void Point::setPoint(int n){
this->point = n;
}
void Point::setImg(string name){
SDL_Surface * oldimg = IMG_Load(name.c_str());
if(oldimg == NULL){
cout << "Errore caricamento immagine: "<<SDL_GetError()<<endl;
return ;
}
this->img = SDL_DisplayFormat(oldimg);
SDL_FreeSurface(oldimg);
if(this->img == NULL)
cout << "Errore aggiornamento immagine: "<<SDL_GetError()<<endl;
}
void Point::draw(SDL_Surface * screen){
SDL_Rect * rect = new SDL_Rect();
rect->x = this->posx;
rect->y = this->posy;
SDL_BlitSurface(this->img, NULL, screen, rect);
delete rect;
}