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.
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.
These can be set and read at will. w and h have width and height as aliases.
Returns a new array representing a rectangle covering all rectangles in array_of_rects.
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 .
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.
Returns whether thing ([x, y, w, h] or [x, y]) fits completely within the rectangle.
Sets self to the same position and size as rect. This is meant for optimizations. Returns self.
Returns an array with the rectangles in the list to overlaps the base rectangle. If no overlaps is found, it will return [].
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.
Returns a new rectangle which is the base rectangle moved by the given amount.
If w and h aren't positive, this will change them to positive and keep the rectangle covering the same space.
Returns true if any area of the two rectangles overlapss.
Returns whether rect is the same area as self.
Sets all properties at once. This is meant for optimizations.
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.
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.
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.
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] )
Removes the map from memory. This instance of CollisionMap will be useless from this call on.
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 )
Returns the size of the collision map.
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"
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
Loads an MPEG stream from file filename
Rect has been discarded. Its methods have moved to the standard Ruby Array. All these methods are now written in C.