• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Bug TED: Strange behaviour in editor

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
If you delete line 72 the code won't work?
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
 
It's not an issue with the editor. It's technically a parsing bug as like the End statement, the command separator can be ambiguous when used with nested conditionals.

The work around is to leave a blank line between each of these lines. Or better yet, never use command separators, as it makes the code hard to read.
 
Okay. I don't use separators often but sometimes it makes code much easier to read.
 
Back
Top Bottom