-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.cpp
More file actions
53 lines (42 loc) · 1.04 KB
/
object.cpp
File metadata and controls
53 lines (42 loc) · 1.04 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
#include "object.h"
//todo: correct HIGHT and WIDTH automatically by picture size
Object::Object(std::string filename)
:Non_living_things(30,30, filename)
{
srand(time(NULL));
// No wins yet
wins = 0;
font = TTF_OpenFont("lazy.ttf", 28);
// The image accompanying the object
object = load_image(filename);
}
// Procedure for when the object was found
void Object::respawn()
{
new_position();
wins = wins + 1;
}
// choose a new position at random
void Object::new_position()
{
m_x = rand() % SCREEN_WIDTH;
m_y = rand() % SCREEN_HEIGHT;
}
// Showing the object
void Object::show()
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = m_x;
offset.y = m_y;
//Blit
SDL_BlitSurface( object, NULL, global::screen, &offset );
SDL_Rect offset2;
offset2.x = 20;
offset2.y = 30;
char score_text[32];
sprintf(score_text, "Score: %d", wins);
score = TTF_RenderText_Solid(font, score_text, {0,0,0});
SDL_BlitSurface(score, NULL, global::screen, &offset2);
}