You are on page 1of 14

KenGamradt Fall2009 LoadingNativeMappy Files

LoadingNativeMappyFiles
y ThissectionbuildsontheideaofcreatinglevelswithMappy. y ItwillprovideinformationandsourcecodeneededtoloadupanativeMappy

filedirectlywithAllegro. y ThiswillallowfortheeditingandloadingofaMappyFMPfiledirectlyintoa game. y ThiswilleliminatetheneedtoexporttheleveldatafromMappy. y Thiswillgreatlyspeedupandsimplifythedevelopmentofatilebasedgame. Majortopicstobecovered y StudyingtheMappyfileformat. y LoadinganativeMappyfile. y EnhancingTankWar.

GameProgramming KenGamradt Fall2009

StudyingtheMappy AllegroLibrary(MappyAL)
y TheMappyfilestructureisbinaryandincludesnotonlythedata,butalsothe

tiles. y AlibrarynamedMappyAL hasbeencreatedtosupportMappywithAllegro programs. y Fortheexamplesshownhereallthatisneededistoaddthemappyal.cand mappyal.hsourcesfilestotheVisualC++projectfolderandthenaddthemas projectresources. TheMappyALLibrary


y TheMappyALlibraryisveryeasytouse,basically:
y MapLoadisusedtoopenaMappyFile. y MapDrawBGdrawsabackgroundoftiles. y MapDrawFGdrawsaforegroundoftiles(specifiedbyalayernumber).

GameProgramming KenGamradt Fall2009

StudyingtheMappy AllegroLibrary(MappyAL)
y Theauthorstatesthatadrawbackof

theMappyALlibraryisthatitonly supports8bitcolor. y TheMappyforumsstatethatit supportsallformats. y Listedherearesomeofthemost usefulglobalvariablesexposedby theMappyALcode.

GameProgramming KenGamradt Fall2009

StudyingtheMappy AllegroLibrary(MappyAL)
Listedherearesomeofthecommonlyusedlibraryfunctions: y voidMapFreeMem(void) y intMapLoad(char*) y intMapLoadVRAM(char*) y intMapGetBlockID(int,int) y intMapGenerateYLookup(void) y intMapChangeLayer(int) y intMapGetXOffset(int,int) y intMapGetYOffset(int,int) y voidMapInitAnims(void) y voidMapUpdateAnims(void) y voidMapDrawBG(BITMAP*,int,int,int,int,int,int) y voidMapDrawFG(BITMAP*,int,int,int,int,int,int,int) y BITMAP*MapMakeParallaxBitmap(BITMAP*,int) y voidMapDrawParallax(BITMAP*,BITMAP*,int,int,int,int,int,int)
GameProgramming KenGamradt Fall2009 5

LoadingaMappy File
y HereisanexampleofusingtheMapLoadfunction:

MapLoad(level.fmp);
y OncetheMappyfilehasbeenloaded,theMappyALlibraryexposesalotof

globalvariablesandfunctionsforworkingwiththeMappyfile. MapFreeMem();
y Shouldalwaysbeusedbeforeloadinganewlevelorendingthegame.

GameProgramming KenGamradt Fall2009

RetrievingtheTileNumber
tile_num =MapGetBlockID(200,300);
y Usedtoobtainthetilenumberatthespecifiedlocation.

DrawingaBackgroundLayer
y Mappyallowsatiletobeconfiguredtobedrawnasthebackgroundorasthe

foregroundforthelayerbeingworkedon. MapDrawBG(screen,map_pos_x,map_pos_y,1,1,200,200);
y Usedtodrawthebackgroundlayerstartingattheupperleftcornercoordinates

(map_pos_x,map_pos_y)ofthescreenwithsize200x200.
GameProgramming KenGamradt Fall2009 7

DrawingaForegroundLayer
y Uptothreeforegroundlayerscanbespecifiedforasinglemap. y Mostofthetimeasinglelayerwillbeusedforalevelwithsometilesbeing

solidandsometilesnot. y Theonlytimethataforegroundneedstobedrawniswhenaparallaxlevelis createdwherethebackground(suchascloudsormountains)scrolls independentlyoftheforegroundobjects(suchasledgesorotherthingsthat arewalkedon). y Forsimplegamesgenerallyonlyabackgroundisdrawn. MapDrawFG(screen,map_pos_x,map_pos_y,1,1,200,200);


y Usedtodrawtheforegroundlayeroverthetopofthebackgroundlayer(with

transparency).

GameProgramming KenGamradt Fall2009

LoadingaNativeMappy File
y TheTestMappyprogramisusedto

demonstrateloadingaNativeMappy fileintoanAllegrobasedprogram. y Dontforgettoaddthemappyal.c andmappyal.hsourcefilestothe projectfolderandaddthemas projectreferences. y ThesefilesmustbecompiledasC fileswhichVisualC++knowshowto dobasedonthefileextension. y Dontforgettoincludethe mappyal.hheaderfile.

GameProgramming KenGamradt Fall2009

LoadingaNativeMappy File

GameProgramming KenGamradt Fall2009

10

EnhancingTankWar(version7)
y ThisversionaddsnativeMappyfile

support. y MappyALwillbeusedtotakecare ofallofthescrollingsotherewillbe alotofcoderemoved. y Thisversionusesthesamemap versionthatwasusedwiththe TestMappyprogram.

GameProgramming KenGamradt Fall2009

11

ProposedChangestoTankWar
y Addmappyal.candmappyal.hto

theproject. ModifyingTankWar(tankwar.h)
y Add:
y #includemappyal.h

y Remove:
y externintmap[]; y BITMAP*tiles;

Mappylevelscontaintiles y BITMAP*scroll;
y

GameProgramming KenGamradt Fall2009

12

ModifyingTankWar(main.cpp)
y setupscreen remove
y Createvirtualbackgroundsection y Loadtilebitmapsection y Drawtilesonvirtualbackgroundsection

y movetank replace
y scroll>w y mapwidth*mapblockwidth y scroll>h y mapheight*mapblockheight

//old //new //old //new

GameProgramming KenGamradt Fall2009

13

ModifyingTankWar(main.cpp)
y main addjustabovethegameloop

//loadtheMappyfile if(MapLoad(map3.fmp)!=0){ allegro_message(Cannotfindmap3.fmp); return1; }


y main drawscrollingwindowssection replace
y blit(scroll,buffer,) y MapDrawBG(buffer,)

//old //new

y main programshutdownsection
y destroy_bitmap(scroll); y MapFreeMem();

//remove //add
14

GameProgramming KenGamradt Fall2009

You might also like