O
One Handed Man \( OHM - Terry Burns \)
I havent played much with threading and Im testing stuff out with a little
space invaders game. My Invader class has a StopInvader StartInvader and
Invade subs.
There is a class level variable called Alive of Type Boolean.
On StartInvader I begin a new thread at the address of Invade and inside
this While Alive . . . . . . . Do Stuff ( Move etc ) Wend.
Stop invalder simply sets Alive to False.
OK
So the start starts it OK, and it shoots across the screeen, Fine; Stop
Stops the Invade, however, StartInvader only works the first time,
any ideas ? ( Excuse any bad programming as Im only playing )
Public Class Invader
Private invaderImage As Image
Private invaderImageDelete As Image
Private space As Graphics
Private startPoint As Point
Private currentPoint As New Point
Private Enum direction
left
right
End Enum
Private invaderDirection As direction
Private alive As Boolean = True
Private parentForm As Form1
Private invadeThread As Threading.Thread
Public Sub New(ByVal iSpace As Graphics, ByVal refForm As Form1, ByVal
iInvader As String, ByVal iInvaderDelete As String)
space = iSpace
invaderDirection = direction.right
startPoint = New Point(10, 10)
parentForm = refForm
invaderImage = Image.FromFile(iInvader)
invaderImageDelete = Image.FromFile(iInvaderDelete)
End Sub
Public Sub startInvader()
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
parentForm.newGameButton.Enabled = False
parentForm.stopGameButton.Enabled = True
invadeThread = New Threading.Thread(AddressOf invade)
invadeThread.IsBackground = True
invadeThread.Start()
End Sub
Public Sub stopInvader()
parentForm.newGameButton.Enabled = True
parentForm.stopGameButton.Enabled = False
alive = False
End Sub
Private Sub Fire()
End Sub
Private Sub invade()
While alive
If currentPoint.X > space.VisibleClipBounds.Width Then
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
End If
Threading.Thread.CurrentThread.Sleep(20)
space.DrawImage(MyClass.invaderImageDelete, currentPoint)
currentPoint.X += 5
space.DrawImage(MyClass.invaderImage, currentPoint)
End While
End Sub
--
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
space invaders game. My Invader class has a StopInvader StartInvader and
Invade subs.
There is a class level variable called Alive of Type Boolean.
On StartInvader I begin a new thread at the address of Invade and inside
this While Alive . . . . . . . Do Stuff ( Move etc ) Wend.
Stop invalder simply sets Alive to False.
OK
So the start starts it OK, and it shoots across the screeen, Fine; Stop
Stops the Invade, however, StartInvader only works the first time,
any ideas ? ( Excuse any bad programming as Im only playing )
Public Class Invader
Private invaderImage As Image
Private invaderImageDelete As Image
Private space As Graphics
Private startPoint As Point
Private currentPoint As New Point
Private Enum direction
left
right
End Enum
Private invaderDirection As direction
Private alive As Boolean = True
Private parentForm As Form1
Private invadeThread As Threading.Thread
Public Sub New(ByVal iSpace As Graphics, ByVal refForm As Form1, ByVal
iInvader As String, ByVal iInvaderDelete As String)
space = iSpace
invaderDirection = direction.right
startPoint = New Point(10, 10)
parentForm = refForm
invaderImage = Image.FromFile(iInvader)
invaderImageDelete = Image.FromFile(iInvaderDelete)
End Sub
Public Sub startInvader()
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
parentForm.newGameButton.Enabled = False
parentForm.stopGameButton.Enabled = True
invadeThread = New Threading.Thread(AddressOf invade)
invadeThread.IsBackground = True
invadeThread.Start()
End Sub
Public Sub stopInvader()
parentForm.newGameButton.Enabled = True
parentForm.stopGameButton.Enabled = False
alive = False
End Sub
Private Sub Fire()
End Sub
Private Sub invade()
While alive
If currentPoint.X > space.VisibleClipBounds.Width Then
currentPoint.X = startPoint.X
currentPoint.Y = startPoint.Y
End If
Threading.Thread.CurrentThread.Sleep(20)
space.DrawImage(MyClass.invaderImageDelete, currentPoint)
currentPoint.X += 5
space.DrawImage(MyClass.invaderImage, currentPoint)
End While
End Sub
--
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--