Author Topic: Sprite Library Layering  (Read 5166 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Sprite Library Layering
« on: October 08, 2018, 03:45:38 pm »
I was having a few really hard to track down issues with layering so I decided to break the sprite library into modules for easy debugging and coding. This is the library control and layering routines section. I have all the layering issues sorted out now and the little parallax demo below shows how easy the layers are to manipulate.

You can move the mouse to the right or left on the image to get the scrolling to change direction.

You'll need the layers.zip file as well that contains 7 layer images.

Code: QB64: [Select]
  1.  
  2.  
  3. CONST SL_ALL = -32767
  4. CONST SL_VALID = -32766
  5. CONST SL_DEST = -32765
  6. CONST SL_SOURCE = -32764
  7. CONST SL_VISIBLE = -32763
  8. CONST SL_INVISIBLE = -32762
  9. CONST SL_LEFT = -32761
  10. CONST SL_TOP = -32760
  11. CONST SL_RIGHT = -32759
  12. CONST SL_BOTTOM = -32758
  13. CONST SL_CENTERX = -32757
  14. CONST SL_CENTERY = -32756
  15. CONST SL_WIDTH = -32755
  16. CONST SL_HEIGHT = -32754
  17. CONST SL_GET = -32753
  18. CONST SL_TOTAL = -32752
  19. CONST SL_UP = -32751
  20. CONST SL_DOWN = -32750
  21. CONST SL_UPRIGHT = -32749
  22. CONST SL_DOWNRIGHT = -32748
  23. CONST SL_DOWNLEFT = -32747
  24. CONST SL_UPLEFT = -32746
  25.  
  26.  
  27.  
  28. TYPE SL_RECT '                          RECTANGULAR OBJECT PROPERTIES
  29.     left AS INTEGER
  30.     top AS INTEGER
  31.     right AS INTEGER
  32.     bottom AS INTEGER
  33.     centerx AS INTEGER
  34.     centery AS INTEGER
  35.     height AS INTEGER
  36.  
  37. TYPE SL_ROUND
  38.     centerx AS INTEGER
  39.     centery AS INTEGER
  40.     radius AS INTEGER
  41.  
  42. TYPE SL_LAYERS ' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ LAYER DATABASE ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  43.     image AS LONG '                     software image of screen layer
  44.     visible AS INTEGER '                -1 (TRUE) if layer is visible
  45.     dest AS INTEGER '                   -1 (TRUE) if layer is destination   ** needed? **
  46.     source AS INTEGER '                 -1 (TRUE) if layer is source        ** needed? **
  47. END TYPE ' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  48.  
  49. TYPE SL_GLOBAL ' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ GLOBALS DATABASE ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  50.     screen AS SL_RECT '                 screen coordinate properties
  51.     framerate AS INTEGER '              global frame rate
  52.     source AS INTEGER '                 current source layer                        0 - x, 0 for main screen, -1 if no layer is a source
  53.     destination AS INTEGER '            current destination layer                   0 - x, 0 for main screen, -1 if no layer is a destination
  54. END TYPE ' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  55.  
  56. REDIM SL_layer(1) AS SL_LAYERS '       master layer array
  57. DIM SL_global AS SL_GLOBAL '            common globals
  58.  
  59.  
  60. ' main program (for testing)
  61.  
  62.  
  63. DIM layer AS INTEGER
  64. DIM direction AS INTEGER
  65.  
  66.  
  67. SL_WINDOW 960, 540, 7
  68.  
  69. SL_SET_LAYER 7, SL_DEST
  70. _PUTIMAGE , _LOADIMAGE("layer7.png", 32)
  71. SL_SET_LAYER 6, SL_DEST
  72. _PUTIMAGE , _LOADIMAGE("layer6.png", 32)
  73. SL_SET_LAYER 5, SL_DEST
  74. _PUTIMAGE , _LOADIMAGE("layer5.png", 32)
  75. SL_SET_LAYER 4, SL_DEST
  76. _PUTIMAGE , _LOADIMAGE("layer4.png", 32)
  77. SL_SET_LAYER 3, SL_DEST
  78. _PUTIMAGE , _LOADIMAGE("layer3.png", 32)
  79. SL_SET_LAYER 2, SL_DEST
  80. _PUTIMAGE , _LOADIMAGE("layer2.png", 32)
  81. SL_SET_LAYER 1, SL_DEST
  82. _PUTIMAGE , _LOADIMAGE("layer1.png", 32)
  83.  
  84.     _LIMIT 30
  85.     IF _MOUSEX < SL_GET_SCREEN(SL_CENTERX) THEN direction = SL_RIGHT ELSE direction = SL_LEFT
  86.     FOR layer = 1 TO 7
  87.         SL_SHIFT_LAYER layer, direction, 8 - layer
  88.     NEXT layer
  89.     SL_DISPLAY
  90.  
  91. SL_QUIT
  92.  
  93.  
  94.  
  95.  
  96. 'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  97. '                                                                    ----------==========                         ==========----------
  98. '                                                                    ----------========== LIBARY CONTROL ROUTINES ==========----------
  99. '                                                                    ----------==========                         ==========----------
  100. 'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  101.  
  102. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  103. SUB SL_WINDOW (swidth AS INTEGER, sheight AS INTEGER, layers AS INTEGER) '                                                                                                                    SL_WINDOW
  104.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  105.  
  106.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  107.     SHARED SL_global AS SL_GLOBAL '     common globals
  108.     DIM layer AS INTEGER '              layer counter
  109.  
  110.     IF layers < 1 THEN '                                                                                creating at least one layer?
  111.         SL_error "SL_WINDOW", 1, "" '                                                                   no, report error to programmer
  112.     END IF
  113.     IF swidth < 1 OR sheight < 1 THEN '                                                                 window width and/or height greater than zero?
  114.         SL_error "SL_WINDOW", 2, "" '                                                                   no, report error to programmer
  115.     END IF
  116.     REDIM SL_layer(layers) AS SL_LAYERS '                                                               increase layer array to match requested number of layers
  117.     SL_global.screen.width = swidth '                                                                   save screen dimensions
  118.     SL_global.screen.height = sheight
  119.     SL_global.screen.top = 0
  120.     SL_global.screen.left = 0
  121.     SL_global.screen.right = swidth - 1
  122.     SL_global.screen.bottom = sheight - 1
  123.     SL_global.screen.centerx = swidth \ 2 - 1
  124.     SL_global.screen.centery = sheight \ 2 - 1
  125.     layer = 0 '                                                                                         reset layer counter
  126.     DO '                                                                                                cycle through layers
  127.         layer = layer + 1 '                                                                             increment layer counter
  128.         SL_layer(layer).image = _NEWIMAGE(swidth, sheight, 32) '                                        create layer software image
  129.         SL_layer(layer).visible = -1 '                                                          (TRUE)  layer is visible
  130.     LOOP UNTIL layer = UBOUND(SL_layer) '                                                               leave when all layers created
  131.     SCREEN _NEWIMAGE(swidth, sheight, 32) '                                                             initialize working screen
  132.     SL_SET_LAYER 1, SL_DEST '                                                                           set layer 1 as the destination
  133.     SL_SET_LAYER 1, SL_SOURCE '                                                                         set layer 1 as the source
  134.  
  135.  
  136. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  137. SUB SL_DISPLAY () '                                                                                                                                                                          SL_DISPLAY
  138.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  139.  
  140.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  141.     SHARED SL_global AS SL_GLOBAL '     common globals array
  142.     DIM layer AS INTEGER '              layer counter
  143.     DIM merge AS LONG '                 software image to merge all layers onto
  144.     DIM hwimage AS LONG '               final hardware image of merged layers
  145.  
  146.     merge = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '                            create image to merge layers
  147.     layer = UBOUND(SL_layer) '                                                                          start with the highest numbered layer
  148.  
  149.     DO '                                                                                                cycle through layers backwards (high to low)
  150.         IF SL_layer(layer).visible THEN '                                                               is this layer visible?
  151.             _PUTIMAGE , SL_layer(layer).image, merge '                                                  place this layer onto merge image
  152.         END IF
  153.         layer = layer - 1 '                                                                             decrement layer counter
  154.     LOOP UNTIL layer = 0 '                                                                              leave when all layers merged
  155.     hwimage = _COPYIMAGE(merge, 33) '                                                                   create hardware image of merged layers
  156.     _PUTIMAGE , hwimage, 0 '                                                                            place hardware image on main screen
  157.     _FREEIMAGE merge '                                                                                  merged software image no longer needed
  158.     _FREEIMAGE hwimage '                                                                                merged hardware image no longer needed
  159.  
  160.     '*
  161.     '* SL_draw_sprites '                                                                                   draw all sprites in use <---------------------------------------------------- LOOK
  162.     '*
  163.  
  164.     _DISPLAY '                                                                                          update display screen with changes
  165.  
  166.  
  167. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  168. SUB SL_QUIT () '                                                                                                                                                                                SL_QUIT
  169.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  170.  
  171.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  172.     DIM count AS INTEGER '              layer counter
  173.  
  174.     SCREEN 0, 0, 0, 0 '                                                                                 go to a text screen
  175.     DO '                                                                                                cycle through layers
  176.         count = count + 1 '                                                                             increment layer counter
  177.         _FREEIMAGE SL_layer(count).image '                                                              remove layer image from meory
  178.     LOOP UNTIL count = UBOUND(SL_layer) '                                                               leave when all layers removed
  179.     SYSTEM '                                                                                            return to OS
  180.  
  181.  
  182. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  183. SUB SL_SET_SCREEN (x AS INTEGER, y AS INTEGER) '                                                                                                                                          SL_SET_SCREEN
  184.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  185.  
  186.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  187.     SHARED SL_global AS SL_GLOBAL '     common globals array
  188.     DIM osource AS LONG '               original source
  189.     DIM odest AS LONG '                 original destination
  190.     DIM temp AS LONG '                  temporary screen and layer image
  191.     DIM current AS LONG '               current screen and layer image
  192.     DIM layer AS INTEGER '              layer counter
  193.     DIM source AS INTEGER '             -1 (TRUE) if layer is the source
  194.     DIM destination AS INTEGER '        -1 (TRUE) if layer is the destination
  195.  
  196.     IF (x < 1) OR (y < 1) THEN SL_error "SL_SET_SCREEN", 9, "" '                                        report error to programmer
  197.  
  198.     ' change the screen's dimensions
  199.  
  200.     osource = _SOURCE '                                                                                 save current source
  201.     odest = _DEST '                                                                                     save current destination
  202.     _SOURCE 0 '                                                                                         set screen as the source
  203.     _DEST 0 '                                                                                           set screen as the destination
  204.     current = _SOURCE '                                                                                 get current screen source handle
  205.     temp = _COPYIMAGE(current, 32) '                                                                    make a copy of the screen
  206.     SCREEN temp '                                                                                       make the copy the current screen
  207.     _FREEIMAGE current '                                                                                remove the old screen from memory
  208.     'currentscreen = _NEWIMAGE(x, y, 32)
  209.     'SCREEN currentscreen
  210.     '_PUTIMAGE (0, 0), tempscreen, currentscreen
  211.     SCREEN _NEWIMAGE(x, y, 32) '                                                                        create the new screen with new dimensions
  212.     _PUTIMAGE , temp '                                                                                  put the old screen image back on top
  213.     _FREEIMAGE temp '                                                                                   remove the temporary image from memory
  214.     _DEST odest '                                                                                       restore the original destination
  215.     _SOURCE osource '                                                                                   restore the original source
  216.     SL_global.screen.width = x '                                                                        save screen dimensions
  217.     SL_global.screen.height = y
  218.     SL_global.screen.top = 0
  219.     SL_global.screen.left = 0
  220.     SL_global.screen.right = x - 1
  221.     SL_global.screen.bottom = y - 1
  222.     SL_global.screen.centerx = x \ 2 - 1
  223.     SL_global.screen.centery = y \ 2 - 1
  224.  
  225.     ' change each layer's dimensions to match new screen dimensions
  226.  
  227.     layer = 0 '                                                                                         reset layer counter
  228.     DO '                                                                                                cycle through all layers
  229.         layer = layer + 1 '                                                                             increment layer counter
  230.         source = 0 '                                                                                    reset source indicator
  231.         destination = 0 '                                                                               reset destination indicator
  232.         temp = _NEWIMAGE(1, 1, 32) '                                                                    create a tempory source and destination place holder
  233.         IF _SOURCE = SL_layer(layer).image THEN _SOURCE temp: source = -1 '                             remember that this layer is the source
  234.         IF _DEST = SL_layer(layer).image THEN _DEST temp: destination = -1 '                            remember that this layer is the destination
  235.         current = _COPYIMAGE(SL_layer(layer).image, 32) '                                               make a copy of the layer's image
  236.         _FREEIMAGE SL_layer(layer).image '                                                              remove current layer from memory
  237.         SL_layer(layer).image = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '        create new layer image
  238.         _PUTIMAGE (0, 0), current, SL_layer(layer).image '                                              put the old layer image back on top
  239.         _FREEIMAGE current '                                                                            remove old layer image from memory
  240.         _FREEIMAGE temp '                                                                               remove temporary image from memory
  241.         IF source THEN _SOURCE SL_layer(layer).image '                                                  this was source, set it back
  242.         IF destination THEN _DEST SL_layer(layer).image '                                               this was destination, set it back
  243.     LOOP UNTIL layer = UBOUND(SL_layer)
  244.  
  245.  
  246. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  247. FUNCTION SL_GET_SCREEN (value AS INTEGER) ' (MULTI_FUNCTION COMMAND)                                                                                                                      SL_GET_SCREEN
  248.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  249.  
  250.     ' sl_get_screen(sl_width)
  251.     ' sl_get_screen(sl_height)
  252.     ' sl_get_screen(sl_centerx)
  253.     ' sl_get_screen(sl_centery)
  254.     ' sl_get_screen(sl_top)
  255.     ' sl_get_screen(sl_left)
  256.     ' sl_get_screen(sl_bottom)
  257.     ' sl_get_screen(sl_right)
  258.  
  259.     SHARED SL_global AS SL_GLOBAL '     common globals array
  260.  
  261.     SELECT CASE value '                                                                                 yes, which one?
  262.         CASE SL_WIDTH '                                                                                 screen width
  263.             SL_GET_SCREEN = SL_global.screen.width '                                                    return the screen width
  264.         CASE SL_HEIGHT '                                                                                screen height
  265.             SL_GET_SCREEN = SL_global.screen.height '                                                   return the screen height
  266.         CASE SL_CENTERX '                                                                               screen x center location
  267.             SL_GET_SCREEN = SL_global.screen.centerx '                                                  return x center location
  268.         CASE SL_CENTERY '                                                                               screen y center location
  269.             SL_GET_SCREEN = SL_global.screen.centery '                                                  return y center location
  270.         CASE SL_TOP '                                                                                   upper y location
  271.             SL_GET_SCREEN = SL_global.screen.top '                                                      return upper y location
  272.         CASE SL_LEFT '                                                                                  left x location
  273.             SL_GET_SCREEN = SL_global.screen.left '                                                     return left x location
  274.         CASE SL_BOTTOM '                                                                                bottom y location
  275.             SL_GET_SCREEN = SL_global.screen.bottom '                                                   return bottom y location
  276.         CASE SL_RIGHT '                                                                                 right x location
  277.             SL_GET_SCREEN = SL_global.screen.right '                                                    return right x location
  278.         CASE ELSE '                                                                                     unknown error?
  279.             SL_error "SL_GET_SCREEN", 10, "" '                                                          report error to programmer
  280.     END SELECT
  281.  
  282.  
  283.  
  284. 'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  285. '                                                                       ----------==========                ==========----------
  286. '                                                                       ----------========== LAYER ROUTINES ==========----------
  287. '                                                                       ----------==========                ==========----------
  288. 'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  289.  
  290.  
  291. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  292. FUNCTION SL_GET_LAYER (layer AS INTEGER, action AS INTEGER) ' (MULTI-FUNCTION COMMAND)                                                                                                     SL_GET_LAYER
  293.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  294.  
  295.     ' usage:
  296.     '           value = SL_GET_LAYER(SL_GET, SL_DEST)       return the value of current destination layer           returns the value of the destination layer, 0 if no destination exists
  297.     '           value = SL_GET_LAYER(SL_GET, SL_SOURCE)     return the value of the current source layer            returns the value of the source layer, 0 if no source exists
  298.     '           value = SL_GET_LAYER(SL_GET, SL_TOTAL)      return the total number of layers available             returns the total number of layers
  299.     '           value = SL_GET_LAYER(x, SL_DEST)            test if the specified layer is the destination          returns -1 if layer is destination, 0 otherwise
  300.     '           value = SL_GET_LAYER(x, SL_SOURCE)          test if the specified layer is the source               returns -1 if layer is source, otherwise 0
  301.     '           value = SL_GET_LAYER(x, SL_VALID)           return either -1 or 0 depending on layer x being valid  returns -1 if layer is valid, 0 if layer is invalid
  302.  
  303.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  304.     SHARED SL_global AS SL_GLOBAL '     common globals array
  305.  
  306.     SELECT CASE action '                                                                                which action was requested?
  307.         CASE SL_VALID '                                                                                 check for valid layer
  308.             IF layer = SL_GET THEN SL_error "SL_GET_LAYER", 3, "" '                                     report error to programmer
  309.             IF (layer > 0) AND (layer <= UBOUND(SL_layer)) THEN SL_GET_LAYER = -1 '                     if layer valid then return -1
  310.         CASE SL_DEST '                                                                                  get destination layer
  311.             IF layer = SL_GET THEN '                                                                    getting the destination layer?
  312.                 IF SL_global.destination <> -1 THEN '                                                   yes, are one of the layers set as a destination?
  313.                     IF _DEST = SL_layer(SL_global.destination).image THEN '                             yes, is this layer actually still the destination?
  314.                         SL_GET_LAYER = SL_global.destination '                                          yes, report current destination layer
  315.                     ELSE '                                                                              no, the programmer changed the destination to something else
  316.                         SL_layer(SL_global.destination).dest = 0 '                                      mark this layer as not the destination layer any longer
  317.                         SL_global.destination = -1 '                                                    set that there are currently no layers set to destination
  318.                     END IF
  319.                 END IF
  320.             ELSE '                                                                                      no, checking one layer for destination
  321.                 IF NOT SL_GET_LAYER(layer, SL_VALID) THEN SL_error "SL_GET_LAYER", 6, "" '              report error to programmer                      (function recursion)
  322.                 IF SL_GET_LAYER(SL_GET, SL_DEST) = layer THEN SL_GET_LAYER = -1 '                       report this layer is the current destination    (function recursion)
  323.             END IF
  324.         CASE SL_SOURCE '                                                                                get source layer
  325.             IF layer = SL_GET THEN '                                                                    getting the source layer?
  326.                 IF SL_global.source <> -1 THEN '                                                        yes, are one of the layers set as a source?
  327.                     IF _SOURCE = SL_layer(SL_global.source).image THEN '                                yes, is this layer actually still the source?
  328.                         SL_GET_LAYER = SL_global.source '                                               yes, report current source layer
  329.                     ELSE '                                                                              no, the programmer changed the source to something else
  330.                         SL_layer(SL_global.source).source = 0 '                                         mark this layer as not the source layer any longer
  331.                         SL_global.source = -1 '                                                         set that there are currently no layers set to source
  332.                     END IF
  333.                 END IF
  334.             ELSE '                                                                                      no, checking one layer for source
  335.                 IF NOT SL_GET_LAYER(layer, SL_VALID) THEN SL_error "SL_GET_LAYER", 6, "" '              report error to programmer                      (function recursion)
  336.                 IF SL_GET_LAYER(SL_GET, SL_SOURCE) = layer THEN SL_GET_LAYER = -1 '                     report this layer is the current source         (function recursion)
  337.             END IF
  338.         CASE SL_TOTAL
  339.             IF layer <> SL_GET THEN SL_error "SL_GET_LAYER", 11, "" '                                   report error to programmer
  340.             SL_GET_LAYER = UBOUND(SL_layer) '                                                           return total number of layers present
  341.         CASE ELSE '                                                                                     command not formatted properly
  342.             SL_error "SL_GET_LAYER", 5, "" '                                                            report error to programmer
  343.     END SELECT
  344.  
  345.  
  346. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  347. SUB SL_CLEAR_LAYER (layer AS INTEGER) '                                                                                                                                                  SL_CLEAR_LAYER
  348.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  349.  
  350.     ' usage:
  351.     '           SL_CLEAR_LAYER x             clear layer x
  352.     '           SL_CLEAR_LAYER SL_ALL        clear all layers
  353.  
  354.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  355.     SHARED SL_global AS SL_GLOBAL '     common globals array
  356.     DIM count AS INTEGER '              layer counter
  357.     DIM temp AS LONG '                  temp source/destination image
  358.     DIM source AS INTEGER '             -1 (TRUE) if current layer is the source
  359.     DIM destination AS INTEGER '        -1 (TRUE) if current layer is the destination
  360.  
  361.     IF layer <> SL_ALL THEN '                                                                           clear all layers?
  362.         IF NOT SL_GET_LAYER(layer, SL_VALID) THEN SL_error "SL_CLEAR_LAYER", 6, "" '                    report error to programmer
  363.         count = layer '                                                                                 no, just clear this one layer
  364.     ELSE '                                                                                              yes, clear all layers
  365.         count = 1 '                                                                                     start with first layer
  366.     END IF
  367.     temp = _NEWIMAGE(1, 1, 32) '                                                                        great a temp image for source / destination
  368.     DO '                                                                                                cycle through layer(s)
  369.         source = 0 '                                                                                    reset source indicator
  370.         destination = 0 '                                                                               reset destination indicator
  371.         IF _SOURCE = SL_layer(count).image THEN _SOURCE temp: source = -1 '                             remember that this layer is the source
  372.         IF _DEST = SL_layer(count).image THEN _DEST temp: destination = -1 '                            remember that this layer is the destination
  373.         _FREEIMAGE SL_layer(count).image '                                                              remove current layer from memory
  374.         SL_layer(count).image = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '        create new layer image
  375.         IF source THEN _SOURCE SL_layer(count).image '                                                  this was source, set it back
  376.         IF destination THEN _DEST SL_layer(count).image '                                               this was destination, set it back
  377.         count = count + 1 '                                                                             increment layer counter
  378.     LOOP UNTIL count = UBOUND(SL_layer) + 1 OR layer <> SL_ALL '                                        leave when layer(s) cleared
  379.     _FREEIMAGE temp '                                                                                   remove temp image from memory
  380.  
  381.  
  382. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  383. SUB SL_SET_LAYER (layer AS INTEGER, action AS INTEGER) ' (MULTI-FUNCTION COMMAND)                                                                                                          SL_SET_LAYER
  384.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  385.  
  386.     ' usage:
  387.     '           SL_SET_LAYER(x, SL_DEST)            set layer x as destination
  388.     '           SL_SET_LAYER(x, SL_SOURCE)          set layer x as the source
  389.     '           SL_SET_LAYER(x, SL_VISBILE)         set layer x as visible
  390.     '           SL_SET_LAYER(SL_ALL, SL_VISIBLE)    set all layers as visible
  391.     '           SL_SET_LAYER(x, SL_INVISIBLE)       set layer x as invisible
  392.     '           SL_SET_LAYER(SL_ALL, SL_INVISIBLE)  set all layers as invisible
  393.  
  394.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  395.     SHARED SL_global AS SL_GLOBAL '     common globals array
  396.     DIM count AS INTEGER '              layer counter
  397.     DIM visibility AS INTEGER '         layer visibility status
  398.  
  399.     IF layer <> SL_ALL THEN IF NOT SL_GET_LAYER(layer, SL_VALID) THEN SL_error "SL_SET_LAYER", 6, "" '  report error to programmer
  400.     SELECT CASE action '                                                                                which action was requested?
  401.         CASE SL_DEST '                                                                                  set destination layer
  402.             IF layer = SL_ALL THEN SL_error "SL_SET_LAYER", 7, "" '                                     report error to programmer
  403.             _DEST SL_layer(layer).image '                                                               set layer software image as destination
  404.             SL_global.destination = layer '                                                             save destination layer in global settings
  405.             SL_layer(layer).dest = -1 '                                                                 mark this layer as the destination
  406.         CASE SL_SOURCE '                                                                                set source layer
  407.             IF layer = SL_ALL THEN SL_error "SL_SET_LAYER", 7, "" '                                     report error to programmer
  408.             _SOURCE SL_layer(layer).image '                                                             set layer software image as source
  409.             SL_global.source = layer '                                                                  save source layer in global settings
  410.             SL_layer(layer).source = -1 '                                                               mark this layer as the source
  411.         CASE SL_VISIBLE, SL_INVISIBLE '                                                                 make layer(s) (in)visible
  412.             IF action = SL_VISIBLE THEN visibility = -1 '                                               determine visibility setting
  413.             IF layer = SL_ALL THEN '                                                                    change visibility of all layers?
  414.                 DO '                                                                                    cycle through all layers
  415.                     count = count + 1 '                                                                 increment layer counter
  416.                     SL_layer(count).visible = visibility '                                              change visibility of layer
  417.                 LOOP UNTIL count = UBOUND(SL_layer) '                                                   leave when all layers changed
  418.             ELSE '                                                                                      no, change visibility of one layer
  419.                 SL_layer(layer).visible = visibility '                                                  change visibility of layer
  420.             END IF
  421.         CASE ELSE '                                                                                     unknown error?
  422.             SL_error "SL_SET_LAYER", 8, "" '                                                            report error to programmer
  423.     END SELECT
  424.  
  425.  
  426. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  427. SUB SL_SHIFT_LAYER (layer AS INTEGER, angle AS INTEGER, speed AS INTEGER) '                                                                                                              SL_SHIFT_LAYER
  428.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  429.  
  430.     ' SL_SHIFT_LAYER(x, 90, 5)              SL_UP, SL_RIGHT, SL_DOWN, SL_LEFT
  431.     ' SL_SHIFT_LAYER(SL_ALL, 90, 5)         SL_UPRIGHT, SL_DOWNRIGHT, SL_DOWNLEFT, SL_UPLEFT
  432.  
  433.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  434.     SHARED SL_global AS SL_GLOBAL '     common globals array
  435.     DIM current AS LONG '               current layer image
  436.     DIM xdir AS SINGLE '                direction in x to travel
  437.     DIM ydir AS SINGLE '                direction in y to travel
  438.     DIM source AS INTEGER '             -1 (TRUE) if layer is current source
  439.     DIM destination AS INTEGER '        -1 (TRUE) if layer is current destination
  440.     DIM temp AS LONG '                  temp image for source and destination holding
  441.     DIM degrees AS INTEGER
  442.  
  443.  
  444.     IF NOT SL_GET_LAYER(layer, SL_VALID) THEN '                                                         valid layer requested?
  445.         SL_error "SL_SHIFT_LAYER", 6, "" '                                                              no, report error to programmer
  446.     END IF
  447.  
  448.     SELECT CASE angle '                                                                                 direction passed in?
  449.         CASE SL_UP '                                                                                    straight up (0 use pixel movement)
  450.             xdir = 0 '                                                                                  pixels in x direction
  451.             ydir = -speed '                                                                             pixels in y direction
  452.         CASE SL_UPRIGHT '                                                                               up and to the right (45)
  453.             xdir = speed
  454.             ydir = -speed
  455.         CASE SL_RIGHT '                                                                                 to the right (90)
  456.             xdir = speed
  457.             ydir = 0
  458.         CASE SL_DOWNRIGHT '                                                                             to the right and down (135)
  459.             xdir = speed
  460.             ydir = speed
  461.         CASE SL_DOWN '                                                                                  straight down (180)
  462.             xdir = 0
  463.             ydir = speed
  464.         CASE SL_DOWNLEFT '                                                                              to the left and down (225)
  465.             xdir = -speed
  466.             ydir = speed
  467.         CASE SL_LEFT '                                                                                  to the left (270)
  468.             xdir = -speed
  469.             ydir = 0
  470.         CASE SL_UPLEFT '                                                                                up and to the right (315)
  471.             xdir = -speed
  472.             ydir = -speed
  473.         CASE ELSE '                                                                                     use angle movements instead
  474.             degrees = SL_FIX_DEGREES(angle) '                                                           correct angle if needed
  475.             xdir = SIN(degrees * .017453292) * speed '                                                  calculate x distance given angle and speed
  476.             ydir = -COS(degrees * .017453292) * speed '                                                 calculate y distance given angle and speed
  477.     END SELECT
  478.     temp = _NEWIMAGE(1, 1, 32) '                                                                        create temp image to make source and destination
  479.     current = _COPYIMAGE(SL_layer(layer).image, 32) '                                                   get current layer image
  480.  
  481.     'xdir = _CEIL(xdir)
  482.     'ydir = _CEIL(ydir)
  483.  
  484.     IF SL_GET_LAYER(layer, SL_SOURCE) THEN _SOURCE temp: source = -1 '                                  remember that this layer is the current source
  485.     IF SL_GET_LAYER(layer, SL_DEST) THEN _DEST temp: destination = -1 '                                 remember that this layer is the currnt destination
  486.     _FREEIMAGE SL_layer(layer).image '                                                                  free the old layer image from memory
  487.     SL_layer(layer).image = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '            create a new clean layer image
  488.     _PUTIMAGE (xdir, ydir), current, SL_layer(layer).image '                                            place old layer image in new spot
  489.     _PUTIMAGE (xdir - SGN(xdir) * SL_global.screen.width, ydir), current, SL_layer(layer).image '       place old layer image to fill gap left or right
  490.     _PUTIMAGE (xdir, ydir - SGN(ydir) * SL_global.screen.height), current, SL_layer(layer).image '      place old layer image to fill gap top or bottom
  491.     _PUTIMAGE (xdir - SGN(xdir) * SL_global.screen.width, ydir - SGN(ydir) * SL_global.screen.height), current, SL_layer(layer).image ' place old layer image to fill diagonal gap
  492.     IF source THEN _SOURCE SL_layer(layer).image '                                                      return layer as source if necessary
  493.     IF destination THEN _DEST SL_layer(layer).image '                                                   return layer as destination if necessary
  494.     _FREEIMAGE temp '                                                                                   free temporary images from memory
  495.     _FREEIMAGE current
  496.  
  497.  
  498. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  499. SUB SL_SWAP_LAYER (layer1 AS INTEGER, layer2 AS INTEGER) '                                                                                                                                SL_SWAP_LAYER
  500.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  501.  
  502.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  503.     DIM current1 AS LONG '              layer 1 current image
  504.     DIM current2 AS LONG '              layer 2 current image
  505.     DIM source AS INTEGER '             -1 (TRUE) if layer is current source
  506.     DIM destination AS INTEGER '        -1 (TRUE) if layer is current destination
  507.     DIM temp AS LONG '                  source/destination place holder image
  508.  
  509.     IF (NOT SL_GET_LAYER(layer1, SL_VALID)) OR (NOT SL_GET_LAYER(layer2, SL_VALID)) THEN '              valid layers requested?
  510.         SL_error "SL_SWAP_LAYER", 6, "" '                                                               no, report error to programmer
  511.     END IF
  512.  
  513.     current1 = _COPYIMAGE(SL_layer(layer1).image, 32) '                                                 get first layer image
  514.     current2 = _COPYIMAGE(SL_layer(layer2).image, 32) '                                                 get second layer image
  515.     temp = _NEWIMAGE(1, 1, 32) '                                                                        image to act as source/destination place holder
  516.     IF SL_GET_LAYER(layer1, SL_SOURCE) THEN _SOURCE temp: source = -1 '                                 remember that this layer is the current source
  517.     IF SL_GET_LAYER(layer1, SL_DEST) THEN _DEST temp: destination = -1 '                                remember that this layer is the currnt destination
  518.     _FREEIMAGE SL_layer(layer1).image '                                                                 remove layer image from memory
  519.     SL_layer(layer1).image = _COPYIMAGE(current2, 32) '                                                 this layer now contains the other layer's image
  520.     IF source THEN _SOURCE SL_layer(layer1).image '                                                     return layer as source if necessary
  521.     IF destination THEN _DEST SL_layer(layer1).image '                                                  return layer as destination if necessary
  522.     source = 0 '                                                                                        reset source indicator
  523.     destination = 0 '                                                                                   reset destination indicator
  524.     IF SL_GET_LAYER(layer2, SL_SOURCE) THEN _SOURCE temp: source = -1 '                                 remember that this layer is the current source
  525.     IF SL_GET_LAYER(layer2, SL_DEST) THEN _DEST temp: destination = -1 '                                remember that this layer is the currnt destination
  526.     _FREEIMAGE SL_layer(layer2).image '                                                                 remove layer image from memory
  527.     SL_layer(layer2).image = _COPYIMAGE(current1, 32) '                                                 this layer now contains the other layer's image
  528.     IF source THEN _SOURCE SL_layer(layer2).image '                                                     return layer as source if necessary
  529.     IF destination THEN _DEST SL_layer(layer2).image '                                                  return layer as destination if necessary
  530.     _FREEIMAGE temp '                                                                                   remove temporary image from memory
  531.     _FREEIMAGE current2 '                                                                               remove current images from memory
  532.     _FREEIMAGE current1
  533.  
  534.  
  535. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  536. SUB SL_KILL_LAYER (layer AS INTEGER) '                                                                                                                                                    SL_KILL_LAYER
  537.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  538.  
  539.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  540.     SHARED SL_global AS SL_GLOBAL '     common globals array
  541.     DIM count AS INTEGER '              layer counter
  542.  
  543.     IF UBOUND(SL_layer) = 1 THEN SL_error "SL_KILL_LAYER", 4, "" '                                      report error to programmer
  544.     IF NOT SL_GET_LAYER(layer, SL_VALID) THEN SL_error "SL_KILL_LAYER", 6, "" '                         report error to programmer
  545.     count = layer '                                                                                     start with layer being deleted
  546.     DO
  547.         IF count <> 1 THEN '                                                                            is layer 1 being deleted?
  548.             IF _DEST = SL_layer(count).image THEN '                                                     no, is this layer the curent destination?
  549.                 _DEST SL_layer(count - 1).image '                                                       yes, make previous layer the new destination
  550.                 SL_global.destination = count - 1 '                                                     set previous layer as the new destination
  551.                 SL_layer(count - 1).dest = -1 '                                                         mark previous layer as the destination
  552.                 SL_layer(count).dest = 0 '                                                              set this layer as no longer the destination
  553.             END IF
  554.             IF _SOURCE = SL_layer(count).image THEN '                                                   is this layer the current source?
  555.                 _SOURCE SL_layer(count - 1).image '                                                     yes, make previous layer the new source
  556.                 SL_global.source = count - 1 '                                                          set previous layer as the new source
  557.                 SL_layer(count - 1).source = -1 '                                                       mark previous layer as the source
  558.                 SL_layer(count).source = 0 '                                                            set this layer as no longer the source
  559.             END IF
  560.         END IF
  561.         SL_SWAP_LAYER count, count + 1 '                                                                swap the layer images
  562.  
  563.         '*
  564.         '* add code to update sprite layers <--------------------------------------------------------------------------------------------------------------------------------------------------- LOOK
  565.         '*
  566.  
  567.         count = count + 1 '                                                                             increment layer counter
  568.     LOOP UNTIL count = UBOUND(SL_layer)
  569.     _FREEIMAGE SL_layer(UBOUND(SL_layer)).image
  570.     REDIM _PRESERVE SL_layer(UBOUND(SL_layer) - 1) AS SL_LAYERS '                                       delete the last layer from the array
  571.  
  572.  
  573. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  574. FUNCTION SL_ADD_LAYER (layers AS INTEGER) '                                                                                                                                                SL_ADD_LAYER
  575.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  576.  
  577.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  578.     SHARED SL_global AS SL_GLOBAL '     common globals array
  579.     DIM newlayer AS INTEGER '           new layers counter
  580.  
  581.     newlayer = UBOUND(SL_layer) + 1 '                                                                   start of new layer(s)
  582.     SL_ADD_LAYER = newlayer '                                                                           return where new layer(s) start
  583.     REDIM _PRESERVE SL_layer(UBOUND(SL_layer) + layers) AS SL_LAYERS '                                  increase size of layer array
  584.  
  585.     DO '                                                                                                cycle through new layers
  586.         SL_layer(newlayer).image = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '     create new layer software image
  587.         SL_layer(newlayer).visible = -1 '                                                      (TRUE)   new layer is visible
  588.         newlayer = newlayer + 1 '                                                                       increment new layer counter
  589.     LOOP UNTIL newlayer = UBOUND(SL_layer) + 1 '                                                        leave when all new layers created
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  622. FUNCTION SL_FIX_DEGREES (degrees AS INTEGER) '                                                                                                                                           SL_FIX_DEGREES
  623.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  624.  
  625.     ' Credits: this function uses code contriibuted by codeguy
  626.     '          https://www.qb64.org/forum/index.php?topic=537.15
  627.  
  628.     DIM degree AS INTEGER '             degree angle passed in
  629.  
  630.     degree = degrees MOD 360 '                                                                          get -359 to 359
  631.     IF degree < 0 THEN '                                                                                need to make positive?
  632.         SL_FIX_DEGREES = degree + 360 '                                                                 yes, correct value and return degree angle
  633.     ELSE
  634.         SL_FIX_DEGREES = degree '                                                                       no correction needed, return degree angle
  635.     END IF
  636.  
  637.  
  638. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  639. SUB SL_error (routine AS STRING, errno AS INTEGER, info AS STRING) '                                                                                                                           SL_error
  640.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  641.  
  642.     DIM tune AS INTEGER
  643.     tune = INT(RND(1) * 2) + 1
  644.     SELECT CASE tune
  645.         CASE 1
  646.             PLAY "o2l8eeel2c" '                                                                         duh, duh, duh, dooooh
  647.         CASE 2
  648.             PLAY "o2l8gl16ddl8ed" '                                                                     shave and a hair cut
  649.         CASE 3
  650.  
  651.     END SELECT
  652.     SCREEN 0, 0, 0, 0 '                                                                                 go to a pure text screen
  653.     _FONT 16 '                                                                                          set the standard screen 0 font
  654.     IF _FULLSCREEN THEN _FULLSCREEN _OFF '                                                              turn off full screen if on
  655.     _AUTODISPLAY '                                                                                      auto update the display
  656.     CLS '                                                                                               clear the screen
  657.     COLOR 10, 0
  658.     PRINT "                    **************************************" '                                print error header
  659.     PRINT "                    ** Sprite Library Error Encountered **"
  660.     PRINT "                    **************************************"
  661.     PRINT
  662.     COLOR 15, 0
  663.     PRINT " "; routine;
  664.     COLOR 7, 0
  665.     PRINT " has reported error";
  666.     COLOR 30, 0
  667.     PRINT STR$(errno)
  668.     COLOR 7, 0
  669.     PRINT
  670.     SELECT CASE errno '                                                                                 which error number is being reported?
  671.  
  672.         ' general purpose errors for all subs/functions
  673.  
  674.         CASE 1
  675.             PRINT " You must create at least one layer to work in."
  676.         CASE 2
  677.             PRINT " You must specify a window width and height greater than zero (0)."
  678.         CASE 3
  679.             PRINT " SL_GET can't be used with SL_VALID."
  680.             PRINT
  681.             PRINT " usage  : ";
  682.             COLOR 14, 0
  683.             PRINT "result = SL_GET_LAYER(x, SL_VALID)"
  684.             COLOR 7, 0
  685.             PRINT
  686.             PRINT "      x = the layer being checked for validity"
  687.             PRINT " result = -1 if the layer is valid, 0 if the layer is invalid"
  688.         CASE 4
  689.             PRINT " Only one layer remains. Unable to delete last remaining layer."
  690.         CASE 5
  691.             PRINT " SL_DEST, SL_SOURCE, and SL_VALID are the only second parameter values allowed."
  692.             PRINT
  693.             PRINT " usage  : ";
  694.             COLOR 14, 0
  695.             PRINT "result = SL_GET_LAYER(SL_GET, SL_DEST)"
  696.             PRINT "          result = SL_GET_LAYER(SL_GET, SL_SOURCE)"
  697.             PRINT "          result = SL_GET_LAYER(x, SL_DEST)"
  698.             PRINT "          result = SL_GET_LAYER(x, SL_SOURCE"
  699.             PRINT "          result = SL_GET_LAYER(x, SL_VALID)"
  700.             COLOR 7, 0
  701.         CASE 6
  702.             PRINT "- The specified layer(s) does not exist."
  703.         CASE 7
  704.             PRINT " SL_ALL can't be used with SL_DEST or SL_SOURCE."
  705.             PRINT
  706.             PRINT " usage  : ";
  707.             COLOR 14, 0
  708.             PRINT " SL_SET_LAYER x, SL_DEST"
  709.             PRINT
  710.             PRINT "           SL_SET_LAYER x, SL_SOURCE"
  711.             COLOR 7, 0
  712.             PRINT
  713.             PRINT "      x = the layer being set as source or destination"
  714.         CASE 8
  715.             PRINT " SL_DEST, SL_SOURCE, SL_VISIBLE, and SL_INVISIBLE are the only second"
  716.             PRINT " parameter values allowed."
  717.             PRINT
  718.             PRINT " usage  : ";
  719.             COLOR 14, 0
  720.             PRINT "SL_SET_LAYER x, SL_DEST"
  721.             PRINT "          SL_SET_LAYER x, SL_SOURCE"
  722.             PRINT "          SL_SET_LAYER x, SL_VISIBLE"
  723.             PRINT "          SL_SET_LAYER SL_ALL, SL_VISIBLE"
  724.             PRINT "          SL_SET_LAYER x, SL_INVISIBLE"
  725.             PRINT "          SL_SET_LAYER SL_ALL, SL_INVISIBLE"
  726.         CASE 9
  727.             PRINT " You must specify a screen width and height greater than zero (0)."
  728.         CASE 10
  729.             PRINT " Incorrect parameter given."
  730.             PRINT
  731.             PRINT " usage  : ";
  732.             COLOR 14, 0
  733.             PRINT "result = SL_SCREEN(SL_WIDTH)"
  734.             PRINT "          result = SL_SCREEN(SL_HEIGHT)"
  735.             PRINT "          result = SL_SCREEN(SL_CENTERX)"
  736.             PRINT "          result = SL_SCREEN(SL_CENTERY)"
  737.             PRINT "          result = SL_SCREEN(SL_TOP)"
  738.             PRINT "          result = SL_SCREEN(SL_LEFT)"
  739.             PRINT "          result = SL_SCREEN(SL_BOTTOM)"
  740.             PRINT "          result = SL_SCREEN(SL_RIGHT)"
  741.         CASE 11
  742.             PRINT "SL_GET must be used with SL_TOTAL."
  743.             PRINT
  744.             PRINT " usage  : ";
  745.             COLOR 14, 0
  746.             PRINT "result = SL_GET_LAYER(SL_GET, SL_TOTAL)"
  747.             COLOR 7, 0
  748.             PRINT
  749.             PRINT "result = the total number of layers availabel"
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.     END SELECT
  758.     COLOR 12, 0
  759.     PRINT
  760.     PRINT " See sprite library doumentation for further explanation."
  761.     COLOR 7, 0
  762.     SELECT CASE tune
  763.         CASE 1
  764.             PLAY "o2l8dddl2o1b" '                                                                       duh duh duh dum
  765.         CASE 2
  766.             PLAY "o2p8l8f#g" '                                                                          two bits
  767.     END SELECT
  768.     DO: LOOP UNTIL INKEY$ = "" '                                                                        clear the keyboard buffer
  769.     END '                                                                                               end the program
  770.  
  771.  
* layers.zip (Filesize: 1.06 MB, Downloads: 299)
« Last Edit: October 08, 2018, 03:46:54 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Sprite Library Layering
« Reply #1 on: October 08, 2018, 03:56:16 pm »
LOL, I just noticed the stars pass in front of the moon! Not in this universe. O.o

I thought the fix would be easy by renaming level 6 to 7 and 7 to 6, but nope. I grabbed the layers off of an art site on the net so the original artist goofed.

Oh well, you get the idea.
« Last Edit: October 08, 2018, 04:09:40 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Sprite Library Layering
« Reply #2 on: October 08, 2018, 03:57:54 pm »
Shooting stars!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Sprite Library Layering
« Reply #3 on: October 08, 2018, 03:59:27 pm »
Love it.
You're not done when it works, you're done when it's right.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Sprite Library Layering
« Reply #4 on: October 08, 2018, 04:06:34 pm »
Shooting stars!

LOL, correct! The stars should not be moving.
In order to understand recursion, one must first understand recursion.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Sprite Library Layering
« Reply #5 on: October 11, 2018, 05:43:04 am »
Hi Terry
cool layering
Programming isn't difficult, only it's  consuming time and coffee

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Sprite Library Layering
« Reply #6 on: October 11, 2018, 11:10:23 am »
Thanks Tempo, although I don't know how much layering will get used. With two or three layers there is a slight speed decrease. However, get into the 5 to 10 layer area, especially at higher resolutions and performance takes a pretty good hit. I'm still investigating ways on making this faster.
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Sprite Library Layering
« Reply #7 on: October 11, 2018, 11:59:14 am »
Thanks Tempo, although I don't know how much layering will get used. With two or three layers there is a slight speed decrease. However, get into the 5 to 10 layer area, especially at higher resolutions and performance takes a pretty good hit. I'm still investigating ways on making this faster.

In many cases, layers can be pre-saved and reused.  Draw a blue sky background.  Put a red house on it for layer 2.  Add a fence for layer 3.  Character walking by for layer 4..

If the character walks in front of it all, layers 1-3 can be drawn and saved together as the "background".  If the character is going to walk behind the fence, but in front of the sky and house, then layer 1-2 is "background", 4 is "active layer", 3 is "foreground".

Unless every layer has individual movement on seperate planes, a lot of the layering can be preapplied and not have to be done on the fly.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Sprite Library Layering
« Reply #8 on: October 11, 2018, 12:12:38 pm »
That's pretty much what I'm doing:

Code: QB64: [Select]
  1. '    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  2. SUB SL_DISPLAY () '                                                                                                                                                                          SL_DISPLAY
  3.     'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  4.  
  5.     SHARED SL_layer() AS SL_LAYERS '    master layer array
  6.     SHARED SL_global AS SL_GLOBAL '     common globals array
  7.     DIM layer AS INTEGER '              layer counter
  8.     DIM merge AS LONG '                 software image to merge all layers onto
  9.     DIM hwimage AS LONG '               final hardware image of merged layers
  10.  
  11.     merge = _NEWIMAGE(SL_global.screen.width, SL_global.screen.height, 32) '                            create image to merge layers
  12.     layer = UBOUND(SL_layer) '                                                                          start with the highest numbered layer
  13.  
  14.     DO '                                                                                                cycle through layers backwards (high to low)
  15.         IF SL_layer(layer).visible THEN '                                                               is this layer visible?
  16.             _PUTIMAGE , SL_layer(layer).image, merge '                                                  place this layer onto merge image
  17.         END IF
  18.         layer = layer - 1 '                                                                             decrement layer counter
  19.     LOOP UNTIL layer = 0 '                                                                              leave when all layers merged
  20.     hwimage = _COPYIMAGE(merge, 33) '                                                                   create hardware image of merged layers
  21.     _PUTIMAGE , hwimage, 0 '                                                                            place hardware image on main screen
  22.     _FREEIMAGE merge '                                                                                  merged software image no longer needed
  23.     _FREEIMAGE hwimage '                                                                                merged hardware image no longer needed
  24.  
  25.     '*
  26.     '* SL_draw_sprites '                                                                                   draw all sprites in use <---------------------------------------------------- LOOK
  27.     '*
  28.  
  29.     _DISPLAY '                                                                                          update display screen with changes
  30.  

The layers remain the same during each loop, unless acted upon by drawing something to them. Even then, as seen in the routine above, I'm simply taking the layers, merging their images and then displaying that merged image.
In order to understand recursion, one must first understand recursion.