-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRect.cpp
More file actions
101 lines (90 loc) · 1.45 KB
/
Rect.cpp
File metadata and controls
101 lines (90 loc) · 1.45 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "Rect.h"
Rect::Rect(int wrect, int hrect, int xrect, int yrect, int r, int g, int b, int a) :
_wrect(wrect), _hrect(hrect), _xrect(xrect), _yrect(yrect), _r(r), _g(g), _b(b), _a(a)
{
}
void Rect::draw()
{
SDL_Rect rect;
rect.w = _wrect;
rect.h = _hrect;
rect.x = _xrect;
rect.y = _yrect;
SDL_SetRenderDrawColor(Window::renderer, _r, _g, _b, _a);
SDL_RenderFillRect(Window::renderer, &rect);
}
void Rect::keyevent()
{
SDL_Event event;
if(SDL_PollEvent(&event))
{
if(event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_UP)
{
if (_yrect <= 0)
{
//jak wyjezdza za ekran to nie rob nic
}
else
{
_yrect -= 20;
}
}
else if (event.key.keysym.sym == SDLK_DOWN)
{
if(_yrect >= 440)
{
//jak wyjezdza za ekran to nie rob nic
}
else
{
_yrect += 20;
}
}
}
}
}
void Rect::movement()
{
// KIERUNEK Y
if(_yrect == 599 && _yoff == 0)
{
_yoff = 1;
}
else if (_yrect == 1 && _yoff == 1)
{
_yoff = 0;
}
else if(_yoff == 0)
{
_yrect++;
SDL_Delay(10);
}
else if(_yoff == 1)
{
_yrect--;
SDL_Delay(10);
}
// KIERUNEK X
if (_xrect == 799 && _xoff == 0)
{
_xoff = 1;
}
else if (_xrect == 1 && _xoff == 1)
{
_xoff = 0;
}
else if (_xoff == 0)
{
_xrect++;
}
else if (_xoff == 1)
{
_xrect--;
}
}
int Rect::yer()
{
return _yrect;
}