MoofWars/TTileGrid.h

/*
    File:       TTileGrid.h
 
    Contains:   A TileGrid is a class that describes a 2 dimensional array of tiles that can be
                drawn as the background for a game.  This current version only supplies
                graphics routines, but collision and other logic should be fairly easy to
                generate.
 
    Written by: Timothy Carroll 
 
    Copyright:  Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
                8/15/96     Timothy Carroll Initial Release
                
 
*/
 
#ifndef _TTILEGRID_
#define _TTILEGRID_
 
#pragma once
 
#include "TTileCollection.h"
#include "GridTilesFormat.h"
 
 
#if PRAGMA_STRUCT_ALIGN
#pragma options align=power
#endif
 
 
 
 
class TTileGrid {
 
    public:
    
    /*************************************************************************************
    Constructor/Destructor
    
    Constructor is mostly used to initialize the object to a clean and known state, but
    doesn't do any actual work.  The actual work of creating the object is a later call.
    
    The Destructor frees all allocated memory and releases the link to the Tile Collection.
    
    *************************************************************************************/
 
    TTileGrid (void);
    ~TTileGrid (void);
 
/*************************************************************************************
    Creating a TileGrid.
    
    A TileGrid (by default) is loaded from a resource, although the potential exists to
    create other methods of creating the tile grid.
 
*************************************************************************************/
    OSErr CreateGridFromResource (SInt16 resID);
    
    
/*************************************************************************************
    Accessors
    
    A couple of accessors are provided for looking up the grid values.  By default, if
    the h and v are outside the grid bounds, we return the "defaultTile" value.
 
*************************************************************************************/
    
    CellGridType GetGridValue (SInt32 h, SInt32 v);
    void SetGridValue (SInt32 h, SInt32 v, CellGridType value);
    
    SInt32  GetGridWidth (void) { return fWidth;};
    SInt32  GetGridHeight (void) { return fHeight;};
    
/*************************************************************************************
    Drawing
    
    This routine takes a point in 16.16 global space, and the clipping rectangle in screen
    coordinates, and does all the right things to draw the grid inside the entire clip rect.
 
*************************************************************************************/
    
    void   DrawGrid (Rect *screenRect, SInt32 topGlobal, SInt32 leftGlobal);
 
 
/*************************************************************************************
    Data for a TileGrid object.
    
*************************************************************************************/
    
    protected:
    
    SInt32              fWidth;
    SInt32              fHeight;
    UInt32              fDefaultTile; // used to draw all out of bounds tiles.
    TTileCollection     *fTiles;
    CellGridType        **fTileData; // variable length array of cell data.
};
 
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#endif
 
 
#endif /* _TTILEGRID_ */