Es gibt ein neues Interface mit 2D TileMap & Camera Funktionen
Interface:
Code: Alles auswählen
Interface NAUTILUS_ENGINE
;...
CreateOrtho.i(TilesX.i,TilesY.i,TileWidth.i,TileHeight.i);<- Create NAUTILUS_ORTHO object/interface
;...
EndInterface
Interface NAUTILUS_ORTHO
Tiles.i()
TilesX.i()
TilesY.i()
TileWidth.i()
TileHeight.i()
CameraCreate.i(X.f,Y.i,Width.f,Height.f)
CameraOrigin.i(Camera.i,*Origin,*Offset = #Null)
CameraMove.i(Camera.i,*Move,*Offset = #Null)
CameraIndex.i(Camera.i,*Index)
CameraPosition.i(Camera.i,*Position)
CameraClamp.i(Camera.i,TilesX.i = 2,TilesY.i = 2)
CameraZoom.f(Camera.i,Min.f,Max.f,*Scale = #Null)
CameraScale.f(Camera.i)
CameraUpdate.i(Camera.i,*Clamp = #Null,*Translation = #Null)
CameraDestroy.i(Camera.i)
Mouse.i(Camera.i,*Mouse,*Position,*Index = #Null)
WorldToScreen.i(Camera.i,*Input,*Output)
ScreenToWorld.i(Camera.i,*Input,*Output)
TileMapCreate.i()
TileMapToScreen.i(Camera.i,X.i,Y.i,*Position,*Link = #Null)
TileMapGet.i(X.i,Y.i)
TileMapSet.i(X.i,Y.i,Link.i)
TileMapDestroy.i()
Release.i()
EndInterface
Code:
Code: Alles auswählen
EnableExplicit
;Nautilus Engine
;Version: 0.33 beta
;Author: Mijikai
;Ortho Camera Example
XIncludeFile "nautilus.pbi"
Macro WindowEvents()
Repeat
win_msg = WindowEvent()
If win_msg = #PB_Event_CloseWindow
Break 2
EndIf
Until win_msg = #Null
EndMacro
Procedure.i Demo(Width.i,Height.i,Title.s,ViewWidth.i,ViewHeight.i,FPS.i)
Protected win.i
Protected win_handle.i
Protected win_flag.i
Protected win_msg.i
Protected *engine.NAUTILUS_ENGINE
Protected engine_delta.f
Protected engine_fps.i
Protected engine_error.i
Protected screen_center.NAUTILUS_VECTOR_STRUCT
Protected *atlas.NAUTILUS_ATLAS
Protected *tile.NAUTILUS_TILE
;---------------------------------------------------------
Protected mouse.NAUTILUS_VECTOR_STRUCT
Protected *ortho.NAUTILUS_ORTHO
Protected cam.i
Protected cam_scale.f
Protected cam_origin.NAUTILUS_VECTOR_STRUCT
Protected cam_move.NAUTILUS_VECTOR_STRUCT
Protected cam_clamp.NAUTILUS_CLAMP_STRUCT
Protected px.i
Protected py.i
Protected tile_position.NAUTILUS_VECTOR_STRUCT
Protected tile_link.i
Protected mouse_active.i
Protected mouse_position.NAUTILUS_VECTOR_STRUCT
Protected mouse_index.NAUTILUS_INDEX_STRUCT
;---------------------------------------------------------
win_flag|#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget
win_flag|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
win = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,win_flag)
If win
win_handle = WindowID(win)
*engine = nautilusCreate(win_handle,ViewWidth,ViewHeight,FPS)
If *engine
*engine\RenderFilter()
*engine\RenderAspect()
*engine\RenderColor($400A05)
*engine\ViewPortCenter(@screen_center)
*atlas = *engine\CreateAtlas(?floor,#Null$)
*tile = *atlas\CreateTile(2,1,0,0,32,32)
;---------------------------------------------------------
*ortho = *engine\CreateOrtho(100,100,32,32) ;<- create the ortho object/interface
*ortho\TileMapCreate() ;<- create a tilemap (not needed a camera can also be used with a custom tilemap!)
For py = 0 To *ortho\TilesY() - 1
For px = 0 To *ortho\TilesX() - 1
*ortho\TileMapSet(px,py,Random(1)) ;<- set the link - the link stores informations related ti the tile
Next
Next
cam = *ortho\CameraCreate(100,100,400,200) ;<- create a camera
cam_scale = 1 ;<- initial scale/zoom factor
cam_origin\x = 16 ;<- camera origin
cam_origin\x = 16
*ortho\CameraOrigin(cam,@cam_origin) ;<- set camera origin
;---------------------------------------------------------
Repeat
WindowEvents()
If *engine\InputKey(#VK_ESCAPE):Break:EndIf
If *engine\InputKey(#VK_W):cam_move\y - 4 * engine_delta:EndIf
If *engine\InputKey(#VK_S):cam_move\y + 4 * engine_delta:EndIf
If *engine\InputKey(#VK_A):cam_move\x - 4 * engine_delta:EndIf
If *engine\InputKey(#VK_D):cam_move\x + 4 * engine_delta:EndIf
*engine\InputMouse(@mouse)
cam_scale + (*engine\InputMouseWheel() / 1000) ;<- camera zoom
Round(cam_scale ,#PB_Round_Nearest)
mouse_active = *ortho\Mouse(cam,@mouse,@mouse_position,@mouse_index) ;<- get the tile map mouse positions
*ortho\CameraMove(cam,@cam_move) ;<- move the camera to new position
*ortho\CameraZoom(cam,0.5,3,@cam_scale) ;<- zoom the camera
*engine\RenderBegin(@engine_delta,@engine_fps,@engine_error)
;---------------------------------------------------------
*engine\RenderClip(100,100,400,200) ;<- clip the camera
*engine\RenderPush() ;<- backup the current render matrix
*ortho\CameraUpdate(cam,@cam_clamp) ;<- update the camera
For py = cam_clamp\min\y To cam_clamp\max\y
For px = cam_clamp\min\x To cam_clamp\max\x
*ortho\TileMapToScreen(cam,px,py,@tile_position,@tile_link) ;<- translate all tiles that are visible
If mouse_active
If px = mouse_index\x And py = mouse_index\y
*tile\DrawEx(tile_link,tile_position\x,tile_position\y,#False,#Null,#Null,$FF00FF)
Else
*tile\Draw(tile_link,tile_position\x,tile_position\y)
EndIf
Else
*tile\Draw(tile_link,tile_position\x,tile_position\y)
EndIf
Next
Next
*engine\RenderPop() ;<- restore render matrix
*engine\RenderUnclip() ;<- unclip the camera
*engine\DrawBox(100,100,400,200)
;---------------------------------------------------------
*engine\DrawText(10,10,"Nautilus Engine",#False,#False,200)
*engine\DrawText(10,25,"FPS " + Str(engine_fps),#False,#False,200)
*engine\DrawText(10,40,"DLT " + StrF(engine_delta,2),#False,#False,200)
*engine\DrawText(10,55,"Mouse Index: " + Str(mouse_index\x) + " x " + Str(mouse_index\y),#False,#False,200)
*engine\RenderEnd()
If engine_error;exit if there is an error
Break
EndIf
ForEver
*engine\Release();this will free all resources and objects/interfaces
EndIf
CloseWindow(win)
EndIf
EndProcedure
Demo(1080,720,"Nautilus Engine (Ortho Camera) v.0.33 beta",600,400,60)
End
DataSection
floor:
;{ floor.png - Size: 236 Bytes
!dw 05089h, 0474Eh, 00A0Dh, 00A1Ah, 00000h, 00D00h, 04849h, 05244h, 00000h, 04000h, 00000h, 02000h, 00208h, 00000h, 02D00h, 0E9FFh, 000D3h, 00000h, 049B3h, 04144h, 05854h, 0EDC3h, 0C198h, 00409h, 00C21h, 03345h, 0F4CBh, 055E0h, 06CF0h, 0E917h, 032C5h, 0C3ACh, 0925Eh, 0522Ah, 05D85h, 0C1ECh, 09645h, 07765h, 01660h, 0701Dh
!dw 039F8h, 08129h, 05F07h, 03BC9h, 0CB64h, 0D339h, 0B5CAh, 09113h, 07AAAh, 067EFh, 043D0h, 0B308h, 07BF9h, 0A53Bh, 08694h, 04BD3h, 0FD29h, 08F3Ch, 00AFFh, 02220h, 0C631h, 07481h, 0DCE7h, 0F5FBh, 06F80h, 0CC66h, 06B5Ch, 0D53Dh, 0FCEAh, 02D07h, 0085Eh, 00080h, 03403h, 04D7Ah, 0D999h, 096AFh, 09C88h, 0F56Dh, 0BE21h, 0002Eh
!dw 0AF33h, 003FDh, 06D5Fh, 08D08h, 00022h, 04002h, 0D0A3h, 03428h, 00B0Ah, 00021h, 00A34h, 0428Dh, 018A3h, 00462h, 083B8h, 00F46h, 0F734h, 07D47h, 0E66Ch, 06BA6h, 05554h, 03EC7h, 0034Ch, 0E5B6h, 054EEh, 0B6FEh, 07AFAh, 009FDh, 00798h, 0BD79h, 02B92h, 094DFh, 00000h, 00000h, 04549h, 0444Eh, 042AEh, 08260h
;}
EndDataSection