class Animation
attr_accessor :data , :state , :player , :n
def initialize player
@player = player
@data = data
@state = state
@n = n
@n = 0
datarip()
end
def datarip
file = Read.new
data = file.yaml_read("data/images.yml")
@data = data['images']
@state = @data[@n]
display()
end
def display
@player.image = Rubygame::Surface.load_image(@state)
end
def change
@n += 1
if @n == 3
@n = 0
end
@state = @data[@n]
display()
end
def down
@player.image.rotozoom(180,0,true)
end
def right
@player.image.rotozoom(90,0,true)
end
def left
@player.image.rotozoom(-90,0,true)
end
end
Move class
class Move
attr_accessor :x , :y , :animate , :move , :direct
def initialize player
@x = x
@x = player.rect.x
@y = y
@y = player.rect.y
@animate = animate
@animate = Animation.new(player)
@move = move
@move = false
@direct = direct
end
def right
@x += 8
@animate.change()
@animate.right()
end
def left
@x -= 8
@animate.change()
@animate.left()
end
def up
@y -= 8
end
def down
@y += 8
@animate.change()
@animate.down()
end
def action
if @move == true
case @direct
when 1
down()
when 2
up()
when 3
left()
when 4
right()
end
end
end
end