-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaby_turtle.cpp
85 lines (75 loc) · 1.69 KB
/
Baby_turtle.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
76
77
78
79
80
81
82
83
84
85
#include "Baby_turtle.h"
// private functions
// constructor and distructor
BabyTurtle::BabyTurtle(std::vector<sf::Sprite> gParts)
{
fallTime = 1;
speed = 1.f;
direction = RIGHT;
is_free = false;
groundParts = gParts;
}
BabyTurtle::~BabyTurtle()
{
}
// FUNCS
void BabyTurtle::make_free(sf::Sprite free_baby_sprite)
{
set_texture(free_baby_sprite);
is_free = true;
}
void BabyTurtle::set_texture(sf::Sprite new_baby)
{
baby = new_baby;
}
void BabyTurtle::move()
{
if (is_free)
baby.move(speed * direction, 0);
for (auto part : groundParts)
if (is_it_on_ground())
{
return;
}
baby.move(0, ACCELERATION * fallTime);
fallTime++;
}
void BabyTurtle::moveBack()
{
baby.move(0, -ACCELERATION * fallTime);
}
void BabyTurtle::go_back()
{
direction *= -1;
baby.scale(-1.f, 1.f);
move();
}
void BabyTurtle::render(sf::RenderTarget &target)
{
target.draw(baby);
}
int BabyTurtle::get_dir()
{
return direction;
}
bool BabyTurtle::collided(sf::Sprite target)
{
if (baby.getGlobalBounds().intersects(target.getGlobalBounds()))
{
return true;
}
return false;
}
bool BabyTurtle::is_in_world(sf::Sprite world)
{
if (baby.getGlobalBounds().left >= world.getGlobalBounds().left &&
baby.getGlobalBounds().top >= world.getGlobalBounds().top &&
baby.getGlobalBounds().left + baby.getGlobalBounds().width <=
world.getGlobalBounds().left + world.getGlobalBounds().width &&
baby.getGlobalBounds().top + baby.getGlobalBounds().height <=
world.getGlobalBounds().top + world.getGlobalBounds().height)
{
return true;
}
return false;
}