[WinAPI] 충돌
Bullet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#pragma once
class Bullet
{
public:
ObLine arrow;
ObCircle arrowPet;
float scalar;
Vector2 fireDir;
Vector2 velocity;
float gravity;
public:
Bullet();
void Update(ObRect player);
void LateUpdate(); //추가
void Render();
bool Shoot(ObRect player, float scalar, Vector2 firePos);
};
|
cs |
void LateUpdate(); 추가
Bullet.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
|
#include "stdafx.h"
Bullet::Bullet()
{
...
}
void Bullet::Update(ObRect player)
{
if (!arrow.isVisible) return;
if (!arrowPet.isVisible) return;
//gravity += 600.0f * DELTA;
Vector2 velocity = fireDir * scalar; //+DOWN * gravity; 중력값 다시 빼줌.
arrow.MoveWorldPos(velocity * DELTA);
arrowPet.rotation2 += 360.0f * ToRadian * DELTA;
arrow.rotation = Utility::DirToRadian(velocity);
arrow.Update();
arrowPet.Update();
}
void Bullet::LateUpdate() //추가
{
//위
if (arrow.GetWorldPos().y >= app.GetHalfHeight())
{
fireDir.y *= -1.0f;
arrow.SetWorldPosY(app.GetHalfHeight() + CAM->position.y);
}
//아래
if (arrow.GetWorldPos().y <= app.GetHalfHeight())
{
fireDir.y *= -1.0f;
arrow.SetWorldPosY(-app.GetHalfHeight() + CAM->position.y);
}
//오른쪽
if (arrow.GetWorldPos().x >= app.GetHalfWidth())
{
fireDir.x *= -1.0f;
arrow.SetWorldPosY(app.GetHalfWidth() + CAM->position.x);
}
//왼쪽
if (arrow.GetWorldPos().y <= app.GetHalfWidth())
{
fireDir.x *= -1.0f;
arrow.SetWorldPosY(-app.GetHalfWidth() + CAM->position.x);
}
}
void Bullet::Render()
{
arrow.Render();
arrowPet.Render();
}
bool Bullet::Shoot(ObRect player, float scalar, Vector2 firePos)
{
...
}
|
cs |
void Bullet::LateUpdate() 추가
- fireDir는 arrow의 벡터.
- 창의 끝을 넘어가면 fireDir의 x값에 음수(-)를 곱함(또는 y값에 음수를 곧함 ).
- Camera 만큼 같이 이동하기 위해 CAM->position.x 또는 y를 더해줌.
Main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#pragma once
#define MAX 30
class Main : public Scene
{
private:
ObRect player;
ObCircle pet;
ObRect playerGauge;
Bullet bullet[MAX];
Vector2 lastPos;
GameObject firePos;
public:
virtual void Init() override;
virtual void Release() override; //해제
virtual void Update() override;
virtual void LateUpdate() override;//갱신
virtual void Render() override;
virtual void ResizeScreen() override;
};
|
cs |
변동사항 없음
Main.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
|
#include "stdafx.h"
#include "Main.h"
void Main::Init() { ... }
void Main::Release() { }
void Main::Update()
{
...
player.Update();
pet.Update();
for (int i = 0; i < MAX; i++)
{
bullet[i].Update(player);
}
playerGauge.Update();
firePos.Update();
}
void Main::LateUpdate()
{
for (int i = 0; i < MAX; i++) //추가
{
bullet[i].LateUpdate();
}
}
void Main::Render()
{
player.Render();
pet.Render();
playerGauge.Render();
for (int i = 0; i < MAX; i++)
{
bullet[i].Render();
}
firePos.Render();
}
void Main::ResizeScreen() { }
int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR param, int command) { ... }
|
cs |
void Main::LateUpdate() 추가
Window.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
|
#include "Framework.h"
Application app;
Scene* Window::main = nullptr;
WPARAM Window::Run(Scene* main)
{
Window::main = main;
//Window->D3D->main
Create();
D3D->Create();
GameObject::CreateStaticMember();
ObRect::CreateStaticMember();
ObLine::CreateStaticMember();
ObCircle::CreateStaticMember();
ObImage::CreateStaticMember();
main->Init();
MSG msg = { 0 };
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
TIMER->Chronometry(app.fixFrame);
INPUT->Update();
SOUND->Update();
//GUI->Update();
main->Update(); // Update 호출
main->LateUpdate(); // LateUpdate 호출
CAM->Set();
LIGHT->Set();
D3D->SetRenderTarget();
D3D->Clear(app.background);
{
main->Render();
//GUI->Render();
}
D3D->Present();
}
}
Save();
GameObject::DeleteStaticMember();
ObRect::DeleteStaticMember();
ObLine::DeleteStaticMember();
ObCircle::DeleteStaticMember();
ObImage::DeleteStaticMember();
main->Release();
TIMER->DeleteSingleton();
INPUT->DeleteSingleton();
GUI->DeleteSingleton();
CAM->DeleteSingleton();
RANDOM->DeleteSingleton();
SOUND->DeleteSingleton();
TEXTURE->DeleteSingleton();
LIGHT->DeleteSingleton();
SCENE->DeleteSingleton();
D3D->DeleteSingleton();
Destroy();
return msg.wParam;
}
void Window::Create() { ... }
void Window::Load() { ... }
void Window::Save() { ... }
void Window::Destroy() { ... }
LRESULT Window::WndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) { ... }
|
cs |
변동사항 없음.
main->Update(); // Update 호출
main->LateUpdate(); // LateUpdate 호출
스칼라
방향
확인
'⭐ DirectX > DirectX11 2D + WinAPI' 카테고리의 다른 글
[DirectX11] 렌더링 파이프라인 (0) | 2022.08.11 |
---|---|
[WinAPI] 포물선 충돌 및 마찰계수 설정 (0) | 2022.08.11 |
[WinAPI] 마우스 회전 (0) | 2022.08.09 |
[WinAPI] 총알 발사 (0) | 2022.08.08 |
[WinAPI] Bullet 속도를 Gauge Bar와 연동 (0) | 2022.07.29 |
댓글
이 글 공유하기
다른 글
-
[DirectX11] 렌더링 파이프라인
[DirectX11] 렌더링 파이프라인
2022.08.11 -
[WinAPI] 포물선 충돌 및 마찰계수 설정
[WinAPI] 포물선 충돌 및 마찰계수 설정
2022.08.11 -
[WinAPI] 마우스 회전
[WinAPI] 마우스 회전
2022.08.09 -
[WinAPI] 총알 발사
[WinAPI] 총알 발사
2022.08.08