0
나는 간단한 게임을 다시 만들려고 노력하고 있지만, 나는 캐릭터 (또는 플레이어)를 뛰어 넘기 위해 노력하고있다. 나는 고수 (고수)의 예를보고 있었지만 나에게는 분명하지 않다. 누군가 나를 도울 수 있습니까? 여기 Ruby에서 Gosu gem으로 어떻게 이동할 수 있습니까?
내 창 코드 :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
기본적으로 생각이되며, 여기에 내가해야 애니메이션을 재현하여 "y"위치를 위로 이동시킨 다음 (예 : 15 픽셀) 다시 움직일 수 있습니다. 그냥 내 마음에 @y 변수의 값을 변경할 수 있지만 애니메이션을 사용하여 수행하고 원래 지점으로 돌아갈 방법을 모른다.
감사합니다.