rudl_video_bitmask

Back to index

# Index

CollisionMap
Class Methods
`CollisionMap#new( surface )`
`CollisionMap#new( size )`
`CollisionMap#collides_with( own_coord, other_map, other_coord )`
`CollisionMap#destroy`
`CollisionMap#set( coord )`
`CollisionMap#unset( coord )`
`CollisionMap#[ x, y ]`
`CollisionMap#[ x, y ]= collidebit`
`CollisionMap#size`

# CollisionMap

This code is "bitmask" from <URL:http://www.ifm.liu.se/~ulfek/projects/2d_Collision_Detection.html>

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

`CollisionMap#new( surface )`
`CollisionMap#new( size )`

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 )

`CollisionMap#collides_with( own_coord, other_map, other_coord )`

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 Surface#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] )

`CollisionMap#destroy`

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

`CollisionMap#set( coord )`
`CollisionMap#unset( coord )`

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"

`CollisionMap#[ x, y ]`
`CollisionMap#[ x, y ]= collidebit`

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.

`CollisionMap#size`

Returns an array of [width, height] of the collision map.

Back to index