home *** CD-ROM | disk | FTP | other *** search
-
- // This is an Abstract Class from which sprites may be derived.
- // This basically provides basic variables to hold location and the
- // necessary methods to access the location instance variables. For
- // basic funtionality, -move: and -drawActorWithOffset: need to be
- // overridden. -move: should change nextLocation to tell the object
- // where to move to and -drawActorWithOffset: should be able to draw
- // a representation of the GKActor. Note that actual movement happens
- // when -moveOneFrame is called; -renderAt:move: will therefor call
- // the -moveOneFrame method if move:YES is chosen.
- // A simple form of animation is provided which you may use with the
- // need to write a -drawActorWithOffset: method, if you like. It uses
- // the idea of a "series" and "frames" within that series. What you
- // do is make a .tiff image with all the frames of animation. Since
- // a given actor will look different, say, depending upon the direction
- // it is moving, you have a series of frames for each appearance. In
- // the .tiff, each series is a horizontal strip of the .tiff and they
- // are numbered with series zero at the bottom, higher numbered series
- // are above lower numbered series. The frames are numbered starting
- // with zero at the left side, higher frame numbers to the right.
- // Note that all series MUST be the same height and all frames the
- // same width! You set the width/height using the -setSize: method.
-
- #import <appkit/appkit.h>
-
- #define GK_DEFAULT_ACTOR_WIDTH 16
- #define GK_DEFAULT_ACTOR_HEIGHT 16
- #define GK_DEAD_ACTOR 0
-
- // Warning: take note of this #define--it fakes an instance variable for us.
- #define GK_location (boundingBox.origin) // an NXPoint; our current location
- // It's here rather than in the .m files because it may be handy for
- // use when writing subclasses...
-
- @interface GKActor:Object
- {
- id renderedImage; // NXImage
- id stage; // the stage the actor is on .. there can only be one
- int drawingLevel; // drawing level on the stage
- NXPoint nextLocation, lastLocation, lastDrawnLocation;
- NXRect boundingBox; // Actor's bounding box (embodies current location)
- int series, frame, cycles, maxSeries, state;
- int *maxFrames;
- BOOL movedThisFrame; // did we move or are we stationary? Set to YES
- // automatically if the actor moved, but you should set this to YES
- // yourself if in an overridden -updateDrawingState method and you
- // changed the actor's appearance such that it needs a redraw
- }
-
- - init; // initialize the new instance vars
-
- // configuring the basic actor...
- - setSize:(const NXSize *)aSize; // set actor's size (enclosing frame in image)
- - setRenderedImage:anImage; // set the bitmap image used to render
- - setSeries:(int)anInt; // set the animation series (row) to use in bitmap
- - setMaxFrames:(const int *)anIntArray count:(int)anInt; // array indexed by
- // series number; gives the number of frames in the series. The
- // input array is copied, so free it when you're done with it
- - (int)drawingLevel;
- - setDrawingLevel:(int)aLevel;
- - stage;
- - setStage:aStage;
-
- // Moving the actor - you usually won't call these but do override -move:
- - move:sender; // Move the actor one animation frame
- - moveOneFrame; // makes the animation advance one step. Call -move:
- // first to set up params. (Called by -renderAt:move:)
- - leaveTheStage; // get the actor off the stage and into the "free" list
-
- // Handling collisions
- - (int)collisionType; // called to determine type of collision shape
- - (void *)shapeStruct; // return pointer to the collision shape
- - collidedWith:anActor; // called when it is detected that we hit something
- // right now does nothing.
-
- // getting info about the GKActor
- - lastAt:(NXPoint *)aPoint; // to find out where actor was last located
- - lastDrawnAt:(NXPoint *)aPoint; // to find out where actor was last drawn
- - at:(NXPoint *)aPoint; // where is the actor now?
- - getBoundingBox:(NXRect *)box; // obtain the bounding box
- - (int)series; // the series we're currently using
- - (int)frame; // the next frame that will be drawn
-
- // drawing the actor and advancing the internal state machine
- - eraseInDirtPile:dirtPile;
- - markInDirtPile:dirtPile; // same as above but called at different times
- - renderAt:(NXPoint *)offset move:(BOOL)moveOk withDirtPile:dirtPile;
- // do movement (possibly) and do the render/draw
- // you should lock focus on view that gets the image before calling.
- // use offset=NULL if no offset is needed.
- - drawActorWithOffset:(NXPoint *)offset; // draw the actor
- // here's what you override to change the way it's drawn.
- // offset MUST be non-NULL, unlike -renderAt:move:
- - updateDrawingState; // called after drawing to advance frames, etc.
-
- @end
-