-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.cpp
74 lines (64 loc) · 1.62 KB
/
button.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
#include "button.h"
Button::Button(int x, int y, int w, int h)
{
box.x = x;
box.y = y;
box.w = w;
box.h = h;
}
void Button::handle_events(bool *win,Uint32 *score1,Uint32 *score2,bool *menuState,bool *gameState,Uint32 *firstTick)
{
int x = 0 ;
int y = 0 ;
while( SDL_PollEvent(&event))
{
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
x = event.button.x;
y = event.button.y;
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Reset the values of the match (win and scores) and return to the game state
*win = false;
*score1 = 0;
*score2 = 0;
*menuState = false;
*gameState = true;
*firstTick =0;
}
}
}
}
}
void Button::handle_events1(bool *gameState,bool *menuState)
{
int x = 0 ;
int y = 0 ;
while( SDL_PollEvent(&event))
{
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
x = event.button.x;
y = event.button.y;
if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
{
//Do after button is pressed
*gameState = true;
*menuState = false;
}
}
}
}
}
void Button::show()
{
apply_surface(box.x, box.y, button, screen);
}
void Button::show1()
{
apply_surface(box.x, box.y, button2, screen);
}