[2D] Möglicher 3D Effekt für 2D Spiele in der Vogelperspekt.

Fragen zu Grafik- & Soundproblemen und zur Spieleprogrammierung haben hier ihren Platz.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

[2D] Möglicher 3D Effekt für 2D Spiele in der Vogelperspekt.

Beitrag von Mijikai »

Bild

Bin über einen 3D Effekt für 2D Spiele in der Vogelperspektive gestolpert :)

Eventuell hat jemand Interesse daran diesen Effekt für mehrere Objekte nutzbar zu machen.
Ich habe noch nicht herausgefunden was ich tun muss wenn das Objekt nicht zentral liegt.

Hier der Code:

Code: Alles auswählen

EnableExplicit

;Nautilus Engine
;Version: 0.26 beta

XIncludeFile "nautilus.pbi"

Structure VECTOR_STRUCT
  x.f
  y.f
EndStructure

Procedure.i Dummy(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.VECTOR_STRUCT
  Protected *atlas.NAUTILUS_ATLAS
  Protected *tile.NAUTILUS_TILE
  Protected *sprite.NAUTILUS_SPRITE
  Protected *light.NAUTILUS_LIGHT
  Protected index.i
  Protected player.VECTOR_STRUCT
  Protected center_ground.VECTOR_STRUCT
  Protected center_top.VECTOR_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\RenderAspect()
      *engine\ViewPortCenter(@screen_center)
      
      Repeat
        Repeat
          win_msg = WindowEvent()
          If win_msg = #PB_Event_CloseWindow
            Break 2
          EndIf 
        Until win_msg = #Null
        If *engine\InputKey(#VK_W):player\y + 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_S):player\y - 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_A):player\x + 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_D):player\x - 5 * engine_delta:EndIf
        
        *engine\RenderBegin(@engine_delta,@engine_fps,@engine_error) 
        *engine\DrawCircle(screen_center\x,screen_center\y,16)
        *engine\DrawText(screen_center\x + 5,screen_center\y + 10,"Player",#True)
 
        
        center_ground\x = screen_center\x + player\x
        center_ground\y = screen_center\y + player\y
        center_top\x = screen_center\x + (player\x * 1.2)
        center_top\y = screen_center\y + (player\y * 1.2)
        
        *engine\DrawLine(center_ground\x - 50,center_ground\y - 50,center_top\x - 50,center_top\y - 50)
        *engine\DrawLine(center_ground\x + 50,center_ground\y - 50,center_top\x + 50,center_top\y - 50)
        *engine\DrawLine(center_ground\x + 50,center_ground\y + 50,center_top\x + 50,center_top\y + 50)
        *engine\DrawLine(center_ground\x - 50,center_ground\y + 50,center_top\x - 50,center_top\y + 50)
        
        *engine\DrawText(screen_center\x + player\x,screen_center\y + player\y + 55,"House or Wall with Antenna",#True)
        *engine\DrawBox(screen_center\x + player\x,screen_center\y + player\y,100,100,#True)
        *engine\DrawBox(screen_center\x + (player\x * 1.2),screen_center\y + (player\y * 1.2),100,100,#True)
 
        center_ground\x = screen_center\x + (player\x * 1.2) - 10
        center_ground\y = screen_center\y + (player\y * 1.2) - 10
        center_top\x = screen_center\x + (player\x * 1.4) - 10
        center_top\y = screen_center\y + (player\y * 1.4) - 10
        
        *engine\DrawLine(center_ground\x - 5,center_ground\y - 5,center_top\x - 5,center_top\y - 5)
        *engine\DrawLine(center_ground\x + 5,center_ground\y - 5,center_top\x + 5,center_top\y - 5)
        *engine\DrawLine(center_ground\x + 5,center_ground\y + 5,center_top\x + 5,center_top\y + 5)
        *engine\DrawLine(center_ground\x - 5,center_ground\y + 5,center_top\x - 5,center_top\y + 5)

        *engine\DrawBox(screen_center\x + (player\x * 1.2) - 10,screen_center\y + (player\y * 1.2) - 10,10,10,#True)
        *engine\DrawBox(screen_center\x + (player\x * 1.4) - 10,screen_center\y + (player\y * 1.4) - 10,10,10,#True)

        
        *engine\DrawText(10,10,"Nautilus Engine")
        *engine\DrawText(10,25,"FPS " + Str(engine_fps))
        *engine\DrawText(10,40,"DLT " + StrF(engine_delta,2))
        *engine\RenderEnd()
        If engine_error
          Break
        EndIf 
      ForEver
      
      *engine\Release()
    EndIf 
    CloseWindow(win)
  EndIf
EndProcedure

Dummy(1080,720,#Null$,600,400,30)

End
Derren
Beiträge: 557
Registriert: 23.07.2011 02:08

Re: [2D] Möglicher 3D Effekt für 2D Spiele in der Vogelpersp

Beitrag von Derren »

Mijikai hat geschrieben:Ich habe noch nicht herausgefunden was ich tun muss wenn das Objekt nicht zentral liegt.
Was meinst du damit? Den Player?

Schöner GTA-Effekt. Geht das auch mit Texturen?
Signatur und so
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [2D] Möglicher 3D Effekt für 2D Spiele in der Vogelpersp

Beitrag von Mijikai »

Derren hat geschrieben:
Mijikai hat geschrieben:Ich habe noch nicht herausgefunden was ich tun muss wenn das Objekt nicht zentral liegt.
Was meinst du damit? Den Player?

Schöner GTA-Effekt. Geht das auch mit Texturen?

Das Objekt (Haus) muss im Zentrum liegen sonst funktioniert der Effekt nicht.
Die Verschiebung die den 3D Effekt erzeugt hängt mit dem Abstand des Spielers zusammen.
Kann bestimmt für andere Positionen umgerechnet werden - nur wie?

Geht mit Texturen (Beispiel ohne Tiefen-Sortierung) :)

Bild

Code (benötigt Version 0.3 beta):

Code: Alles auswählen

EnableExplicit

;Nautilus Engine Example
;Version: 0.30 beta
;Author: Mijikai

XIncludeFile "nautilus.pbi"

Structure VECTOR_STRUCT
  x.f
  y.f
EndStructure

Procedure.i Main(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.VECTOR_STRUCT
  Protected *atlas.NAUTILUS_ATLAS
  Protected *sprite.NAUTILUS_SPRITE
  Protected index.i
  Protected player.VECTOR_STRUCT
  Protected center_ground.VECTOR_STRUCT
  Protected center_top.VECTOR_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);init the engine
    If *engine
      *engine\RenderAspect()                ;keep the aspect ratio
      *engine\RenderColor($400A05)          ;change render color
      *engine\RenderFilter()
      *engine\ViewPortCenter(@screen_center);get the screen (viewport) center
      *engine\DrawTextResize(8,12)          ;set new size for standart text drawing with the ENGINE interface
      *engine\DrawTextSetSpacing(6)         ;and set the spacing between chars
      *atlas = *engine\CreateAtlas(?house,#Null$)
      *sprite = *atlas\CreateSprite(0,0,20,32)
      Repeat
        Repeat
          win_msg = WindowEvent()
          If win_msg = #PB_Event_CloseWindow
            Break 2
          EndIf 
        Until win_msg = #Null
        If *engine\InputKey(#VK_W):player\y + 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_S):player\y - 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_A):player\x + 5 * engine_delta:EndIf
        If *engine\InputKey(#VK_D):player\x - 5 * engine_delta:EndIf

        *engine\RenderBegin(@engine_delta,@engine_fps,@engine_error)
        
       
        
        center_ground\x = screen_center\x + player\x
        center_ground\y = screen_center\y + player\y
        center_top\x = screen_center\x + (player\x * 1.2)
        center_top\y = screen_center\y + (player\y * 1.2)
        
        *engine\DrawCircle(screen_center\x,screen_center\y,10)
        *engine\DrawLine(screen_center\x,screen_center\y,center_ground\x,center_ground\y)
        
        ;map the texture onto the house
        *sprite\DrawMap(center_top\x - 50,center_top\y + 50,center_top\x + 50,center_top\y + 50,center_ground\x + 50,center_ground\y + 50,center_ground\x - 50,center_ground\y + 50) 
        *sprite\DrawMap(center_top\x - 50,center_top\y - 50,center_top\x + 50,center_top\y - 50,center_ground\x + 50,center_ground\y - 50,center_ground\x - 50,center_ground\y - 50)
        *sprite\DrawMap(center_top\x + 50,center_top\y + 50,center_top\x + 50,center_top\y - 50,center_ground\x + 50,center_ground\y - 50,center_ground\x + 50,center_ground\y + 50) 
        *sprite\DrawMap(center_top\x - 50,center_top\y + 50,center_top\x - 50,center_top\y - 50,center_ground\x - 50,center_ground\y - 50,center_ground\x - 50,center_ground\y + 50) 
        *engine\DrawBox(screen_center\x + (player\x * 1.2),screen_center\y + (player\y * 1.2),100,100,#True,#True,$FF555555)
          
        *engine\DrawText(10,10,"Nautilus Engine",#False,#False,200,$FFDFBF)
        *engine\DrawText(10,25,"FPS " + Str(engine_fps),#False,#False,200,$FFDFBF)
        *engine\DrawText(10,40,"DLT " + StrF(engine_delta,2),#False,#False,200,$FFDFBF)
        *engine\RenderEnd()
        If engine_error
          Break
        EndIf 
      ForEver
      *engine\Release()
    EndIf 
    CloseWindow(win)
  EndIf
EndProcedure

Main(1080,720,"Example Nautilu Engine v.0.30 beta",600,400,30)

End

DataSection
  house:
  ;{ house.png - Size: 207 Bytes
  !dw 05089h, 0474Eh, 00A0Dh, 00A1Ah, 00000h, 00D00h, 04849h, 05244h, 00000h, 01400h, 00000h, 02000h, 00208h, 00000h, 09D00h, 0CF00h, 000E1h, 00000h, 07009h, 05948h, 00073h, 00E00h, 000C4h, 00E00h, 001C4h, 02B95h, 01B0Eh, 00000h, 08100h, 04449h, 05441h, 0CB38h, 0BC63h, 07070h, 0033Bh, 080B9h, 08189h, 03002h, 099AAh, 0C044h
  !dw 0A102h, 0BDF6h, 04510h, 05093h, 0B4FBh, 0465Fh, 0074Dh, 02CBFh, 09C0Bh, 06DCFh, 08720h, 07F22h, 08508h, 05587h, 06876h, 01807h, 02804h, 0B1F3h, 0D9C3h, 0303Fh, 06294h, 0B2CAh, 043C0h, 0E18Fh, 01610h, 0F80Dh, 01965h, 07347h, 090D5h, 0244Ch, 00C0Ch, 04F0Ch, 05D6Eh, 0AFC1h, 09E01h, 0B0D5h, 03E68h, 0E4FDh, 01E0Bh, 0A69Dh
  !dw 03C32h, 03824h, 0C5DBh, 065C5h, 087F8h, 09136h, 025BEh, 0F360h, 03D9Eh, 0F67Bh, 0D9ECh, 02C33h, 02793h, 09200h, 024AAh, 02695h, 0A88Bh, 0007Ah, 00000h, 04900h, 04E45h, 0AE44h, 06042h, 00082h
  ;}
EndDataSection
Antworten