Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Go Back  Xtreme Visual Basic Talk > > > Game with jumping while moving and sensing colour


Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2011, 02:06 PM
itrabarkahc itrabarkahc is offline
Newcomer
 
Join Date: Jan 2011
Posts: 5
Default Game with jumping while moving and sensing colour


So here is my problem. I have a vb game with animated sprites and all, and the character even jumps. However it only works in the y direction. So if i'm moving, he stops in place and jumps, instead of jumping forward. I was wondering if someone knew how to make him move at the same speed forward during the jump.

Also, I remember in VB 6 there was a way to have the object stop in a collision when it recognizes a colour. Is there a way to do that with the new VB studio?

Yes I know VB is terrible for games, but i'm just dabbling.

Here is my code

Code:
Class Form1

    'Dim thehero As Rectangle
    'Dim thefloor As Rectangle

    Dim speedx As Integer = 5
    Dim SpeedY As Integer = 0
    Dim Gravity As Integer = 4
    Dim JumpSpeed As Integer = -10
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Left
                Orialphus.Visible = True
                Orialphus3.Visible = False
                Orialphus2.Visible = False
                Orialphus5.Visible = False
                Orialphus6.Visible = False
                Orialphus.Left = Orialphus.Left - speedx
                Orialphus2.Left = Orialphus2.Left - speedx
                Orialphus3.Left = Orialphus3.Left - speedx
                Orialphus4.Left = Orialphus4.Left - speedx
                Orialphus5.Left = Orialphus5.Left - speedx
                Orialphus6.Left = Orialphus6.Left - speedx
                If Keys.Left = Keys.Left Then
                    Timer1.Enabled = True
                    Timer2.Enabled = False
                End If
            Case Keys.Right
                Orialphus3.Visible = True
                Orialphus.Visible = False
                Orialphus5.Visible = False
                Orialphus.Left = Orialphus.Left + speedx
                Orialphus2.Left = Orialphus2.Left + speedx
                Orialphus3.Left = Orialphus3.Left + speedx
                Orialphus4.Left = Orialphus4.Left + speedx
                Orialphus5.Left = Orialphus5.Left + speedx
                Orialphus6.Left = Orialphus6.Left + speedx
                If Keys.Right = Keys.Right Then
                    Timer2.Enabled = True
                    Timer1.Enabled = False
                End If
            Case Keys.Up
                Orialphus.Top = Orialphus.Top - SpeedY
                Orialphus2.Top = Orialphus2.Top - SpeedY
                Orialphus3.Top = Orialphus3.Top - SpeedY
                Orialphus4.Top = Orialphus4.Top - SpeedY
                Orialphus5.Top = Orialphus5.Top - SpeedY
                Orialphus6.Top = Orialphus6.Top - SpeedY
                If Timer1.Enabled = True Then
                    Timer1.Enabled = False
                ElseIf Timer2.Enabled = True Then
                    Timer2.Enabled = False
                End If
                If Orialphus.Visible = True Then
                    Orialphus.Visible = False
                    Orialphus5.Visible = True
                ElseIf Orialphus2.Visible = True Then
                    Orialphus2.Visible = False
                    Orialphus5.Visible = True
                End If
                If Orialphus3.Visible = True Then
                    Orialphus3.Visible = False
                    Orialphus6.Visible = True
                ElseIf Orialphus4.Visible = True Then
                    Orialphus4.Visible = False
                    Orialphus6.Visible = True
                End If
                If e.KeyCode = Keys.Up Then
                    SpeedY = JumpSpeed
                    TmrGravity.Enabled = True
                End If
        End Select
        If Timer1.Enabled = False Then
            Orialphus2.Visible = False
        End If
        If Timer2.Enabled = False Then
            Orialphus4.Visible = False
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Orialphus.Visible = False
        Orialphus2.Visible = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Orialphus4.Visible = True
        Orialphus3.Visible = False
    End Sub

    Private Sub TmrGravity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrGravity.Tick
        SpeedY += Gravity
    End Sub

    Private Sub TimerY_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerY.Tick
        'thehero = New Rectangle(Orialphus.Left, Orialphus.Top, Orialphus.Width, Orialphus.Height)
        'thefloor = New Rectangle(PictureBox1.Left, PictureBox1.Top, PictureBox1.Width, PictureBox1.Height)
        Orialphus.Location = New Point(Orialphus.Location.X, Orialphus.Location.Y + SpeedY)
        Orialphus2.Location = New Point(Orialphus2.Location.X, Orialphus2.Location.Y + SpeedY)
        Orialphus3.Location = New Point(Orialphus3.Location.X, Orialphus3.Location.Y + SpeedY)
        Orialphus4.Location = New Point(Orialphus4.Location.X, Orialphus4.Location.Y + SpeedY)
        Orialphus5.Location = New Point(Orialphus5.Location.X, Orialphus5.Location.Y + SpeedY)
        Orialphus6.Location = New Point(Orialphus6.Location.X, Orialphus6.Location.Y + SpeedY)
        'If thehero.IntersectsWith(thefloor) Then
        'SpeedY = 0
        'TmrGravity.Enabled = False
        'End If
        If Orialphus.Top + Orialphus.Height = PictureBox1.Location.Y Then
            SpeedY = 0
            TmrGravity.Enabled = False
        End If
    End Sub

    Private Sub TimerX_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerX.Tick
        
    End Sub
End Class
Reply With Quote
  #2  
Old 02-05-2011, 03:07 PM
passel's Avatar
passelGame with jumping while moving and sensing colour passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

That code is using the keyboard auto-repeat to move the sprite.
You shouldn't depend on the rate of the keyboard presses to determine the movement.
Also, as you noted, you can have two keys pressed at the same time and be receiving repeated keystrokes from both, only the last key pressed will be the one repeated.

Change the code to note when the keys goes down (set a boolean perhaps) and when the keys goes up (clear the boolean), then at a reqular interval when you should be moving all your players, move them based on what keys are currently down.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 02-23-2011, 09:30 PM
itrabarkahc itrabarkahc is offline
Newcomer
 
Join Date: Jan 2011
Posts: 5
Default

Thanks a bunch passel, i'll definitely try this out.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
 
Game with jumping while moving and sensing colour
Game with jumping while moving and sensing colour
 
-->