-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoodler.cpp
137 lines (121 loc) · 2.16 KB
/
doodler.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <string>
#include "doodler.hpp"
Doodler::Doodler(int x, int y)
{
position.x = x;
position.y = y;
picture = "assets//main pictures//right.png";
width = 62;
height = 60;
acceleration.x = 0;
acceleration.y = -0.8;
velocity.x = 0;
velocity.y = 25;
score = 0;
ghost = false;
}
int Doodler::get_score()
{
return score;
}
int Doodler::get_width()
{
return width;
}
int Doodler::get_height()
{
return height;
}
bool Doodler::is_ghost()
{
return ghost;
}
void Doodler::you_are_dead()
{
ghost = true;
}
bool Doodler::is_out_of_range()
{
if (position.y + height < 0)
{
return true;
}
else
{
return false;
}
}
void Doodler::draw_me(Window *window, int window_width, int window_height)
{
window->draw_img(picture, Rectangle(position.x - width, window_height -(position.y + 2*height), 2*width, 2*height));
}
void Doodler::set_horizontal_velocity(float vx)
{
if (ghost)
{
return;
}
velocity.x = vx;
if (vx > 0)
picture = "assets//main pictures//right.png";
else if (vx < 0)
picture = "assets//main pictures//left.png";
}
void Doodler::set_vertical_velocity(float vy)
{
velocity.y = vy;
}
void Doodler::change_vertical_position(int y)
{
position.y -= y;
score += y;
}
Point Doodler::get_position()
{
return position;
}
Velocity Doodler::get_velocity()
{
return velocity;
}
void Doodler::update_position(int window_width, int window_height)
{
position.x += velocity.x;
position.y += velocity.y;
velocity.x += acceleration.x;
velocity.y += acceleration.y;
if (position.x > window_width)
{
position.x -= window_width;
}
else if (position.x < 0)
{
position.x += window_width;
}
update_picture();
}
void Doodler::update_picture()
{
if (velocity.y > 20)
{
if (picture == "assets//main pictures//right.png")
{
picture = "assets//main pictures//right_jumping.png";
}
else if (picture == "assets//main pictures//left.png")
{
picture = "assets//main pictures//left_jumping.png";
}
}
else
{
if (picture == "assets//main pictures//right_jumping.png")
{
picture = "assets//main pictures//right.png";
}
else if (picture == "assets//main pictures//left_jumping.png")
{
picture = "assets//main pictures//left.png";
}
}
}