home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / obero / oberon-a / examples / libraries / graphics / simplesprite.mod < prev    next >
Text File  |  1995-07-02  |  4KB  |  138 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: SimpleSprite.mod $
  4.   Description: Port of ssprite.c - Simple Sprite example
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 1.1 $
  8.       $Author: fjc $
  9.         $Date: 1995/01/25 23:51:02 $
  10.  
  11.   Copyright © 1994, Frank Copeland.
  12.   This example program is part of Oberon-A.
  13.   See Oberon-A.doc for conditions of use and distribution.
  14.  
  15.   Log entries are at the end of the file.
  16.  
  17. *************************************************************************)
  18.  
  19. <* STANDARD- *>
  20.  
  21. MODULE SimpleSprite;
  22.  
  23. IMPORT
  24.   SYS := SYSTEM, Kernel, e := Exec, gfx := Graphics, i := Intuition,
  25.   d := Dos, WbConsole;
  26.  
  27. CONST
  28.   VersionTag = "$VER: SimpleSprite 1.2 (23.1.95)\r\n";
  29.   VersionStr = "SimpleSprite 1.2 (23.1.95)\n";
  30.   CopyrightStr = "Copyright © 1994-1995 Frank Copeland";
  31.  
  32. (*------------------------------------*)
  33.  
  34. (* Real boring sprite data  *)
  35.  
  36. TYPE
  37.  
  38.   SpriteDataArray = ARRAY 22 OF INTEGER;
  39.   SpriteDataPtr = POINTER [2] TO SpriteDataArray;
  40.  
  41. VAR
  42.  
  43.   spriteData : SpriteDataPtr;
  44.  
  45. CONST
  46.  
  47.   SpriteDataStr =
  48.     "\x00\x00\x00\x00" (* position control *)
  49.     "\xFF\xFF\x00\x00" (* image data line 1, color 1 *)
  50.     "\xFF\xFF\x00\x00" (* image data line 2, color 1 *)
  51.     "\x00\x00\xFF\xFF" (* image data line 3, color 2 *)
  52.     "\x00\x00\xFF\xFF" (* image data line 4, color 2 *)
  53.     "\x00\x00\x00\x00" (* image data line 5, transparent *)
  54.     "\x00\x00\xFF\xFF" (* image data line 6, color 2 *)
  55.     "\x00\x00\xFF\xFF" (* image data line 7, color 2 *)
  56.     "\xFF\xFF\xFF\xFF" (* image data line 8, color 3 *)
  57.     "\xFF\xFF\xFF\xFF" (* image data line 9, color 3 *)
  58.     "\x00\x00\x00\x00" (* reserved, must init to 0 0 *)
  59.   ;
  60.  
  61. (*------------------------------------*)
  62. PROCEDURE Init ();
  63.  
  64. BEGIN (* Init *)
  65.   Kernel.Allocate (spriteData, SIZE (SpriteDataArray), {e.chip});
  66.   ASSERT (spriteData # NIL);
  67.   SYS.MOVE (SYS.ADR (SpriteDataStr), spriteData, SIZE (SpriteDataArray))
  68. END Init;
  69.  
  70. (*------------------------------------*)
  71. PROCEDURE Main ();
  72.  
  73.   VAR
  74.     sprite : gfx.SimpleSprite;
  75.     viewport : gfx.ViewPortPtr;
  76.     spriteNum : INTEGER;
  77.     deltaMove, ktr1, ktr2, colorReg : INTEGER;
  78.     screen : i.ScreenPtr;
  79.  
  80. BEGIN (* Main *)
  81.   ASSERT (gfx.base.libNode.version >= 37, d.fail);
  82.   ASSERT (i.base.libNode.version >= 37, d.fail);
  83.   (* opened library, need a viewport to render a sprite over. *)
  84.   screen := i.OpenScreenTagsA (NIL, NIL);
  85.   ASSERT (screen # NIL, d.fail);
  86.   viewport := SYS.ADR (screen.viewPort);
  87.   spriteNum := gfx.GetSprite (sprite, 2);
  88.   IF spriteNum = -1 THEN
  89.     i.OldCloseScreen (screen);
  90.     HALT (d.warn)
  91.   ELSE
  92.     (* Calculate the correct base color register number, *)
  93.     (* set up the color registers.                       *)
  94.     colorReg := 16 + ((spriteNum MOD 7) * 2);
  95.     gfx.SetRGB4 (viewport, colorReg + 1, 12, 3, 8);
  96.     gfx.SetRGB4 (viewport, colorReg + 2, 13, 13, 13);
  97.     gfx.SetRGB4 (viewport, colorReg + 3, 4, 4, 15);
  98.  
  99.     sprite.x := 0;      (* initialize position and size info     *)
  100.     sprite.y := 0;      (* to match that shown in spriteData     *)
  101.     sprite.height := 9; (* so system knows layout of data later. *)
  102.  
  103.     (* install sprite data and move sprite to start position. *)
  104.     gfx.ChangeSprite (NIL, sprite, spriteData);
  105.     gfx.MoveSprite (NIL, sprite, 30 , 0);
  106.  
  107.     (* move the sprite back and forth. *)
  108.     deltaMove := 1;
  109.     FOR ktr1 := 0 TO 5 DO
  110.       FOR ktr2 := 0 TO 99 DO
  111.         gfx.MoveSprite
  112.           (NIL, sprite, sprite.x + deltaMove, sprite.y + deltaMove);
  113.         gfx.WaitTOF (); (* one move per video frame *)
  114.  
  115.         (* Show the effect of turning off sprite DMA *)
  116.         IF ktr2 = 40 THEN gfx.OffSprite() END;
  117.         IF ktr2 = 60 THEN gfx.OnSprite() END;
  118.       END;
  119.       deltaMove := -deltaMove
  120.     END;
  121.     (* NOTE: if you turn off the sprite at the wrong time (when it
  122.     ** is being displayed), the sprite will appear as a vertical bar
  123.     ** on the screen.  To really get rid of the sprite, you must
  124.     ** OffSprite while it is not displayed.  This is hard in a
  125.     ** multi-tasking system (the solution is not addressed in
  126.     ** this program).
  127.     *)
  128.     gfx.OnSprite(); (* just to be sure *)
  129.     gfx.FreeSprite (spriteNum);
  130.   END;
  131.   i.OldCloseScreen (screen)
  132. END Main;
  133.  
  134. BEGIN (* SimpleSprite *)
  135.   Init ();
  136.   Main ();
  137. END SimpleSprite.
  138.