Jump to content

Ruby Dash


gameus
 Share

Recommended Posts

Posted Image


What is Ruby Dash?

What is Ruby Dash you might be asking? If you know what MLP is I know exactly whats going through your mind. Let me tell you that this project has nothing to do with Rainbow Dash from MLP. This is a game engine I am creating using C# and XNA with Ruby scripting support. That means you'll be able to create 2-D games from scratch using Ruby. Thus removing the hassles of you having to setup your own development environment. This project will allow you to start creating 2-D games very quickly using the main script support, hence the word "dash" and the word "ruby". Oh and because I fucking love Rainbow Dash. <3

About

The main heart and flames of this project is for a grade. I'm in a software development class where I don't do follow the cirriculum the rest of the class follows. My teacher grades me on software and web programs I create. I told her I'd be doing a game engine which might take a bit longer then any of the other stuff she graded me on. Other noteworthy things is that this project will be completely free for use by anyone. I'll probably make it open source and you'll be able to use creations you make commercial or non-commercial without any royalties. (As long as proper credit is given to the original engine.) More on licenses and copyright later.

Behind the Engine

So the engine runs off of C#. A pre-compiled language. (Code must be compiled before use) So its hard to create a dynamic engine unless you decide to use a scripting language that uses a dynamic language (ruby, php, lua, python). I'm also using XNA which is basically a DirectX interface to C# allowing you to create 2D and 3D games without all the hassle of setting up an environment for that. In order for me to be able to use Ruby as a scripting language, I have to use IronRuby. Basically a Ruby processor and interpreter between Ruby and C#. I can expose C# classes to Ruby and visa versa.

The current version of IronRuby is running Ruby 1.9 which is pretty fast compared to previous versions of ruby.

What to Expect and Things to Note

Unfortunately, this engine will only be available to people runnings the Windows OS. I'm not experienced with C++ or C enough to be able to create the engine and embed ruby. If I were, I'd gladly compile everything on a Mac and a Linux OS so everyone would be able to enjoy it. All in good time though my friends. :)

As for beta-releases and debug-builds, there won't be an editor or tools to pack a game. Really, all an editor will consist of is a textbox with syntax highlighting. Hell I might include that with every build. However, tools to distribute a game probably won't come out for awhile after the initial version. Packing your game will come with XNA 4.0 Redist. I plan on finding a way to pack graphics and scripts but as an indie developer I could really care less if people use my content as long as credit is given. But not everyone is like me.

The engine is being made for 2D purposes, but because XNA is also for 3D games, you'll most likely be able to create 3D games with the engine as well. Also, being that it is IronRuby, you'll be able to import .NET assemblies and use them in your code. Opening up the .NET world to Ruby is pretty damn awesome. The engine will also have dynamic image generation using .net GDI+ so you don't have to make a graphic for everything. XNA lacks that but I'm bringing it in. You'll also be able to export generated images to actual files.

Script Example

Bouncy Balls



Here's the full script file.

include Ruby
include Microsoft::Xna::Framework::Input

class BouncyBall
	attr_accessor :sprite
	def initialize
		@hspeed = 2 + rand(10)
		@vspeed = 2 + rand(10)
		@sprite = Sprite.new
		@sprite.x = rand(Hook.screenWidth - 32)
		@sprite.y = rand(Hook.screenHeight - 32)
		@sprite.bitmap = Bitmap.new(32, 32)
		@sprite.bitmap.fillEllipse(0, 0, 32, 32, Color.new(rand(255), rand(255), rand(255)))
		@sprite.bitmap.drawEllipse(0, 0, 32, 32, Color.new(0, 0, 0))
	end
	def update
		@sprite.x += @hspeed
		@sprite.y += @vspeed
		@hspeed = -@hspeed if @sprite.x > Hook.screenWidth - 32 || @sprite.x < 0
		@vspeed = -@vspeed if @sprite.y > Hook.screenHeight - 32 || @sprite.y < 0
	end
end

class Main
	def initialize
		@sprite = Sprite.new
		@sprite.bitmap = Bitmap.new(480, 64)
		@sprite.bitmap.drawText("Press Space to Add Ball", 0, 0)
		@sprite.bitmap.drawText("Press LCtrl to Remove Ball", 0, 32)
		@balls = []
		@balls.push(BouncyBall.new)
	end
	def update
		for i in @balls
			i.update
		end
		if Input.trigger(Keys.Space)
			@balls.push(BouncyBall.new)
		end
		if Input.trigger(Keys.LeftControl)
			@balls[@balls.size - 1].sprite.dispose
			@balls.delete_at(@balls.size - 1)
		end
	end
end

$main = Main.new



Here's an example script that runs perfectly in my engine as of right now. However, I plan on making it so you don't have to use a draw command, I want to make it so all drawable objects you create, will be drawn onto the screen automatically.

