Foray in Game Making
Foray in Game Making
Foray in Game Making
Foray in Game Making
Foray in Game Making
Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making
Foray in Game Making Foray in Game Making
Foray in Game Making
Go Back  Xtreme Visual Basic Talk > > > Foray in Game Making


Reply
 
Thread Tools Display Modes
  #1  
Old 06-03-2011, 03:52 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default Foray in Game Making


Hi Newbie to Game Making but not VB so need a few pointers and help i can get is great

Have attached the code so far and would like to be able to rotate my car sprite through 360 degrees and have it move in diagonal fashion.

any suggestions would be great cheers guys
Attached Files
File Type: zip 503.zip (112.7 KB, 14 views)
Reply With Quote
  #2  
Old 06-04-2011, 03:58 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

Also would like some input into this query.

I have drawn a map in Fireworks it is 6000 * 6000 pixels in size, and i would like it so the car stays in the center of the screen and the map scrolls.

which way in vb is the best way of doing this

Many Thanks
Reply With Quote
  #3  
Old 06-06-2011, 02:38 PM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

The simple thing to do, would be to use DrawImage to copy a portion of your 6000*6000 pixel map as your background. As the car moves, the you change the source offset to copy a section of you map based on car position.
You will also use DrawImage to draw the image of your car on top of the map, centered.
Before drawing the car, you set up a rotation matrix so the car is drawn at the angle you want. I don't have time to create an example using your car bitmap, but if you look at post #5 in this thread the example code does make use of rotation and translation to implement an ADI instrument, so it may help in understanding some uses of that capability.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 06-07-2011, 01:42 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

many thanks for the pointer have downloaded the example

cheers

shall let you know how it goes
Reply With Quote
  #5  
Old 06-14-2011, 03:25 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

looked into that but dont understand on how you make it rotate the picture as you said could you explain it a bit for me.

sorry
Reply With Quote
  #6  
Old 06-14-2011, 10:43 AM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

Well, it is lunch time at work so I'll try a quick example using your code from the first post.

At the top of the Form1 class, where you have "Dim LastLeft, LastTop as Integer" add
Dim Heading as Single.

