none
Controller of sprites for a two player based game

    Question

  • This is my two player based game which I have carried out the process of determine whos turn will it be. The next part is from what the title says how will my game detect when player 2 is controlling a sprite and when is it not. I have made the game menu section which indicates which player is assigned to what color for instance player 2 is assigned to the team colour red. 

    Therefore does anybody have a good way or an example of something similar to this format where the assigned colour chosen to player means they can only control the units/buildings that are that colour? for example player 2 has selected the team colour red thus they can only take control of buildings that are theirs (or the team colour they have selected)


    WRA

    Thursday, April 13, 2017 10:36 AM

Answers

  • Alright I will take a look at this example. 

    WRA


    PS

    Note how update labels just displays the current data. When the data is changed the update routine is called and all the data is updated at once on the screen. Not just the current step etc.

    That's how you get things objectified and methodized. You make things so you call them anytime anyplace anyway. The object should be smart enough to know what it does. ie update the labels with the current data. The object only knows that. The object does not know or care what step it is. All the object does is display the current data.

    • Marked as answer by Waliur Rahman Thursday, April 20, 2017 9:06 AM
    Saturday, April 15, 2017 5:34 PM

All replies

  • Does anybody have an actual recommendation of how I could carry this out such as I have a code which assigns each player a team colour the next part is actually assigning each player a certain colour that they are able to control depending on the condition of the selected team colour from the game menu. 

    WRA

    Saturday, April 15, 2017 11:18 AM
  • Does anybody have an actual recommendation of how I could carry this out such as I have a code which assigns each player a team colour the next part is actually assigning each player a certain colour that they are able to control depending on the condition of the selected team colour from the game menu. 

    WRA

    Make a class with exactly what you want.

    Public Class MyGameData Public Class MySprite Public pic As PictureBox Public Name As String Public Range As Integer End Class

    Public Class Player Public Name As String Public Score As String End Class

    Public PlayerTurnIndex As Integer Public Players As New List(Of Player) Public Sprites As New List(Of MySprite) Public AttackPic As PictureBox Public TargetPic As PictureBox End Class



    • Edited by tommytwotrain Saturday, April 15, 2017 1:04 PM add new
    Saturday, April 15, 2017 1:02 PM
  • Alrighty tommy I will carry this out. 

    WRA

    Saturday, April 15, 2017 1:05 PM
  • @Tommy

    Private Class Sprite
            Public Name As String
            Public Pic As PictureBox
            Public ColRow As Point
            Public Steps As Integer = -1    '-1 = unlimited move
            Public Visible As Integer = 2   '0 = not visible  1= Frozen  2=Active   
            Public Range As Integer
            Public AP As Integer
            Public HP As Integer
        End Class

    Quick question do any of these characteristics change?


    WRA

    Saturday, April 15, 2017 1:12 PM
  • @Tommy

    Private Class Sprite
            Public Name As String
            Public Pic As PictureBox
            Public ColRow As Point
            Public Steps As Integer = -1    '-1 = unlimited move
            Public Visible As Integer = 2   '0 = not visible  1= Frozen  2=Active   
            Public Range As Integer
            Public AP As Integer
            Public HP As Integer
        End Class

    Quick question do any of these characteristics change?


    WRA


    I dont know. Its not my game. You tell us.

    I know you cant copy what I show exactly, it has to be modified for your exact code.

    Saturday, April 15, 2017 1:40 PM
  • Fair enough so adjust it to my preferences to suit my needs. 

    WRA

    Saturday, April 15, 2017 2:22 PM
  • Fair enough so adjust it to my preferences to suit my needs. 

    WRA

    Here is an example that shows keeping a global flag I called GameStage and incrementing it as events occur. See how with each click the flag is set to the next value, the screen is updated with the current data, a message given to the player, and then await the next event.

    There are hundreds of ways to do things this is just some examples. But it shows the basic game loop again. Event/input, calculate, update screen, repeat. This game is three loops and reset.

    Public Class Form2
        Private Label1 As New Label With {.Parent = Me, .Location = New Point(150, 100), .AutoSize = True, .Font = New Font("tahoma", 12, FontStyle.Bold), .ForeColor = Color.AntiqueWhite}
        Private Label2 As New Label With {.Parent = Me, .Location = New Point(150, 150), .AutoSize = True, .Font = New Font("tahoma", 12, FontStyle.Bold), .ForeColor = Color.AntiqueWhite}
        Private Label3 As New Label With {.Parent = Me, .Location = New Point(150, 200), .AutoSize = True, .Font = New Font("tahoma", 12, FontStyle.Bold), .ForeColor = Color.AntiqueWhite}
        Private MyPicList As New List(Of PictureBox)
        Private SelectedPictureboxesList As New List(Of PictureBox)
        Private GameStage As Integer = 3
        Private Msg As String
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(300, 300)
    
            For i = 0 To 4
                Dim thisPic As New PictureBox
                thisPic.Name = "My Pic " & i.ToString
                thisPic.BackColor = Color.FromArgb(255, i * 50, 255 - (i * 50), 100)
                thisPic.Location = New Point(20, (i * 50) + 40)
                thisPic.Size = New Size(50, 50)
                AddHandler thisPic.MouseDown, AddressOf Pics_MouseDown
                Controls.Add(thisPic)
                MyPicList.Add(thisPic)
            Next
    
            GameReset()
    
        End Sub
    
        Private Sub UpdateLabels()
            For i = 1 To 3
                Select Case i
                    Case 1
                        If SelectedPictureboxesList.Count > 0 Then
                            Label1.Text = SelectedPictureboxesList(0).Name
                            Label1.BackColor = SelectedPictureboxesList(0).BackColor
                        Else
                            Label1.Text = "Not Selected"
                            Label1.BackColor = Color.Black
                        End If
    
                    Case 2
                        If SelectedPictureboxesList.Count > 1 Then
                            Label2.Text = SelectedPictureboxesList(1).Name
                            Label2.BackColor = SelectedPictureboxesList(1).BackColor
                        Else
                            Label2.Text = "Not Selected"
                            Label2.BackColor = Color.Black
                        End If
    
                    Case 3
                        If SelectedPictureboxesList.Count > 2 Then
                            Label3.Text = SelectedPictureboxesList(2).Name
                            Label3.BackColor = SelectedPictureboxesList(2).BackColor
                        Else
                            Label3.Text = "Not Selected"
                            Label3.BackColor = Color.Black
                        End If
                End Select
            Next
        End Sub
    
        Private Sub Pics_MouseDown(sender As Object, e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                Dim thisPic As PictureBox = DirectCast(sender, PictureBox)
    
                Select Case GameStage
                    Case 0  'first picturebox selection
                        SelectedPictureboxesList.Add(thisPic)
                        Msg = "Select the Second Picturebox"
                        GameStage = 1
                    Case 1
                        SelectedPictureboxesList.Add(thisPic)
                        Msg = "Select the Third Picturebox"
                        GameStage = 2
                    Case 2
                        SelectedPictureboxesList.Add(thisPic)
                        Msg = "Selection Complete." & vbLf & "Click the Form to Play Again."
                        GameStage = 3
                End Select
                UpdateLabels()
                Me.Refresh()
            End If
        End Sub
    
        Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.DrawString(Msg, New Font("arial", 12), Brushes.Blue, 20, 5)
        End Sub
    
        Private Sub Form2_Click(sender As Object, e As EventArgs) Handles Me.Click
            GameReset()
        End Sub
    
        Private Sub GameReset()
            If GameStage = 3 Then
                GameStage = 0
                SelectedPictureboxesList.Clear()
                Msg = "Select the First Picturebox"
                UpdateLabels()
                Refresh()
            End If
        End Sub
    End Class


    • Edited by tommytwotrain Saturday, April 15, 2017 5:27 PM refresh
    Saturday, April 15, 2017 5:21 PM
  • Alright I will take a look at this example. 

    WRA

    Saturday, April 15, 2017 5:27 PM
  • Alright I will take a look at this example. 

    WRA


    PS

    Note how update labels just displays the current data. When the data is changed the update routine is called and all the data is updated at once on the screen. Not just the current step etc.

    That's how you get things objectified and methodized. You make things so you call them anytime anyplace anyway. The object should be smart enough to know what it does. ie update the labels with the current data. The object only knows that. The object does not know or care what step it is. All the object does is display the current data.

    • Marked as answer by Waliur Rahman Thursday, April 20, 2017 9:06 AM
    Saturday, April 15, 2017 5:34 PM
  • @Tommy or Acamar

    One of my threads to do with limiting the number of steps a sprite can take might have answered this question here. 

    So I was thinking this by using the button to be able to refresh the movements of each sprite, I could use it in another way as well. 

    What i mean is I could disable for example player 1 is assigned the team color blue while player 2 is assigned red. As soon as I select the button in the game grid for player 1 the result will be It disables player 1s sprites from attacking or moving and vice versa. Perhaps this could be the answer to this question. 


    WRA

    Sunday, April 16, 2017 11:41 AM
  • Finally solved this one So I know That I can determine whos turn it is and what I basically did was disable a set of sprites such as the ones in the colour red then enable the sprites in the color blue and vice versa.

    WRA

    Thursday, April 20, 2017 9:09 AM