- Joined
- Jan 2, 2020

- Messages
- 922

Is it allowed to use two IF statements on one line?

Cerberus:

```
Import mojo2
Function Main()
New MyGame()
End Function
Const screenwidth:Int = 640
Const screenheight:Int = 480
Const numstars:Int = 150
Global s:List<star> = New List<star>
Global p:player = New player
Class MyGame Extends App
Field canvas:Canvas
Method OnCreate()
SetSwapInterval 1 ; SetUpdateRate 0 ' Vertical blanking
canvas = New Canvas
For Local i = 0 Until numstars
s.AddLast(New star())
Next
End Method
Method OnUpdate()
p.update
End Method
Method OnRender()
canvas.Clear 0,0,0
canvas.SetColor 1,1,1
canvas.DrawText "Use cursor keys to control the ship.",0,0
For Local i:=Eachin s
i.draw(canvas)
Next
p.draw(canvas)
canvas.Flush
End Method
End Class
' ---------------------------------------
Class player
Field x:Float = screenwidth/2
Field y:Float = screenheight/2
Field incx:Float = 0
Field incy:Float = 0
Field w:Int = 16
Field h:Int = 16
Field angle:Int = 0
Method draw(canvas:Canvas)
canvas.PushMatrix
canvas.Translate 320,240
canvas.Rotate -angle
canvas.DrawPoly([Float(0-16),0 ,16,0-16 ,16,16])
canvas.DrawLine -10,0,8,0
canvas.PopMatrix
End Method
Method update()
If KeyDown(KEY_UP) Then incx = incx+Cos(angle)/10 ; incy = incy+Sin(angle)/10
If KeyDown(KEY_DOWN) Then incx = incx-Cos(angle)/30 ; incy = incy-Sin(angle)/30
If incx>3 Then incx = 3
If incy>3 Then incy = 3
If incx<-3 Then incx = -3
If incy<-3 Then incy = -3
If KeyDown(KEY_LEFT) Then angle = angle - 1 ; If angle < -180 Then angle = 180
' delete me
If KeyDown(KEY_RIGHT) Then angle = angle + 1 ; If angle > 180 Then angle = -180
For Local i := Eachin s
i.x = i.x + incx
i.y = i.y + incy
If i.x > screenwidth Then i.x = 0 ; i.y = Rnd(screenheight)
If i.y > screenheight Then i.y = 0 ; i.x = Rnd(screenwidth)
If i.x < 0 Then i.x = screenwidth ; i.y = Rnd(screenheight)
If i.y < 0 Then i.y = screenheight ; i.x = Rnd(screenwidth)
Next
End Method
End Class
Class star
Field x:Float
Field y:Float
Method New()
x = Rnd(screenwidth)
y = Rnd(screenheight)
End Method
Method draw(canvas:Canvas)
canvas.DrawPoint x,y
End Method
End Class
Function distance:Int(x1:Int,y1:Int,x2:Int,y2:Int)
Return Abs(x2-x1) + Abs(y2-y1)
End Function
Function getangle:Int(x1:Int,y1:Int,x2:Int,y2:Int)
Return ATan2(y1-y2, x1-x2) ' Use Sin, Cos etc for degrees and Sinr, Cosr etc for radians
End Function
Function leftangle:Bool(_angle:Int,_destinationangle:Int)
Local cnt1 = 0
Local a1 = _angle
While a1 <> _destinationangle
a1 = a1 + 1
If a1 > 180 Then a1 = a1 - 180
cnt1 = cnt1 + 1
Wend
If cnt1 < 180 Then Return True Else Return False
End Function
```