-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutterfly.cpp
71 lines (64 loc) · 1.21 KB
/
butterfly.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
#pragma once
#include "butterfly.hpp"
// Sprite will form at x and y coordinates of screen
Butterfly::Butterfly(int x, int y) : Unit()
{
Unit::srcRect = {256, 24, 174, 134};
Unit::moverRect = {x, y, 50, 50};
}
// Sprite move down
void Butterfly::moveDown()
{
moverRect.x += 5;
moverRect.y += 5;
}
// Sprite move up
void Butterfly::moveUp()
{
moverRect.x += 5;
moverRect.y -= 5;
}
void Butterfly::fly()
{
// Sprite will flap it wings
switch (frame)
{
case 0:
srcRect = {256, 24, 174, 134};
frame = 1;
break;
case 1:
srcRect = {257, 182, 192, 214};
frame = 2;
break;
case 2:
srcRect = {248, 433, 247, 178};
frame = 0;
break;
}
// moving up or down
if (down == true)
{
moveDown();
}
else if (down == false)
{
moveUp();
}
// moving upright or downright after collision with upper or lower boundary
if (moverRect.y >= 600)
{
moverRect.y -= 10;
down = false;
}
if (moverRect.y <= 0)
{
moverRect.y += 10;
down = true;
}
// rotate sprite
if (moverRect.x >= 1000)
{
moverRect.x = 0;
}
}