Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include Ruby
- load_assembly 'Microsoft.Xna.Framework'
- include Microsoft::Xna::Framework::Input
- dialog = Dialog.new
- dialog.message = "Dear C#,\r\n Its Ruby, interfacing you."
- dialog.title = "IronRuby Tests"
- dialog.button = DialogButtons.OK
- result = dialog.show
- class PlayerObject
- attr_accessor :x
- attr_accessor :y
- attr_accessor :sprite
- def initialize
- @bitmap = Bitmap.new(128, 32)
- @bitmap.drawRect(0, 0, 127, 31, Color.new(255, 0, 0))
- @bitmap.drawText("Player", 0, 0)
- @playerLocation = Bitmap.new(200, 200)
- @playerLocation.drawText("X: 128", 4, 4)
- @playerLocation.drawText("Y: 128", 4, 32)
- @x = 128
- @y = 128
- @hspeed = 2
- @vspeed = 3
- end
- def update
- @y -= @vspeed if Input.press(Keys.Up)
- @y += @vspeed if Input.press(Keys.Down)
- @x += @hspeed if Input.press(Keys.Right)
- @x -= @hspeed if Input.press(Keys.Left)
- end
- def draw
- @playerLocation.clear
- @playerLocation.drawText("X: " + @x.to_s, 4, 4)
- @playerLocation.drawText("Y: " + @y.to_s, 4, 32)
- $kernel.drawSprite(@playerLocation, 4, 4)
- $kernel.drawSprite(@bitmap, @x, @y)
- end
- end
- player = PlayerObject.new
Add Comment
Please, Sign In to add comment