0
我正在尝试重新创建一个简单的游戏,但当我尝试跳转我的角色(或玩家)时,我被卡住了。 我一直在检查gosu的例子,但对我来说并不是很清楚。 有人可以帮我吗?如何从Ruby跳上Gosu宝石?
这里是我的窗口代码:
class Game < Gosu::Window
def initialize(background,player)
super 640,480
self.caption = "My First Game!"
@background = background
@player = player
@player.warp(170,352)
@x_back = @y_back = 0
@allow_to_press = true
end
# ...
def update
#...
if Gosu.button_down? Gosu::KbSpace and @allow_to_press
@allow_to_press = false
@player.jump
end
end
end
然后我的播放器类:
class Player
def initialize(image)
@image = image
@x = @y = @vel_x = @vel_y = @angle = 0.0
@score = 0
end
def warp(x,y)
@x,@y = x,y
end
def draw
@image.draw_rot(@x,@y,1,@angle,0.5,0.5,0.3,0.3)
end
def jump
#@y -= 15 # THIS IS NOT CORRECT
end
end
基本上,这个想法是当u按空格键,然后跳转方法被调用,在这里,我要能够重新创建动画以将“y”位置向上移动(例如15px),然后再次下移。 只是我在我的脑海里改变了@y变量的值,但我不知道如何用动画做到这一点,然后回到原点。
谢谢!