Created: 2014-05-19 14:18
Updated: 2014-06-04 22:50

README.md

#Gosu API http://www.libgosu.org/rdoc

#Chipmunk API http://beoran.github.io/chipmunk/

Ruin API guide

require.rb

Thanks to our patented require_ALL_the_things(TM) technology, we may now require ALL the things. require.rb will require all ruby files in the src directory. It will then require all ruby files in the src subdirectories. It will then require all ruby files in the subdirectories of the src subdirectories, and so on. The idea is to put a file which has no dependencies into the src directory (such as entity.rb), then put those files which depend on it in a subfolder (such as entities).

(P.S. If you're requiring external libraries such as gosu and chipmunk, you can just add those to the top of require.rb in the traditional fashion.)

Ruin

initialize(w, h)

Create a new instance of Ruin with window dimensions w, h. Ruin inherits Gosu::Window, so you can access all of Gosu::Window's functionality through ruin.

addEntity(class_name, *params)

Add an entity to the ruin instance. This function instantiates the entity, passes the entity a reference to the ruin instance, and calls the entity's create() function, forwarding all of the *params.

print(text, x, y, color=0xFFAA0000)

Print text to the screen. Great for debugging!

_ms_x() and ms_y()

Returns the absolute x/y position of the mouse in the game world. For example, if your character is at x = 1000 and your mouse is hovering over him, then ms_x will return 1000.

_ms_x() and _ms_y()

Returns the relative x/y position of the mouse to the top-left corner of the screen. So if your character is at x = 1000, and your mouse is resting on top of him (he's currently in the center of a 800 x 600 screen) then _ms_x will return 400.

show_cursor(show_cursor)

Passing true will turn the cursor on, whereas passing false will hide it.

Entity

initialize(ruin)

DON'T USE THIS! I find it annoying to create instances, pass the game to them, then pass them to the game. Yeesh. To fix this, I've created the addEntity() method in Ruin, which will handle all this junk for you. Use the create() method to set up entities.

create()

This is called when the entity is added to the game. Put all of your creation / setup code here.

x(), y(), w(), and h()

The x, y location and width, height of the entity. They are all 0 by default. w,h are updated to match the size of the sprite (unless autowidth = false).

_draw() and _update()

These are called automatically by Ruin. _update() automatically increments the animation and then calls update(). _draw() just calls draw(). The idea is that base code for entity can be put here, and subclasses of entity can still override update() and draw() without overriding existing functionality. If you plan to create a class that will be implemented by subclasses, consider overriding _update() or _draw(), (don't forget to call super()), that way your subclasses won't have to worry about overriding functionality. Otherwise, just ignore these and use draw() and update()

update()

Once this entity is added to an instance of Ruin, the update() method will be called every step of the game.

draw()

Once this entity is added to an instance of Ruin, the draw() method will be called every time the screen needs to be drawn. Put your draw code here!

render()

This is a convenience function which will draw the current sprite at _x, _y. Call this only in the draw() method!

animation()

Returns the animation for this entity. (An animation is just an array of sprites. (Sprites are just images.))

animation=(path, animation_speed=1, tileable=true, autowidth=true)

Sets the animation for this entity. If path is a directory, the animation will be created from all images in the subdirectory (in alphanumeric order). If path is an image, that image will be used as the only frame for the animation. animation_speed will usually be 1 or a decimal (0.5 means one frame every two steps).

(P.S. Ruby has syntactic sugar which lets you treat this function like an assignment. IE instead of writing sprite=("myimage.png"), you can write self.sprite = "myimage.png")

sprite=(path, animation_speed=1, tileble=true, autowidth=true)

This is an alias for animation=, since static sprites are still stored as animations.

sprite()

Returns the current sprite/animation frame for this entity. If you do not want to use render(), sprite.draw is a good way to get more control over your sprite rendering.

Map

create(width, height)

Create a new map of width by height blocks. Typically, you would call this via something along the lines of: ruin.addEntity(Map,1000,1000)

block(x, y)

Use this to retrieve a block at a particular location! Ruby arrays wrap around, so @myarray[-1][0] gives you the value at @myarray[max,0]. Also, if @myarray[10] is nil, then @myarray[10][0] throws an error. This is irritating. The block(x,y) method will return nil if negative numbers are passed or if the x index doesn't exist. That way you can be sure that block(x,y) returns a block when it exists and nil when it doesn't! Yay!

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more