[ENGINE] 2D Engine Nautilus (Win x86 & x64)

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win)

Post by Mijikai »

Mythros wrote:Where to download this?!
Download Engine & Iso Example (x64):
-

More Examples & Demos:
-
Last edited by Mijikai on Wed Jul 01, 2020 9:44 pm, edited 1 time in total.
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: [ENGINE] 2D Engine Nautilus (Win)

Post by Lord »

Mythros wrote:Where to download this?!
Look 4 postings up.
Image
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win)

Post by Mijikai »

Update v.1.046:
- new renderer & timing code

How to render now:

Code: Select all

While *engine\RenderUpdate();<- sheduled update loop (clocked at the internal 'fps' / fixed timestamp)
;- update physics here
Wend

*engine\RenderBegin()
;- render everything in here
*engine\RenderEnd()
Download:
-
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by Mijikai »

Update: 1.050

This Update brings huge changes as i rewrote most parts of the engine.
I really want the engine to be small and easy to use.

So all besides rendering is on you :)

Here is the new include:

Code: Select all


EnableExplicit

Import "nautilus.lib"
  nautilusWindow.i(Width.i,Height.i,Title.s = #Null$,Type.i = #Null,TopMost.i = #False)
  nautilusEngine.i(Hwnd.i,Width.i,Height.i)
  nautilusVersion.i()
EndImport

#NAUTILUS_VERSION = $1050

Enumeration
  #NAUTILUS_WINDOW_NORMAL
  #NAUTILUS_WINDOW_SIZEABLE
  #NAUTILUS_WINDOW_POPUP
  #NAUTILUS_WINDOW_SCREEN
EndEnumeration

Structure NAUTILUS_SIZE_STRUCT
  x.f
  y.f
  cx.f
  cy.f
EndStructure

Structure NAUTILUS_TEXTURE_STRUCT
  Object.i
  size.NAUTILUS_SIZE_STRUCT
EndStructure

Interface NAUTILUS_WINDOW
  Hwnd.i()
  Screen.i(Code.i = #Null)
  ScreenMode.i()
  Title.i(Title.s,Append.i = #False)
  CursorHide.i(Flag.i = #True)
  CursorClip.i(Flag.i = #True)
  TimerCreate.i(*Fps = #Null,*Delta = #Null,Milliseconds.i = 20)
  TimerEvent.i()
  TimerWait.i()
  TimerError.i()
  PollEvents.i()
  KeyState.i()
  KeyDown.i(Code.i)
  KeyUp.i(Code.i)
  KeyPushed.i(Code.i)
  KeyChr.i(*Code)
  MouseState.i()
  MousePosition.i(*PosX,*PosY)
  MouseWheel.i(*Pos)
  MouseLeftDown.i()
  MouseLeftUp.i()
  MouseLeftPushed.i()
  MouseLeftDbl.i()
  MouseRightDown.i()
  MouseRightUp.i()
  MouseRightPushed.i()
  MouseRightDbl.i()
  Callback.i(*Callback,*Parameter)
  Close.i()
  Exit.i()
  Release.i()
EndInterface

Interface NAUTILUS_FONT
  SpacingGet.i(*Spacing.Float)
  SpacingSet.i(Spacing.f = #Null)
  Release.i()
EndInterface

Interface NAUTILUS_ANIMATION
  Active.i(Flag.i = #True)
  Once.i(Flag.i = #True)
  FrameStart.i(Start.i = -1)
  FrameStop.i(Stop.i = -1)
  FramePos.i(Pos.i = -1)
  Frame.i()
  FrameCount.i()
  FrameOutput.i(*Output)
  Release.i()
EndInterface

Interface NAUTILUS_TILE
  Count.i()
  SizeGet.i(*Width,*Height)
  SizeSet.i(Width.f,Height.f)
  SizeReset.i()
  Draw.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  DrawText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDraw.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDrawText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  Release.i()  
EndInterface

Interface NAUTILUS_TEXTURE
  SizeGet.i(*Width,*Height)
  SizeSet.i(Width.f,Height.f)
  SizeReset.i()
  Draw.i(X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDraw.i(Layer.i,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  CreateTile.i(CountX.i,CountY.i,X.i,Y.i,Width.i,Height.i,OffsetX.i = #Null,OffsetY.i = #Null)
  Release.i() 
EndInterface

Interface NAUTILUS_ENGINE
  RenderVSync.i()
  RenderVSyncMode.i(Flag.i = #False)
  RenderAspect.i(Flag.i = #True)
  RenderSize.i(*Width.Integer,*Height.Integer)
  RenderResize.i(Width.i,Height.i)
  RenderViewport.i()
  RenderFilter.i(Flag.i = #True)
  RenderColor.i(Color.i = #Null)
  RenderClip.i(X.f,Y.f,Width.f,Height.f)
  RenderUnclip.i()
  RenderPush.i()
  RenderPop.i()
  RenderRotate.i(Angle.f)
  RenderScale.i(X.f,Y.f)
  RenderTranslate.i(X.f,Y.f)
  RenderReset.i()
  RenderTextureMode.i()
  RenderPrimitiveMode.i()
  RenderBegin.i()
  RenderEnd.i()
  RenderLayer.i()
  RenderUpdate.i()
  RenderMouse.i(X.i,Y.i,*OutX.Integer,*OutY.Integer)
  DrawTextObject.i(*Texture.Integer = #Null,*Tile.Integer = #Null,*Font.Integer = #Null)
  DrawTextSize.i(*Width.Float,*Height.Float)
  DrawTextResize.f(Width.f,Height.f)
  DrawTextResetSize.i()
  DrawTextSpacingGet.i(*Spacing.Float)
  DrawTextSpacingSet.i(Spacing.f)
  DrawText.i(X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(X.f,Y.f,Text.s,Width.f,Height.f,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawPointSize.i(Size.f = 1)
  DrawLineSize.i(Size.f = 1)
  DrawPoint.i(X.f,Y.f,Color.i = $FFFFFFFF)
  DrawLine.i(X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  DrawTriangle.i(X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawBox.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawRhombus.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawCircle.i(X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawPointSize.i(Layer.i,Size.f = 1)
  LayerDrawLineSize.i(Layer.i,Size.f = 1)
  LayerDrawPoint.i(Layer.i,X.f,Y.f,Color.i = $FFFFFFFF)
  LayerDrawLine.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  LayerDrawTriangle.i(Layer.i,X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawBox.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawRhombus.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawCircle.i(Layer.i,X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerClip.i(Layer.i,X.f,Y.f,Width.f,Height.f)
  LayerUnclip.i(Layer.i)
  LayerPush.i(Layer.i)
  LayerPop.i(Layer.i)
  LayerRotate.i(Layer.i,Angle.f)
  LayerScale.i(Layer.i,X.f,Y.f)
  LayerTranslate.i(Layer.i,X.f,Y.f)
  LayerReset.i(Layer.i)
  LayerCallback.i(Layer.i,*Function,*Paramater)
  CreateTexture.i(*Buffer,File.s = #Null$)
  CreateAnimation.i(Start.i,Stop.i,Cycle.i,Active.i = #True,Once.i = #False)
  CreateFont.i(Offset.i = #Null,Layout.s = #Null$,Spacing.i = #Null)
  Release.i()
EndInterface
Hello World example:

Code: Select all


EnableExplicit

XIncludeFile "nautilus.pbi"

Procedure.i Main()
  Protected *window.NAUTILUS_WINDOW
  Protected *engine.NAUTILUS_ENGINE
  If nautilusVersion() = #NAUTILUS_VERSION
    *window = nautilusWindow(800,600)
    If *window
      If *window\TimerCreate();<- create a window timer to control rendering
        *engine = nautilusEngine(*window\Hwnd(),600,400);<- initialize the engine
        If *engine
          *engine\RenderColor($FF603E14)
          *engine\DrawTextResize(32,32)
          Repeat
            *window\PollEvents()
            *engine\RenderBegin()
            *engine\DrawText(300,160,"NAUTILUS ENGINE",#True,#True,$FF)
            *engine\DrawText(300,240,"Hello World!",#True,#True,$80)
            *engine\RenderEnd()
            *window\TimerWait()
          Until *window\Exit()
          *engine\Release()
        EndIf
      EndIf
      *window\Release()
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
Documentation is still missing - need more time.

Download:
-
Last edited by Mijikai on Fri Nov 27, 2020 9:50 am, edited 2 times in total.
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by IceSoft »

Mijikai wrote:Documentation is still missing - need more time.
Good examples be enough.
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by leonhardt »

Mijikai wrote:Update: 1.050

This Update brings huge changes as i rewrote most parts of the engine.
I really want the engine to be small and easy to use.

So all besides rendering is on you :)

Here is the new include:

Code: Select all


EnableExplicit

Import "nautilus.lib"
  nautilusWindow.i(Width.i,Height.i,Title.s = #Null$,Type.i = #Null,TopMost.i = #False)
  nautilusEngine.i(Hwnd.i,Width.i,Height.i)
  nautilusVersion.i()
EndImport

#NAUTILUS_VERSION = $1050

Enumeration
  #NAUTILUS_WINDOW_NORMAL
  #NAUTILUS_WINDOW_SIZEABLE
  #NAUTILUS_WINDOW_POPUP
  #NAUTILUS_WINDOW_SCREEN
EndEnumeration

Structure NAUTILUS_SIZE_STRUCT
  x.f
  y.f
  cx.f
  cy.f
EndStructure

Structure NAUTILUS_TEXTURE_STRUCT
  Object.i
  size.NAUTILUS_SIZE_STRUCT
EndStructure

Interface NAUTILUS_WINDOW
  Hwnd.i()
  Screen.i(Code.i = #Null)
  ScreenMode.i()
  Title.i(Title.s,Append.i = #False)
  CursorHide.i(Flag.i = #True)
  CursorClip.i(Flag.i = #True)
  TimerCreate.i(*Fps = #Null,*Delta = #Null,Milliseconds.i = 20)
  TimerEvent.i()
  TimerWait.i()
  TimerError.i()
  PollEvents.i()
  KeyState.i()
  KeyDown.i(Code.i)
  KeyUp.i(Code.i)
  KeyPushed.i(Code.i)
  KeyChr.i(*Code)
  MouseState.i()
  MousePosition.i(*PosX,*PosY)
  MouseWheel.i(*Pos)
  MouseLeftDown.i()
  MouseLeftUp.i()
  MouseLeftPushed.i()
  MouseLeftDbl.i()
  MouseRightDown.i()
  MouseRightUp.i()
  MouseRightPushed.i()
  MouseRightDbl.i()
  Callback.i(*Callback,*Parameter)
  Close.i()
  Exit.i()
  Release.i()
EndInterface

Interface NAUTILUS_FONT
  SpacingGet.i(*Spacing.Float)
  SpacingSet.i(Spacing.f = #Null)
  Release.i()
EndInterface

Interface NAUTILUS_ANIMATION
  Active.i(Flag.i = #True)
  Once.i(Flag.i = #True)
  FrameStart.i(Start.i = -1)
  FrameStop.i(Stop.i = -1)
  FramePos.i(Pos.i = -1)
  Frame.i()
  FrameCount.i()
  FrameOutput.i(*Output)
  Release.i()
EndInterface

Interface NAUTILUS_TILE
  Count.i()
  SizeGet.i(*Width,*Height)
  SizeSet.i(Width.f,Height.f)
  SizeReset.i()
  Draw.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  DrawText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDraw.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDrawText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  Release.i()  
EndInterface

Interface NAUTILUS_TEXTURE
  SizeGet.i(*Width,*Height)
  SizeSet.i(Width.f,Height.f)
  SizeReset.i()
  Draw.i(X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDraw.i(Layer.i,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  CreateTile.i(CountX.i,CountY.i,X.i,Y.i,Width.i,Height.i,OffsetX.i = #Null,OffsetY.i = #Null)
  Release.i() 
EndInterface

Interface NAUTILUS_ENGINE
  RenderVSync.i()
  RenderVSyncMode.i(Flag.i = #False)
  RenderAspect.i(Flag.i = #True)
  RenderSize.i(*Width.Integer,*Height.Integer)
  RenderResize.i(Width.i,Height.i)
  RenderViewport.i()
  RenderFilter.i(Flag.i = #True)
  RenderColor.i(Color.i = #Null)
  RenderClip.i(X.f,Y.f,Width.f,Height.f)
  RenderUnclip.i()
  RenderPush.i()
  RenderPop.i()
  RenderRotate.i(Angle.f)
  RenderScale.i(X.f,Y.f)
  RenderTranslate.i(X.f,Y.f)
  RenderReset.i()
  RenderTextureMode.i()
  RenderPrimitiveMode.i()
  RenderBegin.i()
  RenderEnd.i()
  RenderLayer.i()
  RenderUpdate.i()
  RenderMouse.i(X.i,Y.i,*OutX.Integer,*OutY.Integer)
  DrawTextObject.i(*Texture.Integer = #Null,*Tile.Integer = #Null,*Font.Integer = #Null)
  DrawTextSize.i(*Width.Float,*Height.Float)
  DrawTextResize.f(Width.f,Height.f)
  DrawTextResetSize.i()
  DrawTextSpacingGet.i(*Spacing.Float)
  DrawTextSpacingSet.i(Spacing.f)
  DrawText.i(X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(X.f,Y.f,Text.s,Width.f,Height.f,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawPointSize.i(Size.f = 1)
  DrawLineSize.i(Size.f = 1)
  DrawPoint.i(X.f,Y.f,Color.i = $FFFFFFFF)
  DrawLine.i(X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  DrawTriangle.i(X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawBox.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawRhombus.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawCircle.i(X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawPointSize.i(Layer.i,Size.f = 1)
  LayerDrawLineSize.i(Layer.i,Size.f = 1)
  LayerDrawPoint.i(Layer.i,X.f,Y.f,Color.i = $FFFFFFFF)
  LayerDrawLine.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  LayerDrawTriangle.i(Layer.i,X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawBox.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawRhombus.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawCircle.i(Layer.i,X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerClip.i(Layer.i,X.f,Y.f,Width.f,Height.f)
  LayerUnclip.i(Layer.i)
  LayerPush.i(Layer.i)
  LayerPop.i(Layer.i)
  LayerRotate.i(Layer.i,Angle.f)
  LayerScale.i(Layer.i,X.f,Y.f)
  LayerTranslate.i(Layer.i,X.f,Y.f)
  LayerReset.i(Layer.i)
  LayerCallback.i(Layer.i,*Function,*Paramater)
  CreateTexture.i(*Buffer,File.s = #Null$)
  CreateAnimation.i(Start.i,Stop.i,Cycle.i,Active.i = #True,Once.i = #False)
  CreateFont.i(Offset.i = #Null,Layout.s = #Null$,Spacing.i = #Null)
  Release.i()
EndInterface
Hello World example:

Code: Select all


EnableExplicit

XIncludeFile "nautilus.pbi"

Procedure.i Main()
  Protected *window.NAUTILUS_WINDOW
  Protected *engine.NAUTILUS_ENGINE
  If nautilusVersion() = #NAUTILUS_VERSION
    *window = nautilusWindow(800,600)
    If *window
      If *window\TimerCreate();<- create a window timer to control rendering
        *engine = nautilusEngine(*window\Hwnd(),600,400);<- initialize the engine
        If *engine
          *engine\RenderColor($FF603E14)
          *engine\DrawTextResize(32,32)
          Repeat
            *window\PollEvents()
            *engine\RenderBegin()
            *engine\DrawText(300,160,"NAUTILUS ENGINE",#True,#True,$FF)
            *engine\DrawText(300,240,"Hello World!",#True,#True,$80)
            *engine\RenderEnd()
            *window\TimerWait()
          Until *window\Exit()
          *engine\Release()
        EndIf
      EndIf
      *window\Release()
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
Documentation is still missing - need more time.

Download:
https://www.dropbox.com/s/u3y7gefo6dyl3 ... 0.zip?dl=0
Hello, the engine doesn't surpport X86 anymore?
poor English...

PureBasic & Delphi & VBA
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by Mijikai »

leonhardt wrote:Hello, the engine doesn't support X86 anymore?
I will add x86 support with the next update.
IceSoft wrote:Good examples be enough.
Im working on a complete game that i will release as example with the next update.
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by leonhardt »

Mijikai wrote:
leonhardt wrote:Hello, the engine doesn't support X86 anymore?
I will add x86 support with the next update.
IceSoft wrote:Good examples be enough.
Im working on a complete game that i will release as example with the next update.
Great! :P
BTW, I think api documents would be better than demos,because not all functions and all parameters would be used in demos. especially for those unproffesional coders like hobbiests. :wink:
poor English...

PureBasic & Delphi & VBA
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by IceSoft »

leonhardt wrote:[...]
Great! :P
BTW, I think api documents would be better than demos,because not all functions and all parameters would be used in demos. especially for those unproffesional coders like hobbiests. :wink:
Yes. But let me ask this:
How many "PureBasic coders" will use this kind of engine really?

We have seen lot of good wrapper of third party engines for example 'RayLib' (There is a good documentation, lot of examples):
...but will use this wrapper with PureBasic really?
How many "profesional PureBasic coders" will use these kind of wrapper engines really?
Lot of work and small usecase. That's the true tale.

For me it seems the PureBasic native stuff be always the winner.
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x64)

Post by Mijikai »

Update: 1.070

Changes:
- Added Icon(); Width() and Height() functions to the window interface
- Unified internal color handling
- Fixed a bug in animation (callback parameter was not updated)
- Added x86 support

Here is the new interface (i commented to most of the functions):

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  Import "ne32.lib"
    nautilusWindow.i(Width.i,Height.i,Title.s = #Null$,Type.i = #Null,TopMost.i = #False)
    nautilusEngine.i(Hwnd.i,Width.i,Height.i)
    nautilusVersion.i()
  EndImport
CompilerElse
  Import "ne64.lib"
    nautilusWindow.i(Width.i,Height.i,Title.s = #Null$,Type.i = #Null,TopMost.i = #False)
    nautilusEngine.i(Hwnd.i,Width.i,Height.i)
    nautilusVersion.i()
  EndImport
CompilerEndIf

#NAUTILUS_VERSION = $1070

Enumeration
  #NAUTILUS_WINDOW_NORMAL
  #NAUTILUS_WINDOW_SIZEABLE
  #NAUTILUS_WINDOW_POPUP
  #NAUTILUS_WINDOW_SCREEN
EndEnumeration

Structure NAUTILUS_SIZE_STRUCT                                      ;<- x = width / y = height / cx = (witdh / 2) / cy = (height / 2)
  x.f
  y.f
  cx.f
  cy.f
EndStructure

Structure NAUTILUS_TEXTURE_STRUCT                                   ;<- Texture interface/object structure (same for tiles) maybe useful for custom collision code ;)
  Object.i
  size.NAUTILUS_SIZE_STRUCT
EndStructure

Interface NAUTILUS_WINDOW
  Hwnd.i()                                                          ;<- Get window hwnd | returns the window handle
  Width.i()                                                         ;<- Get window width | returns client width
  Height.i()                                                        ;<- Get window height | returns client height
  Icon.i(*Icon)                                                     ;<- Get window icon (pointer to a icon in memory / needs to be *.icon) | returns true/false
  Screen.i(Code.i = #Null)                                          ;<- Toggle fullscreen mode / [optional] Code = #VK_ keycode - if this key is pressed in fullscreen the window gets restored | returns true/false - fullscreen yes/no
  ScreenMode.i()                                                    ;<- Fullscreen mode active? | returns true/false
  Title.i(Title.s,Append.i = #False)                                ;<- Change the window title or append text to it | if the function fails the return value is zero
  CursorHide.i(Flag.i = #True)                                      ;<- Hides the cursor (client area) | returns nothing
  CursorClip.i(Flag.i = #True)                                      ;<- Clips the mouse cursor - the mouse cursor cant leave the window (client area) | returns nothing
  TimerCreate.i(*Fps = #Null,*Delta = #Null,Milliseconds.i = 20)    ;<- Create a event timer (the timer attempts to get the highest possible resolution) - a event is fired if the set milliseconds have elapsed - point *Fps to a integer to get frames per second - point *Delta to a float to get the deltatime | returns true/false
  TimerEvent.i()                                                    ;<- Checks for the timer event (does not wait) | returns true/false
  TimerWait.i()                                                     ;<- Waits for a timer event | returns true/false
  TimerError.i()                                                    ;<- Check for timer errors | returns true/false
  PollEvents.i()                                                    ;<- Process all window events | returns true/false - returns if the application wants to close
  KeyState.i()                                                      ;<- Can keyboard input be processed? | returns true/false
  KeyDown.i(Code.i)                                                 ;<- Is the key pressed?(#VK_ kecode) | retuens true/false
  KeyUp.i(Code.i)                                                   ;<- Is the key not pressed? (#VK_ kecode) | retuens true/false
  KeyPushed.i(Code.i)                                               ;<- Was the key pressed? (#VK_ kecode) | retuens true/false
  KeyChr.i(*Code)                                                   ;<- What was the last pressed chr? - point *Code to a integer to get the chr code | returns the chr code or nothing
  MouseState.i()                                                    ;<- Is the mouse inside the client area? | returns true/false
  MousePosition.i(*PosX,*PosY)                                      ;<- Returns the mouse position - point *PosX and *PosX to integers to get the position | reurns the mouse state
  MouseWheel.i(*Pos)                                                ;<- Was the mousewheel turned? - point *Pos to a integer to get the wheel position | returns the wheel position
  MouseLeftDown.i()                                                 ;<- Is the left mouse button pressed? (ALL MOUSE FUNCTIONS WILL WORK CORRECTLY EVEN IF THE MOUSE BUTTONS ARE SWAPPED!) | returns true/false
  MouseLeftUp.i()                                                   ;<- Is the left mouse button not pressed? | returns true/false
  MouseLeftPushed.i()                                               ;<- Was the left mouse button pressed? | retuens true/false
  MouseLeftDbl.i()                                                  ;<- Was there a left double click? | returns true/false
  MouseRightDown.i()                                                ;<- Is the right mouse button pressed? | returns true/false
  MouseRightUp.i()                                                  ;<- Is the right mouse button not pressed? | returns true/false
  MouseRightPushed.i()                                              ;<- Was the right mouse button pressed? | retuens true/false
  MouseRightDbl.i()                                                 ;<- Was there a right double click? | returns true/false
  Callback.i(*Callback,*Parameter)                                  ;<- Install a window callback - CallbackProc(*window,hWnd.i,Message.i,wParam.i,lParam.i,*CustomParameter) | returns nothing
  Close.i()                                                         ;<- Issues a close request | returns nothing
  Exit.i()                                                          ;<- Waits for a exit/close messahe - (this function is needed if *Fps and *Delta of the timer should be processed) | returns true/false
  Release.i()                                                       ;<- Releases the window | returns nothing
EndInterface

Interface NAUTILUS_FONT
  Spacing.i(*Spacing.Float)                                         ;<- Get the font spacing (distcance between chrs) - point *Spacing to a float | returns nothing
  SpacingChange.i(Spacing.f = #Null)                                ;<- Set the font spacing (distcance between chrs) | returns nothing
  Release.i()                                                       ;<- Release the font | returns nothing
EndInterface

Interface NAUTILUS_ANIMATION
  Active.i(Flag.i = #True)                                          ;<- Activates the animation (ANIMATIONS ARE PROCESSED WITH A CALL TO NAUTILUS_ENGINE\RenderUpdate()) | returns nothing
  Once.i(Flag.i = #True)                                            ;<- If this flag is set the animation is only run once  | returns nothing
  FrameStart.i(Start.i = -1)                                        ;<- Where should the animation start (frame aka tile index) - if Start is -1 nothing gets changed and the current frame start postition is returned | othwise returns true/false
  FrameStop.i(Stop.i = -1)                                          ;<- Where should the animation end (frame aka tile index) - if Stop is -1 nothing gets changed and the current frame stop postition is returned | othwise returns true/false
  FramePos.i(Pos.i = -1)                                            ;<- Set the current postition of the animation (frame aka tile index) - if Pos is -1 nothing gets changed and the current frame postition is returned | othwise returns true/false
  Frame.i()                                                         ;<- Get the current position/frame of the animation | returns the frame pos
  FrameCount.i()                                                    ;<- How many frames does the animation have? | returns frame count
  FrameOutput.i(*Output)                                            ;<- Reports the current frame position - point *Output to an integer (set this once and it will auto update) | returns nothing
  Release.i()                                                       ;<- Release the animation | returns nothing
EndInterface

Interface NAUTILUS_TILE
  Count.i()                                                         ;<- How many tiles? | returns tile count
  SizeGet.i(*Width,*Height)                                         ;<- Get tile size - point *Width and *Height to floats | returns nothing
  SizeSet.i(Width.f,Height.f)                                       ;<- Set size (resize the tile - this affects all functions below!) (THERE CAN BE ARTEFACTS INTRIDUCED THROUGH ANY SIZE FUNCTION - USE WITH CARE) | returns nothing
  SizeReset.i()                                                     ;<- Resets the original size | returns nothing
  Draw.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)                                                       
  DrawMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  DrawText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendText.i(*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendTextMod.i(*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDraw.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null);<- LAYER FUNCTIONS WILL DISPATCH THE RENDER COMMANDS TO A LAYER (there are 10 layers 0 - 9 which can be used in succession) - (LAYERS ARE PROCESSED WITH A CALL TO NAUTILUS_ENGINE\RenderLayer()) 
  LayerDrawMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,Index.i,*Animation,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,Index.i,*Animation,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,Index.i,*Animation,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDrawText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendText.i(Layer.i,*Font,X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendTextMod.i(Layer.i,*Font,X.f,Y.f,Text.s,Width.f = #Null,Height.f = #Null,CenterX.i = #False,CenterY.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  Release.i()  
EndInterface

Interface NAUTILUS_TEXTURE
  SizeGet.i(*Width,*Height)     ;<- Get tile size - point *Width and *Height to floats | returns nothing
  SizeSet.i(Width.f,Height.f)   ;<- Get tile size - point *Width and *Height to floats | returns nothing
  SizeReset.i()
  Draw.i(X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  Blend.i(X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMod.i(X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  BlendMap.i(X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  LayerDraw.i(Layer.i,X.f,Y.f,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerDrawMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Alpha.i = $FF,Tint.i = $FFFFFF)
  LayerBlend.i(Layer.i,X.f,Y.f,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMod.i(Layer.i,X.f,Y.f,Width.f = #Null,Height.f = #Null,Center.i = #False,Tint.i = $FFFFFF,Angle.f = #Null)
  LayerBlendMap.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,X3.f,Y3.f,X4.f,Y4.f,Tint.i = $FFFFFF)
  CreateTile.i(CountX.i,CountY.i,X.i,Y.i,Width.i,Height.i,OffsetX.i = #Null,OffsetY.i = #Null);<- Creates a tile | returns a tile or false
  Release.i() 
EndInterface

Interface NAUTILUS_ENGINE
  RenderVSync.i()                                                   ;<- Is vsync enabled? | returns true/false
  RenderVSyncMode.i(Flag.i = #False)                                ;<- Enable/disable vsync if possible | returns true/false
  RenderAspect.i(Flag.i = #True)                                    ;<- If the flag is set the render will keep the aspect ratio (this affects RenderViewport() which should be called on a resize event) | returns nothing
  RenderSize.i(*Width,*Height)                                      ;<- Get the render size (render surface) - point *Width and *Height to integers | returns nothing           
  RenderResize.i(Width.i,Height.i)                                  ;<- You can change the render size (render surface) | returns true/false (calls RenderViewport() internally so no seperate call to it is needed)
  RenderViewport.i()                                                ;<- Adjusts the viewport accordingly if the host window is resized | returns true/false
  RenderFilter.i(Flag.i = #True)                                    ;<- This will enable/disable bilinear filtering for all textures loaded after this call | returns nothing (use with care as there can be artefacts)
  RenderColor.i(Color.i = #Null)                                    ;<- Set the render color (ALL COLORS REPRESENTED/HANDLED AS RGB/ARGB!) | returns nothing
  RenderClip.i(X.f,Y.f,Width.f,Height.f)                            ;<- This will clip/scissor a area - nothing will be rendered outside this area | returns nothing
  RenderUnclip.i()                                                  ;<- This will unclip a previously clipped area | returns nothing
  RenderPush.i()                                                    ;<- Push the render matrix onto the stack | returns nothing
  RenderPop.i()                                                     ;<- Pops the render matrix from the stack | returns nothing
  RenderRotate.i(Angle.f)                                           ;<- Rotates the render surface (matix function) | returns nothing
  RenderScale.i(X.f,Y.f)                                            ;<- Scales the render surface (matix function) | returns nothing
  RenderTranslate.i(X.f,Y.f)                                        ;<- Translates the render surface (matix function) | returns nothing
  RenderReset.i()                                                   ;<- Resets all matrix operations | returns nothing
  RenderTextureMode.i()                                             ;<- Enables texture mode (the engine expects this to be on by default!) - to ease the use of custom opengl code | returns nothing
  RenderPrimitiveMode.i()                                           ;<- Disable texture mode - to ease the use of custom opengl code | returns nothing
  RenderBegin.i()                                                   ;<- Begins rendering - render only after this call | returns nothing
  RenderEnd.i()                                                     ;<- Ends rendering | returns nothing
  RenderLayer.i()                                                   ;<- Renders all layers (can be used in sucession) | returns nothing
  RenderUpdate.i()                                                  ;<- This funtion processes all animations (call once every frame) | returns nothing
  RenderMouse.i(X.i,Y.i,*OutX,*OutY)                                ;<- Returns the mouse position (takes in window mouse coordinates that will be mapped to surface coordinates) - point | returns nothing
  DrawTextObject.i(*Texture = #Null,*Tile = #Null,*Font = #Null)    ;<- Get default font interfaces - point *Texture *Tile and *Font to interfaces | returns nothing
  DrawTextSize.i(*Width,*Height)
  DrawTextResize.f(Width.f,Height.f)
  DrawTextResetSize.i()
  DrawTextSpacingGet.i(*Spacing)
  DrawTextSpacingSet.i(Spacing.f)
  DrawText.i(X.f,Y.f,Text.s,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawTextMod.i(X.f,Y.f,Text.s,Width.f,Height.f,CenterX.i = #False,CenterY.i = #False,Alpha.i = $FF,Tint.i = $FFFFFF,Angle.f = #Null)
  DrawPointSize.i(Size.f = 1)
  DrawLineSize.i(Size.f = 1)
  DrawPoint.i(X.f,Y.f,Color.i = $FFFFFFFF)
  DrawLine.i(X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  DrawTriangle.i(X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawBox.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawRhombus.i(X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  DrawCircle.i(X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawPointSize.i(Layer.i,Size.f = 1)
  LayerDrawLineSize.i(Layer.i,Size.f = 1)
  LayerDrawPoint.i(Layer.i,X.f,Y.f,Color.i = $FFFFFFFF)
  LayerDrawLine.i(Layer.i,X1.f,Y1.f,X2.f,Y2.f,Color.i = $FFFFFFFF)
  LayerDrawTriangle.i(Layer.i,X.f,Y.f,Width.f,Height.f,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawBox.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawRhombus.i(Layer.i,X.f,Y.f,Width.f,Height.f,Center.i = #False,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerDrawCircle.i(Layer.i,X.f,Y.f,Radius.f,Skip.i = #Null,Fill.i = #False,Color.i = $FFFFFFFF)
  LayerClip.i(Layer.i,X.f,Y.f,Width.f,Height.f)
  LayerUnclip.i(Layer.i)
  LayerPush.i(Layer.i)
  LayerPop.i(Layer.i)
  LayerRotate.i(Layer.i,Angle.f)
  LayerScale.i(Layer.i,X.f,Y.f)
  LayerTranslate.i(Layer.i,X.f,Y.f)
  LayerReset.i(Layer.i)
  LayerCallback.i(Layer.i,*Function,*Paramater);<- register one or mutliple callbacks in a layer - (all callbacks are reset once the layer is rendered)
  CreateTexture.i(*Buffer,File.s = #Null$)
  CreateAnimation.i(Start.i,Stop.i,Cycle.i,Active.i = #True,Once.i = #False)
  CreateFont.i(Offset.i = #Null,Layout.s = #Null$,Spacing.i = #Null)
  Release.i()
EndInterface
Download (includes example game):
-

Example Game Asteroids:

Image

Code: Select all

EnableExplicit

;NAUTILUS ENGINE EXAMPLE - Asteroids
;Version: alpha
;Author: Mijikai

;Ateroids was written to showcase basic functions of the NAUTILUS ENGINE
;The game does not use any external graphics
;The game is not optimized and sound is missing

;Code starts @ Main()

;INFO TO THE GAME
;- Bullets are tied to the games score!
;- U can get bullets/points through movement!
;- Asteroids give points based on their size

XIncludeFile "nautilus.pbi";< - Version: 1.070

Structure VECTOR_STRUCT
  x.f
  y.f
EndStructure

Structure STAR_STRUCT
  alpha.i
  pos.VECTOR_STRUCT
EndStructure

Structure ROCK_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f
  skip.i
  siz.f
EndStructure

Structure ASTEROID_STRUCT
  color.i
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f
  skip.i
  siz.f
  rocks.ROCK_STRUCT[6]
EndStructure

Structure BULLET_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  ttl.i
EndStructure

Structure SHIP_STRUCT
  pos.VECTOR_STRUCT
  upd.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f[2]
  rad.f
  fri.f
  thrust.i
  siz.f
  health.i
  tick_gun.i
  List bullet.BULLET_STRUCT()
EndStructure

Structure BLAST_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
EndStructure

Structure EXPLOSION_STRUCT
  ttl.i
  blast.BLAST_STRUCT[20]
EndStructure

Structure GAME_STRUCT
  *window.NAUTILUS_WINDOW
  *engine.NAUTILUS_ENGINE
  init.i
  score.i
  ready.i
  flicker.i
  countdown.i
  count.i
  clock.i
  tick.i
  tick_score.i
  ship.SHIP_STRUCT
  star.STAR_STRUCT[200]
  List asteroid.ASTEROID_STRUCT()
  List explosion.EXPLOSION_STRUCT()
EndStructure

Global game.GAME_STRUCT

Procedure.i GameCreateAsteroid(X.f,Y.f,Size.f)
  With game
    If AddElement(\asteroid())
      \asteroid()\color = RGBA(200,80 + Random(50),80 + Random(50),180)
      \asteroid()\pos\x = X 
      \asteroid()\pos\y = Y
      \asteroid()\mov\x = (0.2 + (Random(100) / 120))
      \asteroid()\mov\y = (0.2 + (Random(100) / 120)) 
      \asteroid()\vel = 0.5
      If Random(1)
        \asteroid()\mov\x * -1 
        \asteroid()\vel * -1
      EndIf
      If Random(1)
        \asteroid()\mov\y * -1 
      EndIf
      \asteroid()\rot = Random(359)
      \asteroid()\siz = Size
      \asteroid()\skip = 30 + Random(50)
    EndIf
  EndWith  
EndProcedure

Procedure.i GameInit(*Window,*Engine)
  Protected index.i
  With game
    \engine = *Engine
    \window = *Window
    \init = #True
    \ready = #True
    \countdown = 8
    \count = \countdown
    \clock = 0
    \ship\pos\x = 200
    \ship\pos\y = 200
    \ship\mov\x = 0
    \ship\mov\y = 0
    \ship\rot[0] = 4
    \ship\rot[1] = 0
    \ship\vel = 0.05
    \ship\fri = 0.005
    \ship\thrust = #False
    \ship\siz = 6
    \ship\health = 3
    For index = 0 To 199
      \star[index]\alpha = 40 + Random(99)
      \star[index]\pos\x = Random(399)
      \star[index]\pos\y = Random(399)
    Next
    ClearList(\asteroid())
    For index = 0 To 11
      GameCreateAsteroid(Random(399),Random(399),10 + Random(20))
    Next
    ClearList(\ship\bullet())
    ClearList(\explosion())
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameWrap(*Vector.VECTOR_STRUCT,Radius.f)
  With *Vector
    If \x + Radius < 0
      \x = 399 + Radius
    EndIf
    If \y + Radius < 0
      \y = 399 + Radius
    EndIf
    If \x - Radius > 399
      \x = 0 - Radius
    EndIf
    If \y - Radius > 399
      \y = 0 - Radius
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.f GameDistance(X1.f,Y1.f,X2.f,Y2.f)
  ProcedureReturn Sqr(Pow(X1 - X2,2) + Pow(Y1 - Y2,2))
EndProcedure

Procedure.i GameAsteroidCollision(X.f,Y.f,Siz.f,*Asteroid.ASTEROID_STRUCT) 
  With game
    ProcedureReturn Bool(Siz + *Asteroid\siz > GameDistance(X,Y,*Asteroid\pos\x,*Asteroid\pos\y))
  EndWith
EndProcedure

Procedure.i GameCreateExplosion(X.f,Y.f)
  Protected index.i
  With game
    If AddElement(\explosion())
      \explosion()\ttl = 200
      For index = 0 To 19
        \explosion()\blast[index]\pos\x = X
        \explosion()\blast[index]\pos\y = Y
        \explosion()\blast[index]\mov\x = (0.5 + (Random(200) / 120))
        \explosion()\blast[index]\mov\y = (0.5 + (Random(200) / 120))
        If Random(1)
          \explosion()\blast[index]\mov\x * -1 
        EndIf
        If Random(1)
          \explosion()\blast[index]\mov\y * -1 
        EndIf
      Next
      
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameUpdateStars()
  Protected index.i
  With game
    For index = 0 To 199
      If \star[index]\pos\y > 399
        \star[index]\alpha = 40 + Random(99)
        \star[index]\pos\x = Random(399)
        \star[index]\pos\y = 0
      Else
        \star[index]\pos\y + \star[index]\alpha / 200
      EndIf
    Next
    ProcedureReturn #Null  
  EndWith
EndProcedure

Procedure.i GameUpdateAsteroids()
  With game
    ForEach \asteroid()
      \asteroid()\pos\x + \asteroid()\mov\x
      \asteroid()\pos\y + \asteroid()\mov\y
      \asteroid()\rot + \asteroid()\vel
      GameWrap(@\asteroid()\pos,\asteroid()\siz)
      If GameAsteroidCollision(\ship\pos\x,\ship\pos\y,\ship\siz,\asteroid()) And \ready = #False
        \ship\health - 1
        If \ship\health = 0
          GameInit(\window,\engine)  
        Else
          \count = \countdown
          \ready = #True
        EndIf
      EndIf
    Next
    ProcedureReturn #Null  
  EndWith
EndProcedure

Procedure.i GameUpdateExplosions()
  Protected index.i
  With game
    ForEach \explosion()
      \explosion()\ttl - 4
      If \explosion()\ttl = 0
        DeleteElement(\explosion())
      Else
        For index = 0 To 19
         \explosion()\blast[index]\pos\x + \explosion()\blast[index]\mov\x
         \explosion()\blast[index]\pos\y + \explosion()\blast[index]\mov\y
        Next
      EndIf
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameUpdateShip()
  Protected index.i
  Protected siz.f
  Protected pos.VECTOR_STRUCT
  With game
    If \window\KeyDown(#VK_W)
      \ship\thrust = #True
      \ship\rad = Radian(90.0 - \ship\rot[1])
      \ship\upd = \ship\mov
      \ship\upd\x + \ship\vel * Cos(\ship\rad)
      \ship\upd\y - \ship\vel * Sin(\ship\rad)
      If Abs(\ship\upd\x) < 3 And Abs(\ship\upd\y) < 3
        \ship\mov = \ship\upd
      EndIf
    Else
      \ship\thrust = #False
      \ship\mov\x - \ship\fri * \ship\mov\x
      \ship\mov\y - \ship\fri * \ship\mov\y
    EndIf
    \ship\rot[1] - \window\KeyDown(#VK_A) * \ship\rot[0]
    \ship\rot[1] + \window\KeyDown(#VK_D) * \ship\rot[0]
    \ship\pos\x + \ship\mov\x
    \ship\pos\y + \ship\mov\y
    GameWrap(@\ship\pos,\ship\siz)
    \ship\rad = Radian(90.0 - \ship\rot[1])
    If \window\KeyDown(#VK_S) And \score
      If \tick - \ship\tick_gun > 12
        If AddElement(\ship\bullet())
          \ship\bullet()\pos\x = \ship\pos\x
          \ship\bullet()\pos\y = \ship\pos\y
          \ship\bullet()\mov\x = \ship\mov\x + 3 * Cos(\ship\rad)
          \ship\bullet()\mov\y = \ship\mov\y - 3 * Sin(\ship\rad)
          \ship\bullet()\ttl = 400
          \score - 1
        EndIf
        \ship\tick_gun = \tick
      EndIf
    EndIf
    ForEach \ship\bullet()
      \ship\bullet()\pos\x + \ship\bullet()\mov\x
      \ship\bullet()\pos\y + \ship\bullet()\mov\y
      \ship\bullet()\ttl - 1
      If \ship\bullet()\ttl = 0
        DeleteElement(\ship\bullet())
      Else
        ForEach \asteroid()
          If GameAsteroidCollision(\ship\bullet()\pos\x,\ship\bullet()\pos\y,1,\asteroid())
            GameCreateExplosion(\ship\bullet()\pos\x,\ship\bullet()\pos\y)
            \score + 40 - \asteroid()\siz
            siz = \asteroid()\siz / 2
            pos\x = \asteroid()\pos\x 
            pos\y = \asteroid()\pos\y
            DeleteElement(\asteroid())
            If siz > 6
              GameCreateAsteroid(pos\x,pos\y,siz)
              GameCreateAsteroid(pos\x,pos\y,siz)
            EndIf
            DeleteElement(\ship\bullet())
            Break 2
          EndIf
        Next
      EndIf
    Next
    ProcedureReturn #Null  
  EndWith
EndProcedure

Procedure.i GameUpdate()
  Static old.VECTOR_STRUCT
  With game
    \tick + 1
    If \init
      If \window\KeyPushed(#VK_ESCAPE)
        \score = 0
      EndIf
      \init = Bool(\window\KeyPushed(#VK_SPACE) = #False) 
      If Not \init
        old\x = 0
        old\y = 0
        \tick_score = \tick
        \score = 0
      EndIf
    Else 
      If \window\KeyPushed(#VK_ESCAPE)
        old\x = 0
        old\y = 0
        \tick_score = \tick
        \score = 0
        GameInit(\window,\engine)
      Else
        GameUpdateShip()
        GameUpdateAsteroids()
        GameUpdateExplosions()
        If ListSize(\asteroid()) < 12
          GameCreateAsteroid(-100,-100,10 + Random(20))
        EndIf
        If \tick - \tick_score > 100
          If GameDistance(\ship\pos\x,\ship\pos\y,old\x,old\y) > 50
            \score + 2
          EndIf
          old\x = \ship\pos\x
          old\y = \ship\pos\y
          \tick_score = \tick
        EndIf
      EndIf
    EndIf
    GameUpdateStars()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderStars()
  Protected index.i
  With game
    For index = 0 To 199
      \engine\DrawRhombus(\star[index]\pos\x,\star[index]\pos\y,2,2,#True,#True,RGBA(index,100,255,\star[index]\alpha))
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderAsteroids()
  With game
    ForEach \asteroid()
      \engine\RenderPush()
      \engine\RenderTranslate(\asteroid()\pos\x,\asteroid()\pos\y)
      \engine\RenderRotate(\asteroid()\rot)
      \engine\DrawCircle(#Null,#Null,\asteroid()\siz,\asteroid()\skip,#True,\asteroid()\color)
      \engine\DrawCircle(#Null,#Null,\asteroid()\siz,\asteroid()\skip,#False,$B0FFFFFF)
      \engine\RenderPop()
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderExplostions()
  Protected index.i
  With game
    ForEach \explosion()
      For index = 0 To 19
        \engine\DrawRhombus(\explosion()\blast[index]\pos\x,\explosion()\blast[index]\pos\y,3,3,#True,#True,RGBA(200,80,50,\explosion()\ttl))
      Next
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderBullets()
  With game
    \engine\DrawPointSize(3)
    ForEach \ship\bullet()
      \engine\DrawPoint(\ship\bullet()\pos\x,\ship\bullet()\pos\y,$C0FFFFFF)
    Next
    \engine\DrawPointSize(1)
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShip()
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(\ship\pos\x,\ship\pos\y)
    \engine\RenderRotate(\ship\rot[1])
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0FF4464)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    If \ship\thrust
      \engine\DrawTriangle(#Null,10,6,-8,#True,$B060FFFB)
    EndIf
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShipHealth(X.f,Y.f)
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(X,Y)
    \engine\RenderScale(1.6,1.6)
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0BBBBBB)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShipLogo(X.f,Y.f,Thrust.i,Rotate.f,Zoom.f)
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(X,Y)
    \engine\RenderRotate(Rotate)
    \engine\RenderScale(Zoom,Zoom)
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0FF4464)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    If Thrust
      \engine\DrawTriangle(#Null,10,6,-8,#True,$B060FFFB)
    EndIf
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderState()
  With game
    \engine\DrawTextMod(200,20,"Score: " + Str(\score),8,12,#True,#True,$C0)
    If \ship\health = 3
      GameRenderShipHealth(200,376)
      GameRenderShipHealth(200 - 20,376)
      GameRenderShipHealth(200 + 20,376)
    ElseIf \ship\health = 2
      GameRenderShipHealth(190,376)
      GameRenderShipHealth(210,376)
    Else
      GameRenderShipHealth(200,376)
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderInfo(X.f,Y.f)
  With game
    \engine\DrawTextResize(8,8)
    \engine\DrawText(X - 40,Y,"PLAYER",#True,#True,$40)
    GameRenderShipLogo(160,Y + 22,#False,\tick,1.2)
    \engine\DrawText(X + 40,Y,"ASTEROID",#True,#True,$40)
    \engine\RenderPush()
    \engine\RenderTranslate(X + 40,Y + 22)
    \engine\RenderRotate(-\tick)
    \engine\DrawCircle(#Null,#Null,10,80,#True,$B08050C8)
    \engine\DrawCircle(#Null,#Null,10,80,#False,$B0FFFFFF)
    \engine\RenderPop()
    \engine\DrawText(X,Y + 50,"MOVEMENT",#True,#True,$40)
    \engine\DrawText(X,Y + 60,"[W] - UP   ",#True,#True,$40)
    \engine\DrawText(X,Y + 70,"[A] - LEFT ",#True,#True,$40)
    \engine\DrawText(X,Y + 80,"[D] - RIGHT",#True,#True,$40)
    \engine\DrawText(X,Y + 90,"[S] - SHOOT",#True,#True,$40)
    \engine\DrawTextResetSize()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRender()
  With game
    \engine\RenderBegin()
    If \init
      GameRenderStars()
      \engine\DrawTextSpacingSet(-1.6)
      \engine\DrawTextMod(200 - 1,110,"ASTEROIDS",40,40,#True,#True)
      \engine\DrawTextMod(200 + 1,110,"ASTEROIDS",40,40,#True,#True,$FF,$FF2200)
      GameRenderShipLogo(274,64,#True,45,2)
      \engine\DrawTextSpacingSet(0)
      \engine\DrawTextMod(200,160,"- Score: " + Str(\score) + " -",8,12,#True,#True)
      \engine\DrawTextMod(200,200,"[SPACE] TO START",10,20,#True,#True,$AA)
      GameRenderInfo(200,240)
    Else
      If \ready
        GameRenderStars()
        GameRenderBullets()
        GameRenderAsteroids()
        If \flicker = 20
          \flicker = 0
          \count - 1
        Else
          \flicker + 1
        EndIf
        If \flicker > 10
          GameRenderShip()
        EndIf
        GameRenderExplostions()
        GameRenderState()
        \ready = \count 
      Else
        GameRenderStars()
        GameRenderBullets()
        GameRenderAsteroids()
        GameRenderShip()
        GameRenderExplostions()
        GameRenderState()
      EndIf
    EndIf
    \engine\RenderEnd()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i Main()
  Protected *window.NAUTILUS_WINDOW 
  Protected *engine.NAUTILUS_ENGINE
  If nautilusVersion() = #NAUTILUS_VERSION
    *window = nautilusWindow(800,800,"Nautilus Engine - ASTEROIDS - Example by Mijikai")
    If *window
      If *window\TimerCreate()
        *engine = nautilusEngine(*window\Hwnd(),400,400)
        If *engine
          GameInit(*window,*engine) 
          Repeat 
            *window\PollEvents()
            GameUpdate()
            GameRender()
            *window\TimerWait()
          Until *window\Exit() Or *window\TimerError()
          *engine\Release()
        EndIf
      EndIf
      *window\Release()
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
Have fun and let me know what u think :)
Last edited by Mijikai on Fri Nov 27, 2020 9:52 am, edited 1 time in total.
User avatar
Guevara-chan
User
User
Posts: 13
Joined: Sat Jun 18, 2011 12:20 pm

Re: [ENGINE] 2D Engine Nautilus (Win x86 & x64)

Post by Guevara-chan »

Now also available for Nim: https://github.com/Guevara-chan/Nimnaut
I guess, extending your fellow userbase is always good ?
life MOV.I #life+1, *life
האם יש זמן לעצור ?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x86 & x64)

Post by Mijikai »

Guevara-chan wrote:Now also available for Nim: https://github.com/Guevara-chan/Nimnaut
I guess, extending your fellow userbase is always good ?
Thank you :)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x86 & x64)

Post by Mijikai »

Update v.1.090 (most important changes):
- Fixed a bug where not all textures where released on *engine\Release()

Download:
-
Last edited by Mijikai on Fri Nov 27, 2020 9:36 am, edited 2 times in total.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [ENGINE] 2D Engine Nautilus (Win x86 & x64)

Post by Mijikai »

Update v.1.100 (most important changes):
- Removed the Window Interface

I want Nautilus to be as small and versatile as possible :)
Moving forward there will only be bugfixes (no more changes to the interfaces)!

Download:
https://www.dropbox.com/s/uei3loep7q3db ... 0.zip?dl=0

Game Asteroids Example:

Code: Select all

EnableExplicit

;Nautilus Engine Example - Asteroids
;Version: alpha
;Author: Mijikai

;The game does not use any external graphics
;The game is not optimized and sound is missing

;Code starts @ Main()

;INFO TO THE GAME
;- Bullets are tied to the games score!
;- U can get bullets/points through movement!
;- Asteroids give points based on their size

;CONTROLS (Keys):
;[W] - thrust
;[A] - turn left
;[D] - turn right
;[S] - shoot
;[SPACE] - start game
;[ESC] - restart game

XIncludeFile "nautilus.pbi";< - Version: 1.100

Structure VECTOR_STRUCT
  x.f
  y.f
EndStructure

Structure STAR_STRUCT
  alpha.i
  pos.VECTOR_STRUCT
EndStructure

Structure ROCK_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f
  skip.i
  siz.f
EndStructure

Structure ASTEROID_STRUCT
  color.i
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f
  skip.i
  siz.f
  rocks.ROCK_STRUCT[6]
EndStructure

Structure BULLET_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  ttl.i
EndStructure

Structure SHIP_STRUCT
  pos.VECTOR_STRUCT
  upd.VECTOR_STRUCT
  mov.VECTOR_STRUCT
  vel.f
  rot.f[2]
  rad.f
  fri.f
  thrust.i
  siz.f
  health.i
  tick_gun.i
  List bullet.BULLET_STRUCT()
EndStructure

Structure BLAST_STRUCT
  pos.VECTOR_STRUCT
  mov.VECTOR_STRUCT
EndStructure

Structure EXPLOSION_STRUCT
  ttl.i
  blast.BLAST_STRUCT[20]
EndStructure

Structure GAME_STRUCT
  *window.NAUTILUS_WINDOW
  *engine.NAUTILUS_ENGINE
  init.i
  score.i
  ready.i
  flicker.i
  countdown.i
  count.i
  clock.i
  tick.i
  tick_score.i
  ship.SHIP_STRUCT
  star.STAR_STRUCT[200]
  List asteroid.ASTEROID_STRUCT()
  List explosion.EXPLOSION_STRUCT()
EndStructure

Global game.GAME_STRUCT

Macro Key(_vk_)
  (GetKeyState_(_vk_) & $8000)
EndMacro

Procedure.i GameCreateAsteroid(X.f,Y.f,Size.f)
  With game
    If AddElement(\asteroid())
      \asteroid()\color = RGBA(200,80 + Random(50),80 + Random(50),180)
      \asteroid()\pos\x = X
      \asteroid()\pos\y = Y
      \asteroid()\mov\x = (0.2 + (Random(100) / 120))
      \asteroid()\mov\y = (0.2 + (Random(100) / 120))
      \asteroid()\vel = 0.5
      If Random(1)
        \asteroid()\mov\x * -1
        \asteroid()\vel * -1
      EndIf
      If Random(1)
        \asteroid()\mov\y * -1
      EndIf
      \asteroid()\rot = Random(359)
      \asteroid()\siz = Size
      \asteroid()\skip = 30 + Random(50)
    EndIf
  EndWith 
EndProcedure

Procedure.i GameInit(*Engine)
  Protected index.i
  With game
    \engine = *Engine
    \init = #True
    \ready = #True
    \countdown = 8
    \count = \countdown
    \clock = 0
    \ship\pos\x = 200
    \ship\pos\y = 200
    \ship\mov\x = 0
    \ship\mov\y = 0
    \ship\rot[0] = 4
    \ship\rot[1] = 0
    \ship\vel = 0.05
    \ship\fri = 0.005
    \ship\thrust = #False
    \ship\siz = 6
    \ship\health = 3
    For index = 0 To 199
      \star[index]\alpha = 40 + Random(99)
      \star[index]\pos\x = Random(399)
      \star[index]\pos\y = Random(399)
    Next
    ClearList(\asteroid())
    For index = 0 To 11
      GameCreateAsteroid(Random(399),Random(399),10 + Random(20))
    Next
    ClearList(\ship\bullet())
    ClearList(\explosion())
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameWrap(*Vector.VECTOR_STRUCT,Radius.f)
  With *Vector
    If \x + Radius < 0
      \x = 399 + Radius
    EndIf
    If \y + Radius < 0
      \y = 399 + Radius
    EndIf
    If \x - Radius > 399
      \x = 0 - Radius
    EndIf
    If \y - Radius > 399
      \y = 0 - Radius
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.f GameDistance(X1.f,Y1.f,X2.f,Y2.f)
  ProcedureReturn Sqr(Pow(X1 - X2,2) + Pow(Y1 - Y2,2))
EndProcedure

Procedure.i GameAsteroidCollision(X.f,Y.f,Siz.f,*Asteroid.ASTEROID_STRUCT)
  With game
    ProcedureReturn Bool(Siz + *Asteroid\siz > GameDistance(X,Y,*Asteroid\pos\x,*Asteroid\pos\y))
  EndWith
EndProcedure

Procedure.i GameCreateExplosion(X.f,Y.f)
  Protected index.i
  With game
    If AddElement(\explosion())
      \explosion()\ttl = 200
      For index = 0 To 19
        \explosion()\blast[index]\pos\x = X
        \explosion()\blast[index]\pos\y = Y
        \explosion()\blast[index]\mov\x = (0.5 + (Random(200) / 120))
        \explosion()\blast[index]\mov\y = (0.5 + (Random(200) / 120))
        If Random(1)
          \explosion()\blast[index]\mov\x * -1
        EndIf
        If Random(1)
          \explosion()\blast[index]\mov\y * -1
        EndIf
      Next
     
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameUpdateStars()
  Protected index.i
  With game
    For index = 0 To 199
      If \star[index]\pos\y > 399
        \star[index]\alpha = 40 + Random(99)
        \star[index]\pos\x = Random(399)
        \star[index]\pos\y = 0
      Else
        \star[index]\pos\y + \star[index]\alpha / 200
      EndIf
    Next
    ProcedureReturn #Null 
  EndWith
EndProcedure

Procedure.i GameUpdateAsteroids()
  With game
    ForEach \asteroid()
      \asteroid()\pos\x + \asteroid()\mov\x
      \asteroid()\pos\y + \asteroid()\mov\y
      \asteroid()\rot + \asteroid()\vel
      GameWrap(@\asteroid()\pos,\asteroid()\siz)
      If GameAsteroidCollision(\ship\pos\x,\ship\pos\y,\ship\siz,\asteroid()) And \ready = #False
        \ship\health - 1
        If \ship\health = 0
          GameInit(\engine) 
        Else
          \count = \countdown
          \ready = #True
        EndIf
      EndIf
    Next
    ProcedureReturn #Null 
  EndWith
EndProcedure

Procedure.i GameUpdateExplosions()
  Protected index.i
  With game
    ForEach \explosion()
      \explosion()\ttl - 4
      If \explosion()\ttl = 0
        DeleteElement(\explosion())
      Else
        For index = 0 To 19
         \explosion()\blast[index]\pos\x + \explosion()\blast[index]\mov\x
         \explosion()\blast[index]\pos\y + \explosion()\blast[index]\mov\y
        Next
      EndIf
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameUpdateShip()
  Protected index.i
  Protected siz.f
  Protected pos.VECTOR_STRUCT
  With game
    If Key(#VK_W)
      \ship\thrust = #True
      \ship\rad = Radian(90.0 - \ship\rot[1])
      \ship\upd = \ship\mov
      \ship\upd\x + \ship\vel * Cos(\ship\rad)
      \ship\upd\y - \ship\vel * Sin(\ship\rad)
      If Abs(\ship\upd\x) < 3 And Abs(\ship\upd\y) < 3
        \ship\mov = \ship\upd
      EndIf
    Else
      \ship\thrust = #False
      \ship\mov\x - \ship\fri * \ship\mov\x
      \ship\mov\y - \ship\fri * \ship\mov\y
    EndIf
    If Key(#VK_A)
      \ship\rot[1] - \ship\rot[0]
    EndIf
    If Key(#VK_D)
      \ship\rot[1] + \ship\rot[0]
    EndIf
    \ship\pos\x + \ship\mov\x
    \ship\pos\y + \ship\mov\y
    GameWrap(@\ship\pos,\ship\siz)
    \ship\rad = Radian(90.0 - \ship\rot[1])
    If Key(#VK_S) And \score
      If \tick - \ship\tick_gun > 12
        If AddElement(\ship\bullet())
          \ship\bullet()\pos\x = \ship\pos\x
          \ship\bullet()\pos\y = \ship\pos\y
          \ship\bullet()\mov\x = \ship\mov\x + 3 * Cos(\ship\rad)
          \ship\bullet()\mov\y = \ship\mov\y - 3 * Sin(\ship\rad)
          \ship\bullet()\ttl = 400
          \score - 1
        EndIf
        \ship\tick_gun = \tick
      EndIf
    EndIf
    ForEach \ship\bullet()
      \ship\bullet()\pos\x + \ship\bullet()\mov\x
      \ship\bullet()\pos\y + \ship\bullet()\mov\y
      \ship\bullet()\ttl - 1
      If \ship\bullet()\ttl = 0
        DeleteElement(\ship\bullet())
      Else
        ForEach \asteroid()
          If GameAsteroidCollision(\ship\bullet()\pos\x,\ship\bullet()\pos\y,1,\asteroid())
            GameCreateExplosion(\ship\bullet()\pos\x,\ship\bullet()\pos\y)
            \score + 40 - \asteroid()\siz
            siz = \asteroid()\siz / 2
            pos\x = \asteroid()\pos\x
            pos\y = \asteroid()\pos\y
            DeleteElement(\asteroid())
            If siz > 6
              GameCreateAsteroid(pos\x,pos\y,siz)
              GameCreateAsteroid(pos\x,pos\y,siz)
            EndIf
            DeleteElement(\ship\bullet())
            Break 2
          EndIf
        Next
      EndIf
    Next
    ProcedureReturn #Null 
  EndWith
EndProcedure

Procedure.i GameUpdate()
  Static old.VECTOR_STRUCT
  With game
    \tick + 1
    If \init
      If Key(#VK_ESCAPE)
        \score = 0
      EndIf
      \init = Bool(Key(#VK_SPACE) = #False)
      If Not \init
        old\x = 0
        old\y = 0
        \tick_score = \tick
        \score = 0
      EndIf
    Else
      If Key(#VK_ESCAPE)
        old\x = 0
        old\y = 0
        \tick_score = \tick
        \score = 0
        GameInit(\engine)
      Else
        GameUpdateShip()
        GameUpdateAsteroids()
        GameUpdateExplosions()
        If ListSize(\asteroid()) < 12
          GameCreateAsteroid(-100,-100,10 + Random(20))
        EndIf
        If \tick - \tick_score > 100
          If GameDistance(\ship\pos\x,\ship\pos\y,old\x,old\y) > 50
            \score + 2
          EndIf
          old\x = \ship\pos\x
          old\y = \ship\pos\y
          \tick_score = \tick
        EndIf
      EndIf
    EndIf
    GameUpdateStars()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderStars()
  Protected index.i
  With game
    For index = 0 To 199
      \engine\DrawRhombus(\star[index]\pos\x,\star[index]\pos\y,2,2,#True,#True,RGBA(index,100,255,\star[index]\alpha))
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderAsteroids()
  With game
    ForEach \asteroid()
      \engine\RenderPush()
      \engine\RenderTranslate(\asteroid()\pos\x,\asteroid()\pos\y)
      \engine\RenderRotate(\asteroid()\rot)
      \engine\DrawCircle(#Null,#Null,\asteroid()\siz,\asteroid()\skip,#True,\asteroid()\color)
      \engine\DrawCircle(#Null,#Null,\asteroid()\siz,\asteroid()\skip,#False,$B0FFFFFF)
      \engine\RenderPop()
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderExplostions()
  Protected index.i
  With game
    ForEach \explosion()
      For index = 0 To 19
        \engine\DrawRhombus(\explosion()\blast[index]\pos\x,\explosion()\blast[index]\pos\y,3,3,#True,#True,RGBA(200,80,50,\explosion()\ttl))
      Next
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderBullets()
  With game
    \engine\DrawPointSize(3)
    ForEach \ship\bullet()
      \engine\DrawPoint(\ship\bullet()\pos\x,\ship\bullet()\pos\y,$C0FFFFFF)
    Next
    \engine\DrawPointSize(1)
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShip()
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(\ship\pos\x,\ship\pos\y)
    \engine\RenderRotate(\ship\rot[1])
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0FF4464)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    If \ship\thrust
      \engine\DrawTriangle(#Null,10,6,-8,#True,$B060FFFB)
    EndIf
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShipHealth(X.f,Y.f)
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(X,Y)
    \engine\RenderScale(1.6,1.6)
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0BBBBBB)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderShipLogo(X.f,Y.f,Thrust.i,Rotate.f,Zoom.f)
  With game
    \engine\RenderPush()
    \engine\RenderTranslate(X,Y)
    \engine\RenderRotate(Rotate)
    \engine\RenderScale(Zoom,Zoom)
    \engine\DrawTriangle(#Null,#Null,10,12,#True,$B0FF4464)
    \engine\DrawTriangle(#Null,#Null,10,12,#False,$B0FFFFFF)
    \engine\DrawRhombus(#Null,#Null,2,4,#True,#True,$B0FFFFFF)
    If Thrust
      \engine\DrawTriangle(#Null,10,6,-8,#True,$B060FFFB)
    EndIf
    \engine\RenderPop()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderState()
  With game
    \engine\DrawTextMod(200,20,"Score: " + Str(\score),8,12,#True,#True,$C0)
    If \ship\health = 3
      GameRenderShipHealth(200,376)
      GameRenderShipHealth(200 - 20,376)
      GameRenderShipHealth(200 + 20,376)
    ElseIf \ship\health = 2
      GameRenderShipHealth(190,376)
      GameRenderShipHealth(210,376)
    Else
      GameRenderShipHealth(200,376)
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRenderInfo(X.f,Y.f)
  With game
    \engine\DrawTextResize(8,8)
    \engine\DrawText(X - 40,Y,"PLAYER",#True,#True,$40)
    GameRenderShipLogo(160,Y + 22,#False,\tick,1.2)
    \engine\DrawText(X + 40,Y,"ASTEROID",#True,#True,$40)
    \engine\RenderPush()
    \engine\RenderTranslate(X + 40,Y + 22)
    \engine\RenderRotate(-\tick)
    \engine\DrawCircle(#Null,#Null,10,80,#True,$B08050C8)
    \engine\DrawCircle(#Null,#Null,10,80,#False,$B0FFFFFF)
    \engine\RenderPop()
    \engine\DrawText(X,Y + 50,"MOVEMENT",#True,#True,$40)
    \engine\DrawText(X,Y + 60,"[W] - UP   ",#True,#True,$40)
    \engine\DrawText(X,Y + 70,"[A] - LEFT ",#True,#True,$40)
    \engine\DrawText(X,Y + 80,"[D] - RIGHT",#True,#True,$40)
    \engine\DrawText(X,Y + 90,"[S] - SHOOT",#True,#True,$40)
    \engine\DrawTextResetSize()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRender()
  With game
    \engine\RenderBegin()
    If \init
      GameRenderStars()
      \engine\DrawTextSpacingSet(-1.6)
      \engine\DrawTextMod(200 - 1,110,"ASTEROIDS",40,40,#True,#True)
      \engine\DrawTextMod(200 + 1,110,"ASTEROIDS",40,40,#True,#True,$FF,$FF2200)
      GameRenderShipLogo(274,64,#True,45,2)
      \engine\DrawTextSpacingSet(0)
      \engine\DrawTextMod(200,160,"- Score: " + Str(\score) + " -",8,12,#True,#True)
      \engine\DrawTextMod(200,200,"[SPACE] TO START",10,20,#True,#True,$AA)
      GameRenderInfo(200,240)
    Else
      If \ready
        GameRenderStars()
        GameRenderBullets()
        GameRenderAsteroids()
        If \flicker = 20
          \flicker = 0
          \count - 1
        Else
          \flicker + 1
        EndIf
        If \flicker > 10
          GameRenderShip()
        EndIf
        GameRenderExplostions()
        GameRenderState()
        \ready = \count
      Else
        GameRenderStars()
        GameRenderBullets()
        GameRenderAsteroids()
        GameRenderShip()
        GameRenderExplostions()
        GameRenderState()
      EndIf
    EndIf
    \engine\RenderEnd()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameFramerate(FPS.i)
  Static tmr_clock.q
  Protected tmr_duration.q
  Protected tmr_target.q
  Protected tmr_exit.q
  tmr_target = 1000 / FPS
  tmr_exit = tmr_target - 1
  Repeat
    tmr_duration = ElapsedMilliseconds() - tmr_clock
    If tmr_duration < tmr_target
      Delay(tmr_target - tmr_duration)
    EndIf
  Until tmr_duration > tmr_exit
  tmr_clock = ElapsedMilliseconds()
  ProcedureReturn #Null
EndProcedure

Procedure.i Main()
  Protected *engine.NAUTILUS_ENGINE
  If nautilusVersion() = #NAUTILUS_VERSION
    If OpenWindow(0,0,0,800,800,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
      AddKeyboardShortcut(0,#PB_Shortcut_W,1)
      *engine = nautilusEngine(WindowID(0),400,400)
      If *engine
        GameInit(*engine)
        Repeat
          GameFramerate(60)
          Repeat
            Select WindowEvent()
              Case #PB_Event_CloseWindow
                Break 2
              Case #Null
                Break
            EndSelect
          ForEver
          GameUpdate()
          GameRender()
        ForEver
        *engine\Release()
      EndIf
      CloseWindow(0)  
    EndIf  
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: [ENGINE] 2D Engine Nautilus (Win x86 & x64)

Post by Rinzwind »

Interesting. With what programming language is the engine made?

Would be good to see the other examples in this thread updated for the latest version now that the interface is 'stable' (they won't compile) and include some in the zip file.
Post Reply