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
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
#include "stdafx.h"
 
Bullet::Bullet()
{
    arrow.SetWorldPos(Vector2(2000.0f, 2000.0f));
    arrow.scale.x = 30.0f;
    arrow.rotation = 0.0f;
    arrow.isVisible = false;
 
    arrowPet.SetLocalPos(Vector2(30.0f, 30.0f));
    arrowPet.scale = Vector2(20.0f, 20.0f);
    arrowPet.isVisible = false;
    arrowPet.isAxis = true;
    arrowPet.SetParentRT(arrow);
}
 
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() + CAM->position.y)
    {
        fireDir.y *= -1.0f;
        arrow.SetWorldPosY(app.GetHalfHeight() + CAM->position.y);
    }
    //아래
    if (arrow.GetWorldPos().y <= -app.GetHalfHeight() + CAM->position.y)
    {
        fireDir.y *= -1.0f;
        gravity *= -1.0f; //추가, 반사 후 위로 튀어오름
 
        scalar *= 0.7f;  //추가, 마찰계수 설정
        gravity *= 0.7f; //추가, 충돌 시 보다 덜 튀어오르게 설정
 
        arrow.SetWorldPosY(-app.GetHalfHeight() + CAM->position.y);
    }
    //오른쪽
    if (arrow.GetWorldPos().x >= app.GetHalfWidth() + CAM->position.x)
    {
        fireDir.x *= -1.0f;
        scalar *= 0.7f;  //추가
 
        arrow.SetWorldPosX(app.GetHalfWidth() + CAM->position.x);
    }
    //왼쪽
    if (arrow.GetWorldPos().x <= -app.GetHalfWidth() + CAM->position.x)
    {
        fireDir.x *= -1.0f;
        scalar *= 0.7f;  //추가
 
        arrow.SetWorldPosX(-app.GetHalfWidth() + CAM->position.x);
    }
}
 
void Bullet::Render()
{
    arrow.Render();
    arrowPet.Render();
}
 
bool Bullet::Shoot(ObRect player, float scalar, Vector2 firePos)
{
    if (!arrow.isVisible)
    {
        arrow.isVisible = true;
        arrowPet.isVisible = true;
        
        arrow.SetWorldPos(firePos);
        arrow.rotation = Utility::DirToRadian(player.GetRight());
 
        this->scalar = 300.0f + scalar * 5.0f;
        fireDir = player.GetRight();
 
        gravity = 0.0f;
 
        arrowPet.rotation2 = 0.0f;
 
        return true;
    }
    return false;
}
 
cs
 
Vector2 velocity = fireDir * scalar + DOWN * gravity; //중력값 더함

gravity *= -1.0f; //추가, 반사 후 위로 튀어오름

scalar *= 0.7f;  //추가, 마찰계수 설정

gravity *= 0.7f; //추가, 충돌 시 보다 덜 튀어오르게 설정

 

 

'⭐ DirectX > DirectX11 2D + WinAPI' 카테고리의 다른 글

[DirectX11] 별찍기  (0) 2022.08.17
[DirectX11] 렌더링 파이프라인  (0) 2022.08.11
[WinAPI] 충돌  (0) 2022.08.10
[WinAPI] 마우스 회전  (0) 2022.08.09
[WinAPI] 총알 발사  (0) 2022.08.08