Results 1 to 29 of 29

Thread: Falling Game

Threaded View

  1. #16

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    12

    Re: Falling Game

    Quote Originally Posted by dday9 View Post
    A few things:
    1) You don't have to type out every picturebox like that
    2) you don't have to set the Top like that as well

    From what you gave me there I'd do something like this:
    Code:
    Option Strict On
    Option Explicit On
    Public Class Form1
        'Declare a new instance of the random object here,
        'or declare it here, and set it as a new instance at the form load
        Private r As New Random
        Private hit As Integer = 1
        Private pbList As New List(Of PictureBox)
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            pbList.AddRange({PictureBox2, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox2, PictureBox8, PictureBox9, PictureBox10})
    
            Timer1.Start()
        End Sub
    
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            For Each pb As PictureBox In pbList
                pb.Top += 5
    
                If pb.Bottom >= Me.Bottom Then
                    'Hit the bottom
                    pb.Location = New Point(r.Next(0, Me.Width), -r.Next(0, 10))
                ElseIf pb.Bounds.IntersectsWith(picCharmander.Bounds) Then
                    'Hit charmander
                    hit += 1
                    pb.Location = New Point(r.Next(0, Me.Width), -r.Next(0, 10) - Me.Height)
                ElseIf hit = 4 Then
                    'end game
                    Timer1.Stop()
                End If
            Next
        End Sub
    
        Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If e.KeyCode = Keys.Left Then
                picCharmander.Left -= 10
            ElseIf e.KeyCode = Keys.Right Then
                picCharmander.Left += 10
            End If
        End Sub
    End Class
    I think this is the last question, how do I change the speed and number of pictureboxes falling. This is for harder or easier levels. Before, when I had all the pictureboxes typed out I could see and change what their falling speeds were, how do I do that with the new code written here?
    Last edited by cheekson; May 13th, 2013 at 03:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width