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

CMap.cpp

Go to the documentation of this file.
00001 // Copyright 2002 Kenneth Guy,
00002 // 
00003 // You are free to take the source and do as you wish with it.
00004 // However it would be nice if you let me know if the code was useful
00005 // to you and give me an acknowledgement if you use a significant portion
00006 // of the code in an application.
00007 // 
00008 // CMap.cpp
00009 
00014 #include "CMap.h"
00015 #include "CGame.h"
00016 
00017 #include <e32svr.h>
00018 #include <e32base.h>
00019 
00020 #include "TMapLineType.h"
00021 
00026 CMap::CMap(CGame &aGame,const TUint16* aMapSprites,const TInt16* aMapData)
00027   : iMapData(aMapData), iMapSprites(aMapSprites), iGame(aGame) {
00028 
00029 };
00030 
00039 CMap* CMap::NewL(CGame &aGame,const TUint16* aMapSprites,
00040                  const TInt16* aMapData) {
00041   CMap* self= new (ELeave) CMap(aGame,aMapSprites,aMapData);
00042   CleanupStack::PushL(self);
00043   self->ConstructL();
00044   CleanupStack::Pop(self);
00045   return(self);
00046 }
00047 
00054 void CMap::ConstructL() {
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 }
00085 
00086 
00088 CMap::~CMap() {
00089   delete [] iOffScreenMap;
00090 }
00091 
00094 TUint16* CMap::BlitStart() {
00095   return iBlitStart;
00096 }
00097 
00100 TUint16* CMap::DrawEnd() {
00101   return iDrawEnd;
00102 }
00103 
00106 TBool CMap::Finished() {
00107   return iFinished;
00108 }
00109 
00120 void CMap::ScrollMap() {
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 };
00146 
00154 void CMap::ProcessMapLine() {
00155   PlotMapLineAsm();
00156   while(iMapData[0] & EMapLineObject) {
00157     iGame.AddBadGuy(iMapData[0],iMapData+1);                 
00158     iMapData+=8;
00159   }
00160 }
00161 
00162 

Documentation for Game (Beta) version 1.44.