School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,103 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,029 people online right now. Registration is fast and FREE... Join Now!




Create a Game in Ruby ~pt 1~

 
Reply to this topicStart new topic

> Create a Game in Ruby ~pt 1~, Requires the Gosu libary.

Rickster0
Group Icon



post 5 Oct, 2009 - 05:38 AM
Post #1


Ok im going to create a series of tuts on how to create a Very simple game in Ruby.

Firstly, you'll need the Gosu Lib. found HERE!

after you have that done. Create a folder for the project. then extract the Gosu folder (somewhere thats not in the project folder) then go into the Lib folder of gosu. copy "gosu.for_1_8.so", "gosu.rb" and "fmod.dll" into your project folder.

now. open up Notepad(or a texteditor of your choice) and put this code in:
CODE
require 'gosu'

class GameWindow < Gosu::Window
  def initialize
    super(640, 480, false)
    self.caption = "Gosu Window"
  end

  def update
  end

  def draw
  end
end

window = GameWindow.new
window.show


now save it as main.rb and run.

now i shall explain what all this does.

CODE
require 'gosu'

this allows the ruby file to use Gosu's built in classes.

CODE
class GameWindow < Gosu::Window

creates a new class defined by the Gosu::Window class, allowing you to create a window.

CODE
def initialize
    super(640, 480, false)
    self.caption = "Gosu Window"
  end


when the GameWindow is created, it sets up a new window of 640 width and 480 hight, with a caption of Gosu Window.

CODE
window = GameWindow.new
window.show

creates a new instance of the GameWindow class, then displays it on the screen.

if there are any problems feel free to ask.

the next part of this tut will show you how to create a sprite on the screen and move it using the arrow keys .. keep a look out biggrin.gif







Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 12:32PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month