Question Random Event ... Timer Trigger?

PRo-Beaniie

Well-known member
Joined
Mar 17, 2011
Messages
55
Location
Hertford, Hertfordshire, United Kingdom
Programming Experience
3-5
Hey Guys,

As you may have read in my other posts i am creating a game in VB.NET for my First Diploma college course;) ... Im just putting the finishing touches on the game now. However Thought to myslef why not make te game that little bit more interesting... i have a genral idea of what i want to happen but have no knowledge of Random events...:confused:

Basically what i have is three enemys (helicopters) going across the screen to the Right. when fired appon they recycle back to the starting position. THey do the same if they reach the end of the form also, What i am hoping for is to learn some code that could make the enemy projectile fall from the Enemys Randomly.

Like i said i have no knowledge of random events and i am hoping you guys could enlighten me. I think i have the code for the Enemyprojectile to fall from the Enemy as shown below...

VB.NET:
    Private Sub DropMissilePosition()
        For Me.x = 1 To NumOfEnemy
            If Enemy(x).Left = Me.ClientRectangle.Left + 250 And EnemyMissile.Visible = False Then
                EnemyMissile.Top = Enemy(x).Top
                EnemyMissile.Left = Enemy(x).Left + (Enemy(x).Width / 2) - (EnemyMissile.Width / 2)
                EnemyMissile.Visible = True And (EnemyMissile.Top >= Enemy(x).Height + Enemy(x).Width) And Me.ClientRectangle.Width
            End If
        Next
    End Sub
    Private Sub DropMissile()
        'EnemyMissile Timer Variables ...
        If EnemyMissile.Visible = True Then
            EnemyMissile.Top += enemymissilespeed
        End If
        If EnemyMissile.Top + EnemyMissile.Height < Me.ClientRectangle.Top Then
            EnemyMissile.Visible = False
        End If
    End Sub

If you could help it would be much appreciated. ;)

Thanks,
 
Just taking from PRo-Beannii's code and methods, why not just add the extra lines in the collision detection:

VB.NET:
'Collision Code heli 1
        If Missile.Top < heli1.Top + heli1.Height And Missile.Left > heli1.Left And Missile.Left < heli1.Left + heli1.Width Then
            heli1.Visible = False
            heli1.Left = -100
            heli1.Visible = True
        End If

~Scorp
 
You must rememeber...

you must remeber that your code is refering to objects on the form.... :)
As scorpionDiety posted earlier ... to get the helicopters to restart add these two lines in after the collision code like this ... (Repeat for all collision code..)

VB.NET:
'Collision Code heli 1
        If Missile.Top < heli1.Top + heli1.Height And Missile.Left > heli1.Left And Missile.Left < heli1.Left + heli1.Width Then
            heli1.Visible = False
[COLOR=lime]            heli1.Left = -100
            heli1.Visible = True[/COLOR]
        End If
P.S sorry abou the late reply been really busy with college ... :)
 
Last edited:
Has anyone got a clue how to make a score board..... i m trying to make sure that when the target gets hit the score board gives a certain amount of score and also to stop at a certain digit... now i ve tried one out before but it didn't work
 
hey there,
i have almost finished making my game but theres a slight problem, the shooter fire the shot and the enemy gets hit and goes to a restart point but
when it's moving across the screen it dissapears when reaches he where the shooter is
it doesn't go past that point and the enemy just keeps going back to it's restart point.....HELP Pls
 
Dim SRight As Boolean
Dim SLeft As Boolean
Dim ShooterSpeed As Integer
Dim shotspeed As Integer
Private Sub TimerMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerMain.Tick
MoveShooter()
FireShot()
CheckHit()
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.Right Then
SRight = True
SLeft = False
End If
If e.KeyValue = Keys.Left Then
SLeft = True
SRight = False
End If
If e.KeyValue = Keys.Space And Shot.Visible = False Then
Shot.Top = Shooter.Top
Shot.Left = Shooter.Left + (Shooter.Width / 2) - (Shot.Width / 2)
Shot.Visible =
True
End If
End Sub
Private Sub MoveShooter()
If SRight = True And Shooter.Left + Shooter.Width < Me.ClientRectangle.Width Then
Shooter.Left += ShooterSpeed
End If
If SLeft = True And Shooter.Left > Me.ClientRectangle.Left Then
Shooter.Left -= ShooterSpeed
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyValue = Keys.Right Then
SRight = False
End If
If e.KeyValue = Keys.Left Then
SLeft = False
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loadsettings()
End Sub
Private Sub loadsettings()
shotspeed = 6
ShooterSpeed = 3
Shot.Visible =
False
End Sub
Private Sub FireShot()
If Shot.Visible = True Then
Shot.Top -= shotspeed
End If
If Shot.Top + Shot.Height < Me.ClientRectangle.Top Then
Shot.Visible = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Timer1.Enabled = True Then
Enemy.Left = Enemy.Left + 15
End If
If Enemy.Left >= Me.ClientRectangle.Width Then
Enemy.Left = -50
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Timer1.Enabled = True Then
Enemy1.Left = Enemy1.Left + 20
End If
If Enemy1.Left >= Me.ClientRectangle.Width Then
Enemy1.Left = -50
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
If Timer1.Enabled = True Then
Enemy2.Left = Enemy2.Left + 20
End If
If Enemy2.Left >= Me.ClientRectangle.Width Then
Enemy2.Left = -50
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
If Timer1.Enabled = True Then
Enemy3.Left = Enemy3.Left + 15
End If
If Enemy3.Left >= Me.ClientRectangle.Width Then
Enemy3.Left = -50
End If
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
If Timer1.Enabled = True Then
Enemy4.Left = Enemy4.Left + 20
End If
If Enemy4.Left >= Me.ClientRectangle.Width Then
Enemy4.Left = -50
End If
End Sub
Private Sub CheckHit()
'Collision Code enemy
If Shot.Top < Enemy.Top + Enemy.Height And Shot.Left > Enemy.Left And Shot.Left < Enemy.Left + Enemy.Width Then
Enemy.Visible = False
Enemy.Left = -100
Enemy.Visible =
True
End If
'Collision Code enemy1
If Shot.Top < Enemy1.Top + Enemy1.Height And Shot.Left > Enemy1.Left And Shot.Left < Enemy1.Left + Enemy1.Width Then
Enemy1.Visible = False
Enemy1.Left = -100
Enemy1.Visible =
True
End If
'Collision Code enemy2
If Shot.Top < Enemy2.Top + Enemy2.Height And Shot.Left > Enemy2.Left And Shot.Left < Enemy2.Left + Enemy2.Width Then
Enemy2.Visible = False
Enemy2.Left = -100
Enemy2.Visible =
True
End If
'Collision Code enemy3
If Shot.Top < Enemy3.Top + Enemy3.Height And Shot.Left > Enemy3.Left And Shot.Left < Enemy3.Left + Enemy3.Width Then
Enemy3.Visible = False
Enemy3.Left = -100
Enemy3.Visible =
True
End If
'Collision Code enemy
If Shot.Top < Enemy4.Top + Enemy4.Height And Shot.Left > Enemy4.Left And Shot.Left < Enemy4.Left + Enemy4.Width Then
Enemy4.Visible = False
Enemy4.Left = -100
Enemy4.Visible =
True
End If
End Sub
End
Class
 

Latest posts

Back
Top