Guest User

Untitled

a guest
Apr 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.27 KB | None | 0 0
  1. include Ruby
  2. load_assembly 'Microsoft.Xna.Framework'
  3. include Microsoft::Xna::Framework::Input
  4.  
  5. dialog = Dialog.new
  6. dialog.message = "Dear C#,\r\n  Its Ruby, interfacing you."
  7. dialog.title = "IronRuby Tests"
  8. dialog.button = DialogButtons.OK
  9. result = dialog.show
  10.  
  11. class PlayerObject
  12.  
  13.     attr_accessor :x
  14.     attr_accessor :y
  15.     attr_accessor :sprite
  16.    
  17.     def initialize
  18.         @bitmap = Bitmap.new(128, 32)
  19.         @bitmap.drawRect(0, 0, 127, 31, Color.new(255, 0, 0))
  20.         @bitmap.drawText("Player", 0, 0)
  21.         @playerLocation = Bitmap.new(200, 200)
  22.         @playerLocation.drawText("X: 128", 4, 4)
  23.         @playerLocation.drawText("Y: 128", 4, 32)
  24.         @x = 128
  25.         @y = 128
  26.         @hspeed = 2
  27.         @vspeed = 3
  28.     end
  29.    
  30.     def update
  31.         @y -= @vspeed if Input.press(Keys.Up)
  32.         @y += @vspeed if Input.press(Keys.Down)
  33.         @x += @hspeed if Input.press(Keys.Right)
  34.         @x -= @hspeed if Input.press(Keys.Left)
  35.     end
  36.    
  37.     def draw
  38.         @playerLocation.clear
  39.         @playerLocation.drawText("X: " + @x.to_s, 4, 4)
  40.         @playerLocation.drawText("Y: " + @y.to_s, 4, 32)
  41.         $kernel.drawSprite(@playerLocation, 4, 4)
  42.         $kernel.drawSprite(@bitmap, @x, @y)
  43.     end
  44. end
  45.  
  46. player = PlayerObject.new
Add Comment
Please, Sign In to add comment