0

this is the code that i am using in Monkey X to try and build a game, the final method is supposed to draw the sprite within the game but it seems to register as an error and does not allow the method to be there, is there any way i can fix this

Import mojo

Class Vec2D
    Field x: Float
    Field y: Float

    Method New (x: Float = 0, y: Float = 0)
        set( x, y)
    End

    Method set (x: Float, y: Float)
        Self.x = x
        Self.y = y
    End
End

Class Vec2Di
    Field x: int
    Field y: int

    Method New (x: int = 0, y: int = 0)
        set( x, y)
    End

    Method set (x: int, y: int)
        Self.x = x
        Self.y = y
    End
End

Class Player
    Field OriginalPosition: Vec2D
    Field Position: Vec2D
    Field Velocity: Vec2D

    Field SpeedLR: Float = 2.0
    Field SpeedUD: Float = 4.0

    Field leftKey: Int
    Field rightKey: Int
    Field upKey: Int
    Field downKey: Int

    Method New(leftKey: Int, rightKey: Int, upKey: Int, downKey:Int, x: Float, y: Float)
        OriginalPosition = New Vec2D(x, y)
        Position = New Vec2D(x, y)
        Velocity = New Vec2D()

        Self.leftKey = leftKey
        Self.rightKey = rightKey
        Self.upKey = upKey
        Self.downKey = downKey

    End

    Method Update()
        Velocity.x = 0
        Velocity.y = 0

        If KeyDown (leftKey)
            Velocity.x = -SpeedLR
        If KeyDown (rightKey)
            Velocity.x = SpeedLR

        If KeyDown (upKey)
            Velcity.y = SpeedUD
        If KeyDown (downKey)
            Velocity.y = -SpeedUD

        End

        Position.x += Velocity.x
        Position.y += Velocity.y

    End

    Method Draw()
        SetColor (0, 255, 0)

        DrawRect (Position.x-16, Position.y-16, 32, 32)

    End

End

after this i looked into the main catagory of my game and it has no problems apart from this one and for sopme reason i cannot seem to find the problem with it however hard i try. I have been following a tutorial on how to draw a sprite in game and this has been the exact same way that he did it but it still will not register the method. Does anyone have any ideas on a way that i can fix this issue and get the game to run.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
DavNav
  • 1
  • 1

0 Answers0