-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.h
More file actions
64 lines (57 loc) · 1.35 KB
/
box.h
File metadata and controls
64 lines (57 loc) · 1.35 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
#ifndef BOX_H
#define BOX_H
#include "SDL2.h"
#include<iostream>
using namespace std;
struct Box {
int x,y;
int size=10;
int stepX=0;
int stepY=0;
Box(int _x, int _y):x(_x), y(_y){}
bool color=true;
void render(SDL_Renderer* renderer) {
SDL_Rect filled_rect;
filled_rect.x = x;
filled_rect.y = y;
filled_rect.w = size;
filled_rect.h = size;
if (color)
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); // green
else
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);//red
SDL_RenderFillRect(renderer, &filled_rect);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // black
SDL_RenderDrawRect(renderer, &filled_rect);
}
void move()
{
x+=stepX;
y+=stepY;
}
void turnLeft()
{
stepX=-10; stepY=0;
}
void turnRight()
{
stepX=10; stepY=0;
}
void turnDown()
{
stepY=10; stepX=0;
}
void turnUp()
{
stepY=-10; stepX=0;
}
bool inside(int minX, int minY, int maxX, int maxY)
{
return (minX<=x && minY<=y && x+size<=maxX && y+size<=maxY);
}
bool compare(Box p) {
if(x == p.x && y == p.y) return true;
return false;
};
};
#endif // BOX_H