Professional Documents
Culture Documents
LoadingNativeMappyFiles
y ThissectionbuildsontheideaofcreatinglevelswithMappy. y ItwillprovideinformationandsourcecodeneededtoloadupanativeMappy
StudyingtheMappy AllegroLibrary(MappyAL)
y TheMappyfilestructureisbinaryandincludesnotonlythedata,butalsothe
StudyingtheMappy AllegroLibrary(MappyAL)
y Theauthorstatesthatadrawbackof
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.
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
transparency).
LoadingaNativeMappy File
y TheTestMappyprogramisusedto
demonstrateloadingaNativeMappy fileintoanAllegrobasedprogram. y Dontforgettoaddthemappyal.c andmappyal.hsourcefilestothe projectfolderandaddthemas projectreferences. y ThesefilesmustbecompiledasC fileswhichVisualC++knowshowto dobasedonthefileextension. y Dontforgettoincludethe mappyal.hheaderfile.
LoadingaNativeMappy File
10
EnhancingTankWar(version7)
y ThisversionaddsnativeMappyfile
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
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
13
ModifyingTankWar(main.cpp)
y main addjustabovethegameloop
//old //new
y main programshutdownsection
y destroy_bitmap(scroll); y MapFreeMem();
//remove //add
14