Author Topic: 3D World Game Engine  (Read 7529 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
3D World Game Engine
« on: May 29, 2021, 08:13:15 am »
Hey everyone! I started working on this first person engine 1 year ago... It can load 3d maps with objects to which you can interact..
I will love to see your feedbacks!

Instructions:
  • Move mouse to look around
  • Use W,S,A,D to move forward, backward, left and right respectively
  • Press SPACEBAR to pickup keys and to unlock the doors.
  • All game engine related debugging information is displayed in the console window... you can check for the cause of possible errors in the console window.
  • You will need world_data.cdf file in the same folder where executable is generated in order to work it properly. Download it from the attachment below

Here's the code -

Code: QB64: [Select]
  1. '3D World Game Engine v1.0
  2. 'by Ashish
  3.  
  4. $Let DEBUG = -1
  5.  
  6. Declare Library 'camera control function
  7.     Sub gluLookAt (ByVal eyeX#, Byval eyeY#, Byval eyeZ#, Byval centerX#, Byval centerY#, Byval centerZ#, Byval upX#, Byval upY#, Byval upZ#)
  8.  
  9. Type vec3
  10.     x As Single
  11.     y As Single
  12.     z As Single
  13.  
  14. Type map_element
  15.     x As Single
  16.     y As Single
  17.     typ As Integer
  18.     'below element can be use to store data for any application. (additional data)
  19.     d_1 As Single
  20.     d_2 As Single
  21.     d_3 As Single
  22.     d_4 As Single
  23. Type map_file_header
  24.     signature As String * 8 '3DM@QB64
  25.     'objects
  26.     num_of_wall As _Unsigned Integer
  27.     num_of_floor As _Unsigned Integer
  28.     num_of_ceiling As _Unsigned Integer
  29.     num_of_door As _Unsigned Integer
  30.     num_of_key As _Unsigned Integer
  31.     num_of_point As _Unsigned Integer
  32.     num_of_detail As _Unsigned Integer
  33.     num_of_trap As _Unsigned Integer
  34.     'dimension
  35.     mapW As _Unsigned Integer
  36.     mapH As _Unsigned Integer
  37.     'player starting position
  38.     px As Single
  39.     py As Single
  40.     'player destination position
  41.     destX As Single
  42.     destY As Single
  43.     'global directional light settings
  44.     light_amb As vec3 'ambient color
  45.     light_diff As vec3 'diffuse color
  46.     light_spec As vec3 'specular color
  47.     light_dir As vec3 'direction of light
  48.  
  49. Type game_texture_type
  50.     img_handle As Long
  51.     gl_handle As Long
  52. 'For doors :-
  53. '* d_2 specify the state of the door. 0=closed, 1=opening, 2=opened
  54. '* d_1 specify which side of it is fixed. So, the door rotates from that side when being
  55. ' opened by the user. ±1=left ±2=right ±3=up ±4=down where sign (±) describe the direction of rotation when being open
  56. '* d_3 specify the ID of the key from which it can be unlock and open
  57. '* d_4 specify the angle of rotation when it is being open.
  58. 'For keys :-
  59. '* d_1 specify its ID. Each key have a unique ID.
  60. '* d_2 specify whether it has taken by the user or not. If taken, disable rendering of it.
  61. 'For traps :-
  62. '* Type 1 [laser]
  63. '  * d_4 is used as clock variable in timer
  64. '  * d_2 is frequecncy of on/off of laser for every 4 seconds.
  65.  
  66.  
  67. 'Global Variables
  68. Dim Shared worldStats As map_file_header
  69. ReDim Shared wallMap(0) As map_element, floorMap(0) As map_element, ceilingMap(0) As map_element
  70. ReDim Shared doorMap(0) As map_element, keyMap(0) As map_element, pointMap(0) As map_element
  71. ReDim Shared detailMap(0) As map_element, trapMap(0) As map_element
  72.  
  73. Dim Shared worldTextures(7, 15) As game_texture_type '8 objects, each coming in maximum of 16 varities
  74.  
  75. Dim Shared game_state, worldRotX, worldRotY, playerPos As vec3, playerFarPoint
  76. ReDim Shared collisionMap(0, 0, 1) As _Byte '2 layers, one for collision and second one for interaction with objects
  77.  
  78.  
  79. 'Local Variables
  80. ' dim preMouseX
  81. Dim keyPressed As Long
  82.  
  83. _Title "3D World Game Engine v1.0"
  84. Screen _NewImage(800, 600, 32)
  85. $If DEBUG = -1 Then
  86.     $Console
  87. echo "3D World Game Engine v1.0"
  88. echo "Preparing..."
  89.  
  90. 'LOAD stuffs
  91. loadResource
  92. ' for i = 0 to 15
  93. ' _putimage (0,0),worldTextures(0,i).img_handle
  94. ' sleep
  95. ' next
  96. ' worldTextures(0, 0).img_handle = _LOADIMAGE("Textures/wall/wall_1.jpg")
  97. ' worldTextures(1, 0).img_handle = _LOADIMAGE("Textures/floor/floor_1.jpg")
  98. ' worldTextures(2, 0).img_handle = _LOADIMAGE("Textures/ceiling/ceil_2.jpg")
  99. ' worldTextures(3, 0).img_handle = _LOADIMAGE("Textures/door/door_1.jpg")
  100.  
  101. ' loadWorld "among_us_world.3dm"
  102. playerPos.x = worldStats.px
  103. playerPos.y = 0
  104. playerPos.z = worldStats.py
  105. playerFarPoint = 0.5
  106.  
  107. game_state = 1
  108.     Wend
  109.    
  110.     keyPressed = _KeyHit
  111.    
  112.     worldRotX = map(_MouseY, 0, 600, 60, -60)
  113.    
  114.     ' if _MOUSEX >= _WIDTH - 1 then _mousemove 0,_mousey : preMouseX = 0
  115.    
  116.     worldRotY = worldRotY + (_MOUSEX - preMouseX)
  117.     ' worldRotY = _D2R(_MouseX)
  118.    
  119.     check_key_input:
  120.     __x1 = near_int(playerPos.x + 0.5 * Sin(_D2R(worldRotY)))
  121.     __y1 = near_int(playerPos.z - 0.5 * Cos(_D2R(worldRotY)))
  122.     ' If collisionMap(__x1, __y1, 1) = 1 Then echo "Ouch!!"
  123.     If _KeyDown(Asc("w")) Or _KeyDown(Asc("W")) Then 'forward
  124.         If collisionMap(__x1, __y1, 0) = 0 Then
  125.             playerPos.x = playerPos.x + 0.08 * Sin(_D2R(worldRotY))
  126.             playerPos.z = playerPos.z - 0.08 * Cos(_D2R(worldRotY))
  127.         End If
  128.     End If
  129.     __x1 = near_int(playerPos.x - 0.5 * Sin(_D2R(worldRotY)))
  130.     __y1 = near_int(playerPos.z + 0.5 * Cos(_D2R(worldRotY)))
  131.     ' If collisionMap(__x1, __y1, 1) = 1 Then echo "Ouch!!"
  132.     If _KeyDown(Asc("s")) Or _KeyDown(Asc("S")) Then 'backward, just doing opposite of forward
  133.         If collisionMap(__x1, __y1, 0) = 0 Then
  134.             playerPos.x = playerPos.x - 0.08 * Sin(_D2R(worldRotY))
  135.             playerPos.z = playerPos.z + 0.08 * Cos(_D2R(worldRotY))
  136.         End If
  137.     End If
  138.     __x1 = near_int(playerPos.x - 0.5 * Sin(_D2R(worldRotY + 90)))
  139.     __y1 = near_int(playerPos.z + 0.5 * Cos(_D2R(worldRotY + 90)))
  140.     ' If collisionMap(__x1, __y1, 1) = 1 Then echo "Ouch!!"
  141.     If _KeyDown(Asc("a")) Or _KeyDown(Asc("A")) Then 'leftward
  142.         If collisionMap(__x1, __y1, 0) = 0 Then
  143.             playerPos.x = playerPos.x - 0.08 * Sin(_D2R(worldRotY + 90))
  144.             playerPos.z = playerPos.z + 0.08 * Cos(_D2R(worldRotY + 90))
  145.         End If
  146.     End If
  147.     __x1 = near_int(playerPos.x + 0.5 * Sin(_D2R(worldRotY + 90)))
  148.     __y1 = near_int(playerPos.z - 0.5 * Cos(_D2R(worldRotY + 90)))
  149.     ' If colslisionMap(__x1, __y1, 1) = 1 Then echo "Ouch!!" <--- temporarily commented
  150.     If _KeyDown(Asc("d")) Or _KeyDown(Asc("D")) Then 'rightward, opposite of leftward
  151.         If collisionMap(__x1, __y1, 0) = 0 Then
  152.             playerPos.x = playerPos.x + 0.08 * Sin(_D2R(worldRotY + 90))
  153.             playerPos.z = playerPos.z - 0.08 * Cos(_D2R(worldRotY + 90))
  154.         End If
  155.     End If
  156.     'animation stuffs (khaaskar traps ke liye)
  157.     If worldStats.num_of_trap > 0 Then
  158.         For i = 1 To worldStats.num_of_trap
  159.             If trapMap(i).typ = 1 Then 'laser
  160.                 If (Timer - trapMap(i).d_4) > (4 / trapMap(i).d_2) Then
  161.                     If trapMap(i).d_3 = 1 Then
  162.                         trapMap(i).d_3 = 0
  163.                         collisionMap(trapMap(i).x, trapMap(i).y, 1) = 0 'no damage
  164.                     Else
  165.                         trapMap(i).d_3 = 1
  166.                         collisionMap(trapMap(i).x, trapMap(i).y, 1) = 1 'damage
  167.                     End If
  168.                     trapMap(i).d_4 = Timer
  169.                 End If
  170.             End If
  171.         Next
  172.     End If
  173.     'interaction with objects
  174.     If keyPressed = Asc(" ") Then
  175.         __x1 = near_int(playerPos.x): __y1 = near_int(playerPos.z)
  176.         __x2 = near_int(playerPos.x + 0.5 * Sin(_D2R(worldRotY))): __y2 = near_int(playerPos.z - 0.5 * Cos(_D2R(worldRotY)))
  177.         'interaction with key
  178.         If collisionMap(__x1, __y1, 1) = 3 Then
  179.             'find by which key user have interacted?
  180.             For i = 1 To worldStats.num_of_key
  181.                 If keyMap(i).d_2 = 0 Then
  182.                     If keyMap(i).x = __x1 And keyMap(i).y = __y1 Then
  183.                         keyMap(i).d_2 = 1 'disable rendering of the key as it is now taken by the user.
  184.                         echo "KeyMap(" + _Trim$(Str$(i)) + ").d_2 = 1"
  185.                         Exit For
  186.                     End If
  187.                 End If
  188.             Next
  189.         End If
  190.         'interaction with door
  191.         If collisionMap(__x2, __y2, 1) = 2 Then
  192.             'finding by which door user have interacted
  193.             doorFound = 0
  194.             For i = 1 To worldStats.num_of_door
  195.                 If doorMap(i).d_2 = 0 Then
  196.                     If doorMap(i).x = __x2 And doorMap(i).y = __y2 Then
  197.                         doorIndex = i
  198.                         doorFound = 1
  199.                         echo "door is found at index : " + Str$(doorIndex)
  200.                     End If
  201.                 End If
  202.             Next
  203.             'checking if user has the key for this door
  204.             If doorFound = 1 Then
  205.                 For i = 1 To worldStats.num_of_key
  206.                     If doorMap(doorIndex).d_3 = keyMap(i).d_1 Then
  207.                         If keyMap(i).d_2 = 1 Then
  208.                             'okay, so the user do have the key for this door and the door is not yet opened.
  209.                             'now, I change the state of this door from "closed" to "opening"
  210.                             doorMap(doorIndex).d_2 = 1
  211.                             echo "state of door is now changed."
  212.                             Exit For
  213.                         else
  214.                             echo "You don't have key for this door... Try it find it somewhere"
  215.                         End If
  216.                     End If
  217.                 Next
  218.             End If
  219.         End If
  220.     End If
  221.    
  222.    
  223.     _Limit 30
  224.    
  225.     preMouseX = _MouseX
  226. ' for i = 1 to worldStats.num_of_wall
  227. ' pset (wallMap(i).x,wallMap(i).y)
  228. ' next
  229. ' for i = 1 to worldStats.num_of_floor
  230. ' pset (floorMap(i).x, floorMap(i).y), _RGB(255,0,0)
  231. ' next
  232.  
  233. Sub _GL ()
  234.     Static tex_load_type
  235.     If game_state = 0 Then Exit Sub
  236.     If game_state = 1 Then
  237.         ' If tex_load_type > 4 Then
  238.             ' For i = 0 To UBound(playerTextures)
  239.                 ' playerTextures(i).gl_handle = feedGLTexture(playerTextures(i).img_handle)
  240.                 ' _FreeImage playerTextures(i).img_handle
  241.             ' Next
  242.             ' game_state = game_state + 1
  243.             ' initPlayerObject
  244.             ' Exit Sub
  245.         ' End If
  246.         For i = 0 To 15
  247.             If worldTextures(tex_load_type, i).img_handle < -1 Then
  248.                 worldTextures(tex_load_type, i).gl_handle = feedGLTexture(worldTextures(tex_load_type, i).img_handle)
  249.                 _FreeImage worldTextures(tex_load_type, i).img_handle
  250.             End If
  251.         Next
  252.         tex_load_type = tex_load_type + 1
  253.         if tex_load_type>4 then game_state = game_state + 1
  254.         Exit Sub
  255.     End If
  256.  
  257.     If game_state = 2 Then 'world rendering
  258.         _glViewport 0, 0, _Width, _Height
  259.  
  260.         _glEnable _GL_DEPTH_TEST
  261.         _glEnable _GL_TEXTURE_2D
  262.         _glEnable _GL_LIGHTING
  263.         _glEnable _GL_BLEND
  264.         _glDisable _GL_MULTISAMPLE
  265.        
  266.         'Global Light Settings of World
  267.         _glEnable _GL_LIGHT0
  268.         _glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(worldStats.light_amb.x, worldStats.light_amb.y, worldStats.light_amb.z, 1)
  269.         _glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(worldStats.light_diff.x, worldStats.light_diff.y, worldStats.light_diff.z, 1)
  270.         _glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(worldStats.light_spec.x, worldStats.light_spec.y, worldStats.light_spec.z, 1)
  271.         _glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(worldStats.light_dir.x, worldStats.light_dir.y, worldStats.light_dir.z, 1)
  272.  
  273.         _glMatrixMode _GL_PROJECTION
  274.         _glLoadIdentity
  275.         _gluPerspective 60, _width/_Height, 0.1, worldStats.mapW
  276.        
  277.         _glMatrixMode _GL_MODELVIEW
  278.         _glLoadIdentity
  279.         '_glTranslatef playerPos.x, 1, playerPos.z
  280.         ' _glRotatef worldRotX, 1, 0, 0
  281.         ' _glRotatef worldRotY+180, 0, 1, 0
  282.        
  283.         gluLookAt playerPos.x , playerPos.y + 0.4, playerPos.z,_
  284. playerPos.x + playerFarPoint * Cos(_D2R(worldRotY-90)), playerPos.y+0.4*sin(_d2r(worldRotX)) , playerPos.z + playerFarPoint * Sin(_D2R(worldRotY-90)),_
  285. 0, 1, 0
  286.  
  287.         drawWalls
  288.         drawDoors
  289.         drawFloors
  290.         drawCeilings
  291.         drawKeys
  292.         drawBonusObj
  293.         drawTraps
  294.  
  295.         _glFlush
  296.     End If
  297.  
  298. Sub loadResource ()
  299.     Dim n, i, j, k, f$
  300.     n = 15
  301.     echo "------------In SUB loadResource()------------------"
  302.     echo "extracting map and textures"
  303.    
  304.     extract_file_all "world_data.cdf", "./"
  305.    
  306.     extract_file_all "wall.cdf", "./"
  307.    
  308.     'wall textures
  309.     For i = 0 To n
  310.         ' worldTextures(0, i).img_handle = _LoadImage("Textures/wall/wall_" + _Trim$(Str$(i + 1)) + ".png")
  311.         f$ = "wall_" + _Trim$(Str$(i + 1)) + ".png"
  312.         worldTextures(0, i).img_handle = _LoadImage(f$)
  313.         kill f$
  314.     Next
  315.     kill "wall.cdf"
  316.     echo "wall... DONE"
  317.    
  318.     'floor textures
  319.     extract_file_all "floor.cdf", "./"
  320.     For i = 0 To n
  321.         f$ = "floor_" + _Trim$(Str$(i + 1)) + ".jpg"
  322.         ' worldTextures(1, i).img_handle = _LoadImage("Textures/floor/floor_" + _Trim$(Str$(i + 1)) + ".jpg")
  323.         worldTextures(1, i).img_handle = _LoadImage(f$)
  324.         kill f$
  325.     Next
  326.     kill "floor.cdf"
  327.     echo "floor... DONE"
  328.     'ceiling textures
  329.     extract_file_all "ceil.cdf","./"
  330.     n = 2
  331.     For i = 0 To n
  332.         f$ = "ceil_" + _Trim$(Str$(i + 1)) + ".jpg"
  333.         ' worldTextures(2, i).img_handle = _LoadImage("Textures/ceiling/ceil_" + _Trim$(Str$(i + 1)) + ".jpg")
  334.         worldTextures(2, i).img_handle = _LoadImage(f$)
  335.         kill f$
  336.     Next
  337.     kill "ceil.cdf"
  338.     echo "ceiling... DONE"
  339.     'door textures
  340.     extract_file_all "door.cdf", "./"
  341.     n = 6
  342.     For i = 0 To n
  343.         f$ = "door_" + _Trim$(Str$(i + 1)) + ".jpg"
  344.         ' worldTextures(3, i).img_handle = _LoadImage("Textures/door/door_" + _Trim$(Str$(i + 1)) + ".jpg")
  345.         worldTextures(3, i).img_handle = _LoadImage(f$)
  346.         kill f$
  347.     Next
  348.     kill "door.cdf"
  349.     echo "door... DONE"
  350.     'key textures
  351.     extract_file_all "key.cdf", "./"
  352.     n = 7
  353.     For i = 0 To n
  354.         For j = 1 To 2
  355.             f$ = "key_" + _Trim$(Str$(i + 1)) + "_" + _Trim$(Str$(j)) + ".png"
  356.             ' worldTextures(4, k).img_handle = _LoadImage("Textures/key/key_" + _Trim$(Str$(i + 1)) + "_" + _Trim$(Str$(j)) + ".png")
  357.             worldTextures(4, k).img_handle = _LoadImage(f$)
  358.             k = k + 1
  359.             kill f$
  360.         Next
  361.         kill "key_"+_Trim$(Str$(i + 1))+".png"
  362.     Next
  363.     kill "key.cdf"
  364.     echo "key... DONE"
  365.     echo ""
  366.     echo "Loading Map"
  367.     loadWorld "test.3dm"
  368.     kill "test.3dm"
  369.    
  370.    
  371.  
  372. Sub drawWalls ()
  373.     For i = 1 To worldStats.num_of_wall
  374.         selectTexture worldTextures(0, wallMap(i).typ - 1).gl_handle
  375.         ' drawBox wallMap(i).x, 0, wallMap(i).y, 1, 2, 1
  376.         drawXYPlane wallMap(i).x, 0, wallMap(i).y - 0.5, 1, 2, -1 'front face
  377.         drawXYPlane wallMap(i).x, 0, wallMap(i).y + 0.5, 1, 2, 1 'back face
  378.         drawYZPlane wallMap(i).x - 0.5, 0, wallMap(i).y, 2, 1, -1 'left face
  379.         drawYZPlane wallMap(i).x + 0.5, 0, wallMap(i).y, 2, 1, 1 'right face
  380.     Next
  381.  
  382. Sub drawFloors ()
  383.     _glMaterialfv _GL_FRONT_AND_BACK, _GL_SHININESS, glVec4(0.5 * 128, 0, 0, 0)
  384.     For i = 1 To worldStats.num_of_floor
  385.         selectTexture worldTextures(1, floorMap(i).typ - 1).gl_handle
  386.         drawXZPlane floorMap(i).x, -1, floorMap(i).y, 1, 1, 1
  387.     Next
  388.  
  389. Sub drawCeilings ()
  390.     For i = 1 To worldStats.num_of_ceiling
  391.         selectTexture worldTextures(2, ceilingMap(i).typ - 1).gl_handle
  392.         drawXZPlane ceilingMap(i).x, 1, ceilingMap(i).y, 1, 1, -1
  393.     Next
  394.  
  395. Sub drawDoors ()
  396.     '±1,±2,±3,,
  397.     For i = 1 To worldStats.num_of_door
  398.         selectTexture worldTextures(3, doorMap(i).typ - 1).gl_handle
  399.         If doorMap(i).d_2 = 0 Then 'closed?
  400.             If Abs(doorMap(i).d_1) = 1 Or Abs(doorMap(i).d_1) = 2 Then
  401.                 'it must be slim in XY depth
  402.                 drawXYPlane doorMap(i).x, 0, doorMap(i).y - 0.1, 1, 2, -1 'front face
  403.                 drawXYPlane doorMap(i).x, 0, doorMap(i).y + 0.1, 1, 2, 1 'back face
  404.                
  405.                 drawYZPlane doorMap(i).x - 0.5, 0, doorMap(i).y, 2, 0.2, -1 'left face
  406.                 drawYZPlane doorMap(i).x + 0.5, 0, doorMap(i).y, 2, 0.2, 1 'right face
  407.             Else
  408.                 drawXYPlane doorMap(i).x, 0, doorMap(i).y - 0.5, 0.2, 2, -1 'front face
  409.                 drawXYPlane doorMap(i).x, 0, doorMap(i).y + 0.5, 0.2, 2, 1 'back face
  410.                
  411.                 'it must be slim in YZ along X
  412.                 drawYZPlane doorMap(i).x - 0.1, 0, doorMap(i).y, 2, 1, -1 'left face
  413.                 drawYZPlane doorMap(i).x + 0.1, 0, doorMap(i).y, 2, 1, 1 'right face
  414.             End If
  415.         ElseIf doorMap(i).d_2 = 1 Then 'opening
  416.             If doorMap(i).d_1 > 0 Then s = 1 Else s = -1
  417.             If Abs(doorMap(i).d_1) = 1 Then 'left
  418.                 _glPushMatrix
  419.                 _glTranslatef doorMap(i).x - 0.5, 0, doorMap(i).y
  420.                 _glRotatef doorMap(i).d_4, 0, 1, 0
  421.  
  422.                 If doorMap(i).d_4 = 90 * s Then collisionMap(doorMap(i).x, doorMap(i).y, 0) = 0 Else doorMap(i).d_4 = doorMap(i).d_4 + 2 * s
  423.                 drawXYPlane 0.5, 0, -0.1, 1, 2, -1 'front face
  424.                 drawXYPlane 0.5, 0, 0.1, 1, 2, 1 'back face
  425.                
  426.                 drawYZPlane 0, 0, 0, 2, 0.2, -1 'left face
  427.                 drawYZPlane 1, 0, 0, 2, 0.2, 1 'right face
  428.                 _glPopMatrix
  429.             ElseIf Abs(doorMap(i).d_1) = 2 Then 'right
  430.                 _glPushMatrix
  431.                 _glTranslatef doorMap(i).x + 0.5, 0, doorMap(i).y
  432.                 _glRotatef doorMap(i).d_4, 0, 1, 0
  433.                
  434.                 If doorMap(i).d_4 = 90 * s Then collisionMap(doorMap(i).x, doorMap(i).y, 0) = 0 Else doorMap(i).d_4 = doorMap(i).d_4 + 2 * s
  435.                 drawXYPlane -0.5, 0, -0.1, 1, 2, -1 'front face
  436.                 drawXYPlane -0.5, 0, 0.1, 1, 2, 1 'back face
  437.                
  438.                 drawYZPlane -1, 0, 0, 2, 0.2, -1 'left face
  439.                 drawYZPlane 0, 0, 0, 2, 0.2, 1 'right face
  440.                 _glPopMatrix
  441.             ElseIf Abs(doorMap(i).d_1) = 3 Then 'up
  442.                 _glPushMatrix
  443.                 _glTranslatef doorMap(i).x, 0, doorMap(i).y - 0.5
  444.                 _glRotatef doorMap(i).d_4, 0, 1, 0
  445.                 If doorMap(i).d_4 = 90 * s Then collisionMap(doorMap(i).x, doorMap(i).y, 0) = 0 Else doorMap(i).d_4 = doorMap(i).d_4 + 2 * s
  446.                 drawXYPlane 0, 0, 0, 0.2, 2, -1 'front face
  447.                 drawXYPlane 0, 0, 1, 0.2, 2, 1 'back face
  448.                
  449.                 drawYZPlane -0.1, 0, 0.5, 2, 1, -1 'left face
  450.                 drawYZPlane 0.1, 0, 0.5, 2, 1, 1 'right face
  451.                 _glPopMatrix
  452.             Else 'down
  453.                 _glPushMatrix
  454.                 _glTranslatef doorMap(i).x, 0, doorMap(i).y + 0.5
  455.                 _glRotatef doorMap(i).d_4, 0, 1, 0
  456.  
  457.                 If doorMap(i).d_4 = 90 * s Then collisionMap(doorMap(i).x, doorMap(i).y, 0) = 0 Else doorMap(i).d_4 = doorMap(i).d_4 + 2 * s
  458.                 drawXYPlane 0, 0, -1, 0.2, 2, -1 'front face
  459.                 drawXYPlane 0, 0, 0, 0.2, 2, 1 'back face
  460.                
  461.                 drawYZPlane -0.1, 0, -0.5, 2, 1, -1 'left face
  462.                 drawYZPlane 0.1, 0, -0.5, 2, 1, 1 'right face
  463.                 _glPopMatrix
  464.             End If
  465.         End If
  466.     Next
  467.  
  468.  
  469. Sub drawKeys ()
  470.     Static keyRotY
  471.     keyRotY = keyRotY + 1
  472.     _glDisable _GL_LIGHTING
  473.     For i = 1 To worldStats.num_of_key
  474.         If keyMap(i).d_2 = 0 Then 'd_2 store whether it has been taken by the user or not.
  475.             _glPushMatrix
  476.             _glTranslatef keyMap(i).x, -.98, keyMap(i).y
  477.             _glRotatef keyRotY, 0, 1, 0
  478.             selectTexture worldTextures(4, keyMap(i).typ - 1).gl_handle
  479.             drawXZPlane 0, 0, 0, .25, .15, 1
  480.             _glPopMatrix
  481.         End If
  482.     Next
  483.     _glEnable _GL_LIGHTING
  484.  
  485.  
  486. Sub drawBonusObj ()
  487.     Static calc_done As _Byte, sin120, cos120, sin240, cos240, rotY
  488.     If calc_done = 0 Then
  489.         calc_done = 1
  490.         sin120 = Sin(_D2R(120))
  491.         cos120 = Cos(_D2R(120))
  492.         sin240 = Sin(_D2R(240))
  493.         cos240 = Cos(_D2R(240))
  494.     End If
  495.     rotY = rotY + 2
  496.     r = 0.2: yOff = -0.6
  497.     _glDisable _GL_LIGHTING
  498.     For i = 1 To worldStats.num_of_point
  499.         _glPushMatrix
  500.         _glTranslatef pointMap(i).x, 0, pointMap(i).y
  501.         _glRotatef rotY, 0, 1, 0
  502.         _glBegin _GL_TRIANGLES
  503.         'down open pyramid
  504.         _glColor3f 0, 1, 1
  505.         _glVertex3f 0, -r + yOff, 0
  506.         _glVertex3f r, yOff, 0
  507.         _glVertex3f r * cos120, yOff, r * sin120
  508.         _glColor3f 1, 0, 1
  509.         _glVertex3f 0, -r + yOff, 0
  510.         _glVertex3f r * cos120, yOff, r * sin120
  511.         _glVertex3f r * cos240, yOff, r * sin240
  512.         _glColor3f 1, 1, 0
  513.         _glVertex3f 0, -r + yOff, 0
  514.         _glVertex3f r, yOff, 0
  515.         _glVertex3f r * cos240, yOff, r * sin240
  516.         'upper open pyramid, combined together with to form a diamond like structure
  517.         _glColor3f 1, 0, 1
  518.         _glVertex3f 0, r + yOff, 0
  519.         _glVertex3f r, yOff, 0
  520.         _glVertex3f r * cos120, yOff, r * sin120
  521.         _glColor3f 1, 1, 0
  522.         _glVertex3f 0, r + yOff, 0
  523.         _glVertex3f r * cos120, yOff, r * sin120
  524.         _glVertex3f r * cos240, yOff, r * sin240
  525.         _glColor3f 0, 1, 1
  526.         _glVertex3f 0, r + yOff, 0
  527.         _glVertex3f r, yOff, 0
  528.         _glVertex3f r * cos240, yOff, r * sin240
  529.         _glEnd
  530.         _glPopMatrix
  531.     Next
  532.     _glEnable _GL_LIGHTING
  533.  
  534. Sub drawTraps ()
  535.     _glDisable _GL_LIGHTING
  536.     If worldStats.num_of_trap > 0 Then
  537.         For i = 1 To worldStats.num_of_trap
  538.             Select Case trapMap(i).typ
  539.                 Case 1 'laser trap
  540.                     If trapMap(i).d_3 = 1 Then
  541.                         If trapMap(i).d_1 = 1 Then 'aage piche w.r.t. XY plane
  542.                             _glColor3f 1, 0, 0
  543.                             selectTexture 0
  544.                             _glLineWidth 3.0
  545.                             _glBegin _GL_LINES
  546.                             For j = -0.8 To 0.8 Step 0.4
  547.                                 _glVertex3f trapMap(i).x - 0.5, j, trapMap(i).y - 0.5
  548.                                 _glVertex3f trapMap(i).x - 0.5, j, trapMap(i).y + 0.5
  549.                                
  550.                                 _glVertex3f trapMap(i).x + 0.5, j, trapMap(i).y - 0.5
  551.                                 _glVertex3f trapMap(i).x + 0.5, j, trapMap(i).y + 0.5
  552.                             Next
  553.                             _glEnd
  554.                         Else 'agal bagal w.r.t. XY Plane
  555.                             _glColor3f 1, 0, 0
  556.                             selectTexture 0
  557.                             _glLineWidth 3.0
  558.                             _glBegin _GL_LINES
  559.                             For j = -0.8 To 0.8 Step 0.4
  560.                                 _glVertex3f trapMap(i).x - 0.5, j, trapMap(i).y - 0.5
  561.                                 _glVertex3f trapMap(i).x + 0.5, j, trapMap(i).y - 0.5
  562.                                
  563.                                 _glVertex3f trapMap(i).x - 0.5, j, trapMap(i).y + 0.5
  564.                                 _glVertex3f trapMap(i).x + 0.5, j, trapMap(i).y + 0.5
  565.                             Next
  566.                             _glEnd
  567.                         End If
  568.                     End If
  569.             End Select
  570.         Next
  571.     End If
  572.     _glEnable _GL_LIGHTING
  573.  
  574. Sub drawBox (x, y, z, w, h, d) '(x,y,z)->location to draw, w->width, h->height, d-depth of the box
  575.     'XY
  576.     drawXYPlane x, y, z - d / 2, w, h, -1
  577.     drawXYPlane x, y, z + d / 2, w, h, 1
  578.     'YZ
  579.     drawYZPlane x - w / 2, y, z, h, d, -1
  580.     drawYZPlane x + w / 2, y, z, h, d, 1
  581.     'XZ
  582.     drawXZPlane x, y - h / 2, z, w, d, -1
  583.     drawXZPlane x, y + h / 2, z, w, d, 1
  584.  
  585. Sub drawXZPlane (x, y, z, w, d, n) '(x,z)->location to draw, w->width, d->depth of the plane, n->normal direction in Y direction
  586.     _glBegin _GL_QUADS
  587.     _glTexCoord2f 1, 0
  588.     _glNormal3f 0, n, 0
  589.     _glVertex3f x - (w / 2), y, z - d / 2
  590.     _glTexCoord2f 1, 1
  591.     _glNormal3f 0, n, 0
  592.     _glVertex3f x + (w / 2), y, z - d / 2
  593.     _glTexCoord2f 0, 1
  594.     _glNormal3f 0, n, 0
  595.     _glVertex3f x + (w / 2), y, z + d / 2
  596.     _glTexCoord2f 0, 0
  597.     _glNormal3f 0, n, 0
  598.     _glVertex3f x - (w / 2), y, z + d / 2
  599.     _glEnd
  600.  
  601. Sub drawXYPlane (x, y, z, w, h, n) '(x,y)-> location to draw, w->width, h->height, n->normal direction in Z direction
  602.     _glBegin _GL_QUADS
  603.     _glTexCoord2f 0, 0
  604.     _glNormal3f 0, 0, n
  605.     _glVertex3f x - (w / 2), y - h / 2, z
  606.     _glTexCoord2f 1, 0
  607.     _glNormal3f 0, 0, n
  608.     _glVertex3f x + (w / 2), y - h / 2, z
  609.     _glTexCoord2f 1, 1
  610.     _glNormal3f 0, 0, n
  611.     _glVertex3f x + (w / 2), y + h / 2, z
  612.     _glTexCoord2f 0, 1
  613.     _glNormal3f 0, 0, n
  614.     _glVertex3f x - (w / 2), y + h / 2, z
  615.     _glEnd
  616.  
  617. Sub drawYZPlane (x, y, z, h, d, n) '(y,z)->location to draw, h->height, d->depth, n->normal direction in X direction
  618.     _glBegin _GL_QUADS
  619.     _glTexCoord2f 0, 0
  620.     _glNormal3f n, 0, 0
  621.     _glVertex3f x, y - (h / 2), z - d / 2
  622.     _glTexCoord2f 0, 1
  623.     _glNormal3f n, 0, 0
  624.     _glVertex3f x, y + (h / 2), z - d / 2
  625.     _glTexCoord2f 1, 1
  626.     _glNormal3f n, 0, 0
  627.     _glVertex3f x, y + (h / 2), z + d / 2
  628.     _glTexCoord2f 1, 0
  629.     _glNormal3f n, 0, 0
  630.     _glVertex3f x, y - (h / 2), z + d / 2
  631.     _glEnd
  632.  
  633. Sub selectTexture (tex&)
  634.     _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
  635.     _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR
  636.     _glBindTexture _GL_TEXTURE_2D, tex&
  637.  
  638. Function feedGLTexture& (img As Long)
  639.     If img < -1 Then
  640.         Dim m As _MEM
  641.         m = _MemImage(img)
  642.  
  643.         _glGenTextures 1, _Offset(feedGLTexture&)
  644.         _glBindTexture _GL_TEXTURE_2D, feedGLTexture&
  645.  
  646.         _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGBA, _Width(img&), _Height(img&), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
  647.  
  648.         _MemFree m
  649.         _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
  650.         _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
  651.  
  652.     Else
  653.         echo "FUNCTION feedGlTexture&() : invalid image handle passed"
  654.     End If
  655.  
  656. Sub loadWorld (map_file$) 'load the given .3dm world
  657.     If Not _FileExists(map_file$) Then echo "SUB loadWorld() : map file not found - " + map_file$: Exit Sub
  658.  
  659.     f = FreeFile
  660.     Open map_file$ For Binary As #f
  661.     Get #f, , worldStats
  662.  
  663.     If worldStats.signature <> "3DM@QB64" Then echo "SUB loadWorld() : Invalid Signature - " + map_file$: Exit Sub
  664.    
  665.     'show map info in debug mode
  666.     echo "SUB loadWorld() : Map file loaded - " + map_file$
  667.     echo "World size : " + Str$(worldStats.mapW) + "x" + Str$(worldStats.mapH)
  668.     echo "Player initial position : " + Str$(worldStats.px) + "," + Str$(worldStats.py)
  669.     echo "Number of wall block(s) : " + Str$(worldStats.num_of_wall)
  670.     echo "Number of floor block(s) : " + Str$(worldStats.num_of_floor)
  671.     echo "Number of ceiling block(s) : " + Str$(worldStats.num_of_ceiling)
  672.     echo "Number of door(s) : " + Str$(worldStats.num_of_door)
  673.     echo "Number of key(s) : " + Str$(worldStats.num_of_key)
  674.     echo "Number of point(s) : " + Str$(worldStats.num_of_point)
  675.     echo "Number of detail(s)/interior(s) : " + Str$(worldStats.num_of_detail)
  676.     echo "Number of trap(s) : " + Str$(worldStats.num_of_trap)
  677.     echo "Player destination : " + Str$(worldStats.destX) + "," + Str$(worldStats.destY)
  678.     echo "Global Light Settings :- "
  679.     echo "Ambient Color : (" + Str$(worldStats.light_amb.x) + "," + Str$(worldStats.light_amb.y) + "," + Str$(worldStats.light_amb.z) + ")"
  680.     echo "Diffuse Color : (" + Str$(worldStats.light_diff.x) + "," + Str$(worldStats.light_diff.y) + "," + Str$(worldStats.light_diff.z) + ")"
  681.     echo "Specular Color : (" + Str$(worldStats.light_spec.x) + "," + Str$(worldStats.light_spec.y) + "," + Str$(worldStats.light_spec.z) + ")"
  682.     echo "Direction : (" + Str$(worldStats.light_dir.x) + "," + Str$(worldStats.light_dir.y) + "," + Str$(worldStats.light_dir.z) + ")"
  683.     'wall
  684.     If worldStats.num_of_wall > 0 Then
  685.         ReDim wallMap(worldStats.num_of_wall) As map_element
  686.         For i = 1 To worldStats.num_of_wall
  687.             Get #f, , wallMap(i)
  688.         Next
  689.     End If
  690.     'floor
  691.     If worldStats.num_of_floor > 0 Then
  692.         ReDim floorMap(worldStats.num_of_floor) As map_element
  693.         For i = 1 To worldStats.num_of_floor
  694.             Get #f, , floorMap(i)
  695.         Next
  696.     End If
  697.     'ceiling
  698.     If worldStats.num_of_ceiling > 0 Then
  699.         ReDim ceilingMap(worldStats.num_of_ceiling) As map_element
  700.         For i = 1 To worldStats.num_of_ceiling
  701.             Get #f, , ceilingMap(i)
  702.         Next
  703.     End If
  704.     'door
  705.     If worldStats.num_of_door > 0 Then
  706.         ReDim doorMap(worldStats.num_of_door) As map_element
  707.         For i = 1 To worldStats.num_of_door
  708.             Get #f, , doorMap(i)
  709.         Next
  710.     End If
  711.     'keys
  712.     If worldStats.num_of_key > 0 Then
  713.         ReDim keyMap(worldStats.num_of_key) As map_element
  714.         For i = 1 To worldStats.num_of_key
  715.             Get #f, , keyMap(i)
  716.         Next
  717.     End If
  718.     'point
  719.     If worldStats.num_of_point > 0 Then
  720.         ReDim pointMap(worldStats.num_of_point) As map_element
  721.         For i = 1 To worldStats.num_of_point
  722.             Get #f, , pointMap(i)
  723.         Next
  724.     End If
  725.    
  726.     If worldStats.num_of_detail > 0 Then
  727.         ReDim detailMap(worldStats.num_of_detail) As map_element
  728.         For i = 1 To worldStats.num_of_detail
  729.             Get #f, , detailMap(i)
  730.         Next
  731.     End If
  732.  
  733.     If worldStats.num_of_trap > 0 Then
  734.         ReDim trapMap(worldStats.num_of_trap) As map_element
  735.         For i = 1 To worldStats.num_of_trap
  736.             Get #f, , trapMap(i)
  737.         Next
  738.     End If
  739.  
  740.     Close #f
  741.    
  742.     'generate new collision map
  743.     ReDim collisionMap(worldStats.mapW, worldStats.mapH, 1) As _Byte
  744.     For i = 1 To worldStats.num_of_wall
  745.         collisionMap(wallMap(i).x, wallMap(i).y, 0) = 1
  746.     Next
  747.     For i = 1 To worldStats.num_of_door
  748.         collisionMap(doorMap(i).x, doorMap(i).y, 0) = 1
  749.         collisionMap(doorMap(i).x, doorMap(i).y, 1) = 2
  750.     Next
  751.     For i = 1 To worldStats.num_of_key
  752.         collisionMap(keyMap(i).x, keyMap(i).y, 1) = 3
  753.     Next
  754.    
  755.  
  756. Function near_int (c)
  757.     If (c - Int(c)) >= 0.5 Then near_int = Int(c) + 1 Else near_int = Int(c)
  758.  
  759. Sub echo (a$)
  760.     $If DEBUG = -1 Then
  761.         _Echo a$
  762.     $End If
  763.  
  764. Function glVec4%& (x, y, z, w)
  765.     Static internal_vec4(3)
  766.     internal_vec4(0) = x
  767.     internal_vec4(1) = y
  768.     internal_vec4(2) = z
  769.     internal_vec4(3) = w
  770.     glVec4%& = _Offset(internal_vec4())
  771.  
  772. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  773.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  774.  
  775.  
  776. 'supportive functions
  777.  
  778. '##################################################################################
  779. 'syntax: extract_file_all cdf_file_name$, path_where_file_is_to_be_extracted$
  780. '* extract all the files present in the given cdf file.
  781. '  path_where_file_is_to_be_extracted$ must end either with '/' or '\'
  782. '##################################################################################
  783. sub extract_file_all (f_name$, path$)
  784.     ' $CHECKING:OFF
  785.     DIM header AS cdf_file_header, element AS cdf_file_element
  786.     dim fileToBeExtracted$
  787.  
  788.     IF _FILEEXISTS(f_name$) THEN
  789.         f = FREEFILE
  790.         OPEN f_name$ FOR BINARY AS #f
  791.         GET #f, , header
  792.         IF header.signature <> "cdf@qb64" THEN CLOSE #f: echo "In SUB extract_file_all(): Invalid file - "+f_name$: EXIT SUB 'verify if it is even a cdf_file or not. Then only proceed.
  793.  
  794.         FOR i = 1 TO header.num_of_files
  795.             GET #f, , element
  796.  
  797.                         a$ = SPACE$(element.compressed_bytes)
  798.                         GET #f, , a$ 'get content
  799.             fileToBeExtracted$ = _TRIM$(element.file_name)
  800.                         ff = FREEFILE
  801.                         IF _FILEEXISTS(path$ + fileToBeExtracted$) THEN KILL path$ + fileToBeExtracted$ 'delete if there already exists a file with the same name
  802.                         ea$ = _INFLATE$(a$, element.original_bytes) 'decompress
  803.             echo path$+fileToBeExtracted$
  804.                         OPEN path$ + fileToBeExtracted$ FOR BINARY AS #ff 'create the file at the output path
  805.                         PUT #ff, , ea$
  806.                         CLOSE #ff
  807.         NEXT
  808.         CLOSE #f
  809.         else
  810.                 echo "In SUB extract_file_all(): File "+f_name$+" not found."
  811.     END IF
  812.     ' $CHECKING:ON
  813.  
  814. '####################################################################################
  815. 'syntax: extract_file cdf_file_name$, name_of_file_To_Be_Extracted$, output_path$
  816. '* extract the given file from cdf_file if it exists in it to the required
  817. '  output path. output_path$ must end with either '/' or '\'.
  818. '#####################################################################################
  819. SUB extract_file (f_name$, fileToBeExtracted$, path$)
  820.     ' $CHECKING:OFF
  821.     DIM header AS cdf_file_header, element AS cdf_file_element
  822.  
  823.     IF _FILEEXISTS(f_name$) THEN
  824.         f = FREEFILE
  825.         OPEN f_name$ FOR BINARY AS #f
  826.         GET #f, , header
  827.         IF header.signature <> "cdf@qb64" THEN CLOSE #f: echo "In SUB extract_file(): Invalid file - "+f_name$: EXIT SUB 'verify if it is even a cdf_file or not. Then only proceed.
  828.  
  829.         FOR i = 1 TO header.num_of_files
  830.             GET #f, , element
  831.             IF RTRIM$(element.file_name) = fileToBeExtracted$ THEN 'extract the file, if condition become true
  832. ' ?"ok"
  833.                 a$ = SPACE$(element.compressed_bytes)
  834.                 GET #f, , a$ 'get content
  835.                 ff = FREEFILE
  836.                 IF _FILEEXISTS(path$ + fileToBeExtracted$) THEN KILL path$ + fileToBeExtracted$ 'delete if there already exists a file with the same name
  837.                 ea$ = _INFLATE$(a$, element.original_bytes) 'decompress
  838.                 OPEN path$ + fileToBeExtracted$ FOR BINARY AS #ff 'create the file at the output path
  839.                 PUT #ff, , ea$
  840.                 CLOSE #ff
  841.                 EXIT SUB
  842.             ELSE
  843.                 SEEK f, SEEK(f) + element.compressed_bytes 'file name is not one which user looking for, we just skip to next entry
  844.             END IF
  845.         NEXT
  846.         CLOSE #f
  847.         else
  848.                 echo "In SUB extract_file(): File not found - "+f_name$
  849.     END IF
  850.     ' $CHECKING:ON
  851.  
  852. SUB __internal_dummy_cdf_sub () 'declare required types
  853.     TYPE cdf_file_header
  854.         signature AS STRING * 8 'cdf@qb64
  855.         num_of_files AS INTEGER
  856.     END TYPE
  857.  
  858.     TYPE cdf_file_element
  859.         file_name AS STRING * 128
  860.         original_bytes AS _UNSIGNED _INTEGER64
  861.         compressed_bytes AS _UNSIGNED _INTEGER64
  862.     END TYPE
  863.  


* world_data.cdf (Filesize: 3 MB, Downloads: 266)
SCRST_1.png
* SCRST_1.png (Filesize: 757.33 KB, Dimensions: 800x630, Views: 345)
« Last Edit: May 31, 2021, 08:28:14 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: 3D World Game Engine
« Reply #1 on: May 30, 2021, 02:08:54 pm »
This is probably the best one of these we have. Excellent work. All 3D connoisseurs should take note.
You're not done when it works, you're done when it's right.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: 3D World Game Engine
« Reply #2 on: May 30, 2021, 06:05:50 pm »
This pretty cool.... Mouse was a little sensitive, but a 'gentle' touch, worked fine... The style reminded me of the old Doom engine... but with much better graphics... So cool...

Great job!!  Two thumbs WAY up!!
Logic is the beginning of wisdom.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: 3D World Game Engine
« Reply #3 on: May 31, 2021, 07:01:48 am »
Hello ! your graphics look very nice! I went through it and it was like I was there. It was good to see high-resolution textures and pleasant shadow effects. The fps can also be high, making the movement of objects very silky. Good to see such 3D things! I wish I understood opengl.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: 3D World Game Engine
« Reply #4 on: May 31, 2021, 07:30:21 am »
Thanks @STxAxTIC I have not seen you for a while... I hope you are doing great!
@johnno56 Thanks!
@MasterGy Thanks! To be honest, I like your engine more... as it has more animation and colors.. :D

Here's walkthrough video...

if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: 3D World Game Engine
« Reply #5 on: May 31, 2021, 07:35:29 am »
Here is one more map which you can download from the attachment this post below ("world_data.cdf")... it is much bigger than
the one in first post.




* world_data.cdf (Filesize: 3.01 MB, Downloads: 210)
SCRST_1.png
* SCRST_1.png (Filesize: 898.71 KB, Dimensions: 801x626, Views: 206)
« Last Edit: May 31, 2021, 08:28:37 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D World Game Engine
« Reply #6 on: May 31, 2021, 10:31:59 am »
Well I am no judge of 3D Games but graphics look impressive, very clear.

I am definitely keeping an eye on this thread! :)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: 3D World Game Engine
« Reply #7 on: May 31, 2021, 11:57:54 am »
thanks Ashis! _MAPTRIANGLE is easier to use, making it easier for me to achieve a varied look. But there’s a limit, and unfortunately I can’t go beyond looking better than old, dos games. What you started now looks more modern now, and you can achieve a fantastic look later by placing light sources, for example. I am very curious what can be brought out of opengl, I wish you a lot of success and ideas to continue!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D World Game Engine
« Reply #8 on: May 31, 2021, 04:15:07 pm »
Very nice work, Ashish! Thank you for sharing it!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: 3D World Game Engine
« Reply #9 on: June 03, 2021, 05:41:27 pm »
Magnificent work, @Ashish.  Runs great here.  Thanks for sharing your code.

- Dav

Offline pforpond

  • Newbie
  • Posts: 76
  • I am me
    • View Profile
Re: 3D World Game Engine
« Reply #10 on: June 14, 2021, 04:47:33 pm »
This is insanely good! So smooth and fluid! This has terrific potential, it looks amazing.
I noticed all the corners seem to be 90 degrees, is this a limitation or just an artist choice?
Loading Signature...

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: 3D World Game Engine
« Reply #11 on: July 20, 2021, 04:42:53 pm »
Hi Ashish,

Firstly, it looks good in the video...reminds me of kens labyrinth which i very much enjoyed playing on my IBM 286 WAYYYY back in the day....I can see you've put a lot of work into the look of it (i analysed the code and noticed a few nice little touches! :) ) and it shows promise. I'm gonna be me though and suggest a few 'mods' (hope you dont mind)

1. The code we see should be MINIMAL! Make your work into a .bi and .bm library and your engine into a .bm that you call with a single command.

i.e

$include - lib headers

3D_Engine_ GO ("GamefileName")

$include - libs

This is all we should need to do to launch the underlying engine.

2. Level Editor - Once you've made your bi/bm lib files you can use them to make tools. A basic level editor is essential...your engine can be better than anyting out there but if people have to hard code it then it will flop...

3. GL - The way you're using GL is ok but with _MEM and the fact that qb64 supports es 2 commands (i dont know if it does it work with later versions of gl) but the methods it employs are way faster for rendering...

4. I wanna shot someone! Wheres the enemies bro!?

Good work and hit me up if you need help with the conversions...

Unseen

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: 3D World Game Engine
« Reply #12 on: July 21, 2021, 12:19:48 am »
It's only about 700 lines, discounting the comments and blank lines.  I are impressed.

Are the horizontal red lines that show up sometimes, in some corridors, supposed to
be there?  Laser beams?  Wut?

My mouse cursor isn't surrounded by a nice blue orb like in the video.  Helps for picking
up the keys, I guess.

It works better if you plug it in.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: 3D World Game Engine
« Reply #13 on: July 21, 2021, 01:22:45 am »
This is insanely good! So smooth and fluid! This has terrific potential, it looks amazing.
I noticed all the corners seem to be 90 degrees, is this a limitation or just an artist choice?
The corners are indeed 90degrees. Its not a limitation, its an artist choice.

@Unseen Machine
Quote
1. The code we see should be MINIMAL! Make your work into a .bi and .bm library and your engine into a .bm that you call with a single command.

i.e

$include - lib headers

3D_Engine_ GO ("GamefileName")
Yes, I am working on this.

Quote
Level Editor - Once you've made your bi/bm lib files you can use them to make tools. A basic level editor is essential...your engine can be better than anyting out there but if people have to hard code it then it will flop...
I already have a level editor done by which I create world for my engine.. I have not share it or posted it anywhere for now.

Quote
3. GL - The way you're using GL is ok but with _MEM and the fact that qb64 supports es 2 commands (i dont know if it does it work with later versions of gl) but the methods it employs are way faster for rendering...
Yes, I understand. Using _glDrawArrays will be much for faster if the game have huge number of vertices to be rendered. I will modified that too.

Quote
4. I wanna shot someone! Wheres the enemies bro!?
LOL... Yeah. The engine is in ALPHA stage.. Need to work a lot on this.

I will surely message you if I need any help from you.

Thank you for your feedback. :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: 3D World Game Engine
« Reply #14 on: July 21, 2021, 02:40:53 am »
It's only about 700 lines, discounting the comments and blank lines.  I are impressed.

Are the horizontal red lines that show up sometimes, in some corridors, supposed to
be there?  Laser beams?  Wut?

My mouse cursor isn't surrounded by a nice blue orb like in the video.  Helps for picking
up the keys, I guess.
yes.. They are laser beams.. They are traps.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials