- C
- 오블완
- Java
- Algorithm
- programmers
- app
- c++
- 티스토리챌린지
- Python
- Linux
- Unix_System
- Univ._Study
- Kubernetes
- 리눅스마스터2급
- Artificial_Intelligence
- Image_classification
- 자격증
- Database_Design
- study
- Android
- datastructure
- 2023_1st_Semester
- pytorch
- cloud_computing
- Baekjoon
- tensorflow
- Personal_Study
- codingTest
- Operating_System
- SingleProject
코딩 기록 저장소
[2022/Visual Basic] 게임 프로젝트 본문
프로젝트 정보
프로젝트 명 : MINING STAR
년도 : 2022년
날짜 : 2022년 11월 22일 -> 2022년 12월 12일
개발 언어 : Visual Basic
MINING STAR
광물을 캐서 돈을 모아 외계인으로부터 탈출하자!
개발 목적
한 학기 동안 수업을 듣고 공부한 내용을 바탕으로 게임 프로젝트를 진행하였습니다. 이미 제작해본 서바이벌 게임이 아닌 간단한 스토리와 장비 구매, 아이템 판매 등 다양한 요소를 추가하여 발전된 게임을 제작하려는 목적으로 개발을 하게 되었습니다.
기능 구현 및 소개
- 게임 규칙
날아오는 소행성을 피해 광물 별을 수집하여 상점에 팔아 돈을 벌 수 있습니다. 돈으로 장비를 바꾸고 탈출권을 구매하여 외계인으로 부터 벗어나 지구로 돌아가세요.
- 기능 구현
0. 메인 루프
계속 반복하며 배경음악을 반복하고 상황에 따라 다른 함수를 실행할 수 있도록 관리합니다.
코드 보기
배경음악 설정
Private Sub Sound()
gameSnd.AddSound("BGsound", "sound/BGsound.mp3")
gameSnd.SetVolume("BGsound", 300) '0~1000
gameSnd.Play("BGsound")
End Sub
키보드 입력, 효과음 및 ProgressBar() 설정
Public Class Form2
Private pgBar As New ProgressBar()
Dim currentKeys As New ArrayList
Dim gameSnd As New GameSounds
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
'사운드 추가
gameSnd.AddSound("get_Gold", "sound/get_Gold.mp3")
gameSnd.SetVolume("get_Gold", 200) '0~1000
gameSnd.AddSound("product_purchase", "sound/product_purchase.mp3")
gameSnd.SetVolume("product_purchase", 200) '0~1000
gameSnd.AddSound("star_mining", "sound/star_mining.mp3")
gameSnd.SetVolume("star_mining", 200) '0~1000
gameSnd.AddSound("ast_Collision", "sound/ast_Collision.mp3")
gameSnd.SetVolume("ast_Collision", 200) '0~1000
With pgBar
.Size = New System.Drawing.Size(70, 30)
.ForeColor = Color.Blue
.Step = 1
.Visible = False
End With
Me.Controls.Add(pgBar)
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If Not currentKeys.Contains(e.KeyCode) Then
currentKeys.Add(e.KeyCode)
End If
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
currentKeys.Remove(e.KeyCode)
End Sub
End Class
메인 루프 타이머 함수
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'배경음악 반복
If gameSnd.IsPlaying("BGsound") = False Then
Sound()
End If
GoldLabel.Text = CStr(c_money) + " G"
starControlFunction()
characterControlFunction()
astControlFunction()
HpBarstate = hpBar.Enabled
Invalidate()
End Sub
1. 지구인
방향키를 이용하여 조작 가능합니다. 랜덤으로 생성되는 광물별으로 이동해서 Space Bar를 꾹 누르고 있으면 광물을 캘 수 있습니다.
키보드 E를 누르면 인벤토리를 열 수 있고,P를 누르면 일시정지를 할 수 있습니다. 상점 근처에서 Space Bar를 누른다면 상점이 켜집니다. 이때 방향에 따른 사진 설정 변수를 추가하여 반대방향으로 갈때 사진을 반전 시킬 수 있도록 했습니다.
코드 보기
캐릭터 관련 변수 선언 및 초기화
'캐릭터 관련
Dim character As Image
Dim c_x As Integer
Dim c_y As Integer
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
character = My.Resources.character
c_x = Me.Width / 2 - character.Width
c_y = Me.Height / 3
End Sub
캐릭터 관리
'캐릭터 관리
Dim character_direction As Integer = 0 '방향에 따른 사진 설정 변수
Private Sub characterControlFunction()
For i = 0 To currentKeys.Count - 1
If currentKeys(i) = Keys.Left And c_x > 0 Then '왼쪽 방향키
If character_direction = 1 Then
character.RotateFlip(RotateFlipType.RotateNoneFlipX)
character_direction = 0
End If
c_x = c_x - 10
ElseIf currentKeys(i) = Keys.Right And c_x < Width - (character.Width) Then '오른쪽 방향키
If character_direction = 0 Then
character.RotateFlip(RotateFlipType.RotateNoneFlipX)
character_direction = 1
End If
c_x = c_x + 10
ElseIf currentKeys(i) = Keys.Up And c_y > 0 - (character.Height - 100) Then '위쪽 방향키
c_y = c_y - 10
ElseIf currentKeys(i) = Keys.Down And c_y < Height - (character.Height + 50) Then '아래쪽 방향키
c_y = c_y + 10
ElseIf currentKeys(i) = Keys.E Then ' 인벤
invenControlFunction()
ElseIf c_x < (alien.Width + 1230) And (c_x + (character.Width / 2)) > 1230 And (c_y + 50) < (alien.Height + 0) And (c_y + character.Height) > 0 Then
If currentKeys(i) = Keys.Space Then ' 상점
shopControlFunction()
End If
ElseIf currentKeys(i) = Keys.P Then '일시정지
pausedControlFunction()
End If
Next
End Sub
캐릭터를 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
'캐릭터
e.Graphics.DrawImage(character, c_x, c_y)
End Sub
2. 캐릭터 스탯 및 골드
왼쪽 화면 상단에 뜨는 캐릭터의 스탯 및 골드입니다. 소행성에 부딪히면 체력이 깎이고 일정시간마다 산소가 줄어들게됩니다.
코드 보기
스탯 및 골드 변수 선언 및 초기화
Dim heart As Image
Dim o2 As Image
Dim gold As Image
Dim c_MAX_heart As Integer
Dim c_heart As Integer
Dim c_heart_X As Integer
Dim c_MAX_oxygen As Integer
Dim c_oxygen As Integer
Dim c_oxygen_X As Integer
Dim c_money As Integer
Dim c_ability As Integer
Dim HpBarstate As Boolean
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
c_MAX_heart = 5
c_MAX_oxygen = 3
c_heart = 5
c_oxygen = 3
c_ability = 0
c_money = 0
heart = My.Resources.heart
o2 = My.Resources.oxygen
gold = My.Resources.gold
End Sub
스탯 및 골드 관리
소행성 충돌했을 때 체력 깎이게 되고 효과음을 출력합니다.
'화면 밖의 소행성 삭제 및 소행성 충돌
Dim index As Integer = 0
While index <> astArraylist.Count
Dim obj = CType(astArraylist(index), asteroidData)
If c_x < obj.x_pos + asteroid.Width And c_x + character.Width > obj.x_pos And (c_y + 50) < obj.y_pos + asteroid.Height And (c_y + (character.Height - 30)) > obj.y_pos Then '
gameSnd.Play("ast_Collision")
c_heart -= 1
astArraylist.RemoveAt(index)
index -= 1
If c_heart = 0 Then
gameover_state = True
starTimer.Enabled = False
pgBar.Enabled = False
pgBar.Visible = False
gameSnd.RemoveSound("BGsound")
Timer1.Enabled = False
gameoverTimer.Enabled = True
gameover()
End If
End If
index += 1
End While
End Sub
산소 바 및 산소 부족으로 인해 체력 깎이는 기능을 구현한 timer함수
Private Sub o2bar_Tick(sender As Object, e As EventArgs) Handles o2bar.Tick
If c_oxygen > 0 Then
c_oxygen -= 1
Else
hpBar.Enabled = True
End If
End Sub
Private Sub hpbar_Tick(sender As Object, e As EventArgs) Handles hpBar.Tick
c_heart -= 1
If c_heart = 0 Then
Timer1.Enabled = False
End If
End Sub
캐릭터 스탯 창을 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(alien, 1230, 0)
'캐릭터 스탯 창
c_heart_X = 30
For i = 0 To c_heart - 1
e.Graphics.DrawImage(heart, c_heart_X, 10)
c_heart_X += 50
Next
c_oxygen_X = 30
For i = 0 To c_oxygen - 1
e.Graphics.DrawImage(o2, c_oxygen_X, 60)
c_oxygen_X += 50
Next
e.Graphics.DrawImage(gold, 25, 110)
End Sub
3. 인벤토리 (E)
키보드 E를 통해 켤 수 있습니다. 구매한 장비 및 수집한 광물 별이 인벤토리에 뜨게 됩니다. 인벤토리를 켜고 있는 중에는 소행성, 캐릭터, 체력 및 산소바 전부 정지하게 됩니다. Esc키를 누르면 인벤토리가 꺼지게 됩니다.
코드 보기
인벤토리 관련 구조체, 변수 선언 및 초기화
'인벤토리
Structure inventoryData
Dim tmpX As Integer
Dim tmpY As Integer
Dim item As Image
Dim item_X As Integer
Dim item_Y As Integer
Dim price As Integer
End Structure
Dim inven As Image
Dim invenArraylist As New ArrayList
Dim inven_state As Boolean
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
inven = My.Resources.inven
UI_x = Me.Width / 2 - inven.Width
UI_y = Me.Height / 3 - (inven.Height / 2)
End Sub
인벤토리 관리
'인벤토리 관리
Private Sub invenControlFunction()
Timer1.Enabled = False
o2bar.Enabled = False
hpBar.Enabled = False
invenTimer.Enabled = True
inven_state = True
For i = 0 To currentKeys.Count - 1
If currentKeys(i) = Keys.Escape Then
invenTimer.Enabled = False
o2bar.Enabled = True
If HpBarstate = True Then
hpBar.Enabled = True
End If
Timer1.Enabled = True
inven_state = False
End If
Next
End Sub
인벤토리 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(alien, 1230, 0)
'인벤 켰을때
If inven_state = True Then
e.Graphics.DrawImage(inven, UI_x, UI_y)
If c_pickax_state = 1 Then
e.Graphics.DrawImage(pickax, UI_x + 105, UI_y + 135)
End If
If c_o2tank_state = 1 Then
e.Graphics.DrawImage(o2_tank, UI_x + 470, UI_y + 40)
End If
For i = 0 To invenArraylist.Count - 1
Dim o = CType(invenArraylist(i), inventoryData)
e.Graphics.DrawImage(o.item, o.item_X, o.item_Y)
Next
End If
End Sub
인벤토리 관련 타이머 함수
Private Sub invenTimer_Tick(sender As Object, e As EventArgs) Handles invenTimer.Tick
invenControlFunction()
Invalidate()
End Sub
4. 일시정지 (P)
P를 누르면 뜨는 창입니다. 번호에 따라 다르게 실행되며 Esc를 누를시 창은 꺼지게 됩니다.
코드 보기
일시정지 변수 선언 및 초기화
'인벤토리, 상점 UI 좌표 변수
Dim UI_x As Integer
Dim UI_y As Integer
Dim paused_state As Boolean
Dim paused As Image
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
paused = My.Resources.paused
End Sub
일시정지 관리
Private Sub pausedControlFunction()
Timer1.Enabled = False
o2bar.Enabled = False
hpBar.Enabled = False
pausedTimer.Enabled = True
paused_state = True
For i = 0 To currentKeys.Count - 1
If currentKeys(i) = 49 Or currentKeys(i) = Keys.Escape Then
Timer1.Enabled = True
o2bar.Enabled = True
If HpBarstate = True Then
hpBar.Enabled = True
End If
pausedTimer.Enabled = False
paused_state = False
HTP_state = False
ElseIf currentKeys(i) = 50 Then
HTP_state = True
Exit For
ElseIf currentKeys(i) = 51 Then
gameSnd.Dispose()
Me.Close()
Form1.Close()
End If
Next
End Sub
일시정지 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
'일시정지 창
If paused_state = True Then
e.Graphics.DrawImage(paused, UI_x + CInt(paused.Width / 2), UI_y + 50)
If HTP_state = True Then
e.Graphics.DrawImage(HTP_img, UI_x, UI_y)
End If
End If
End Sub
일시정지 타이머
Private Sub pausedTimer_Tick(sender As Object, e As EventArgs) Handles pausedTimer.Tick
pausedControlFunction()
Invalidate()
End Sub
5. 광물 별
정해진 개수만큼 랜덤으로 생성됩니다. 여러 광물 별이 존재하고, 그에 따라 캐는 시간과 가격 모두 다릅니다.
코드 보기
광물 별 관련 구조체 및 변수 선언 및 초기화
'광물 별
Structure starData
Dim sx_pos As Integer
Dim sy_pos As Integer
Dim scount As Integer
Dim sprice As Integer
Dim star As Image
End Structure
Dim starArraylist As New ArrayList
광물 별 관리
랜덤한 위치에 확률에 따라 사진 및 캐는 속도, 가격을 다르게 하여 구조체를 만든 후 ArrayList에 저장합니다. ArrayList만큼 반복하면서 만약 범위 내에서 스페이스바를 누르고있으면 progress바가 진행됩니다. 캘때 효과음이 출력되고, 캐는속도 - 곡괭이 성능을 하여 곡괭이 성능이 좋으면 캐는 시간을 단축하도록 구현했습니다. 만약 다 된다면 구조체 배열에 있던 것을 인벤토리 ArrayList에 추가하고 광물 별의 ArrayList에 있던 것은 삭제합니다.
'광물 별 관리
Private Sub starControlFunction()
Dim s As starData
Dim inv As inventoryData
Dim n As Integer
Randomize()
n = Rnd() * 100
If n Mod 20 = 0 And starArraylist.Count < 5 Then
If n > 0 And n < 55 Then ' 1 - 54
s.star = My.Resources.coalStar
s.scount = 3
s.sprice = 20
ElseIf n < 80 Then
s.star = My.Resources.Star
s.scount = 5
s.sprice = 50
ElseIf n < 95 Then
s.star = My.Resources.diaStar
s.scount = 10
s.sprice = 300
Else
s.star = My.Resources.emStar
s.scount = 15
s.sprice = 700
End If
s.sx_pos = Rnd() * 1550
s.sy_pos = Rnd() * (900 - (s.star.Height * 2))
If s.sx_pos > 1230 And s.sy_pos < 0 + alien.Height Then
s.sx_pos -= alien.Width
s.sy_pos += alien.Height
End If
starArraylist.Add(s)
End If
For i = 0 To starArraylist.Count - 1
Dim o = CType(starArraylist(i), starData)
starArraylist(i) = o
Next
Dim index As Integer = 0
While index <> starArraylist.Count
Dim obj = CType(starArraylist(index), starData)
If c_x < obj.sx_pos + obj.star.Width And c_x + character.Width > obj.sx_pos And (c_y + 50) < obj.sy_pos + obj.star.Height And (c_y + character.Height) > obj.sy_pos Then
For i = 0 To currentKeys.Count - 1
If currentKeys(i) = Keys.Space Then
If invenArraylist.Count < 12 Then
pgBar.Location = New System.Drawing.Point(c_x, c_y - 30)
pgBar.Visible = True
If (obj.scount - c_ability) <= 0 Then
pgBar.Maximum = 1
Else
pgBar.Maximum = obj.scount - c_ability
End If
starTimer.Enabled = True
Else
character_Text.Visible = True
End If
If pgBar.Value = pgBar.Maximum Then
starTimer.Enabled = False
pgBar.Enabled = False
pgBar.Visible = False
pgBar.Value = 0
inv.tmpX = UI_x + 67
inv.tmpY = UI_y + 270
For j = 1 To invenArraylist.Count
inv.tmpX += 132
If j Mod 4 = 0 Then
inv.tmpX = UI_x + 70
inv.tmpY += 129
End If
Next
inv.item_X = inv.tmpX
inv.item_Y = inv.tmpY
inv.price = obj.sprice
inv.item = obj.star
invenArraylist.Add(inv)
starArraylist.RemoveAt(index)
End If
Exit While
Else
starTimer.Stop()
pgBar.Enabled = False
pgBar.Value = 0
pgBar.Visible = False
End If
Next
Else
pgBar.Visible = False
pgBar.Enabled = False
End If
index += 1
End While
End Sub
광물 별 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
'별
For i = 0 To starArraylist.Count - 1
Dim s = CType(starArraylist(i), starData)
e.Graphics.DrawImage(s.star, s.sx_pos, s.sy_pos)
Next
End Sub
6. 소행성
좌우에서 랜덤으로 나타나며 부딪히게 되면 체력이 -1됩니다.
코드 보기
소행성 구조체, 변수 선언 및 초기화
'소행성
Structure asteroidData
Dim x_pos As Integer
Dim y_pos As Integer
Dim direction As Integer
End Structure
Dim asteroid As Image
Dim astArraylist As New ArrayList
소행성 관리
메모리 문제를 해결하기위해 화면 밖으로 나가게되는 소행성은 ArrayList에서 삭제했습니다. 그리고 캐릭터와 충돌하게 되면 체력을 -1하고 부딪힌 소행성은 ArrayList에서 삭제하도록 구현했습니다.
'소행성 관리
Private Sub astControlFunction()
Dim ast As asteroidData
Dim n As Integer
Randomize()
n = Rnd() * 100
If n Mod 20 = 0 And astArraylist.Count < 10 Then
ast.direction = Rnd() * 1
If ast.direction = 0 Then
ast.x_pos = ast.direction * 1600 - asteroid.Width
Else
ast.x_pos = ast.direction * 1600
End If
ast.y_pos = Rnd() * (900 - asteroid.Height)
astArraylist.Add(ast)
End If
For i = 0 To astArraylist.Count - 1
Dim o = CType(astArraylist(i), asteroidData)
If o.direction = 0 Then
o.x_pos = o.x_pos + 7
Else
o.x_pos = o.x_pos - 7
End If
astArraylist(i) = o
Next
'화면 밖의 소행성 삭제 및 소행성 충돌
Dim index As Integer = 0
While index <> astArraylist.Count
Dim obj = CType(astArraylist(index), asteroidData)
If c_x < obj.x_pos + asteroid.Width And c_x + character.Width > obj.x_pos And (c_y + 50) < obj.y_pos + asteroid.Height And (c_y + (character.Height - 30)) > obj.y_pos Then '
gameSnd.Play("ast_Collision")
c_heart -= 1
astArraylist.RemoveAt(index)
index -= 1
If c_heart = 0 Then
gameover_state = True
starTimer.Enabled = False
pgBar.Enabled = False
pgBar.Visible = False
gameSnd.RemoveSound("BGsound")
Timer1.Enabled = False
gameoverTimer.Enabled = True
gameover()
End If
End If
If obj.direction = 0 And obj.x_pos > Me.Width Or obj.direction = 1 And obj.x_pos < 0 - asteroid.Width Then
astArraylist.RemoveAt(index)
index -= 1
End If
index += 1
End While
End Sub
소행성 화면에 그림
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
'소행성
For i = 0 To astArraylist.Count - 1
Dim o = CType(astArraylist(i), asteroidData)
e.Graphics.DrawImage(asteroid, o.x_pos, o.y_pos)
Next
End Sub
7. 상점, 및 아이템
외계인한테 가서 스페이스바를 통해 상점을 열 수 있습니다.
상점에 들어가면 친절한 외계인씨는 산소를 무료로 충전해줍니다.
판매[S키]를 통해 골드를 모을 수 있습니다.
곡괭이, 포션, 산소통,탈출권과 같은 아이템을 구입할 수 있습니다.
코드 보기
상점&아이템 관련 구조체, 변수 선언 및 초기화
'상점
Structure shopData
Dim product_Name As String
Dim product_Price As Integer
Dim product_ability As Integer
End Structure
Dim pickax As Image
Dim o2_tank As Image
Dim alien As Image
Dim shop As Image
Dim shopArraylist As New ArrayList
Dim shop_state As Boolean
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
alien_Text.Visible = False
saleList.Visible = False
'상점 물품 추가
Dim p As shopData
'평범한 곡괭이
p.product_Name = "stone_pickax"
p.product_Price = 1000
p.product_ability = 2
shopArraylist.Add(p)
'좋은 곡괭이
p.product_Name = "steel_pickax"
p.product_Price = 5000
p.product_ability = 5
shopArraylist.Add(p)
'체력 회복 포션
p.product_Name = "HP_potion"
p.product_Price = 100
p.product_ability = c_MAX_heart
shopArraylist.Add(p)
'작은 산소통
p.product_Name = "oxygen_tank"
p.product_Price = 500
p.product_ability = 4
shopArraylist.Add(p)
'큰 산소통
p.product_Name = "big_oxygen _tank"
p.product_Price = 2500
p.product_ability = 5
shopArraylist.Add(p)
'탈출권
p.product_Name = "escape_ticket"
p.product_Price = 15000
p.product_ability = 0
shopArraylist.Add(p)
shop = My.Resources.shop
End Sub
상점 관리
원하는대로 화면에 출력이 안되어서 아쉬웠던 부분입니다. S키를 통해 광물별을 팔거나 물건을 구입하게 되면 효과음이 출력됩니다.
'상점 관리
Private Sub shopControlFunction()
If c_oxygen = 0 Then
hpBar.Stop()
End If
c_oxygen = c_MAX_oxygen
Timer1.Enabled = False
o2bar.Enabled = False
hpBar.Enabled = False
shopTimer.Enabled = True
shop_state = True
For i = 0 To currentKeys.Count - 1
If shop_state = True Then
Dim l1, l2, l3, l4 As Integer
alien_Text.Text = "지구인 안뇽! 준비된 상품이야." + vbCrLf + "편히 둘러보고 가!"
alien_Text.Visible = True
If currentKeys(i) = Keys.S Then
If invenArraylist.Count = 0 Then
alien_Text.Text = "어라 아무것도 가지고 있지 않아!"
Else
character_Text.Visible = False
Dim index As Integer = 0
While index <> invenArraylist.Count
Dim inven = CType(invenArraylist(index), inventoryData)
c_money += inven.price
invenArraylist.RemoveAt(index)
End While
gameSnd.Play("get_Gold")
alien_Text.Text = "판매 성공! 고마워!"
End If
End If
'물건 구매
For j = 0 To shopArraylist.Count - 1
Dim p = CType(shopArraylist(j), shopData)
'숫자 1번
If currentKeys(i) = 49 Then
If p.product_Name = "stone_pickax" Then
If c_money >= p.product_Price Then
If p.product_ability > c_ability Then
alien_Text.Text = "평범한 곡괭이 구매에 성공했어!"
gameSnd.Play("product_purchase")
c_money -= p.product_Price
c_ability = p.product_ability
c_pickax_state = 1
pickax = My.Resources.stone_pickax
shopArraylist.RemoveAt(j)
Exit For
Else
alien_Text.Text = "지금 쓰고있는 곡괭이가 더 좋은것 같아!"
End If
Else
alien_Text.Text = "돈이 부족해"
End If
Else
alien_Text.Text = "평범한 곡괭이는 구매하지 못해"
End If
ElseIf currentKeys(i) = 50 Then
If p.product_Name = "steel_pickax" Then
If c_money >= p.product_Price Then
alien_Text.Text = "좋은 곡괭이 구매에 성공했어!"
gameSnd.Play("product_purchase")
c_money -= p.product_Price
c_ability = p.product_ability
c_pickax_state = 1
pickax = My.Resources.steel_pickax
shopArraylist.RemoveAt(j)
Exit For
Else
alien_Text.Text = "돈이 부족해"
End If
Else
alien_Text.Text = "좋은 곡괭이는 구매하지 못해"
End If
ElseIf currentKeys(i) = 51 Then
If p.product_Name = "HP_potion" Then
If c_money >= p.product_Price Then
If c_heart < c_MAX_heart Then
alien_Text.Text = "너의 체력은 회복됐어!"
gameSnd.Play("product_purchase")
c_money -= p.product_Price
c_heart = p.product_ability
Exit For
Else
alien_Text.Text = "이미 체력은 다 차있어"
End If
Else
alien_Text.Text = "돈이 부족해"
End If
End If
ElseIf currentKeys(i) = 52 Then
If p.product_Name = "oxygen_tank" Then
If c_money >= p.product_Price Then
If p.product_ability > c_MAX_oxygen Then
alien_Text.Text = "작은 산소통 구매에 성공했어!"
gameSnd.Play("product_purchase")
c_money -= p.product_Price
c_MAX_oxygen = p.product_ability
c_oxygen = c_MAX_oxygen
o2bar.Interval = 12000
c_o2tank_state = 1
o2_tank = My.Resources.o2_tank
shopArraylist.RemoveAt(j)
Exit For
Else
alien_Text.Text = "지금 쓰고있는 산소통이 더 좋은것 같아!"
End If
Else
alien_Text.Text = "돈이 부족해"
End If
Else
alien_Text.Text = "작은 산소통은 구매하지 못해"
End If
ElseIf currentKeys(i) = 53 Then
If p.product_Name = "big_oxygen _tank" Then
If c_money >= p.product_Price Then
alien_Text.Text = "큰 산소통 구매에 성공했어!"
gameSnd.Play("product_purchase")
c_money -= p.product_Price
c_MAX_oxygen = p.product_ability
c_oxygen = c_MAX_oxygen
o2bar.Interval = 15000
c_o2tank_state = 1
o2_tank = My.Resources.big_o2_tank
shopArraylist.RemoveAt(j)
Exit For
Else
alien_Text.Text = "돈이 부족해"
End If
Else
alien_Text.Text = "큰 산소통은 구매하지 못해"
End If
ElseIf currentKeys(i) = 54 Then
If p.product_Name = "escape_ticket" Then
If c_money >= p.product_Price Then
gameSnd.RemoveSound("BGsound")
Form3.Show()
Me.Hide()
Exit For
Else
alien_Text.Text = "돈이 부족해"
End If
Else
alien_Text.Text = "탈출권은 구매하지 못해"
End If
End If
Next
For j = 0 To invenArraylist.Count - 1
Dim inven = CType(invenArraylist(j), inventoryData)
If inven.price = 20 Then
l1 += 1
ElseIf inven.price = 50 Then
l2 += 1
ElseIf inven.price = 300 Then
l3 += 1
ElseIf inven.price = 700 Then
l4 += 1
End If
Next
saleList.Text = "광물 별 리스트 (판매 : S키) " + vbCrLf + vbCrLf + "석탄 별 : " + CStr(l1) + "개 x 20G" + vbCrLf + "금 별 : " + CStr(l2) + "개 x 50G" + vbCrLf + "다이아 별 : " + CStr(l3) + "개 x 300G" + vbCrLf + "에메랄드 별 : " + CStr(l4) + "개 x 700G" + vbCrLf
saleList.Visible = True
End If
If currentKeys(i) = Keys.Escape Then
shopTimer.Enabled = False
saleList.Visible = False
alien_Text.Visible = False
o2bar.Enabled = True
If HpBarstate = True Then
hpBar.Enabled = True
End If
Timer1.Enabled = True
shop_state = False
End If
Next
End Sub
상점 화면에 출력
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(alien, 1230, 0)
'상점 켰을때
If shop_state = True Then
e.Graphics.DrawImage(shop, UI_x, UI_y)
End If
End Sub
상점 관련 타이머
Private Sub shopTimer_Tick(sender As Object, e As EventArgs) Handles shopTimer.Tick
GoldLabel.Text = CStr(c_money) + " G"
shopControlFunction()
Invalidate()
End Sub
출처
배경 음악 : Mewpot Music
엔딩 음악 : Mewpot Music
상점 효과음 : Thanks to, Daniel Simion
수집 효과음 : Thanks to, Mike Koenig
피격 효과음 : Thanks to, Mike Koenig
개발 후기
게임의 재미를 추가하기 위해 다양한 요소를 넣는 과정에서 힘들기도 했지만 뿌듯했습니다. 그중에서도 인벤토리를 구현하여 수집한 광물을 인벤토리에 저장 하고, 상점에 팔아 돈을 벌 수 있는 기능이 색다른 시도였습니다.
'프로젝트 > 개인 프로젝트' 카테고리의 다른 글
[2021/Python] 게임 프로젝트 (0) | 2023.01.18 |
---|