VB.NET:
Imports Microsoft.DirectX
'Imports Microsoft.DirectX.DirectInput
Imports Microsoft.DirectX.Direct3D
'Imports Microsoft.DirectX.DirectSound
Imports Microsoft.DirectX.AudioVideoPlayback
Imports Microsoft.DirectX.DXHelp
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
'keyboard
Private KB As New DirectInput.Device(DirectInput.SystemGuid.Keyboard)
'graphicsdevice
Private pars As New PresentParameters
Private GD As Device
'sprites
Private _ship As Sprite = New Sprite(GD)
'textures
Private ship As Texture
Private turn As Single = 0
Private turn2 As Single = 0
Private x As Integer = 0
Private y As Integer = 0
Private z As Integer = 1
Private v As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'graphicsdevice
pars.Windowed = True
pars.SwapEffect = SwapEffect.Discard
GD = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, pars)
'textures
ship = TextureLoader.FromFile(GD, System.IO.Directory.GetCurrentDirectory & "\Graphs\ship0.bmp", 256, 256, D3DX.Default, 0, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, Color.Magenta.ToArgb)
'sprites
_ship = New Sprite(GD)
'keyboard
KB.SetCooperativeLevel(Me, DirectInput.CooperativeLevelFlags.Background Or DirectInput.CooperativeLevelFlags.NonExclusive)
Me.Show()
KB.Acquire()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
KB.Dispose()
KB = Nothing
GD.Dispose()
_ship.Dispose()
ship.Dispose()
End Sub
Private Sub Keys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Keys.Tick
Dim State As DirectInput.KeyboardState
State = KB.GetCurrentKeyboardState
If State.Item(Microsoft.DirectX.DirectInput.Key.Escape) Then
Me.Close()
End If
If State.Item(Microsoft.DirectX.DirectInput.Key.W) Then
y -= 50
z = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))
turn2 = Math.Acos(y / z) + Math.PI - turn
End If
If State.Item(Microsoft.DirectX.DirectInput.Key.S) Then
y += 50
z = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))
turn2 = Math.Acos(y / z) + Math.PI - turn
End If
If State.Item(Microsoft.DirectX.DirectInput.Key.A) Then
turn -= 0.1257
If (turn < 0) Then
turn += 6.285
End If
x = z * Math.Sin(turn2 + turn - Math.PI)
y = z * Math.Cos(turn2 + turn - Math.PI)
End If
If State.Item(Microsoft.DirectX.DirectInput.Key.D) Then
turn += 0.1257
If (turn >= 6.285) Then
turn -= 6.285
End If
x = z * Math.Sin(turn2 + turn - Math.PI)
y = z * Math.Cos(turn2 + turn - Math.PI)
End If
Call Form1_Paint(Nothing, Nothing)
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If GD Is Nothing Then Return
GD.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0F, 0)
GD.BeginScene()
_ship.Begin(SpriteFlags.AlphaBlend)
_ship.Draw2D(ship, Rectangle.Empty, New System.Drawing.Rectangle(0, 0, 40, 40), New Point(125, 125), turn, New Point(x, y), Color.White)
GD.EndScene()
GD.Present()
End Sub
End Class
when i use w, a, s and d buttons the ship goes around like it should, but only for half of the time other times the ship jumps around randomly (I can't figure out the patern)
when i use front (w or s) and turn (a or d) the same time it goes in big circles around the center (this i could fix)
question:
why does it sometimmes randomly jump (not doing what it suposed to do) when i push one button at a time
Last edited: