-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbird.cpp
108 lines (90 loc) · 2.34 KB
/
bird.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
#include "bird.h"
void Bird::Init()
{
// 최초의 포지션 정하기
pos = {150, float(GetScreenHeight()) / 2} ;
// 그림으로 넣기
birdImage = LoadTexture("Assets/birddrawing.png"); // Texture loading
fxJump = LoadSound("Assets/jump.wav");
fxHurt = LoadSound("Assets/zap1.wav");
fxExplosion = LoadSound("Assets/explosion.wav");
// 기존에 있던 플레이어 속성 초기화
Score = 0;
Life = 3;
isInvincible = false;
timer = 0;
}
Bird::~Bird()
{
UnloadTexture(birdImage); // Texture unloading
UnloadSound(fxJump); // Unload sound data
}
void Bird::Update()
{
downSpeed += GRAVITY;
pos.y += downSpeed;
CheckCollision();
if (isInvincible)
{
timer++;
if (timer > MaxTimer)
{
timer = 0;
isInvincible = false;
}
}
}
void Bird::CheckCollision()
{
if (pos.y - halfLengthH <= 0) pos.y = halfLengthH;
if (pos.y + halfLengthH >= GetScreenHeight()) pos.y = GetScreenHeight() - halfLengthH;
}
// 플레이어가 데미지를 입는 메서드
void Bird::Hurt()
{
Life--;
SetInvincible(true);
if (Life > 0) PlaySound(fxHurt);
else PlaySound(fxExplosion);
}
// 플레이어 점수 추가
void Bird::SetAddScore(int increment)
{
Score += increment;
}
// 플레이어 생명력 추가
void Bird::SetAddLife(int increment)
{
Life += increment;
}
void Bird::SetInvincible(bool flag)
{
isInvincible = flag;
}
bool Bird::GetInvincible()
{
return isInvincible;
}
void Bird::Jump()
{
downSpeed = -jumpSpeed;
PlaySound(fxJump); // Play WAV sound
}
// 플레이어 그리기
void Bird::Draw()
{
if (isInvincible)
{
// DrawRectangle(pos.x - halfLength, pos.y - halfLength, halfLength * 2, halfLength * 2, GRAY); // 플레이어가 무적일 떄
DrawTexture(birdImage, int(pos.x) - halfLengthW, int(pos.y) - halfLengthH, GRAY);
}else
{
// DrawRectangle(pos.x - halfLengthW, pos.y - halfLengthH, halfLengthW * 2, halfLengthH * 2, DARKGREEN); // 평상시
DrawTexture(birdImage, int(pos.x) - halfLengthW, int(pos.y) - halfLengthH, WHITE);
}
}
// 플레이어의 컬리젼 네모 값을 리턴한다.
Rectangle Bird::GetPosition()
{
return {pos.x - halfLengthW, pos.y - halfLengthH, halfLengthW * 2, halfLengthH * 2};
}