Paste the following two event handlers into the code.
Code:
'
  Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    Static lastX As Integer
    If e.Button = Windows.Forms.MouseButtons.Left Then
      Heading += (e.X - lastX) / 4
      If Heading < 0 Then Heading = Heading + 360.0
      If Heading > 360.0 Then Heading = Heading - 360.0
      Me.Invalidate() ' Me.Refresh()
    End If

    lastX = e.X
  End Sub

  Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.TranslateTransform(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
    e.Graphics.DrawLine(Pens.Black, -500, 0, 500, 0) 'draw a horizontal line
    e.Graphics.DrawLine(Pens.Black, 0, -500, 0, 500) 'and vertical line through 0,0 our center now
    e.Graphics.RotateTransform(Heading)              'rotate by the heading of the car (actually tail since image is front down)
    'we want the center (or close to it) of the car to be the rotation point, so we offset the draw point
    'by 1/2 the source image width and height

    e.Graphics.DrawImage(picPlayer.Image, _
                        -picPlayer.ClientSize.Width \ 2, _
                        -picPlayer.ClientSize.Height \ 2, _
                        picPlayer.ClientSize.Width, _
                        picPlayer.ClientSize.Height)
  End Sub
When the paint event fires for the form, the code in the paint event will translate the form's 0,0 coordinate to the center of the form.
It will draw a horizontal and vertical line through 0,0 to show where the center of the form is.
It will rotate by the heading value (limited to 0-360), and draw the image of the car from your picPlayer picturebox to the center of the form.

The MouseMove event handler, if you click and drag on the form, will modify the value of heading, keeping it in the limits of 0 to 360 degrees, and invalidate the form so it redraws (calls the Paint event).

So, click and drag on the form with the left button to see the car rotate in the middle of the form.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 06-15-2011, 01:56 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

mucho thanko

i shall try it now before work and thanks once again

Reply With Quote
  #8  
Old 06-17-2011, 05:36 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Talking

once again cheers it works a treat just if i may be as so bold to ask, is it possible to transpose it to the key presses of the arrow keys.

i have tried this but im left with with

Private Sub frmMain_KeyLeft(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

Select Case e.KeyCode

Case Keys.Left
LeftKey = True

Static lastX As Integer
If e.Button = Windows.Forms.MouseButtons.Left Then
Heading += (e.X - lastX) / 4
If Heading < 0 Then Heading = Heading + 360.0
If Heading > 360.0 Then Heading = Heading - 360.0
Me.Invalidate() ' Me.Refresh()
End If

lastX = e.X

End Select
End Sub

if you did the above also you would see it leaves you with e.X is not a member of windows systems forms and neither is button, please if you can point me so to speak if it's poss or im barking up the wrong tree
Reply With Quote
  #9  
Old 06-18-2011, 10:27 PM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

When you press a key what X position on the window did the key click on?
It didn't. There is no screen X,Y position associated with a key.
I presume when you press the key you will want to turn in one direction. A different key will turn in the other direction.
So you don't need X, LastX.
If you press a key that should turn left, then subtract a number from the heading.
If you press a key that should turn right, then add a number to the heading.
Keep the heading in the 0 to 360 bounds.

You're setting LeftKey to true, so in your loop, while LeftKey is true you need to turn left.
Make sure you also set LeftKey to False when the Key goes up, so you stop turnning.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #10  
Old 06-25-2011, 12:12 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

hi guys

well have managed with a bit help to get it to rotate on the arrow keys, but next would like if poss a pointer in how to do the following?

remove the original img called picplayer so just leaving the one that rotates

and then have the one that rotates move back and forward on either the arrow keys or prefabley the A and S keys
Attached Files
File Type: zip 503 Beta.zip (406.3 KB, 5 views)
Reply With Quote
  #11  
Old 06-25-2011, 07:54 PM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

I thought I mentioned that you could set the picturebox Visible propery to false. It doesn't have to be showing in order to access the image, but I think my original post got lost and I had to redo the post and didn't remember to mention that the second time I did the post.

As for the movement, you'll have to convert the heading into relative X and Y magnitudes, and periodically use those magnitudes * speed to determing how far the car moves in X,Y for that motion.

Basically take the heading, in Radians, pass it to a Sin and Cos function to get X,Y relative magnitudes. You would then multiple those values by your speed to determine how far to move the car in that direction (or move the ground in the opposite direction if keeping the car centered).

Sin(0) is 0.0,
Cos(0) is 1.0
so if you use Cos for your Y axis, then 0 degrees would be straight up (use the negative of Cos(angle) * speed since Y decreases as you go up).
Sin(90) is 1, Cos(90) (remember to not use degrees in the actual math calls. use radians, so 90 degress would be 90*(Math.Pi/180) .
Normally, set a const like
Const DEGtoRAD = Math.PI / 180.0
Const RADtoDEG = 180.0 / Math.PI
so you just multiply Degrees by DEGtoRAD to get radians, and multiply radians by RADtoDEG to convert radians to degrees, if necessary.

So use Sin(heading * DEGtoRAD) for your X maxnitude, don't need to negate it like the Cos since positive X is to the right.


This generally involves using an atan2 function, so if you search for that you will probably find what you need. You may need to look at VB6 code, but hopefully you can get the gist of it.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 06-27-2011, 02:35 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

i tried setting the original image to false but that created more problems, as the image that was set as false still moved, any suggestions
Reply With Quote
  #13  
Old 06-27-2011, 09:21 AM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

A couple of suggestions. You don't need to move the picture, but since your collision detection currently depends on it, you could leave it for now.
One thing you may notice is that if you don't have the picturebox visible, it moves a lot faster, so your vertical movement happens transparently, since you're not redrawing for up,down and you have no idea how far the car traveled.
I guess I would suggest not having a loop with DoEvents in your timer call.
You should just set the timer interval to a small value, less than 15 on all the current machines I've worked with will generate ticks at the maximum of 64 hz.
If you start a StopWatch object when you start your game and then just check its ElapsedMilliseconds value to see how much time actually passed between each tick and adjust your movement to make your movement consistent regardless of the power of the machine, or the maximum tick interval of the clock.

Specific to your code, try
- setting the Timer Interval to 10
- remove the line that disables the timer
- remove the loop
- remove the DoEvents in the loop

Now the tick will occur periodically and you will adjust the motion and redraw at that rate.

First step, is propbably just to do the movement based a constant value so you move a little each tick, and not worry about the StopWatch and dynamically adjusting the amount you move each tick.

I did do a quick modification of your code on another machine at home, but I don't have that machine or code with me here.
You could move the speed to the A and S keys, but as a quick test I just used the up and down arrow keys since you had them there.
Since I don't have the code, and won't reproduce it here, I'll just give the gist of what I did.
Note that since your image has the car facing down, I reversed the Up arrow and Down arrow code and did not negate the Math.Cos calculation, so that 0 degrees is technically
at the bottom of the screen, so when you hit the Up arrow to accelerate, the car moves in the direction of its nose, whichever way it is pointed.
Code:
'Up at the top of the class declaration area
Const DEGtoRAD as Double = Math.PI/180.0
Dim Speed as Single

If the down arrow is active Then
  If speed < 9 Then speed += .125     'accelerate at .125 up to around 9 pixels per frame
  If speed < 0 Then speed += .25       'If we were going backwards, accelerate toward 0 faster than then 
                                                 'normal acceleration so we "stop" and head the other way quicker
End If

If the up arrow is active Then
  If speed > -9 Then speed -= .125
  If speed > 0 then speed -= .25      'total slow down when changing directions is .375
End If


If the Left arrow is active Then
  'Turn heading left, as you have it.  'I actually changed the heading by 4 each frame so it turned faster.  
                                        'You'll want to coordinate heading change and max speed values to what you want.
End if

If the Right arrow is active Then
  Turn right by 4 degrees
end if

Dim dx, dy as Single
dx = Math.Sin(Heading * DEGtoRAD) * Speed
dy = Math.Cos(Heading * DEGtoRAD) * Speed

Location.X += dx
Location.Y += dy

Me.Invalidate
I did remove the Me.Invalidate from the Left and Right arrow key processing. We now move the car after the keys are processed, based on heading, and then invalidate to redraw. I also removed the location wrap logic, since it was up in the key processing, so you need to be careful and not loose the car by driving off the screen too far.
You could add the wrapping logic, or some other way of keeping the card on the screen down where you update the location after the dx,dy calculations.

That's about it. I probably could have just re-written the quick change and it wouldn't have taken much longer than this, but I'll guess you can take a shot at it. If later you still want the modifications, I should be able to get them from the other machine.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-06-2011 at 01:45 PM.
Reply With Quote
  #14  
Old 07-05-2011, 06:22 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

could someone explain that a bit simplier as i have tried what has been suggested but i get errors as the syntax isn't correct or exsist ??
Reply With Quote
  #15  
Old 07-06-2011, 08:46 AM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

I mentioned that I didn't have the code so the above is a formatted description, pseudo code, of what I did, not code to be pasted into your source.
If you're getting syntax errors, either you wrote something wrong or copied my pseudo code into your real code.
For instance,

If the right arrow is active then

is not real code. But you already have the code that checks if the right arrow is ative and does some movement.
Now, instead of doing the movement there, it is replaced by code that adjusts the speed (throttle forward).
The code you had in the down arrow active case is replaced by code that adjusts the speed in reverse (throttle backward).
The code in the right and left arrow keys can be left as is, but I increased it to turn by four degrees instead of one degree so there card was more responsive when it turned, otherwise it was hard to turn 180 degrees within the bounds of the window without throttling back.
The actual movement, instead of being done in the individual key processing cases, is done once, after the key processing, and is based on the current heading and speed.

Did you do the other things, like remove the Do ... Loop from the code in the timer, remove the Doevents, change the timer interval, etc..
Don't attempt to cut and paste blindly, start with your original code from post #10, and create a check list, if you want, from my post.
Each change you make, you should try to understand why it is being made, and check it off the list. If you understand what the change does as you make them, you should be able to fix any minor oversight, if there are any.
If you try to take a bunch of changes and just apply them all at once without understanding what the changes do, it can be frustrating and possibly overwhelm your efforts and desire to get it to work.

Again, I'm at work, but since it is approaching lunch time, I'll download the code from post #10, downgrade it from VB2010 to VB2008 so I can play with it on my work machine, and try to implement the changes from post #13 to see if there is any major issue left out of the logic. The one thing I did notice before is that since the picturebox is hidden, it doesn't reposition immediately at startup, so the car does not appear in the center initially, but does jump there when an arrow key is hit, I think.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #16  
Old 07-06-2011, 01:40 PM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

Ok, I gave it a shot. In addition to what I posted, there needed to be an else case to slow the car to a stop when the throttle buttons were not pressed. Something else is different here, than what I originally did. I probably adjusted the heading by 180 or something, but this version reverses the value returned by the Sin function to make the car move in the direction of the front of the car when going east/west.
I'm sure there is some integer truncation going on somewhere, so the position of the car doesn't track 100% to the heading value. Shouldn't be using the picturebox location to specify the position, but rather use a floating point value so subpixel movement can be maintained in memory. Rather than attach, I'll just paste the code here.
Don't forget to set the Timer interval to 10 (I could put it in the form load, but didn't) and set the picturebox's visible property to false
Code:

Public Class Form1
  'declared values for the directional keys 
  Dim UpKey, DownKey, LeftKey, RightKey As Boolean
  Dim LastLeft, LastTop As Integer
  Dim bitmap1 As Bitmap
  Dim Heading As Single

  Const DEGtoRAD As Double = Math.PI / 180.0
  Dim Speed As Single



  Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    'e.Graphics.TranslateTransform(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
    e.Graphics.TranslateTransform(LastLeft, LastTop)
    e.Graphics.RotateTransform(Heading)              'rotate by the heading of the car (actually tail since image is front down)
    'we want the center (or close to it) of the car to be the rotation point, so we offset the draw point
    'by 1/2 the source image width and height

    e.Graphics.DrawImage(picPlayer.Image, _
                                -picPlayer.ClientSize.Width \ 2, _
                                -picPlayer.ClientSize.Height \ 2, _
                                picPlayer.ClientSize.Width, _
                                picPlayer.ClientSize.Height)

  End Sub

  Private Sub InitializeBitmap()
    Try
      bitmap1 = CType(Bitmap.FromFile("C:\Users\Kevin Murray\Pictures\yellow_car_down.png"), Bitmap)
      picPlayer.SizeMode = PictureBoxSizeMode.AutoSize
      picPlayer.Image = bitmap1
    Catch ex As System.IO.FileNotFoundException
      MessageBox.Show("There was an error. Check the path to the bitmap.")
    End Try
  End Sub


  Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    'code for detecting the key presses of the appropiate directional key
    Select Case e.KeyCode
      Case Keys.Up
        UpKey = True
      Case Keys.Down
        DownKey = True
      Case Keys.Left
        LeftKey = True
      Case Keys.Right
        RightKey = True
    End Select
  End Sub

  Private Sub frmMain_KeyRelease(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    'code for detecting the key release of the appropiate directional key
    Select Case e.KeyCode
      Case Keys.Up
        UpKey = False
      Case Keys.Down
        DownKey = False
      Case Keys.Left
        LeftKey = False
      Case Keys.Right
        RightKey = False
    End Select
  End Sub

  Private Sub ClearKeys()
    UpKey = False
    DownKey = False
    LeftKey = False
    RightKey = False
  End Sub

  Private Sub frmMain_KeyUpwards(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    Select Case e.KeyCode

      Case Keys.Up
        UpKey = True

    End Select
  End Sub

  Private Sub frmMain_KeyLeft(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    Select Case e.KeyCode

      Case Keys.Left
        LeftKey = True

    End Select
  End Sub

  Private Sub frmMain_KeyRight(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    Select Case e.KeyCode

      Case Keys.Right
        RightKey = True


    End Select
  End Sub

  Private Sub frmMain_KeyDownwards(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    Select Case e.KeyCode

      Case Keys.Down
        DownKey = True
        'picPlayer.Image = Image.FromFile("C:\Users\Kevin Murray\Pictures\yellow_car_down.png")

    End Select
  End Sub

  Private Function EndCheck() As Boolean
    EndCheck = False

    If picPlayer.Bounds.IntersectsWith(pic503.Bounds) Then
      ClearKeys()
      Timer1.Enabled = False
      pic503.Hide()
      MsgBox("You have done it.")
      EndCheck = True
    End If

  End Function
  Private Sub Collision()
    picPlayer.Left = LastLeft
    picPlayer.Top = LastTop
  End Sub

  Private Sub EventCheck()
    If picPlayer.Bounds.IntersectsWith(picSmile.Bounds) Then
      Collision()
      ClearKeys()
    End If
  End Sub
  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'Delcare End Condition, runs until end condition is reached ie done = true 
    Dim Done As Boolean
    Done = False
    '  Timer1.Enabled = False

    'Game Loop
    '  Do Until Done = True
    ' Application.DoEvents()
    'the below code is for the movement and collison detection making sure that the image does not leave the form
    If UpKey = True Then
      If Speed < 9 Then Speed += 0.125 'accelerate at .125 up to around 9 pixels per frame
      If Speed < 0 Then Speed += 0.25 'If we were going backwards, accelerate toward 0 faster 
      '     If picPlayer.Top >= 10 Then picPlayer.Top -= 1
    Else
      If Speed > 0 Then Speed -= 0.125 'slow down if key not pressed
    End If
    If DownKey = True Then
      If Speed > -9 Then Speed -= 0.125
      If Speed > 0 Then Speed -= 0.25 'total slow down when changing directions is .375
      '    If (picPlayer.Top + picPlayer.Height) <= (Me.Height - 40) Then picPlayer.Top += 1
    Else
      If Speed < 0 Then Speed += 0.125 'slow down if key not pressed
    End If
    If LeftKey = True Then
      '   If picPlayer.Left >= 10 Then picPlayer.Left -= 4
      Heading -= 4
      If Heading < 0 Then Heading = Heading + 360.0
      If Heading > 360.0 Then Heading = Heading - 360.0
      ' Me.Invalidate() ' Me.Refresh()
    End If
    If RightKey = True Then
      '  If (picPlayer.Left + picPlayer.Width) <= (Me.Width - 20) Then picPlayer.Left += 4
      Heading += 4
      If Heading < 0 Then Heading = Heading + 360.0
      If Heading > 360.0 Then Heading = Heading - 360.0
      ' Me.Invalidate() ' Me.Refresh()
    End If

    Dim dx, dy As Single
    dx = -Math.Sin(Heading * DEGtoRAD) * Speed
    dy = Math.Cos(Heading * DEGtoRAD) * Speed
    If Math.Abs(Speed) > 0.1 Then
      Debug.Print("Heading: {0} dx: {1} dy: {2} speed: {3}", Heading, dx, dy, Speed)
    End If

    picPlayer.Left += dx
    picPlayer.Top += dy

    Me.Invalidate()
    If (picPlayer.Left <> LastLeft) Or (picPlayer.Top <> LastTop) Then
      Done = EndCheck()
      EventCheck()
    End If

    LastLeft = picPlayer.Left
    LastTop = picPlayer.Top
    '  Loop

    '  Me.Close()

  End Sub

End Class
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-06-2011 at 01:51 PM.
Reply With Quote
  #17  
Old 07-06-2011, 05:36 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

DUDE, you guys are the ****

i admire your skills and wish i could do half of what you did
Reply With Quote
  #18  
Old 07-07-2011, 01:16 PM
passel's Avatar
passelForay in Game Making passel is offline
Sinecure Expert

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

Note that with that code, the car can sit still and spin left or right, like a tank on treads.
If you don't want that, a simple change is to scale the heading change value by the speed of the car, so if you're going 0, no heading change is possible.
To give that a quick try, since the max speed is +-9, divide the max heading change value by 9, and multiply by speed.
In the Left, and Right key process code change the "4" to "(4 / 9) * Speed"
i.e.
Heading += 4
would become
Heading += (4 / 9) * Speed

Once you get further along, or perhaps now would be a good time, you should use named constants, or variables that are preset for the various literal numbers.
Something like:
Const MaxSpeed As Integer = 9
Const MaxHeadingChange As Integer = 4

Heading += (MaxHeadingChange / MaxSpeed) * Speed
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #19  
Old 07-15-2011, 03:41 PM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

cheers been a while but should knuckle down and get some more done cheers guys n gals for all your help so far
Reply With Quote
  #20  
Old 07-19-2011, 06:22 AM
murrray983 murrray983 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 15
Default

hey guys been looking at scroling and getting the car to stay in the center but the screen wont scroll, even if i turn auto scroll on the car just vanishes of the side of the form window ?

any help or ideas would be greatfull cheers
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
Foray in Game Making
Foray in Game Making
Foray in Game Making Foray in Game Making
Foray in Game Making
Foray in Game Making
Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making Foray in Game Making
Foray in Game Making
Foray in Game Making
 
Foray in Game Making
Foray in Game Making
 
-->