Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An equipment screen for my RPG game
#3
Code: (Select All)
Type equipment_type 'assign the various types to your TYPE field
name As String
damage As Integer
defense As Integer
durability As Integer
count As Integer
End Type

ReDim Shared equipment(20) As equipment_type 'define your variable or array based off that field

Type enemy_type 'the same for the enemies
name As String
damage As Integer
defense As Integer
health As Integer
End Type

ReDim Shared enemy(20) As enemy_type 'assign that type to an array, like above

Init_Enemy
Init_Equipment

Sub Init_Enemy
ReDim enemy(200) As enemy_type 'large enough to hold all enemies in one array
Restore enemy_data 'always use restore to make certain you get the data you want.
Do

Read enemy(count).name, enemy(count).damage, enemy(count).defense, enemy(count).health
If enemy(count).name <> "EOD" Then
count = count + 1
Else
Exit Do
End If
Loop
ReDim _Preserve enemy(count) As enemy_type
Exit Sub
enemy_data:
Data "Rabbit",2,0,6
Data "Crab",3,1,6
Data "EOD",-1,-1,-1 'end of data fields
End Sub

Sub Init_Equipment
ReDim equipment(200) As equipment_type 'define your variable or array based off that field
Restore equipment_data 'always use restore to make certain you get the data you want.
Do
Read equipment(count).name
Read equipment(count).damage, equipment(count).defense, equipment(count).durability
Read equipment(count).count
If enemy(count).name <> "EOD" Then
count = count + 1
Else
Exit Do
End If
Loop
ReDim _Preserve equipment(count) As equipment_type
Exit Sub

equipment_data:
Data "Bone Spear",2,0,20,0
Data "Flint Spear",4,0,30,0
Data "Copper Spear",6,0,40,0
Data "Iron Spear",8,0,50,0
Data "Stone Axe",1,1,20,0
Data "Copper Axe",3,2,35,0
Data "Iron Axe",4,4,50,0
Data "EOD",-1,-1,-1,-1
End Sub

I'm thinking a data structure like the above is what would suit your needs the best. Smile
Reply


Messages In This Thread
An equipment screen for my RPG game - by Delsus - 03-26-2024, 09:41 AM
RE: An equipment screen for my RPG game - by SMcNeill - 03-26-2024, 04:39 PM



Users browsing this thread: 3 Guest(s)