Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

CMap Class Reference

Offscreen map. More...

#include <CMap.h>

Collaboration diagram for CMap:

Collaboration graph
[legend]
List of all members.

Public Methods

 ~CMap ()
 destructor. More...

void ScrollMap ()
 Scroll map. More...

void BlitAsm ()
 Copy the offscreen map to the screen. More...

TUint16 * BlitStart ()
 What will be copied to top left of visible screen. More...

TUint16 * DrawEnd ()
 The end of the offscreen map. More...

TBool Finished ()
 Have we got to the end of the map data. More...


Static Public Methods

CMap * NewL (CGame &aGame, const TUint16 *aMapSprites, const TInt16 *aMapData)
 Leave safe construction. More...


Private Methods

 CMap (CGame &aGame, const TUint16 *aMapSprites, const TInt16 *aMapData)
 Constructor. More...

void ConstructL ()
 2nd phase Constuctor. More...

void ProcessMapLine ()
 Process a line of map data. More...

void PlotMapLineAsm ()
 Plot the next line of map sprites. More...


Private Attributes

const TInt16 * iMapData
 Map data. More...

TUint16 * iMapDrawPoint
 Places to draw next set of background sprites. More...

TUint16 * iDrawArea
 offscreen memory area. More...

TUint16 * iDrawEnd
 End of offscreen memory area. More...

TUint16 * iScreenBase
 Base address of screen memory. More...

TUint16 * iBlitStart
 Point to start copy to screen from Must be the 6th member after the vtable pointer for assembler functions. More...

const TUint16 * iMapSprites
 Background sprites Must be the 7th member after the vtable pointer for assembler functions. More...

TInt iBlitPoint
 How far we have scrolled throw current line of sprites. More...

CGameiGame
 Game object for adding bad guys. More...

TBool iFinished
 Have we got to the end of the map. More...

TUint16 * iOffScreenMap
 Offscreen memory area. More...


Detailed Description

Offscreen map.

This class handles the offscreen map a visible area of which is copied to screen memory for each frame of the game. The area overlaps the visible area so that we can scroll by moving the visible area across the offscreen area. Drawing to this map should wrap at the end of the memory area and start again at the beginning. The current top left is defined by the point at which the copy to the screen till take place which is returned by BlitStart()

The class processes map data to draw the background sprites adding bad guys. See enum TMapLineType for more information.

Definition at line 37 of file CMap.h.


Constructor & Destructor Documentation

CMap::~CMap  
 

destructor.

Definition at line 88 of file CMap.cpp.

References iOffScreenMap.

00088             {
00089   delete [] iOffScreenMap;
00090 }

CMap::CMap CGame   aGame,
const TUint16 *    aMapSprites,
const TInt16 *    aMapData
[private]
 

Constructor.

see CMap::NewL() for parameters

Definition at line 26 of file CMap.cpp.

Referenced by NewL().

00027   : iMapData(aMapData), iMapSprites(aMapSprites), iGame(aGame) {
00028 
00029 };


Member Function Documentation

CMap * CMap::NewL CGame   aGame,
const TUint16 *    aMapSprites,
const TInt16 *    aMapData
[static]
 

Leave safe construction.

Parameters:
aGame  where to add bad guys
aMapSprites  background sprites each 64x50 pixels
aMapData  lines of map data, see enum TMapLineType

Definition at line 39 of file CMap.cpp.

References CMap(), and ConstructL().

Referenced by CGame::ConstructL().

00040                                          {
00041   CMap* self= new (ELeave) CMap(aGame,aMapSprites,aMapData);
00042   CleanupStack::PushL(self);
00043   self->ConstructL();
00044   CleanupStack::Pop(self);
00045   return(self);
00046 }

void CMap::ScrollMap  
 

Scroll map.

Scrolls the map by first adding 4 pixels to the point at which we copy to the screen. Then it checks if we need to plot a new row of map sprites (may sprite is 64 pixels wide so every 16 times round we will need to), if so it calls ProcessMapLine() to plot the sprites and add any bad guys.

Unless we have hit the end of the map, then do nothing.

Definition at line 120 of file CMap.cpp.

References iBlitPoint, iBlitStart, iDrawArea, iDrawEnd, iFinished, iMapData, and ProcessMapLine().

Referenced by CGame::Play().

00120                      {
00121 
00122   if(!(iMapData[0] & EMapLineEndOfMap)) {
00123     iBlitStart+=4;
00124     if(iBlitStart >= iDrawEnd)
00125       iBlitStart=iDrawArea;
00126     
00127     // every 16*4 pixels (a map sprite is 64 pixels wide), we need to plot
00128     // another line of map sprites
00129     iBlitPoint++;
00130     if(iBlitPoint>=16) {
00131       iBlitPoint=0;
00132       ProcessMapLine();
00133     }
00134   } else {
00135     // scroll last line of sprites all the way onto the screen.
00136     if(iBlitPoint <24) {
00137       iBlitPoint++;
00138       iBlitStart+=4;
00139       if(iBlitStart >= iDrawEnd)
00140         iBlitStart=iDrawArea;
00141     } else {
00142       iFinished=ETrue;
00143     }
00144   }
00145 };

void CMap::BlitAsm  
 

Copy the offscreen map to the screen.

Copies from iBlitStart to the screen, will wrap when it reaches iDrawEnd

Referenced by CGame::Play().

TUint16 * CMap::BlitStart  
 

What will be copied to top left of visible screen.

Definition at line 94 of file CMap.cpp.

References iBlitStart.

Referenced by TSprite32x24::Plot().

