daily pastebin goal
34%
SHARE
TWEET

Sem usar a classe Struct

DaxSoft Mar 31st, 2014 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Iremos criar uma classe onde irá guardar as informações de posições X e Y.
  2. #   O efeito é simples, e fazer com que um bloco branco vai e volte ao apertar
  3. # Space.
  4. class Pos
  5.   def initialize(x, y)
  6.     @x, @y = x, y
  7.   end
  8.   def x
  9.     return @x
  10.   end
  11.   def y
  12.     return @y
  13.   end
  14. end
  15.  
  16. block = Sprite.new
  17. block.x, block.y = 16, 16
  18. block.bitmap = Bitmap.new(32, 32)
  19. block.bitmap.fill_rect(block.rect, Color.new(255, 255, 255))
  20.  
  21. position = Pos.new(block.x, block.y)
  22.  
  23. speed = 8
  24. slide = false
  25.  
  26. loop {
  27. Graphics.update
  28. Input.update
  29. if Input.trigger?(:C)
  30.   slide = slide ? false : true
  31.   print "Slide: #{slide}" << "\n"
  32. end
  33. if slide
  34.   block.x += speed unless block.x >= Graphics.width - 32
  35. else
  36.   block.x -= speed unless block.x <= position.x
  37. end
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top