home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / sprite_bob_anim / ssprite / ssprite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  4.4 KB  |  135 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* ssprite.c 19oct89
  23. **
  24. ** lattice c 5.04
  25. ** lc -b1 -cfist -v -y ssprite.c
  26. ** blink FROM LIB:c.o ssprite.o LIB LIB:lc.lib LIB:amiga.lib TO ssprite
  27. */
  28. #include "exec/types.h"
  29. #include "graphics/gfx.h"
  30. #include "graphics/gfxbase.h"
  31. #include "graphics/gfxmacros.h"
  32. #include "graphics/sprite.h"
  33. #include "hardware/custom.h"
  34. #include "hardware/dmabits.h"
  35. #include "libraries/dos.h"
  36.  
  37. #include <stdlib.h>
  38. #include <proto/all.h>
  39.  
  40. struct GfxBase *GfxBase = NULL;
  41. extern struct Custom far custom ;
  42.  
  43. /* real boring sprite data */
  44. UWORD chip sprite_data[ ] =
  45.     {
  46.     0, 0,           /* position control */
  47.     0xffff, 0x0000, /* image data line 1, color 1 */
  48.     0xffff, 0x0000, /* image data line 2, color 1 */
  49.     0x0000, 0xffff, /* image data line 3, color 2 */
  50.     0x0000, 0xffff, /* image data line 4, color 2 */
  51.     0x0000, 0x0000, /* image data line 5, transparent */
  52.     0x0000, 0xffff, /* image data line 6, color 2 */
  53.     0x0000, 0xffff, /* image data line 7, color 2 */
  54.     0xffff, 0xffff, /* image data line 8, color 3 */
  55.     0xffff, 0xffff, /* image data line 9, color 3 */
  56.     0, 0            /* reserved, must init to 0 0 */
  57.     };
  58.  
  59. VOID main(int argc, char **argv)
  60. {
  61. struct SimpleSprite        sprite;
  62. struct ViewPort           *viewport;
  63.  
  64. SHORT sprite_num;
  65. SHORT delta_move;
  66. SHORT ktr1;
  67. SHORT ktr2;
  68. SHORT color_reg;
  69.  
  70. int return_code;
  71.  
  72. return_code = RETURN_OK;
  73.  
  74. if (NULL == (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33L)))
  75.     return_code = RETURN_FAIL;
  76. else
  77.     {
  78.     /* opened library, need a viewport to do a sprite
  79.     ** in real life you use the viewport of the screen that you open
  80.     ** for your application.
  81.     */
  82.     viewport = GfxBase->ActiView->ViewPort ;
  83.  
  84.     if (-1 == (sprite_num = GetSprite(&sprite, 2)))
  85.         return_code = RETURN_WARN;
  86.     else
  87.         {
  88.         /* got a sprite.
  89.         ** calculate the correct base color register number and
  90.         ** set up the color registers.
  91.         */
  92.         color_reg = 16 + ((sprite_num & 0x06) << 1);
  93.         SetRGB4(viewport, (long)color_reg + 1, 12,  3,  8);
  94.         SetRGB4(viewport, (long)color_reg + 2, 13, 13, 13);
  95.         SetRGB4(viewport, (long)color_reg + 3,  4,  4, 15);
  96.  
  97.         sprite.x = 0;       /* initialize position and size info    */
  98.         sprite.y = 0;       /* to match that shown in sprite_data    */
  99.         sprite.height = 9;  /* so system knows layout of data later */
  100.  
  101.         /* install sprite data and move sprite to start position. */
  102.         ChangeSprite(NULL, &sprite, sprite_data);
  103.         MoveSprite(NULL, &sprite, 30, 0);
  104.  
  105.         /* move the sprite to and fro (?) */
  106.         for ( ktr1 = 0, delta_move = 1;
  107.               ktr1 < 6;
  108.               ktr1++, delta_move = -delta_move)
  109.             {
  110.             for ( ktr2 = 0; ktr2 < 185; ktr2++)
  111.                 {
  112.                 MoveSprite(NULL, &sprite, (LONG)(sprite.x + delta_move),
  113.                                           (LONG)(sprite.y + delta_move));
  114.                 WaitTOF(); /* one move per video frame */
  115.                 if (ktr2 == 80)
  116.                     OFF_SPRITE ;
  117.                 if (ktr2 == 100)
  118.                     ON_SPRITE ;
  119.                 }
  120.             }
  121.         /* NOTE:  if you turn off the sprite at the wrong time
  122.         ** (when it is being displayed), the sprite will appear as
  123.         ** a vertical bar on the screen.  To really get rid of the
  124.         ** sprite, you must OFF_SPRITE while it is not displayed.
  125.         ** this is hard in a multi-tasking system (the solution is
  126.         ** not addressed in this program).
  127.         */
  128.         ON_SPRITE ; /* just to be sure */
  129.         FreeSprite((LONG)sprite_num);
  130.         }
  131.     CloseLibrary((struct Library *)GfxBase);
  132.     }
  133. exit(return_code);
  134. }
  135.