JonBoy_Sprite_Tech_3
("SECTOR Collision Detection with up to 40 Sprites")
September 2, 2002 (version 0.7.0)
by JonBoy (jonboy@stdnet.com - http://people.stdnet.com/jonathan)

This demo shows how to use sectors with your sprite collision logic to avoid comparing each sprite with all other sprites.  During initialization, 16 graphic sectors are built.  During each iteration, each sprite "registers" in 1-4 different sectors.  Then, rather than check for collisions within the entire array of sprite objects, each sector checks for collisions in its realm.  The results of these collisions are queued and sorted so duplicate "collision events" can be removed.  

The MAXIMUM "comfortable" number of sprites this code supports is 40.  (44 sprites turn very jittery on my screen.)  This is probably enough to start thinking about the "Asteroid" code I want to write...hopefully application logic (i.e. asteroids cannot collide with other asteroids, so don't check them) will increase this number a bit further, but this is the end of sprite collision demos for now.

+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+


jonboy_sprite documentation

- "NEW": jonboy_sprite(CommonName, SpriteSet, X, Y, Direction, Speed)
  - CommonName: A name for the sprite.  (i.e. "Koopa") Need not be unique.
  - SpriteSet: The name of a Sphere sprite set.  (i.e. "tinyrock.rss") 
    - In this version, jonboy_sprite will only use the FIRST image in the set.
    - A rectangular bounding box (x1,y1,x2,y2) is derived from the spriteset's "base" to assist in RECTANGULAR comparisons
    - A circular center (x,y) and radius is also derived from the spriteset's "base" to assist in CIRCULAR comparisons (not tested)
  - X: The initial X-coordinate of the sprite
  - Y: The initial Y-coordinate of the sprite
  - Direction: The initial direction of the sprite (in RADIANS, 0=NORTH)
  - Speed: The initial speed of the sprite (60 = "normal" walking speed)
- PROPERTIES:
  - direction: (read/write) Direction of sprite. (in RADIANS, 0=NORTH))
  - ID: (read-only, not tested) The 12-char ID.
  - name: (read-only, not tested)  The common name.
  - speed: (read/write) Speed of sprite. (60 = "normal" walking speed) 
  - rectX1: (read-only) Right coordinate of bounding rectangle.
  - rectX2: (read-only) Left coordinate of bounding rectangle.
  - rectY1: (read-only) Top coordinate of bounding rectangle.
  - rectY2: (read-only) Bottom coordinate of bounding rectangle.
  - roundRadius: (read/write, not tested) Radius of bounding circle. 
  - roundX: (read-only, not tested) X-coordinate of bounding circle center.
  - roundY: (read-only, not tested) Y-coordinate of bounding circle center.
  - X: (read/write) X-coordinate of sprite.  
  - Y: (read/write) Y-coordinate of sprite.  
- METHODS:
  - registerinsectors(): Registers this sprite in 1-4 graphics sectors.
  - render(): Draws this sprite to the video buffer.
  - update(): Updates position (X,Y) of the sprite based on direction and speed.  Also "wraps" the sprite to the top or bottom of the screen if it falling off the edge.

+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+

* * * REFERENCES * * * 

Look up "Collision Detection - Getting the most out of you collision test" by Dave Roberts (circa 1995) in the "Dr. Dobbs" journal (www.ddj.com)

* * * TECH * * * 
Tested under Sphere Engine v0.97 for Windows (June 17, 2002 release) on Windows 2000 Server

* * * KNOWN ISSUES * * * 
- Even though different sprites are used, there is no "application" logic in this demo.  (i.e. Fireballs and Goombas simply bounce off one another.)      
- Events are still not passed directly to sprite objects, although by now it should be easy to see how you could do it yourself. (i.e. on collision, call sprite1.collide(sprite2) and sprite2.collide(sprite1).)  
