Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Iremos criar uma classe onde irá guardar as informações de posições X e Y.
- # O efeito é simples, e fazer com que um bloco branco vai e volte ao apertar
- # Space.
- class Pos
- def initialize(x, y)
- @x, @y = x, y
- end
- def x
- return @x
- end
- def y
- return @y
- end
- end
- block = Sprite.new
- block.x, block.y = 16, 16
- block.bitmap = Bitmap.new(32, 32)
- block.bitmap.fill_rect(block.rect, Color.new(255, 255, 255))
- position = Pos.new(block.x, block.y)
- speed = 8
- slide = false
- loop {
- Graphics.update
- Input.update
- if Input.trigger?(:C)
- slide = slide ? false : true
- print "Slide: #{slide}" << "\n"
- end
- if slide
- block.x += speed unless block.x >= Graphics.width - 32
- else
- block.x -= speed unless block.x <= position.x
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement