-
Apr 17th, 2013, 01:18 PM
#1
Thread Starter
Lively Member
Vb .Net Inventory System Tips/help
Working on building a RPG sample for my self and rightnow I need a little help with the inventory system and moving objects around in it. This si what I have but need better way. Just need a sample showing me how to move around a string object right now. Thanks in advance.
Code:
Public Class Form1
Dim PointerIndex As Integer
Dim Item(1) As String
Dim Selected As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Temp
PointerIndex = 1
MovePointer()
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyValue
Case Keys.PageUp
PointerIndex -= 1
'Move Pointer
MovePointer()
Case Keys.PageDown
PointerIndex += 1
'Move Pointer
MovePointer()
Case Keys.Enter
End Select
End Sub
Public Sub MovePointer()
'Check Index
If PointerIndex >= 4 Then
PointerIndex = 1
ElseIf PointerIndex <= 0 Then
PointerIndex = 3
End If
'Location
Select Case PointerIndex
Case 1
pbTriangle.Location = New Point((lblSlot1.Location.X - (pbTriangle.Width + 10)), lblSlot1.Location.Y)
Case 2
pbTriangle.Location = New Point((lblSlot2.Location.X - (pbTriangle.Width + 10)), lblSlot2.Location.Y)
Case 3
pbTriangle.Location = New Point((tbEquiped.Location.X - (pbTriangle.Width + 10)), tbEquiped.Location.Y)
End Select
End Sub
Public Sub SelectedItem()
Select Case Item(1)
Case 0
Item(0) = "Weapon 1"
Case 1
Item(1) = "Weapon 2"
End Select
End Sub
End Class
Designer:
-
Apr 17th, 2013, 01:20 PM
#2
Thread Starter
Lively Member
Re: Vb .Net Inventory System Tips/help
Best thing I could think of it send data or strings to a temp object and swamp objects and send to their perm locations to swap them out.
-
Apr 17th, 2013, 04:23 PM
#3
Thread Starter
Lively Member
Re: Vb .Net Inventory System Tips/help
Got it working, here is code but any suggestions to clean this up/cleaner method?
Code:
Public Class Form1
Dim PointerIndex As Integer
Dim Item(1) As String
Dim Selected As Boolean
Dim Temp(1) As String
Dim Index1 As Integer
Dim Index2 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Temp
PointerIndex = 1
MovePointer()
Items()
lblSlot1.Text = Item(0)
lblSlot2.Text = Item(1)
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyValue
Case Keys.PageUp
PointerIndex -= 1
'Move Pointer
MovePointer()
Case Keys.PageDown
PointerIndex += 1
'Move Pointer
MovePointer()
Case Keys.Enter
SelectObjects()
End Select
End Sub
Public Sub MovePointer()
'Check Index
If PointerIndex >= 4 Then
PointerIndex = 1
ElseIf PointerIndex <= 0 Then
PointerIndex = 3
End If
'Location
Select Case PointerIndex
Case 1
pbTriangle.Location = New Point((lblSlot1.Location.X - (pbTriangle.Width + 10)), lblSlot1.Location.Y)
Case 2
pbTriangle.Location = New Point((lblSlot2.Location.X - (pbTriangle.Width + 10)), lblSlot2.Location.Y)
Case 3
pbTriangle.Location = New Point((tbEquiped.Location.X - (pbTriangle.Width + 10)), tbEquiped.Location.Y)
End Select
End Sub
Public Sub Items()
Item(0) = "Weapon 1"
Item(1) = "Weapon 2"
End Sub
Public Sub SelectObjects()
'Check Index
If PointerIndex >= 4 Then
PointerIndex = 1
ElseIf PointerIndex <= 0 Then
PointerIndex = 3
End If
'Location
Select Case PointerIndex
Case 1
If Selected = False Then
Selected = True
Temp(0) = lblSlot1.Text
Index1 = PointerIndex
ElseIf Selected = True Then
Temp(1) = lblSlot1.Text
Index2 = PointerIndex
MoveObjects()
End If
Case 2
If Selected = False Then
Selected = True
Temp(0) = lblSlot2.Text
Index1 = PointerIndex
ElseIf Selected = True Then
Temp(1) = lblSlot2.Text
Index2 = PointerIndex
MoveObjects()
End If
Case 3
If Selected = False Then
Selected = True
Temp(0) = tbEquiped.Text
Index1 = PointerIndex
ElseIf Selected = True Then
Temp(1) = tbEquiped.Text
Index2 = PointerIndex
MoveObjects()
End If
End Select
If Selected = False Then
pbTriangle.BackColor = Color.Black
Else
pbTriangle.BackColor = Color.Red
End If
End Sub
Public Sub MoveObjects()
If Index1 = 0 Or Index2 = 0 Then
Temp(0) = "Nothing"
Temp(1) = "Nothing"
End If
Select Case Index1
Case 1
lblSlot1.Text = Temp(1).ToString
Case 2
lblSlot2.Text = Temp(1).ToString
Case 3
tbEquiped.Text = Temp(1).ToString
End Select
Select Case Index2
Case 1
lblSlot1.Text = Temp(0).ToString
Case 2
lblSlot2.Text = Temp(0).ToString
Case 3
tbEquiped.Text = Temp(0).ToString
End Select
'Reset
Selected = False
Index1 = 0
Index2 = 0
pbTriangle.BackColor = Color.Black
End Sub
End Class
-
Apr 17th, 2013, 07:09 PM
#4
Thread Starter
Lively Member
Re: Vb .Net Inventory System Tips/help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|