Update: Version 1.044
- new interface for isometric games!
Interface:
Code: Select all
Interface NAUTILUS_WORLD_ISO
CameraCreate.i(X.f,Y.f,Width.f,Height.f)
CameraPosition.i(Camera.i,*InCartesian,*InOffset = #Null)
CameraMove.i(Camera.i,*InCartesian,*InOffset = #Null)
CameraZoomSet.f(Camera.i,Min.f,Max.f,*InScale = #Null)
CameraZoomGet.f(Camera.i)
CameraUnit.i(Camera.i,*OutUnit)
CameraCartesian.i(Camera.i,*OutCartesian)
CameraIsometric.i(Camera.i,*OutIsometric)
CameraClamp.i(Camera.i,*OutClamp)
CameraUpdate.i(Camera.i,*OutTranslation = #Null)
CameraFree.i(Camera.i)
TilesCreate.i()
Tiles.i()
TilesX.i()
TilesY.i()
TileSet.i(X.i,Y.i,Link.i)
TileGet.i(X.i,Y.i)
TileUnit.i(X.i,Y.i,*OutUnit)
TileCartesian.i(X.i,Y.i,*OutCartesian)
TileIsometric.i(X.i,Y.i,*OutIsometric)
TileTranslate.i(Camera.i,X.i,Y.i,*OutPosition,*OutCartesian = #Null,*OutLink = #Null)
TilesFree.i()
Mouse.i(Camera.i,*InMouse,*OutCartesian,*OutUnit = #Null)
TestUnit.i(*InUnit)
TestCartesian.i(*InCartesian)
WorldToScreen.i(Camera.i,*InCartesian,*OutPosition)
ScreenToWorld.i(Camera.i,*InPosition,*OutCartesian,*OutUnit = #Null)
Translate.i(Camera.i,*InIsometric,*OutPosition)
Unit.i(*InCartesian,*OutUnit)
Cartesian.i(*InUnit,*OutCartesian)
Isometric.i(*InCatesian,*OutIsometric)
Release.i()
EndInterface
Code:
Code: Select all
EnableExplicit
XIncludeFile "nautilus.pbi"
;isometric demo
Procedure.i Main()
Protected *engine.NAUTILUS_ENGINE
Protected *iso.NAUTILUS_WORLD_ISO
Protected cam.i
Protected cam_zoom.f
Protected cam_position.NE_VECTOR
Protected cam_move.NE_VECTOR
Protected cam_clamp.NE_CLAMP
Protected px.i
Protected py.i
Protected position.NE_VECTOR
Protected link.i
Protected mouse.NE_VECTOR
Protected mouse_cartesian.NE_VECTOR
Protected mouse_unit.NE_INDEX
Protected tiles.i
Protected engine_delta.f
*engine = nautilusWindow("TEST",800,600,#NE_WINDOW_NORMAL,800,600)
If *engine
*iso = *engine\CreateWorldIso(100,100,40,20);100 x 100 tiles / each tile is 40 x 20 pixels!
If *iso
cam = *iso\CameraCreate(100,100,600,400);camera 'viewport' offset: 100 x 100 & size: 600 x 400
*iso\TilesCreate();create iso tilemap
cam_position\x = 128
cam_position\y = 128
*iso\CameraPosition(cam,@cam_position);position the cam @cartesian pos 128 x 128
cam_zoom = 0.8
*iso\CameraZoomSet(cam,0.5,4,@cam_zoom);set camera zoom (this will change the render matrix so store it before!)
For px = 0 To 99;assing a value to all tiles (could be anything like a pointer to a structure)
For py = 0 To 99
*iso\TileSet(px,py,Random(2))
Next
Next
Repeat
If *engine\InputKey(#VK_A);check 'wasd' keys
cam_move\x - 2 * engine_delta
cam_move\y + 2 * engine_delta
EndIf
If *engine\InputKey(#VK_D)
cam_move\x + 2 * engine_delta
cam_move\y - 2 * engine_delta
EndIf
If *engine\InputKey(#VK_S)
cam_move\x + 2 * engine_delta
cam_move\y + 2 * engine_delta
EndIf
If *engine\InputKey(#VK_W)
cam_move\x - 2 * engine_delta
cam_move\y - 2 * engine_delta
EndIf
*engine\InputMouse(@mouse);get the mouse position
*engine\RenderBegin(#Null,@engine_delta);start rendering
*engine\DrawText(10,10,"TILES RENDERED: " + Str(tiles));how many tiles are currently rendered
cam_zoom + *engine\InputMouseWheel() / 1000;get the mousewheel input
*iso\CameraZoomSet(cam,0.5,4,@cam_zoom);set the zoom according to the mousewheel
If *iso\Mouse(cam,@mouse,@mouse_cartesian,@mouse_unit);translate the mouse to the actual cartesian postition
*iso\TileSet(mouse_unit\x,mouse_unit\y,3);if the mouse is over the tile make it red -> value 3
*engine\DrawText(10,20,"MOUSE POSITION: " + StrF(mouse_cartesian\x,0) + " x " + StrF(mouse_cartesian\y,0));if mouse is inside the iso camere display its position
EndIf
*engine\RenderClip(100,100,600,400);render this will clip all tiles at the camera boundary
*engine\RenderPush();this will backup the render matrix
*iso\CameraMove(cam,@cam_move);move the camera to the new position
*iso\CameraUpdate(cam);update the camera
*iso\CameraClamp(cam,@cam_clamp);clamp - determine what tiles can be drawn - what tile are visible
tiles = 0
For px = cam_clamp\min\x To cam_clamp\max\x
For py = cam_clamp\min\y To cam_clamp\max\y
If *iso\TileTranslate(cam,px,py,@position,#Null,@link);translate the the tile accroding to the camera
Select link;if the tile is visible draw it - color it according to the 'linked' value
Case 0:*engine\DrawDiamond(position\x,position\y,40,20,#False,#True,$FF444444)
Case 1:*engine\DrawDiamond(position\x,position\y,40,20,#False,#True,$FF222222)
Case 2:*engine\DrawDiamond(position\x,position\y,40,20,#False,#True,$FF111111)
Case 3:*engine\DrawDiamond(position\x,position\y,40,20,#False,#False,$FF0000DD)
EndSelect
tiles + 1
EndIf
Next
Next
*engine\RenderPop();restore the render matrix
*engine\RenderUnclip();unclip the render area
*engine\DrawBox(100,100,600,400); draw a box just to show the camera 'view'
*engine\RenderEnd();stop rendering
Until *engine\WindowExit()
*iso\Release()
EndIf
*engine\Release()
EndIf
ProcedureReturn #Null
EndProcedure
Main()
End
Download Engine & Iso Example (x64):
https://www.dropbox.com/s/r71inwbfb8nm9 ... 4.zip?dl=0
More Examples & Demos:
https://www.dropbox.com/s/agw30e7j189y0 ... o.zip?dl=0
Have fun playing around
Im still working on it
Dokumentation is still not done.
Let me know if u have any questions / criticism.