home *** CD-ROM | disk | FTP | other *** search
- #include "SpriteTools.h"
-
- // SpriteTools.h includes SpriteHandlers.h
-
-
- /*** Custom handlers - application dependent ***
-
- Edit this as necessary. It should always include the following three routines:
-
- MoveSprite: move the sprite
-
- HitSprite: handle collisions between two sprites
-
- InitSprites: Load all faces and create initial sprites
-
- ***/
-
-
-
- GrafPtr firstFace, secondFace, thirdFace;
- static Point gPlayerPosition;
-
-
-
- void MoveSprite(SpritePtr theSprite)
- {
- switch (theSprite->kind)
- {
- case playerSprite:
- GetMouse(&theSprite->position);
- gPlayerPosition = theSprite->position;
- break;
- case hunterSprite:
- if (theSprite->position.h < gPlayerPosition.h)
- theSprite->position.h++;
- else
- if (theSprite->position.h > gPlayerPosition.h)
- theSprite->position.h--;
- if (theSprite->position.v < gPlayerPosition.v)
- theSprite->position.v++;
- else
- if (theSprite->position.v > gPlayerPosition.v)
- theSprite->position.v--;
- break;
- case evaderSprite:
- if (theSprite->position.h < gPlayerPosition.h)
- theSprite->position.h--;
- else
- if (theSprite->position.h > gPlayerPosition.h)
- theSprite->position.h++;
- if (theSprite->position.v < gPlayerPosition.v)
- theSprite->position.v--;
- else
- if (theSprite->position.v > gPlayerPosition.v)
- theSprite->position.v++;
-
- /* Keep this sprite a bit inside the bounds so it doesn't just stand in a corner. */
- if (theSprite->position.h < 50)
- theSprite->position.h = 50;
- if (theSprite->position.h > gOffScreen->portRect.right - theSprite->face->portRect.right - 50)
- theSprite->position.h = gOffScreen->portRect.right - theSprite->face->portRect.right - 50;
- if (theSprite->position.v < 50)
- theSprite->position.v = 50;
- if (theSprite->position.v > gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50)
- theSprite->position.v = gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50;
- break;
- }
-
- KeepOnScreen(theSprite);
-
- } /*MoveSprite*/
-
-
- void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
- {
-
- } /*HitSprite*/
-
-
- void InitSprites()
- {
- SpritePtr theSprite;
-
- /*Load all pictures*/
- firstFace = LoadFaceFromCicn(128); /*cicn resource #128.*/
- secondFace = LoadFaceFromCicn(129); /*cicn resource #129.*/
- thirdFace = LoadFaceFromCicn(130); /*cicn resource #130.*/
-
- /*Create sprites*/
- theSprite = NewSprite();
- theSprite->kind = hunterSprite;
- theSprite->face = firstFace;
- SetPt(&theSprite->position, 100, 100);
-
- theSprite = NewSprite();
- theSprite->kind = playerSprite;
- theSprite->face = secondFace;
- SetPt(&theSprite->position, 50, 50);
-
- theSprite = NewSprite();
- theSprite->kind = evaderSprite;
- theSprite->face = thirdFace;
- SetPt(&theSprite->position, 150, 150);
- } /*InitSprites*/
-