-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.cpp
57 lines (44 loc) · 1.22 KB
/
Interface.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
/*
* Licensed under GNU GPL v2
* Author(s): Christofer Oden
* Created on: 091031
*/
#include "Interface.h"
void Interface::initialize( SDL_Surface *screen, Camera *camera,
World *world, PlayerManager *player_manager )
{
the_screen = screen;
the_camera = camera;
the_world = world;
the_player_manager = player_manager;
SDL_Rect map_rect = { SCREEN_WIDTH - the_world->get_col_count() - 16,
16, the_world->get_col_count(), the_world->get_row_count() };
my_interface_map.initialize( &map_rect, the_screen, the_camera,
the_world, the_player_manager );
my_rect.h = SCREEN_HEIGHT;
my_rect.w = 100;
my_rect.x = SCREEN_WIDTH - my_rect.w;
my_rect.y = 0;
}
void Interface::draw() {
SDL_FillRect( the_screen, &my_rect,
SDL_MapRGB( the_screen->format,
0x10, 0x00, 0x00 ) );
my_interface_map.draw();
}
void Interface::on_click( int x, int y ) {
printf( "Interface->Click!\n" );
if( my_interface_map.covers( x, y ) == true ) {
my_interface_map.on_click( x, y );
}
}
bool Interface::covers( int x, int y ) {
if( my_interface_map.covers( x, y ) == true )
return true;
if( x < my_rect.x || x > my_rect.x + my_rect.w
|| y < my_rect.y || y > my_rect.y + my_rect.h )
{
return false;
}
return true;
}