Press ENTER to switch control mode.
Graphics 640, 480, 0, 2 SetBuffer BackBuffer() SeedRnd MilliSecs() px# = 50 py# = 220 tpx# = 0 tpy# = 0 Type missile Field x, y End Type Type asteroid Field x#, y, w, h, s#, l End Type While Not KeyDown(1) Cls Select control Case 0 Text 0, 0, "Standard keyboard control" If KeyDown(200) Then py = py - 3 If KeyDown(208) Then py = py + 3 If KeyDown(203) Then px = px - 3 If KeyDown(205) Then px = px + 3 If KeyDown(57) And dly < MilliSecs() Then fire = True: dly = MilliSecs() + 200: mx = px + 70: my = py + 15 Case 1 Text 0, 0, "Standard mouse control" px = MouseX() - 35 py = MouseY() - 20 If MouseDown(1) And dly < MilliSecs() Then fire = True: dly = MilliSecs() + 200: mx = px + 70: my = py + 15 Case 2 Text 0, 0, "Normalized mouse control" tpx = MouseX() - 35 tpy = MouseY() - 20 d# = Sqr((tpx-px)^2+(tpy-py)^2) If d > 3 Then px = px+Float(tpx-px)/d*3.0 py = py+Float(tpy-py)/d*3.0 Else px = tpx py = tpy End If If MouseDown(1) And dly < MilliSecs() Then fire = True: dly = MilliSecs() + 200: mx = px + 70: my = py + 15 Case 3 Text 0, 0, "Normalized keyboard control" tpx = px + (KeyDown(205)-KeyDown(203))*3 tpy = py + (KeyDown(208)-KeyDown(200))*3 d# = Sqr((tpx-px)^2+(tpy-py)^2) If d > 3 Then px = px+Float(tpx-px)/d*3.0 py = py+Float(tpy-py)/d*3.0 Else px = tpx py = tpy End If If KeyDown(57) And dly < MilliSecs() Then fire = True: dly = MilliSecs() + 200: mx = px + 70: my = py + 15 End Select If KeyHit(28) Then control = (control + 1) Mod 4 End If If fire Then m.missile = New missile m\x = mx m\y = my fire = False End If For m = Each missile m\x = m\x + 7 Rect m\x, m\y, 25, 10 If m\x > 640 Then Delete m End If Next If newast < MilliSecs() Then newast = MilliSecs() + 350 a.asteroid = New asteroid a\x = 640 a\w = Rand(15, 75) a\h = Rand(15, 75) a\y = Rand(0, 480 - a\h) a\s = Rnd(1.5, 5) a\l = 1 + Float(a\w*a\h)/1000.0 End If For a = Each asteroid a\x = a\x - a\s Rect a\x, a\y, a\w, a\h For m = Each missile If RectsOverlap(m\x, m\y, 25, 10, a\x, a\y, a\w, a\h) Then a\l = a\l - 1 Oval m\x, m\y - 12, 25, 25 Delete m If a\l <= 0 Then Oval a\x - a\w, a\y - a\h, a\w*3, a\h*3 Delete a Exit End If End If Next If a <> Null Then If a\x <= -a\w Then Delete a End If End If Next Rect px, py, 70, 40 Flip Wend