这是我在Monkey X中用来尝试构建游戏的代码,最后的方法应该在游戏中绘制精灵,但它似乎注册为错误并且不允许该方法存在,是否存在我可以解决这个问题
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
在此之后,我查看了我的游戏的主要类别,除了这个之外它没有任何问题,并且由于其他原因,我似乎无法找到它的问题,但我努力尝试 . 我一直在关注如何在游戏中绘制精灵的教程,这与他做的完全相同,但它仍然不会注册方法 . 有没有人有任何想法,我可以解决这个问题,让游戏运行 .