Problem reloading/refreshing form

EricBentley

New member
Joined
Jan 16, 2012
Messages
2
Programming Experience
1-3
Hey guys, new to the forums. Been browsing here for a while, casually taking help off other peoples threads, but I come to you now in my time of despair.

I've been working on this game the past few days, a simple game where two people control different tanks, and shoot each other, very basic so far.
The problem I have is when one player is dead. I have the form recognizing each players death by using this code (It's within a timer subroutine)
'Player One Dead
        If intPlayerOneHealth <= 0 Then
            btnReplay.Visible = True
        End If


        'Player Two Dead
        If intPlayerTwoHealth <= 0 Then
            btnReplay.Visible = True
        End If


That enables a button to be visible, and the code for that button is below

Private Sub btnReplay_Click(sender As System.Object, e As System.EventArgs) Handles btnReplay.Click
        intPlayerOneHealth = 100
        intPlayerTwoHealth = 100
        pbxPlayerOne.Location = New Point(27, 53)
        pbxPlayerTwo.Location = New Point(700, 461)
        btnReplay.Visible = False
        Me.Refresh()
    End Sub


I've tried every method so far, and for the most part it works. The code is executed, and the players health is restored and the players go back into position, however, they are unable to move or shoot after that. I use the arrow keys and WASD keys for movement, like the sample below

 Private Sub KeysDown(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        'Left arrow key
        If e.KeyValue = Keys.Left Then
            bolKeyLeft = True
        End If
End Sub


and that code is replicated for every key pressed (Arrow keys, WASD, e, and end). Those booleans are handled in a timer subroutine, where if the boolean is true, they will move/shoot. (Turning the booleans to false is done in the 'Private Sub KeysUp' subroutine)

TL;DR
How do I get the game to restart itself when a player dies and hits the replay button?

P.S. I've tried 'Me.Refresh()' as well, and that didn't do anything
 
What code do you have on your form load? or any control load methods for that matter. Is there something there missing that is required to start the new game?
 
All I have within the form load is two picture box decelerations changing the size and location of the missile pictureboxes (I had a problem with players taking damage on load due to the picturebox spawning on the field, but being invisible), as well as defining the values for an array of walls, to make collision easier. The code is as follows

Private Sub Game_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        pbxPlayerOneMissile.Visible = True
        pbxPlayerOneMissile.Image = My.Resources.BlueDown
        pbxPlayerOneMissile.Location = New Point(-500, -500)
        pbxPlayerOneMissile.Size = New Size(1, 1)
        pbxPlayerOneMissile.BackColor = Color.Blue

        pbxPlayerTwoMissile.Visible = True
        pbxPlayerTwoMissile.Image = My.Resources.RedUp
        pbxPlayerTwoMissile.Location = New Point(-500, -500)
        pbxPlayerTwoMissile.Size = New Size(1, 1)
        pbxPlayerTwoMissile.BackColor = Color.Red

        walls(0) = pbxWall1
        walls(1) = pbxWall2
        walls(2) = pbxWall3
        walls(3) = pbxWall4
        walls(4) = pbxWall5
        walls(5) = pbxWall6
        walls(6) = pbxWall7
        walls(7) = pbxWall8
        walls(8) = pbxWall9
        walls(9) = pbxWall10
        walls(10) = pbxWall11
        walls(11) = pbxWall12
        walls(12) = pbxWall13
        walls(13) = pbxWall14
        walls(14) = pbxWall15
        walls(15) = pbxWall16
    End Sub


I don't think any of this would be causing the problem, but if you see something, let me know
 
Where is the code that handles moving and shooting, I cant see any problem with the on load code, as shooting and moving are effected it might be worth posting that code too
 
Back
Top