home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / BlazingPix 1.0.2 / BlazingPix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-04  |  4.7 KB  |  179 lines  |  [TEXT/CWIE]

  1. // BlazingPix
  2. // version 1.0.2
  3. // updated for CW7 on 951215
  4.  
  5. /************************************************************************/
  6. /*                                                                        */
  7. /*     BlazingPix.c -- Written by Jay Riley to illustrate crude animation.    */
  8. /*                                                                        */
  9. /*    Copyright © 1991 James N Riley Jr, All rights reserved.                */
  10. /*                                                                        */
  11. /*    11/22/91 10.28 PM    JNR        Created.                                */
  12. /*    11/23/91 12.44 PM    JNR        Last Change.                            */
  13. /*                                                                        */
  14. /************************************************************************/
  15.  
  16. /*#include "MacTypes.h"
  17. #include "QuickDraw.h"
  18. #include "WindowMgr.h"*/
  19.  
  20. pascal void main()
  21. {
  22.     long                        oldTCount;
  23.     Handle                        iconHand;
  24.     Point                        mouseIsHere;
  25.     Rect                        bgRect        =    {0, 0, 240, 384},
  26.                                 wRect        =    {60, 64, 300, 448},
  27.                                 drawSpriteHere;
  28.     BitMap                        background,
  29.                                 icon,
  30.                                 mask;
  31.     GrafPort                    bgPort;
  32.     WindowPtr                    ourWindow;
  33.     
  34.     /******************************/
  35.     /* Bare Bones Initialization. */
  36.     /******************************/
  37.     
  38.     InitGraf(&qd.thePort);
  39.     InitFonts();
  40.     InitWindows();
  41.     
  42.     InitCursor();
  43.     
  44.     HideCursor();
  45.     
  46.     /**********************/
  47.     /* Create Our Window. */
  48.     /**********************/
  49.     
  50.     if (ourWindow = NewWindow(0L, &wRect, "\p\"Blazing Pixels\" Sample Program",
  51.         true, 0, (WindowPtr)-1L, false, 0L))
  52.     {
  53.         /*********************************/
  54.         /* Allocate an Offscreen BitMap. */
  55.         /*********************************/
  56.         
  57.         background.bounds = bgRect;
  58.         background.rowBytes = (((bgRect.right - bgRect.left) + 31) / 32) *4;
  59.         
  60.         if (background.baseAddr = NewPtr((long)background.rowBytes *
  61.             (long)(bgRect.bottom - bgRect.top)))
  62.         {
  63.             /*************************************************/
  64.             /* Allocate a GrafPort for the Offscreen BitMap. */
  65.             /*************************************************/
  66.             
  67.             OpenPort(&bgPort);
  68.             
  69.             TextFace(outline);
  70.                     
  71.             /***************************************************/
  72.             /* Make sure GrafPort uses background as portBits. */
  73.             /***************************************************/
  74.             
  75.             SetPortBits(&background);
  76.             ClipRect(&bgRect);
  77.  
  78.             /********************************/
  79.             /* Setup Icon and Mask BitMaps. */
  80.             /********************************/
  81.             
  82.             if (iconHand = GetResource('ICN#', 3))
  83.             {
  84.                 HLock(iconHand);
  85.                 
  86.                 SetRect(&icon.bounds, 0, 0, 32, 32);
  87.                 icon.rowBytes = 4;
  88.                 icon.baseAddr = *iconHand;
  89.                 
  90.                 mask = icon;
  91.                 mask.baseAddr += 128;
  92.                 
  93.                 /***************************************************/
  94.                 /* No Real Event Loop -- Just Check For mouseDown. */
  95.                 /***************************************************/
  96.                 
  97.                 while(! Button())
  98.                 {
  99.                     /*********************/
  100.                     /* Clear Background. */
  101.                     /*********************/
  102.                     
  103.                     SetPort(&bgPort);
  104.                     
  105.                     FillRect(&bgRect, &qd.ltGray);
  106.                     
  107.                     /****************************************/
  108.                     /* Make ourWindow the current GrafPort. */
  109.                     /****************************************/
  110.                     
  111.                     SetPort(ourWindow);
  112.                     
  113.                     /*********************************************/
  114.                     /* Calculate Sprite Position based on Mouse. */
  115.                     /*********************************************/
  116.                     
  117.                     GetMouse(&mouseIsHere);
  118.                     
  119.                     if (mouseIsHere.h < 0)
  120.                         mouseIsHere.h = 0;
  121.                     else if (mouseIsHere.h > bgRect.right)
  122.                         mouseIsHere.h = bgRect.right;
  123.                     
  124.                     if (mouseIsHere.v < 0)
  125.                         mouseIsHere.v = 0;
  126.                     else if (mouseIsHere.v > bgRect.bottom)
  127.                         mouseIsHere.v = bgRect.bottom;
  128.                     
  129.                     SetRect(&drawSpriteHere, mouseIsHere.h - 16,
  130.                         mouseIsHere.v - 16, mouseIsHere.h + 16,
  131.                         mouseIsHere.v + 16);
  132.                          
  133.                     /******************************/
  134.                     /* Draw Sprite on background. */
  135.                     /******************************/
  136.                     
  137.                     SetPort(&bgPort);
  138.                     
  139.                     CopyBits(&mask, &background, &mask.bounds, &drawSpriteHere,
  140.                         srcBic, 0L);
  141.                         
  142.                     CopyBits(&icon, &background, &icon.bounds, &drawSpriteHere,
  143.                         srcOr, 0L);
  144.                     
  145.                     MoveTo(90, 200);
  146.                     DrawString("\pPress Mouse Button To Quit.");
  147.     
  148.                     /**********************************************/
  149.                     /* Synch with VBL Interupt to reduce flicker. */
  150.                     /**********************************************/
  151.                     
  152.                     oldTCount = TickCount();
  153.                     while (oldTCount == TickCount());
  154.                     
  155.                     /*******************************************/
  156.                     /* Copy Offscreen background to ourWindow. */
  157.                     /*******************************************/
  158.                     
  159.                     CopyBits(&background, &ourWindow->portBits, &bgRect, &bgRect,
  160.                         srcCopy, 0L);
  161.                 }    /* END: while(! Button()) */
  162.                     
  163.                 /********************************/
  164.                 /* Clean House Before Quitting. */
  165.                 /********************************/
  166.             
  167.                 HUnlock(iconHand);
  168.                 ReleaseResource(iconHand);
  169.             }    /* END: if (iconHand = GetResource('ICN#', 3)) */
  170.             
  171.             ClosePort(&bgPort);
  172.             
  173.             DisposPtr(background.baseAddr);
  174.         }
  175.         
  176.         DisposeWindow(ourWindow);
  177.     }
  178.     ShowCursor();
  179. }