Hi !
i've some problem with my code ! i don't undersand why, but my asteroid doesn't explode correctly in four directions (45 degree). Thanks for your help !
i've some problem with my code ! i don't undersand why, but my asteroid doesn't explode correctly in four directions (45 degree). Thanks for your help !
Strict Graphics 800,600 Global Asteroids_list:TList = CreateList() Global image:Timage = LoadAnimImage ("media/asteroide.png", 96,96,0,10) MidHandleImage (image) Type TAsteroid Field hImage:Timage Field Size Field Scale# Field Frame Field Time Field x Field y Field xmov# Field ymov# Field Angle Field speed Function Create:TAsteroid (x:Int, y:Int, Size:Int, Angle:Int, Speed:Int) Local a:TAsteroid = New TAsteroid a.x = x a.y = y a.hImage = image a.Frame = Rand (0,9) a.Time = MilliSecs() a.Speed = Speed a.size = size a.angle = Angle a.Scale# = Float(1.0 / a.Size) a.xmov = Cos (a.angle) * a.speed a.ymov = Sin (a.angle) * a.speed ListAddLast Asteroids_List, a Return a End Function Function Draw_all() Local Scale# For Local a:Tasteroid = EachIn Asteroids_List If a.Time + 100 < MilliSecs() Then If a.Frame < 9 Then a.Frame = a.Frame + 1 Else a.Frame = 0 End If a.time = MilliSecs() End If a.x = a.x + a.xmov a.y = a.y + a.ymov SetScale a.Scale#, a.Scale# DrawImage a.Himage, a.x, a.y, a.Frame Next SetScale 1.0,1.0 End Function Method Explode() If Size < 5 Then Size = Size+ 1 TAsteroid.Create (x,y, Size, 45, Speed) TAsteroid.Create (x,y, Size, 135, Speed) TAsteroid.Create (x,y, Size, 225, Speed) TAsteroid.Create (x,y, Size, 315, Speed) Asteroids_list.remove Self End If End Method End Type Local frame = 0 Global Temps = MilliSecs() Local a:TAsteroid a = TAsteroid.Create (400,100, 1, 90,1) While Not KeyDown (key_escape) Cls TAsteroid.Draw_all() If KeyDown (key_space) Then a.Explode() FlushKeys() End If Flip DrawText "press space to explode...",0,0 Wend