; *=-------------------------------------------------------------------=* ; >> Simple Map Editor Example << ; *=-------------------------------------------------------------------=* ; ; This is basic map editor that includes Load and Save functions. ; The editor only supports a single map layer, but you can expand ; on those yourself. ; ; ; Controls: ; ; Mouse Left Button: Write Current block to map ; Mouse Wheel: Change Current block ; Arrow Keys: Scroll View ; F1 Key: Load Previously Saved Level ; F2 Key: Save current level ; ; *=-------------------------------------------------------------------=* // ----------------------------------------------------- // --[INCLUDE MAP]------------------------------------- // ----------------------------------------------------- #Include "maps" ; Make the APP limit itself to 30 frames per second ; or less SetFPS 40 ; set the screen title TitleScreen "Simple Map Editor" ; -------------------------------------- ; CReate a map and level to edit ; -------------------------------------- ; Create a new map with provision for 5 levels ThisMap=NewMap(5) ; Load common grass blocks from the help files Blocks$ =ProgramDir$()+"Help\Commands/Media/" BLocks$+="Grass-Tiles.bmp" LoadMapGFX Blocks$,ThisMap,32,32,RGB(0,0,0),2 ; set the name of the test level we'll Level_file_name$="TestLevel.Level" ; Either load the existing level or ; create a level with the map that's 50 by 50 blocks If FileExist(Level_file_name$) ThisLevel=LoadNewLevel(Level_File_Name$,ThisMap) Else ThisLevel=NewLevel(ThisMap, 50,50) EndIf ; The current block the user is drawing CurrentDrawingBlock = 13 // ----------------------------------------------------- // --[MAIN LOOP]---------------------------------------- // ----------------------------------------------------- Do // Render Scene Cls 0 DrawMap THisMap,ThisLevel,-ScrollX,-ScrollY // handle all the mouse controls Gosub Handle_Mouse Gosub Handle_Key_Board // Display the map info Gosub Display_Map_Info Sync Loop EscKey() End //------------------------------------------------------- Handle_Mouse: //------------------------------------------------------- // Render the current block at mouse position Mx=MouseX() My=MouseY() Mz=MouseMoveZ() Mb=MouseButton() If MZ<>0 CurrentDrawingBlock=WrapValue(CurrentDrawingBlock+Mz,0, GetMapBlocks(THisMap)) EndIf // Convert Mouse Screen coordinates to Map Tile Coords MapTileX = (ScrollX+MX)/GetMapBlockWidth(ThisMap) MapTileY = (ScrollY+MY)/GetMapBlockHeight(ThisMap) // compute the cords of the hower box x1=(MapTileX * GetMapBlockWidth(ThisMap)) - ScrollX y1=(MapTileY * GetMapBlockHeight(ThisMap)) - ScrollY x2=X1+GetMapBlockWidth(ThisMap) y2=Y1+GetMapBlockHeight(ThisMap) // display a hover box, so where the mouse is over BoxC x1,y1,x2,y2,false, $ff0000 // display the current block at the mouses position DrawMapBlk ThisMap,CurrentDrawingBLock,MX,MY,0 // check if thne left mouse button is down If MB And 1 // if the button is press, we write the current drawing block // to the map at this position If MapTileX>=0 And MapTileY>=0 If MapTileX<= GetLevelWidth(ThisMap,ThisLevel) If MapTileY<= GetLevelHeight(ThisMap,ThisLevel) PokeLevelTile ThisMap,ThisLevel,MapTileX,MapTileY,CurrentDrawingBlock EndIf EndIf EndIf EndIf Return //------------------------------------------------------- Handle_Key_Board: //------------------------------------------------------- // ------------------------------------------ // Load Pre existing Level // ------------------------------------------ If FunctionKeys(1)=true If FileExist(Level_file_name$) LoadLevel Level_file_name$,ThisMap,ThisLevel EndIf EndIf // ------------------------------------------ // Save Level existing Level // ------------------------------------------ If FunctionKeys(2)=true SaveLevel Level_file_name$,ThisMap,ThisLevel EndIf // ------------------------------------------ // ARROW KEY scrolling // ------------------------------------------ If ScrollX>0 And LeftKey() ScrollX-=GetMapBlockWidth(ThisMap) EndIf If ScrollX< GetLevelABSWidth(ThisMap,ThisLevel) If RightKey() ScrollX+=GetMapBlockWidth(ThisMap) EndIf EndIf If ScrollY>0 And UpKey() ScrollY-=GetMapBlockHeight(ThisMap) EndIf If ScrollY< GetLevelABSHeight(ThisMap,ThisLevel) If DownKey() ScrollY+=GetMapBlockHeight(ThisMap) EndIf EndIf Return //------------------------------------------------------- Display_Map_Info: //------------------------------------------------------- // ----------------------------------------------- // render current map information // ----------------------------------------------- s$ =" Editing Map:"+Digits$(ThisMap,2) s$+=" Level:"+Digits$(THisLevel,2) // Render current position s$+=" Position:"+Str$(ScrollX) s$+="X, "+Str$(ScrollY)+"Y" s$+=" Current Drawing Block:" s$+=Str$(CurrentDrawingBlock) Print s$ Print " (F1) = Load Level" Print " (F2) = Save Level" Return |