00094                          {
00095   return iBlitStart;
00096 }

TUint16 * CMap::DrawEnd  
 

The end of the offscreen map.

Definition at line 100 of file CMap.cpp.

References iDrawEnd.

Referenced by TSprite32x24::Plot().

00100                        {
00101   return iDrawEnd;
00102 }

TBool CMap::Finished  
 

Have we got to the end of the map data.

Definition at line 106 of file CMap.cpp.

References iFinished.

Referenced by CGame::HandleKeys(), CGame::MapSpeed(), and CGame::Play().

00106                      {
00107   return iFinished;
00108 }

void CMap::ConstructL   [private]
 

2nd phase Constuctor.

Get the screen base from RScreenUtils. Allocate the offscreen map and plot the first 11 lines of the background.

Definition at line 54 of file CMap.cpp.

References RScreenUtils::Close(), iBlitPoint, iBlitStart, iDrawArea, iDrawEnd, iMapDrawPoint, iOffScreenMap, iScreenBase, RScreenUtils::Open(), ProcessMapLine(), and RScreenUtils::ScreenBase().

Referenced by NewL().

00054                       {
00055   // get the base address of screen memory
00056   RScreenUtils screen;
00057   User::LeaveIfError(screen.Open());
00058   iScreenBase=screen.ScreenBase();
00059   screen.Close();
00060 
00061   // offscreen map,
00062   // longer than the screen so we can scroll one set of map sprites
00063   // off while the next is scrolling on, also space above and bellow
00064   // so that we can move sprites on and off
00065   iOffScreenMap=new (ELeave) TUint16[(11*64)*248];
00066   for(TInt i=0;i<(11*64)*248;i++)
00067     iOffScreenMap[i]=0x0000;
00068 
00069   iDrawArea=iOffScreenMap+((11*64)*24);
00070 
00071   // Point at which to draw the next line of map sprites
00072   iMapDrawPoint=iDrawArea;
00073   // where to start copying to the screen
00074   iBlitStart=iDrawArea;
00075   // end of the draw area,
00076   iDrawEnd=iDrawArea+((11*64)*224);
00077 
00078   // keeps track of when we need to plot a new line of map sprites
00079   iBlitPoint=0;
00080 
00081   // draw first screen full of map
00082   for(TInt i=0;i<11;i++) 
00083     ProcessMapLine();
00084 }

void CMap::ProcessMapLine   [private]
 

Process a line of map data.

Map data consits of one row of background sprites, and then zero or more bad guys to add. see enum TMapDataLine for more information.

Leaves the iMapData pointing to the next line of background sprites.

Definition at line 154 of file CMap.cpp.

References CGame::AddBadGuy(), iGame, iMapData, and PlotMapLineAsm().

Referenced by ConstructL(), and ScrollMap().

00154                           {
00155   PlotMapLineAsm();
00156   while(iMapData[0] & EMapLineObject) {
00157     iGame.AddBadGuy(iMapData[0],iMapData+1);                 
00158     iMapData+=8;
00159   }
00160 }

void CMap::PlotMapLineAsm   [private]
 

Plot the next line of map sprites.

This plots the next vertical line of four map sprites to the offscreen map.

Referenced by ProcessMapLine().


Member Data Documentation

const TInt16* CMap::iMapData [private]
 

Map data.

Must be the 1st member after the vtable pointer for assembler functions.

Definition at line 61 of file CMap.h.

Referenced by ProcessMapLine(), and ScrollMap().

TUint16* CMap::iMapDrawPoint [private]
 

Places to draw next set of background sprites.

Must be the 2nd member after the vtable pointer for assembler functions.

Definition at line 64 of file CMap.h.

Referenced by ConstructL().

TUint16* CMap::iDrawArea [private]
 

offscreen memory area.

Must be the 3rd member after the vtable pointer for assembler functions.

Definition at line 67 of file CMap.h.

Referenced by ConstructL(), and ScrollMap().

TUint16* CMap::iDrawEnd [private]
 

End of offscreen memory area.

Must be the 4th member after the vtable pointer for assembler functions.

Definition at line 70 of file CMap.h.

Referenced by ConstructL(), DrawEnd(), and ScrollMap().

TUint16* CMap::iScreenBase [private]
 

Base address of screen memory.

Must be the 5th member after the vtable pointer for assembler functions.

Definition at line 73 of file CMap.h.

Referenced by ConstructL().

TUint16* CMap::iBlitStart [private]
 

Point to start copy to screen from Must be the 6th member after the vtable pointer for assembler functions.

Definition at line 76 of file CMap.h.

Referenced by BlitStart(), ConstructL(), and ScrollMap().

const TUint16* CMap::iMapSprites [private]
 

Background sprites Must be the 7th member after the vtable pointer for assembler functions.

Definition at line 79 of file CMap.h.

TInt CMap::iBlitPoint [private]
 

How far we have scrolled throw current line of sprites.

ie when we need to plot a new line of sprites.

Definition at line 84 of file CMap.h.

Referenced by ConstructL(), and ScrollMap().

CGame& CMap::iGame [private]
 

Game object for adding bad guys.

Definition at line 88 of file CMap.h.

Referenced by ProcessMapLine().

TBool CMap::iFinished [private]
 

Have we got to the end of the map.

Definition at line 89 of file CMap.h.

Referenced by Finished(), and ScrollMap().

TUint16* CMap::iOffScreenMap [private]
 

Offscreen memory area.

Definition at line 90 of file CMap.h.

Referenced by ConstructL(), and ~CMap().


The documentation for this class was generated from the following files:
Documentation for Game (Beta) version 1.44.