Misc

# Array

The standard Ruby array class has been extended to provide methods for using it as a rectangle. Arrays like these have entries 0, 1, 2 and 3 set to floating point values for x, y, width and height.

[10,15,20,25] would be a 20x25 rectangle at position 10,15.

So far these methods are mostly untested.

## Class Methods

#### collide_lists( l1, l2 )

This method looks through list l1, checking collisions with every object in list l2. It does this by calling "rect" on all objects, expecting an array of [x,y,w,h] back, defining the area this object is in. It yields (object_from_l1, object_from_l2) for every collision it detects. A more advanced collision detection method can be found in CollisionMap.

#### h
h=( h )

These can be set and read at will. w and h have width and height as aliases.

#### union_list( array_of_rects )

Returns a new array representing a rectangle covering all rectangles in array_of_rects.

#### w
w=( w )

#### x
x=( x )

#### y
y=( y )

## Instance methods

#### bottom
bottom=( bottom )

These can be set and read at will. Differences with x, y, w and h are: * right and bottom are screen coordinates. right is x + w and bottom is y + h .

#### clamp( rect ) → [x, y, w, h]
clamp!( rect ) → nil

Returns a new rectangle that is moved to be completely inside the base rectangle. If the given rectangle is too large for the base rectangle in an axis, it will be centered on that axis.

#### contains?( thing ) → boolean

Returns whether thing ([x, y, w, h] or [x, y]) fits completely within the rectangle.

#### copy_from( rect ) → self

Sets self to the same position and size as rect. This is meant for optimizations. Returns self.

#### find_overlapping_rects( rects ) → [ [x, y, w, h], ... ]

Returns an array with the rectangles in the list to overlaps the base rectangle. If no overlaps is found, it will return [].

#### inflate( sizes ) → [x, y, w, h]
inflate!( sizes ) → self

Returns a rectangle which has the sizes changed by the given amounts. sizes is an array of [dx, dy]. The rectangle shrinks and expands around the rectangle's center. Negative values will shrink the rectangle.

#### left
left=( left )

#### move( delta )
move!( delta )

Returns a new rectangle which is the base rectangle moved by the given amount.

#### normalize → self
normalize! → [x, y, w, h]

If w and h aren't positive, this will change them to positive and keep the rectangle covering the same space.

#### overlaps?( rect ) → boolean

Returns true if any area of the two rectangles overlapss.

#### right
right=( right )

#### same_size?( rect )

Returns whether rect is the same area as self.

#### set_coordinates( x, y, w, h ) → self

Sets all properties at once. This is meant for optimizations.

#### top
top=( top )

#### union( rect ) → [x, y, w, h]
union!( rect ) → self

Returns a new rectangle that completely covers the given rectangle(s). There may be an area inside the new rectangle that is not covered by the inputs. Rectangles are pre-normalized.

# CollisionMap

This code is "bitmask" from Ulf Ekstrom

This class contains a map of all the visible pixels in a surface. (That's the ones that don't have the color key's color) With it, you can detect whether any pixels in a surface and another surface overlap when they are at two specific positions.

## Class Methods

#### [ x, y ] → Number
[ x, y ]= collidebit → self

The array operator accesses single points in the collision map, in case you want to have collision with parts of a surface that weren't color keyed, or you want parts of the surface to appear "untouchable".

If collidebit is set to 0, no collision will be detected for that point. If it is set to anything else, it will be set to 1 and collisions will be checked at that point.

#### collides_with( own_coord, other_map, other_coord ) → [hit_x, hit_y] or nil

This returns the first found overlapping (colliding) pixel for two collision maps, or nil if no collision occurred. The coordinates specify where the two maps are, which will probably mean that the two surfaces are blitted to the screen at those coordinates.

If using the collision_map attribute, you would get for one surface at [10,10] and another at [20,20]: `onesurface.collision_map( [10,10], other_surface.collision_map, [20,20] )`

#### destroy → nil

Removes the map from memory. This instance of CollisionMap will be useless from this call on.

#### new( surface ) → CollisionMap
new( size ) → CollisionMap

Creates a new collision map.

Supplying a Surface will create the map with the information from surface. The map will not be automatically updated when the surface contents change, so a new CollisionMap will have to be made each time. The Surface's colorkey will be used to identify "uncollidable" area's.

Supplying a size array: [w, h] will create an empty bitmask of that size.

Surface has an attribute, collision_map, that you can use to attach a CollisionMap to. RUDL doesn't use that attribute for itself. The syntax would be:

`some_surface.collision_map=CollisionMap.new( some_surface )`

#### set( coord ) → self

#### size → [w, h]

Returns the size of the collision map.

#### unset( coord ) → self

This fills and erases one point in the collision map, in case you want to have collision with parts of a surface that weren't color keyed, or you want parts of the surface to appear "untouchable"

# Movie

The Movie object represents an opened MPEG file. You control playback similar to a Sound object.

Movie objects have a target Surface. The movie is rendered to this surface in a background thread. If the surface is the DisplaySurface, and the system supports it, the movie will render into a hardware YUV overlay plane. If you don't set a target surface, it will default to the DisplaySurface.

Movies are played back in background threads, so there is very little management needed on the user end. Just load the Movie, set the destination, and play

This is not usable yet

## Class Methods

#### new( filename )

Loads an MPEG stream from file filename

# Rect

Rect has been discarded. Its methods have moved to the standard Ruby Array. All these methods are now written in C.