-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewport.hpp
69 lines (56 loc) · 1.21 KB
/
viewport.hpp
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
#ifndef LIERO_VIEWPORT_HPP
#define LIERO_VIEWPORT_HPP
#include "rect.hpp"
#include "worm.hpp"
#include "rand.hpp"
#include <ctime>
struct Game;
struct Renderer;
struct Viewport
{
Viewport(Rect rect, int wormIdx, int inGameX, int levwidth, int levheight)
: wormIdx(wormIdx)
, bannerY(-8)
, inGameX(inGameX)
, rect(rect)
{
rand.seed((uint32_t)std::clock());
maxX = levwidth - rect.width();
maxY = levheight - rect.height();
centerX = rect.width() >> 1;
centerY = rect.height() >> 1;
x = 0;
y = 0;
shake = 0;
}
Viewport()
{
}
int x, y;
int shake;
int maxX, maxY;
int centerX, centerY;
int wormIdx;
int bannerY;
int inGameX; // 0 for first, 218 for second
Rand rand;
Rect rect;
void setCenter(int x, int y)
{
this->x = x - centerX;
this->y = y - centerY;
}
void scrollTo(int destX, int destY, int iter)
{
for(int c = 0; c < iter; c++)
{
if(x < destX - centerX) ++x;
else if(x > destX - centerX) --x;
if(y < destY - centerY) ++y;
else if(y > destY - centerY) --y;
}
}
void draw(Game& game, Renderer& renderer, bool isReplay);
void process(Game& game);
};
#endif // LIERO_VIEWPORT_HPP