본문 바로가기
개발 일지

비주얼 베이직(vb.net)으로 슈팅게임 만들기 - 2. 캐릭터 이동

by PrintedLove 2020. 10. 4.

이번에는 캐릭터의 이동 부분을 구현해 보았습니다.

영상 먼저 보시죠.

 

 

 

마우스를 클릭하면, 배경의 선이 움직입니다.

네. 사실 캐릭터가 이동하는 것이 아닌 배경이 움직이는 것입니다. 이후에 등장할 적(enmey)들도 이렇게 구현할 생각입니다.

 

Public Function GetAngleTwoPoint(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
    Dim dx As Integer = x2 - x1
    Dim dy As Integer = y2 - y1

    Dim angle As Double = Atan2(dy, dx)

    Return angle
End Function

Public Function GetCoordCircle(ByVal x As Integer, ByVal y As Integer, ByVal dgree As Double, ByVal radius As Integer)
    Dim circle_x As Integer = x + CInt(Cos(dgree) * radius)
    Dim circle_y As Integer = y + CInt(Sin(dgree) * radius)
    Dim circle_coord As New Point(circle_x, circle_y)

    Return circle_coord
End Function

 

위 두 함수는 두 점 사이의 각도를 구하는 함수와 원점과 각도, 반지름이 주어졌을때 원 위의 점을 반환하는 함수입니다.

이 두함수를 이용해 마우스 클릭시, 캐릭터가 이동할 좌표(배경이 이동할 좌표)를 구했습니다.

배경으로 보이는 네모들은 사실 선 4개가 배열된 것으로, 리소스를 최대한 아껴보았습니다.

 

게임의 전체 소스코드는 아래 깃허브 링크에서 확인하실 수 있습니다!

 

 

PrintedLove/VisualBasic-Shooting-Game

shooting game project made with Visual Basic. Contribute to PrintedLove/VisualBasic-Shooting-Game development by creating an account on GitHub.

github.com

 

댓글