Up and down movements....random events

MrMk2gtx

Active member
Joined
Apr 1, 2011
Messages
29
Programming Experience
Beginner
So, I've created this game and I am finishing off the last stage of this game and I wanted to make the last stage difficult so I positioned the shooter to the left side of the form, because I wanted to give it an up and down movements. I've tried and tried but I still couldn't get it right so I came here for help.

 Private Sub Utility_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        'this code moves the Renegade to the right'
        If e.KeyValue = Keys.Up Then
            RRight = True
        End If
        If e.KeyValue = Keys.Down Then
            RLeft = True
            RRight = False
        End If
        'this code moves the Collider to the right'
        If e.KeyValue = Keys.W Then
            CRight = True
            CLeft = False
        End If
        If e.KeyValue = Keys.S Then
            CLeft = True
            CRight = False
        End If
    End Sub
Private Sub Utility_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
        'this code moves the Renegade left or right'
        If e.KeyValue = Keys.Up Then
            RRight = False
        End If
        If e.KeyValue = Keys.Down Then
            RLeft = False
        End If
        'this code moves the Collider left or right'
        If e.KeyValue = Keys.W Then
            CRight = False
        End If
        If e.KeyValue = Keys.S Then
            CLeft = False
        End If
    End Sub
    Private Sub MoveRenegade()
        'this code moves the Renegade'
        If RRight = True And Renegade.Right + Renegade.Height < Me.ClientRectangle.Height Then
            Renegade.Height += RenegadeSpeed
        End If
        If RLeft = True And Renegade.Width > Me.ClientRectangle.Height Then
            Renegade.Height -= RenegadeSpeed
        End If
    End Sub




The enemies I also have, move from left to right and they're cool but I wanted to add a function to make them drop missiles at random.
Anyone know how I can do that (BTW this is what I meant by random events)
 
Whenever you want to do something random, it pretty much always means using the Random class. Create a single instance and use it multiple times, so use a member variable. You can then call Next or NextDouble each time you need a random Integer or Double respectively. What you then do with that random number depends on your circumstances. If you wanted something to happen at random intervals then you could use a Timer and assign the random number to its Interval property each time it ticks. If you wanted to move something a random distance then you could add the random number to is Left or Top property. If you want to select a random item from a list then you could use the random number as an index into an array or collection. Etc.
 
Oh boy! this is quite complicated to understand ¬_¬ damn
Really? Create a Random object, call Next to get a random number, use the number. Which bit is hard to understand?
 
Really? Create a Random object, call Next to get a random number, use the number. Which bit is hard to understand?

sorry, it's just the random event is not the piority right now, it's the movement of the shooter(renegade) that i need to get right for now
 
sorry, it's just the random event is not the piority right now, it's the movement of the shooter(renegade) that i need to get right for now
Then maybe you should have made that clear in your original post. Perhaps you should provide a FULL and CLEAR explanation of exactly what you want to happen and exactly what is happening. Expecting us to work out what you want from code that doesn't work is a bit hopeful don't you think?
 
Then maybe you should have made that clear in your original post. Perhaps you should provide a FULL and CLEAR explanation of exactly what you want to happen and exactly what is happening. Expecting us to work out what you want from code that doesn't work is a bit hopeful don't you think?

Sorry, I'll edit the original post then

EDIT: Just found out I can't edit it because there is no edit functions at the bottom of the first post
 
Back
Top