-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlane.cpp
75 lines (59 loc) · 1.32 KB
/
Plane.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
74
75
#include "Plane.hpp"
#include "Renderer.hpp"
#include "Spritesheet.hpp"
namespace TappyPlane {
using namespace SDLW::Video;
static auto& sourceBounds()
{
static auto bounds = Spritesheet::instance().sourceBounds("plane");
return bounds;
}
constexpr Rectangle baseBounds{250, canvasBounds.height()/2 - 192/2, 231, 192};
constexpr int initialVerticalVelocity{5};
Plane::Plane()
: mBaseBounds(baseBounds)
, mBounds(mBaseBounds)
, mVerticalVelocity{initialVerticalVelocity}
{
}
SDLW::Video::Rectangle Plane::bounds() const noexcept
{
return mBounds;
}
bool Plane::isPlaying() const noexcept
{
return mIsPlaying;
}
void Plane::play() noexcept
{
mIsPlaying = true;
}
void Plane::pause() noexcept
{
mIsPlaying = false;
}
void Plane::reset() noexcept
{
mBounds = mBaseBounds;
mVerticalVelocity = initialVerticalVelocity;
}
void Plane::jump() noexcept
{
mVerticalVelocity += mJumpVelocityBoost;
}
void Plane::update() noexcept
{
if (!isPlaying()) {
return;
}
if (mVerticalVelocity < mVerticalTerminalVelocity) {
mVerticalVelocity += mGravityVelocity;
}
mBounds.setY(mBounds.y() + mVerticalVelocity);
}
void Plane::draw() const
{
Renderer::instance().copy(Spritesheet::instance().texture(),
sourceBounds(), mBounds);
}
} // namespace TappyPlane