-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPlayer.cpp
166 lines (134 loc) · 4.15 KB
/
CPlayer.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "pch.h"
#include "CPlayer.h"
#include "CTimeMgr.h"
#include "CKeyMgr.h"
#include "CResMgr.h"
#include "CPathMgr.h"
#include "CStage.h"
#include "CTexture.h"
#include "CBullet.h"
#include "CAnimation.h"
#include "CAnimator.h"
#include "CCollider.h"
CPlayer::CPlayer()
: m_fSpeed(300.f)
, m_pTex(nullptr)
{
// 이름 설정
SetName(L"Player");
// 텍스처 로딩
m_pTex = CResMgr::GetInst()->LoadTexture(L"PlayerImage", L"texture\\Plane.bmp");
// 충돌체 생성
CCollider* pCol = new CCollider;
pCol->SetOffsetPos(Vec(0.f, 0.f));
pCol->SetScale(Vec(60.f, 40.f));
AddComponent(pCol);
// 애니메이션 생성
CTexture* pAnimAtlasTex = CResMgr::GetInst()->LoadTexture(L"PlayerAnimation", L"texture\\animation\\link_0.bmp");
CAnimator* pAnimator = new CAnimator;
//pAnimator->CreateAnimation(L"IDLE", pAnimAtlasTex, Vec(0.f, 0.f), Vec(60.f, 65.f), Vec(0.f,0.f), 60.f, 0.1f, 3);
//pAnimator->CreateAnimation(L"WALK_DOWN", pAnimAtlasTex, Vec(0.f, 260.f), Vec(60.f, 65.f), Vec(0.f, 0.f), 60.f, 0.05f, 10);
//pAnimator->CreateAnimation(L"WALK_UP", pAnimAtlasTex, Vec(0.f, 390.f), Vec(60.f, 65.f), Vec(0.f, 0.f), 60.f, 0.05f, 10);
//pAnimator->CreateAnimation(L"WALK_RIGHT", pAnimAtlasTex, Vec(0.f, 325.f), Vec(60.f, 65.f), Vec(0.f, 0.f), 60.f, 0.05f, 10);
//pAnimator->CreateAnimation(L"WALK_LEFT", pAnimAtlasTex, Vec(0.f, 455.f), Vec(60.f, 65.f), Vec(0.f,0.f),60.f, 0.05f, 10);
//
//CAnimation* pSaveAnim = nullptr;
//pSaveAnim = pAnimator->FindAnimation(L"IDLE");
//pSaveAnim->Save(L"animation\\player\\");
//pSaveAnim = pAnimator->FindAnimation(L"WALK_DOWN");
//pSaveAnim->Save(L"animation\\player\\");
//pSaveAnim = pAnimator->FindAnimation(L"WALK_UP");
//pSaveAnim->Save(L"animation\\player\\");
//pSaveAnim = pAnimator->FindAnimation(L"WALK_RIGHT");
//pSaveAnim->Save(L"animation\\player\\");
//
//pSaveAnim = pAnimator->FindAnimation(L"WALK_LEFT");
//pSaveAnim->Save(L"animation\\player\\");
/*CAnimation* pLoadAnim = new CAnimation;
pLoadAnim->Load(L"animation\\player\\IDLE.anim");*/
pAnimator->LoadAnimation(L"animation\\player\\IDLE.anim");
pAnimator->LoadAnimation(L"animation\\player\\WALK_DOWN.anim");
pAnimator->LoadAnimation(L"animation\\player\\WALK_UP.anim");
pAnimator->LoadAnimation(L"animation\\player\\WALK_RIGHT.anim");
pAnimator->LoadAnimation(L"animation\\player\\WALK_LEFT.anim");
AddComponent(pAnimator);
pAnimator->PlayAnimation(L"IDLE");
}
CPlayer::~CPlayer()
{
}
void CPlayer::Update()
{
Vec vPos = GetPos();
// Player 이동
if (IS_KEY_PRESSED(KEY::A)) // VK_LEFT가 이전에 누른 적이 없고 호출 시점에는 눌려있는 상태라면
{
vPos.x -= m_fSpeed * DS;
}
if (IS_KEY_PRESSED(KEY::D))
{
vPos.x += m_fSpeed * DS;
}
if (IS_KEY_PRESSED(KEY::W))
{
vPos.y -= m_fSpeed * DS;
}
if (IS_KEY_PRESSED(KEY::S))
{
vPos.y += m_fSpeed * DS;
}
if (IS_KEY_TAP(KEY::A)) // VK_LEFT가 이전에 누른 적이 없고 호출 시점에는 눌려있는 상태라면
{
GetAnimator()->PlayAnimation(L"WALK_RIGHT");
}
if (IS_KEY_TAP(KEY::D))
{
GetAnimator()->PlayAnimation(L"WALK_LEFT");
}
if (IS_KEY_TAP(KEY::W))
{
GetAnimator()->PlayAnimation(L"WALK_UP");
}
if (IS_KEY_TAP(KEY::S))
{
GetAnimator()->PlayAnimation(L"WALK_DOWN");
}
// 총알 생성
if (IS_KEY_TAP(KEY::SPACE))
{
// Bullet 초기화
CObj* pBullet = new CBullet;
Vec vPos = GetPos();
Vec vScale = GetScale();
pBullet->SetScale(vScale / 2.f);
vPos = Vec(vPos.x, vPos.y - vScale.y / 2.f);
CreateObject(pBullet, EOBJ_TYPE::PLAYER_PROJECTILE, vPos);
}
SetPos(vPos);
}
void CPlayer::Render(HDC _dc)
{
// 이미지로 출력
//Vec vRenderPos = CCamera::GetInst()->GetRenderPos(GetPos()); // 카메라 위치에 따른 플래이어 최종 랜더링 위치 구하기
//UINT iWidth = m_pTex->Width();
//UINT iHeight = m_pTex->Height();
////BitBlt(_dc, (int)vPos.x - iWidth/2, (int)vPos.y - iHeight/2, iWidth, iHeight, m_pTex->GetDC(), 0, 0, SRCCOPY);
//TransparentBlt( _dc,
// (int)vRenderPos.x - iWidth / 2,
// (int)vRenderPos.y - iHeight / 2,
// iWidth, iHeight,
// m_pTex->GetDC(),
// 0,0,
// iWidth, iHeight,
// RGB(255,0,255));
Render_Component(_dc);
}
void CPlayer::OnCollisionEnter(CObj* _pOther)
{
}
void CPlayer::OnCollision(CObj* _pOther)
{
}
void CPlayer::OnCollisionExit(CObj* _pOther)
{
}