Due to the code block not showing up right, here's the pastebin link.
http://pastebin.com/H9n26edR

include Ruby
load_assembly 'Microsoft.Xna.Framework'
include Microsoft::Xna::Framework::Input

dialog = Dialog.new
dialog.message = "Dear C#,rn  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



The update and draw methods are being called on the C# side. The C# side also grabs the player variable from the ruby code and has access to all of its methods and variables. Just an example of using both languages with each other. By the way, this example produces this, which runs pretty fast. (The "Player" text is movable. Will post a video later)

Posted Image




Also this chunk of code

dialog = Dialog.new
dialog.message = "Dear C#,rn  Its Ruby, interfacing you."
dialog.title = "IronRuby Tests"
dialog.button = DialogButtons.OK
result = dialog.show
Produces this. You'll be able to have standard message boxes with customizable title, message, and buttons. The dialog also returns a result depending on button pressed, which you then can compare using if branches and whatnot.
Posted Image

Some More Screenshots[/b]

I'll add more screenshots and videos here. Right now I don't have much more to show.

Final Notes

The physical actual release date is set to be in April or May, however, I'd love to show off my work so I'll have plenty of demos and test builds to release to the community. When these demos will come, I can't tell, but be assured I will release some.

Dear tl;dr users
I assure you, if you're a programmer, you might be interested in this project. Even if you're not a programmer, you still might be intersted. If not, feel free to move along and don't post a stupid reply like this.

tl;dr

Whats this project about now?


I'll have plenty more information coming too. I'll eventually create its own webpage for it over at http://decisive-media.net and probably a wiki. But I hope this will interest a couple of people, a little bit of motivation goes a long way.
Link to comment
Share on other sites

Instances of the "Sprite" class are now automatically drawn. So I don't have to hardcode a "draw" method like in the previous code example. This example shows a lightweight example of a sprite being initialized,

 

This (http://pastebin.com/0i0rUx3S)

 

include Ruby
load_assembly 'Microsoft.Xna.Framework'
include Microsoft::Xna::Framework::Input

class Main
    def initialize
        @sprite = Sprite.new
        @sprite.bitmap = Bitmap.new(32, 32)
        @sprite.bitmap.drawRect(0, 0, 31, 31, Color.new(255, 0, 0))
    end
    def update
        if Input.trigger(Keys.Space)
            @sprite.bitmap.fillRect(1, 1, 30, 30, Color.new(0, 255, 0))
        end
    end
end

$main = Main.new

 

 

Which produces this.

Posted Image

And after you press the Space key, it changes to this.

Posted Image

 

I'll have a demo you can tinker with this weekend. You'll be able to load graphics, create graphics dynamically from code, and draw them of course.

Link to comment
Share on other sites

The projects taking a new turn. I'm using the Windows API Code pack which comes with managed DirectX code. This opens up a few more doors with what this engine will be able to do. It'll take a couple of days to convert my methods from XNA to DirectX but I still plan on having a demo this weekend.

Link to comment
Share on other sites

 

Here's the full script file.

 

include Ruby
include Microsoft::Xna::Framework::Input

class BouncyBall
	attr_accessor :sprite
	def initialize
		@hspeed = 2 + rand(10)
		@vspeed = 2 + rand(10)
		@sprite = Sprite.new
		@sprite.x = rand(Hook.screenWidth - 32)
		@sprite.y = rand(Hook.screenHeight - 32)
		@sprite.bitmap = Bitmap.new(32, 32)
		@sprite.bitmap.fillEllipse(0, 0, 32, 32, Color.new(rand(255), rand(255), rand(255)))
		@sprite.bitmap.drawEllipse(0, 0, 32, 32, Color.new(0, 0, 0))
	end
	def update
		@sprite.x += @hspeed
		@sprite.y += @vspeed
		@hspeed = -@hspeed if @sprite.x > Hook.screenWidth - 32 || @sprite.x < 0
		@vspeed = -@vspeed if @sprite.y > Hook.screenHeight - 32 || @sprite.y < 0
	end
end

class Main
	def initialize
		@sprite = Sprite.new
		@sprite.bitmap = Bitmap.new(480, 64)
		@sprite.bitmap.drawText("Press Space to Add Ball", 0, 0)
		@sprite.bitmap.drawText("Press LCtrl to Remove Ball", 0, 32)
		@balls = []
		@balls.push(BouncyBall.new)
	end
	def update
		for i in @balls
			i.update
		end
		if Input.trigger(Keys.Space)
			@balls.push(BouncyBall.new)
		end
		if Input.trigger(Keys.LeftControl)
			@balls[@balls.size - 1].sprite.dispose
			@balls.delete_at(@balls.size - 1)
		end
	end
end

$main = Main.new

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.