N3xtD - Free 3D engine

Started by Brice Manuel, August 25, 2011, 06:40:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter Weis

Hello Frank,
Give me the Organal include file. I want to watch it once in Enum type that goes to Free Basic but not because the data width of the constant is not well known!

But I would like to view the original file FreeBasic times. Who do you send me it might perhaps I can help! :)

regards Peter
  •  

Peter Weis

#46
Hello,
Include many new bug

regards Peter
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  040   as   first terrain sample.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF





    '------------------------------------------------------------------------------------
    DIM terrain AS TerrainNode
    terrain = CreateTerrain("media/height113.bmp", 1, 2.0, 0.45,2.0, 32, %TRUE, %HARDMAPPING.EHM_STATIC)
    TextureTerrain(terrain, 0 , "media/Sol113.jpg", -1, -1)
    TextureTerrain(terrain, 1 , "media/detailmap3.jpg", -1, -1)
    MaterialTypeNode(terrain,  %EMT_LIGHTMAP_M2)

    '_DebugModeNode(terrain, True)
    '------------------------------------------------------------------------------------



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)

    PositionNode(cam, 100,70,100)



    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_= GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        '--------------------------------------------------------
        ' terrain picking zone test
        IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_RIGHT) THEN
            DIM res_ AS INTEGER
            res_ = PickTerrain(terrain)
            IF res_  THEN
                DIM pPos(4) AS SINGLE
                TerrainPickedPosition(terrain, ppos(0))
                HeightTerrain(terrain, 16.0, ppos(0), ppos(2),  1.0, %TH_UP)
            END IF
        END IF





        ' ---------------
        '      Render
        ' ---------------
        BeginScene(1,128,128, 255, 1, 1)
        DrawScene()
        DrawText(font_, "Right click mouse to change height of terrain" ,  10,5,0,0, &h0ffffffff)
        DrawText(font_, "FPS  as  "+ TRIM$(STR$(FPS())),  10,25,0,0, &h0ffffffff)
        DrawText(font_, "Primitives as  "+ TRIM$(STR$(PrimitiveCountDrawn())), 10,45,0,0, &h0ffffffff)
        EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION
                                         
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  041  :  terrain with light.
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Globales
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


    '------------------------------------------------------------------------------------
    ' Create light And set position
    DIM  light AS LightNode
    light = CreateLight(&h0ffffffff, 256.0, %ELT_POINT, %NULL)

    PositionNode(light, 50,100,50)


    '------------------------------------------------------------------------------------
    DIM terrain AS TerrainNode
    terrain = CreateTerrain("media/height113.bmp", 1, 2.0, 0.45, 2.0, 32, %TRUE, %HARDMAPPING.EHM_STATIC)

    TextureTerrain(terrain, 0 , "media/Sol113.jpg", -1, -1)
    TextureTerrain(terrain, 1 , "media/detailmap3.jpg", -1, -1)
    MaterialTypeNode(terrain,  %EMT_LIGHTMAP_LIGHTING_M2)

    '_DebugModeNode(terrain, TRUE)
    '------------------------------------------------------------------------------------



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 100,80,100)



    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    DIM hh AS SINGLE
    WHILE Quit = 0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF



        ' move camera with dir key And mouse (Left click)
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
            hh = TerrainHeight(terrain,  NodeX(cam),  NodeZ(cam), 0)+10.0
            PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
            hh= TerrainHeight(terrain,  NodeX(cam),  NodeZ(cam), 0)+10.0
            PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
            hh = TerrainHeight(terrain,  NodeX(cam),  NodeZ(cam), 0)+10.0
            PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
            hh= TerrainHeight(terrain,  NodeX(cam),  NodeZ(cam), 0)+10.0
            PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
        END IF




        ' ---------------
        '      Render
        ' ---------------
        BeginScene(1,128,128, 255, 1, 1)
        DrawScene()
        DrawText(font_, "FPS : " + TRIM$(STR$(FPS())),  10,25,0,0, &h0ffffffff)
        DrawText(font_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn()))  ,  10,45,0,0, &h0ffffffff)
        EndScene()


    WEND
    ' end
    FreeEngine()

END FUNCTION
                           
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  042: terrain splatting
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' Globales
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF



    DIM light AS LightNode
    light = CreateLight(&h0ffff0000, 256.0, %ELT_POINT , %NULL)
    PositionNode(light, 50,100,50)


    '------------------------------------------------------------------------------------
    DIM terrain AS TerrainNode
    terrain = CreateTerrain("media/aterrain1.bmp", %TQ_MEDIUM, 2.0, 0.35, 2.0, 4, %TRUE, %HARDMAPPING.EHM_STATIC)
    SplattingTerrain(terrain,  -500.0, &hffffffff)

    DIM alphamap AS NTexture
    alphamap = TextureTerrain(terrain, 0,"media/alpha1.bmp", -1, -1)
    TextureTerrain(terrain, 1,"media/025.jpg", -1, -1)
    TextureTerrain(terrain, 2,"media/stone.bmp", -1, -1)
    TextureTerrain(terrain, 3,"media/splatting3.png", -1, -1)
    TextureTerrain(terrain, 4,"media/dirt.bmp", -1, -1)
    TextureTerrain(terrain, 5,"media/detailmap3.jpg", -1, -1)
    '_TextureTerrain(terrain, 6,"media/lightmap.jpg")
    '------------------------------------------------------------------------------------



    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, -100,280,-100)



    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit = 0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        '--------------------------------------------------------
        ' terrain picking zone test
        IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_RIGHT) THEN
            DIM res_ AS INTEGER
            res_ = PickTerrain(terrain)
            IF res_ THEN
                DIM pPos(4) AS SINGLE
                TerrainPickedPosition(terrain, pPos(0))
                WriteTextureTerrain(terrain, alphamap, pPos(0), pPos(2), 8, &h0ffff0000)
            END IF
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(1,128,128, 255, 1, 1)
        DrawScene()
        DrawText(font_, "Right click mouse on terrain to change texture splat" ,  10,5,0,0, &h0ffffffff)
        DrawText(font_, "FPS : " + TRIM$(STR$(FPS())),  10,25,0,0, &h0ffffffff)
        DrawText(font_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn())), 10, 45, 0, 0, &h0ffffffff)
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
               
  •  

Peter Weis

Hello,
Include many new bug

regards Peter
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  043  :  10.000 grass element with wind simulation
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' Globales
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app=%NULL THEN
        EXIT FUNCTION
    END IF




    ' set the curent folder
    ChangeWorkingDirectory("media")


    '----------------------------------------
    ' Load 3D objects
    DIM obj1 AS Mesh
    obj1 = LoadMesh("plane.3ds", %HARDMAPPING.EHM_STATIC)
    '-----------------------------------------
    ' Create plane
    DIM plane AS EntityNode
    plane =  CreateEntityNode(obj1, 0, 0, 0, %NULL)
    ScaleNode(plane, 6,5,6)
    '----------------------------------------




    '----------------------------------------
    ' grass zone
    DIM spritemesh AS Mesh
    spritemesh = LoadMesh("grass1.3ds", %HARDMAPPING.EHM_STATIC)
    ScaleMesh(spritemesh, 0.15, 0.1, 0.15)


    DIM staticArea AS EntityNode


    staticArea = CreateBatchNode(spritemesh, %EMT_TRANSPARENT_ALPHA_CHANNEL_REF, %TRUE, %NULL)
    WindValueBatchZone(staticArea, 0.10, 30)

    DIM k AS LONG
    DIM x AS SINGLE, z AS SINGLE, sac AS SINGLE
    FOR k = 0 TO 10000
        x = -140+RND()*280
        z = -140+RND()*280
        sac = 0.65 + RND()*0.55
        AddBatchElement(staticArea, x, 6.5 ,z, 0,0,0, sac,1,sac)
    NEXT
    '_DebugModeNode(staticArea, DEBUG_BBOX )



    '----------------------------------------
    ' def camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0, 20, -0)


    '-----------------------------------
    ' Load font png
    LoadFont("courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(128,128,128, 255, 1, 1)
        DrawScene()
        DrawText(FONT_, "FPS : " + TRIM$(STR$(FPS()))  ,  10,25,0,0, &h0ffffffff)
        DrawText(FONT_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn()))  ,  10,45,0,0, &h0ffffffff)
        DrawText(FONT_, "10.000 grass element with wind simulation",  10,65,0,0, &h0ffffffff)
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
                                               
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  044   as   LOD Entity system
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


    ' Load the different mesh To construct LOD dim mesh
    DIM earthMesh1 AS Mesh
    earthMesh1 = LoadMesh("media/sphereLOD1.3ds", %HARDMAPPING.EHM_STATIC)

    DIM earthMesh2 AS Mesh
    earthMesh2 = LoadMesh("media/sphereLOD2.3ds", %HARDMAPPING.EHM_STATIC)

    DIM earthMesh3 AS Mesh
    earthMesh3 = LoadMesh("media/sphereLOD3.3ds", %HARDMAPPING.EHM_STATIC)

    DIM earthMesh4 AS Mesh
    earthMesh4 = LoadMesh("media/sphereLOD4.3ds", %HARDMAPPING.EHM_STATIC)

    DIM earthMesh5 AS Mesh
    earthMesh5 = LoadMesh("media/sphereLOD5.3ds", %HARDMAPPING.EHM_STATIC)

    DIM earthMesh6 AS Mesh
    earthMesh6 = LoadMesh("media/sphereLOD6.3ds", %HARDMAPPING.EHM_STATIC)




    '----------------------------------------
    DIM hillmesh AS Mesh
    hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)

    ' quick ground
    DIM hillplane AS EntityNode
    hillplane = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)

    LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)




    DistanceLOD(  80.0,  150.0,  210.0,  250.0,  280.0,  320.0)


    '----------------------------------------
    ' one entitynode LOD setting
    DIM entitylod AS EntityNode
    entitylod = CreateLODEntityNode(earthMesh1, 0)

    AddMeshLODEntityNode(entitylod, earthMesh2, 1 )
    AddMeshLODEntityNode(entitylod, earthMesh3, 2 )
    AddMeshLODEntityNode(entitylod, earthMesh4, 3 )
    AddMeshLODEntityNode(entitylod, earthMesh5, 4 )
    AddMeshLODEntityNode(entitylod, earthMesh6, 5 )
    PositionNode(entitylod, 80,80,0)



    '----------------------------------------
    ' set static zone with entitynode LOD setting
    DIM lod AS EntityNode
    lod = CreateStaticZone(earthMesh1, %NULL)
    SetLODStaticZoneEntityNode(lod, earthMesh2, 1 )
    SetLODStaticZoneEntityNode(lod, earthMesh3, 2 )
    SetLODStaticZoneEntityNode(lod, earthMesh4, 3 )
    SetLODStaticZoneEntityNode(lod, earthMesh5, 4 )
    SetLODStaticZoneEntityNode(lod, earthMesh6, 5 )

    DIM cube AS EntityNode
    DIM i AS INTEGER

    FOR i = 0 TO 60
        DIM sac AS SINGLE
        sac = RND()*10+5
        sac=sac/10.0
        AddElementStaticZone(lod, RND()*150.0-75 ,0, RND()*150.0-75, 0,0,0, sac,sac,sac)
    NEXT
    DebugModeNode(lod, %DEBUG_BBOX )





    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,50,-40)



    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit = 0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF



        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        DrawText(font_, "FPS  as  "+ TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
        DrawText(font_, "Primitives as  "+ TRIM$(STR$(PrimitiveCountDrawn())),  10,45,0,0, &h0ffffffff)
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION

                                                                           
  •  

Peter Weis

Hello,
Include many new bug

regards Peter
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  045   as   Little2D game
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

DECLARE SUB Init()
DECLARE SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DECLARE SUB CreateProjectil()
DECLARE SUB UpdatePlayer()
DECLARE SUB UpdateMeteor()
DECLARE SUB UpdateExplode()
DECLARE SUB UpdateProjectil()
DECLARE SUB DeathPlayer()
DECLARE SUB RenderAllSprite2D()
DECLARE SUB DeleteProjectil(num AS LONG)
DECLARE FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DECLARE SUB GenerateExplode(COL AS LONG)
DECLARE SUB DeleteMeteor(num AS LONG)
DECLARE FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG

    '{ Player definition

'--}
TYPE PLAYER
    sp AS Sprite2D
    posx AS SINGLE
    posy AS SINGLE
    radius AS SINGLE
END TYPE


'{ Meteor definition
TYPE METEOR
    sprite AS Sprite2D
    posx AS SINGLE
    posy AS SINGLE
    transx AS SINGLE
    transy AS SINGLE
    vcreated AS LONG
    radius AS SINGLE
END TYPE
'--}

'{ Projectil definition
TYPE BALL
    sprite AS Sprite2D
    posx AS SINGLE
    posy AS SINGLE
    transx AS SINGLE
    transy AS SINGLE
    created AS LONG
    radius AS SINGLE
END TYPE
'--}

'{ Explode definition
TYPE EXPLO
    sp AS Sprite2D
    anim AS NNodeAnimator
    posx AS SINGLE
    posy AS SINGLE
END TYPE
'--}

%MAXEXPLODE  = 8


FUNCTION PBMAIN
    ' dimes
    DIM app AS DWORD
    DIM Quit AS LONG


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

    IF app = %NULL THEN
        EXIT FUNCTION
    END IF

    '----------------------------------------------------------
    '     Structures definition
    '----------------------------------------------------------






    DIM play_ AS GLOBAL PLAYER
    DIM EndPlayer AS GLOBAL LONG
    DIM speed_ AS GLOBAL SINGLE         : speed_ = 10.0
    DIM proj(17) AS GLOBAL BALL
    DIM num_proj AS GLOBAL SINGLE
    DIM meteorB(64) AS GLOBAL METEOR
    DIM exp0(%MAXEXPLODE) AS GLOBAL EXPLO
    DIM proj_matrix(16) AS GLOBAL SINGLE
    DIM score AS GLOBAL LONG
    DIM longerval_score AS GLOBAL LONG

    LOCAL i AS LONG


    '----------------------------------------------------------
    '----------------------------------------------------------
    ' init all values And structures
    Init()






    '-----------------------------------------
    '-----------------------------------------
    ' Create balll sprite
    GLOBAL balll AS Sprite2D
    balll = CreateSprite2D("media/Particle.png", 1.5, &h0ffffffff, %NULL)

    MaterialTypeNode(balll, %EMT_TRANSPARENT_ALPHA_CHANNEL)
    VisibleNode(balll, %False) ' no render


    '-----------------------------------------
    '-----------------------------------------
    ' Create PLAYER
    play_.sp = CreateSprite2D("media/Space1.png", 1.0, &h0ffffffff, %NULL)
    MaterialTypeNode(play_.sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
    PositionNode(play_.sp, 0,0,1)
    play_.radius = 40.0


    '-----------------------------------------
    '-----------------------------------------
    ' Create EXPLODE PLAYER
    GLOBAL player_explode AS Sprite2D
    player_explode = CreateSprite2D("media/Particle.png", 16.0, &h00ffffff, %NULL)
    MaterialTypeNode(player_explode, %EMT_TRANSPARENT_VERTEX_ALPHA)
    ' Create explose sequance texture
    DIM texturelist AS NArray
    texturelist = CreateListTexture("media/explo2.bmp",64,64)

    DIM anim AS NNodeAnimator
    anim = CreateTextureAnimator( texturelist,  130, %true)
    AddAnimatorTexture(player_explode, anim)


    '-----------------------------------------
    '-----------------------------------------
    ' Create thie first meteors
    FOR i = 0 TO 7
        CreateMeteor(50.0, -1)
    NEXT



    '-----------------------------------------
    '-----------------------------------------
    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam,0,0,0)



    '-----------------------------------------
    '-----------------------------------
    ' Load background textures
    DIM texture AS NTexture
    texture = LoadTexture("media/metal13.jpg")


    '-----------------------------------------
    '-----------------------------------------
    ' Load fonts
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()
    LoadFont("media/font0.xml", %FONT_TYPE.EGDF_DEFAULT)
    DIM font2 AS IGUIFont
    font2 = GetFont()


    '-----------------------------------------
    '-----------------------------------------
    ' 3D elements
    DIM  boxmesh AS Mesh
    boxmesh = CreateCubeMesh(50)

    DIM box_ AS EntityNode
    box_ = CreateEntityNode(boxmesh, 0, 0, 0, %NULL)

    PositionNode(box_, 0,0,100)
    LoadTextureNode(box_, "media/metal13.jpg", 0, 0)




    '-----------------------------------------
    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    '-----------------------------------------
    WHILE Quit = 0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        TurnNode(box_,0,0.5,0.5, 0)


        IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
            TurnNode(play_.sp, 0,0,3, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
            TurnNode(play_.sp, 0,0,-3, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
            MoveNode(play_.sp,0,-3,0, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
            MoveNode(play_.sp,0,3,0, 0)
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
            CreateProjectil()
        END IF



        IF EndPlayer = 0  THEN
            UpdatePlayer()
            UpdateProjectil()
            UpdateMeteor()
            UpdateExplode()
        ELSE
            DeathPlayer()
        END IF

        ' ---------------
        '      Render
        ' ---------------
        BeginScene(20,20,20, 255, 1, 1)

        ' 3D render
        DrawRectImage2D(texture , 0, 0, 0, 0, 800, 600, &h0ff777777, BYVAL %NULL, %FALSE)
        DrawScene()

        ' 2D sprites render
        Begin2D(800,600)
        RenderSprite2D(play_.sp)
        RenderAllSprite2D()
        IF EndPlayer<>0 THEN RenderSprite2D(player_explode)
        End2D()


        DrawText(font_, "score: "+ TRIM$(STR$(score)),  10,10,0,0, &h0ffffffff)
        DrawText(font_, "Use 'dir' and 'space' key",  450,8,0,0, &h0ff00ffff)
        IF EndPlayer<>0 THEN
            DrawText(font2, "END",  360,250,0,0, &h0ffffff00)
            DrawText(font2, "score: "+ TRIM$(STR$(score)) ,  350,310,0,0, &h0ffff00ff)
        END IF

        EndScene()
        ' ---------------
        '  End Render
        ' ---------------

    WEND
    ' end
    FreeEngine()
END FUNCTION

'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
SUB RenderAllSprite2D()
  DIM i AS LONG
  FOR i = 0 TO 63
    IF meteorB(i).vcreated <> 0  THEN
        RenderSprite2D( meteorB(i).sprite)
    END IF
  NEXT

  FOR i = 0 TO 16
    IF proj(i).created <> 0  THEN
      RenderSprite2D( proj(i).sprite)
    END IF
  NEXT

  FOR i = 0 TO %MAXEXPLODE-1
    IF(exp0(i).sp )  THEN
      RenderSprite2D(exp0(i).sp)
    END IF
  NEXT
END SUB
'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
' { initialise structures
SUB Init()
    DIM i AS LONG
    ' init projectil tab
    FOR i = 0 TO 16
      proj(i).sprite = %Null
      proj(i).created = 0
    NEXT
    FOR i = 0 TO %MAXEXPLODE-1
      exp0(i).sp = %Null
      exp0(i).anim = %Null
    NEXT
END SUB
' }

'-----------------------------------------


'-----------------------------------------
' { update player
SUB UpdatePlayer()
  DIM  pos_space(3) AS SINGLE

  NodePosition(play_.sp, pos_space(0))
  play_.posx =  pos_space(0)
  play_.posy =  pos_space(1)

  IF ( play_.posx>450 ) THEN
      play_.posx = -450
      PositionNode(play_.sp, play_.posx, play_.posy, 1)
  END IF
    IF ( play_.posx<-450 )THEN
        play_.posx = 450
        PositionNode(play_.sp, play_.posx, play_.posy, 1)
    END IF
    IF ( play_.posy>350 ) THEN
        play_.posy = -350
        PositionNode(play_.sp, play_.posx, play_.posy, 1)
    END IF
    IF ( play_.posy<-350 ) THEN
        play_.posy = 350
        PositionNode(play_.sp, play_.posx, play_.posy, 1)
    END IF

END SUB
' }

'-----------------------------------------
' { update all projectils
SUB UpdateProjectil()
    DIM COL AS LONG, rd AS SINGLE, i AS LONG

    FOR i = 0 TO 16
      IF proj(i).created <> 0  THEN
        proj(i).posx = proj(i).posx + proj(i).transx
        proj(i).posy = proj(i).posy + proj(i).transy
        PositionNode( proj(i).sprite, proj(i).posx, proj(i).posy, 1)
      IF ( proj(i).posx>400 OR  proj(i).posx<-400 ) THEN    DeleteProjectil(i)
      IF ( proj(i).posy>300 OR  proj(i).posy<-300 ) THEN    DeleteProjectil(i)
      COL = CollideProjectil(i)
      IF COL<>-1  THEN
        rd = meteorB(COL).radius
        DeleteProjectil(i)
        IF rd>13  THEN
          rd = rd / 2.0
          CreateMeteor(rd, COL)
          CreateMeteor(rd, COL)
        ELSE
          ' explosion
          GenerateExplode(COL)
        END IF
        DeleteMeteor(COL)
      END IF
      END IF
    NEXT
END SUB
' }

' { Create projectils (16 maxi)
SUB CreateProjectil()
    DIM pos_space(3) AS SINGLE
    DIM rot_space(3) AS SINGLE
    DIM i AS LONG

    num_proj = -1
    FOR i = 0 TO 15
      IF proj(i).created = 0 THEN
        num_proj = i
        EXIT FOR
      END IF
    NEXT
    IF num_proj<0 THEN RETURN

    proj(num_proj).sprite =  CloneNode(balll, %NULL)

    NodePosition(play_.sp, pos_space(0))
    NodeRotation(play_.sp, rot_space(0))

    pos_space(0) = pos_space(0) + SIN( -rot_space(2)*0.01745329 ) * 55.0
    pos_space(1) = pos_space(1) + COS( -rot_space(2)*0.01745329 ) * 55.0

    PositionNode(proj(num_proj).sprite, pos_space(0), pos_space(1), pos_space(2))
    proj(num_proj).posx = pos_space(0)
    proj(num_proj).posy = pos_space(1)
    proj(num_proj).transx = SIN( -rot_space(2)*0.01745329) * speed_
    proj(num_proj).transy = COS( -rot_space(2)*0.01745329) * speed_
    proj(num_proj).created = 1
    proj(num_proj).radius = 10.0
END SUB
' }

' { destruct projectil
SUB DeleteProjectil(num AS LONG)
  IF (proj(num).sprite) THEN
    FreeNode(proj(num).sprite)
    proj(num).sprite = %Null
    proj(num).created = 0
  END IF
END SUB
' }

'-----------------------------------------
' { Create Meteor
SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
    DIM pos_space(3) AS SINGLE
    DIM rot_space(3) AS SINGLE
    DIM i AS LONG
    DIM num_meteor AS LONG, posx AS SINGLE, posy AS SINGLE

    num_meteor = -1
    FOR i = 0 TO 63
      IF meteorB(i).vcreated = 0 THEN
        num_meteor = i
        EXIT FOR
      END IF
    NEXT
    IF num_meteor<0 THEN RETURN

        meteorB(num_meteor).sprite = CreateSprite2D("media/meteor.png", rad*0.01,  &h0ffffffff, %NULL)
        MaterialTypeNode(meteorB(num_meteor).sprite, %EMT_TRANSPARENT_ALPHA_CHANNEL)

        IF numcol<0  THEN
          DO
            posx = RND()*800.0
          LOOP UNTIL (posx<250.0 OR posx>550.0)
          posx = posx -400.0
          DO
            posy = RND()*600.0
          LOOP UNTIL (posy<200.0 OR posy>400.0)
          posy = posy -300.0
        ELSE
          posx = meteorB(numcol).posx
          posy = meteorB(numcol).posy
        END IF
        PositionNode(meteorB(num_meteor).sprite, posx, posy, 1 )
        meteorB(num_meteor).posx = posx
        meteorB(num_meteor).posy = posy

        meteorB(num_meteor).transx = -1.5+RND()*3.0
        meteorB(num_meteor).transy = -1.5+RND()*3.0
        meteorB(num_meteor).vcreated = 1
        meteorB(num_meteor).radius = rad

END SUB
' }

' { update all meteor
SUB UpdateMeteor()
    DIM i AS LONG
    FOR i = 0 TO 63
        IF meteorB(i).vcreated<> 0  THEN
            meteorB(i).posx = meteorB(i).posx + meteorB(i).transx
            meteorB(i).posy = meteorB(i).posy + meteorB(i).transy
            PositionNode( meteorB(i).sprite, meteorB(i).posx, meteorB(i).posy, 1)

            IF ( meteorB(i).posx>450 ) THEN meteorB(i).posx = -450
            IF ( meteorB(i).posx<-450 )THEN meteorB(i).posx = 450
            IF ( meteorB(i).posy>350 ) THEN meteorB(i).posy = -350
            IF ( meteorB(i).posy<-350 )THEN meteorB(i).posy = 350

            TurnNode(meteorB(i).sprite, 0,0,0.5, 0)

            IF CollideMeteor(i)<>0  THEN
                EndPlayer = 11
            END IF
        END IF
    NEXT
END SUB
' }

' { destruct meteor
SUB DeleteMeteor(num AS LONG)
    FreeNode(meteorB(num).sprite)
    meteorB(num).sprite = %Null
    meteorB(num).vcreated = 0
END SUB
' }

'-----------------------------------------
' { test collide between palyer spaceship And one meteor
FUNCTION CollideMeteor (numMeteor AS LONG)AS LONG
    DIM dist AS SINGLE, bt AS SINGLE, COL AS SINGLE

    dist = play_.radius + meteorB(numMeteor).radius
    ' cal distance
    bt =  (play_.posx - meteorB(numMeteor).posx)*(play_.posx - meteorB(numMeteor).posx) + (play_.posy - meteorB(numMeteor).posy)*(play_.posy - _
    meteorB(numMeteor).posy)
    bt = SQR(bt)
    COL = 0
    IF bt<dist THEN  COL = 1
    FUNCTION = COL
END FUNCTION
' }

' { test collide between palyer spaceship And one meteor
FUNCTION CollideProjectil(numProj AS LONG) AS LONG
    DIM dist AS SINGLE, bt AS SINGLE, COL AS LONG
    DIM i AS LONG

    COL = -1
    FOR i = 0 TO 63
        IF meteorB(i).vcreated <> 0  THEN
            dist = proj(numProj).radius + meteorB(i).radius
            ' cal distance
            bt = (proj(numProj).posx - meteorB(i).posx)*(proj(numProj).posx - meteorB(i).posx) + (proj(numProj).posy - _
            meteorB(i).posy)*(proj(numProj).posy - meteorB(i).posy)
            bt = SQR(bt)
            IF bt<dist THEN
                COL = i
                FUNCTION = COL
                EXIT FUNCTION
            END IF
        END IF
    NEXT
    FUNCTION = -1
END FUNCTION
' }

'-----------------------------------------
' { Generate Explode
SUB GenerateExplode(COL AS LONG)
    DIM posx AS SINGLE, posy AS SINGLE
    DIM num_exp AS LONG
    num_exp =-1
    DIM i AS LONG

    score = score + 1
    longerval_score = longerval_score + 1
    IF (longerval_score=4) THEN
        longerval_score=0
        CreateMeteor(50.0, -1)
    END IF

    posx = meteorB(COL).posx
    posy = meteorB(COL).posy

    num_exp = -1
    FOR i = 0 TO %MAXEXPLODE-1
        IF exp0(i).sp = %Null  THEN
            num_exp = i
            EXIT FOR
        END IF
    NEXT
    IF num_exp<0 THEN EXIT SUB

    exp0(num_exp).sp = CreateSprite2D("media/Particle.png", 2.0,  &h0ffffffff, %NULL)
    MaterialTypeNode(exp0(num_exp).sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)

    ' Create explose sequance texture
    DIM texturelist AS NArray
    texturelist = CreateListTexture("media/explode.png", 64, 64)
    exp0(num_exp).anim = CreateTextureAnimator( texturelist,  130, %False)
    AddAnimatorTexture(exp0(num_exp).sp, exp0(num_exp).anim)

    PositionNode( exp0(num_exp).sp, posx, posy, 1)
    VisibleNode( exp0(num_exp).sp, %True)

END SUB
' }

' { Update Explode
SUB UpdateExplode()
    LOCAL i AS LONG
    FOR i = 0 TO %MAXEXPLODE-1
        IF(exp0(i).sp)  THEN
            IF ( AnimatorTextureIndex(exp0(i).anim) = AnimatorTextureSize(exp0(i).anim)-1 )  THEN
                FreeNode( exp0(i).sp )
                exp0(i).sp = %Null
                exp0(i).anim = %Null
            END IF
        END IF
    NEXT

END SUB
' }

'-----------------------------------------
' { Death Player
SUB DeathPlayer()
    DIM  pos_space(3) AS SINGLE

    NodePosition(play_.sp, pos_space(0))
    PositionNode(player_explode, pos_space(0), pos_space(1), 0.1)

END SUB
' }
  •  

Theo Gottwald

#55
I trtied to compile and run that game.
To get the needed DLL's i downloaded the PureBasic Package on that site.

It compiles fine with PB 10, but when i run that game-executable it crashes.

Brice Manuel

#56
Quote from: Theo Gottwald on October 04, 2011, 08:24:59 PM
I trtied to compile and run that game.
To get the needed DLL's i downloaded the PureBasic Package on that site.

It compiles fine with PB 10, but when i run that game-executable it crashes.
I haven't tried it, but from looking at the code, he is using DX9.  Do you have the DirectX 9 runtimes installed?  DX9 support does not ship with Vista/7 and must be downloaded and installed separately.

If you do not have DX9, in the last file Pete posted "Little2D game", you can change this line:

  app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

to

  app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_OPENGL, %TRUE)

and recompile it.  This will set it to use hardware OpenGL (which you should have as long as you have downloaded the graphics card drivers from your manufacturer's site).
  •  

Peter Weis

Hi Theo,

Of course you always have the latest current use include file and the example of mine that I've rewritten it should work for me it goes anyway
Today there is a new include

regards Peter
  •  

Peter Weis

Hello Manuel,
I have no problem with Windows 7 Who is this a problem with Vista, then it must also be so with PureBasic! Definitely has nothing to do with the PowerBASIC

regards Peter
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  045  :  Little2D game version 3D
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

DECLARE SUB Init()
DECLARE SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DECLARE SUB CreateProjectil()
DECLARE SUB UpdatePlayer()
DECLARE SUB UpdateMeteor()
DECLARE SUB UpdateExplode()
DECLARE SUB UpdateProjectil()
DECLARE SUB DeathPlayer()
DECLARE SUB RenderAllSprite2D()
DECLARE SUB DeleteProjectil(num AS LONG)
DECLARE FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DECLARE SUB GenerateExplode(COL AS LONG)
DECLARE SUB DeleteMeteor(num AS LONG)
DECLARE FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG
DECLARE SUB Set2DCamera(wwidth AS SINGLE, height AS SINGLE)
DECLARE SUB Set3DCamera()
DECLARE SUB Visible3D( flag AS BYTE)
DECLARE SUB Visible2D( flag AS BYTE)

    '----------------------------------------------------------
    '     Structures definition
    '----------------------------------------------------------
    '{ Player definition
TYPE PLAYER
    sp AS SpriteSceneNode
    posx AS SINGLE
    posy AS SINGLE
    radius AS SINGLE
END TYPE
'--}

'{ Meteor definition
TYPE METEOR
    pbmesh AS EntityNode
    posx AS SINGLE
    posy AS SINGLE
    transx AS SINGLE
    transy AS SINGLE
    vcreated AS LONG
    radius AS SINGLE
END TYPE
'--}

'{ Projectil definition
TYPE BALL
    sprite AS SpriteSceneNode
    posx AS SINGLE
    posy AS SINGLE
    transx AS SINGLE
    transy AS SINGLE
    created AS LONG
    radius AS SINGLE
END TYPE
'--}

'{ Explode definition
TYPE EXPLO
    sp AS SpriteSceneNode
    anim AS NNodeAnimator
    posx AS SINGLE
    posy AS SINGLE
END TYPE

%MAXEXPLODE  = 8

FUNCTION PBMAIN
    ' dimes
    DIM app AS DWORD
    DIM Quit AS LONG

    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


'--}


    DIM PBPLAY AS GLOBAL PLAYER
    DIM EndPlayer AS GLOBAL LONG
    DIM PBSPEED AS GLOBAL SINGLE : PBSPEED =10.0
    DIM proj(17) AS GLOBAL BALL
    DIM num_proj AS GLOBAL SINGLE
    DIM meteorB(64) AS GLOBAL METEOR
    DIM exp0(%MAXEXPLODE) AS GLOBAL EXPLO
    DIM proj_matrix(17) AS GLOBAL SINGLE
    DIM score AS GLOBAL LONG
    DIM integererval_score AS GLOBAL LONG
    LOCAL i AS LONG

    '----------------------------------------------------------
    '----------------------------------------------------------
    ' init all values And structures
    Init()





    '-----------------------------------------
    '-----------------------------------------
    ' Create ball sprite
    DIM ballmesh AS GLOBAL Mesh
    ballmesh = CreateSpriteMesh( 12.0, &h0ffffffff)


    '-----------------------------------------
    ' Create sphere meteor mesh
    DIM spheremesh AS GLOBAL Mesh
    spheremesh = CreateSphereMesh(1.0, 6)

    '-----------------------------------------
    '-----------------------------------------
    ' Create PLAYER
    DIM playmesh AS GLOBAL Mesh
    playmesh = CreateSpriteMesh( 50.0, &h0ffffffff)
    pbplay.sp = CreateSprite3D(playmesh, "media/space1.png", %NULL)
    MaterialTypeNode(pbplay.sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
    PositionNode(pbplay.sp, 0,0,1)
    pbplay.radius = 40.0


    '-----------------------------------------
    '-----------------------------------------
    ' Create EXPLODE PLAYER
    DIM playerexplodemesh AS GLOBAL Mesh
    playerexplodemesh = CreateSpriteMesh(160, &h00ffffff)
    DIM player_explode AS GLOBAL SpriteSceneNode
    player_explode = CreateSprite3D(playerexplodemesh, "media/Particle.png", %NULL)
    ' adapt material blend value

    DIM material AS NMaterial
    material = NodeMaterial(player_explode, 0)

    TypeMaterial(material,  %EMT_ONETEXTURE_BLEND )
    TypeBlendMaterial(material, %EBF_ONE, %EBF_ONE_MINUS_SRC_COLOR,  %EMFN_MODULATE_1X,  %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
    ' Create explose sequance texture

    DIM texturelist AS NArray
    texturelist = CreateListTexture("media/explo2.bmp",64,64)

    DIM anim AS NNodeAnimator
    anim = CreateTextureAnimator( texturelist,  130, %TRUE)

    AddAnimatorTexture(player_explode, anim)
    VisibleNode(player_explode, %False) ' no render



    '-----------------------------------------
    '-----------------------------------------
    ' Create thie first meteors
    FOR i = 0 TO 7
        CreateMeteor(50.0, -1)
    NEXT



    '-----------------------------------------
    '-----------------------------------------
    ' Create first  camera
    DIM cam AS GLOBAL CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam,0,0,-50)



    '-----------------------------------------
    '-----------------------------------
    ' Load background textures
    DIM texture AS NTexture
    texture = LoadTexture("media/metal13.jpg")


    '-----------------------------------------
    ' Load fonts
    _LoadFont("media/courriernew.png")
    DIM FONT_ AS IGUIFont
    font_ = GetFont()

    LoadFont("media/font0.xml", %FONT_TYPE.EGDF_DEFAULT)

    DIM font2 AS IGUIFont
    font2 = GetFont()


    '----------------------------------------
    ' Create EARTH
    '----------------------------------------
    DIM obj1 AS Mesh
    obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)

    DIM obj0 AS Mesh
    obj0 = CreateMeshWithTangents(obj1, %False, %False, %False, %True)

    FreeLoadedMesh(obj1)

    ' set the alpha value of all vertices To 200
    VertexColorAlphaMesh(obj0,  190)
    ' scale And position mesh
    ScaleMesh(obj0, 16,16,16)

    DIM sphere AS GLOBAL EntityNode
    sphere = CreateEntityNode(obj0, 0, 0, 0, %NULL)

    ' Create New sphere with tangent composants
    PositionNode(sphere, -70,130,45)
    ' Load heightmap, Create normal map from it And set it
    DIM earthNormalMap AS NTexture
    earthNormalMap = LoadTexture( "media/earthbump.bmp")
    ' Creates a normal map from a height map texture.
    NormalMapTexture(earthNormalMap, 9.0)
    MaterialTextureNode(sphere, earthNormalMap , 1)
    ' adjust material settings
    MaterialTypeNode(sphere,  %EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA )
    PositionNode(sphere, 0,0,5)
    '-----------------------------------------


    '----------------------------------------
    ' Create light And set position
    DIM light AS GLOBAL LightNode
    light = CreateLight(&hffffffff, 150, %ELT_POINT , %NULL)
    PositionNode(light, 10, 20,-2)
    '----------------------------------------


    ' save 3D data
    Set2DCamera(800,600)
    '-----------------------------------------
    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    '-----------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        TurnNode(sphere,0,0.2,0, 0)

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
            TurnNode(pbplay.sp, 0, 0, 3, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
            TurnNode(pbplay.sp, 0, 0, -3, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
            MoveNode(pbplay.sp, 0, -3, 0, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
            MoveNode(pbplay.sp, 0, 3, 0, 0)
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
            CreateProjectil()
        END IF


        IF EndPlayer=0 THEN
            UpdatePlayer()
            UpdateProjectil()
            UpdateMeteor()
            UpdateExplode()
        ELSE
            DeathPlayer()
        END IF

        ' ---------------
        '      Render
        ' ---------------
        BeginScene(20,20,20, 255, 1, 1)

        VisibleNode(player_explode, %False)

        Visible3D( %True)
        Visible2D( %False)
        Set3DCamera()
        IF EndPlayer<>0 THEN VisibleNode(player_explode, %False)
        DrawRectImage2D(texture , 0,  0, 0, 0, 800, 600, &h0ff555555, BYVAL %NULL, %FALSE)
        DrawScene()


        Visible2D( %True)
        Visible3D( %False)
        Set2DCamera(800,600)
        IF  EndPlayer<>0 THEN VisibleNode(player_explode, %True)
        DrawScene()
        DrawText(font_, "score: "+ TRIM$(STR$(score)),  10,10,0,0, &h0ffffffff)
        DrawText(font_, "Use 'dir' and 'space' key",  450,8,0,0, &h0ff00ffff)
        IF EndPlayer<>0 THEN
            DrawText(font2, "END",  360,250,0,0, &h0ffffff00)
            DrawText(font2, "score: "+ TRIM$(STR$(score)),  350,310,0,0, &h0ffff00ff)
        END IF


        EndScene()
        ' ---------------
        '  End Render
        ' ---------------
    WEND
    ' end
    FreeEngine()
END FUNCTION

'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
' { initialise structures
SUB Init()
    DIM i AS LONG
    ' init projectil tab
    FOR i = 0 TO 16
        proj(i).sprite = %NULL
        proj(i).created = 0
    NEXT
    FOR i = 0 TO %MAXEXPLODE-1
        exp0(i).sp = %NULL
        exp0(i).anim = %NULL
    NEXT
END SUB

' }

'-----------------------------------------

' { set camera in 2D mode
SUB Set2DCamera(wwidth AS SINGLE, height AS SINGLE)
    DIM PBMAT(17) AS SINGLE
    CameraProjectionMatrix(cam, proj_matrix(0))
    ProjectionMatrixOrthoLH( wwidth, height, pbMAT(0), 0.1, 100.0)
    ProjectionMatrixCamera(cam,  PBMAT(0),  %FALSE)
END SUB
' }
' { set camera in 2D mode
SUB Set3DCamera()
    ProjectionMatrixCamera(cam,  proj_matrix(0), %False)
END SUB
' }

'-----------------------------------------

' { update player
SUB UpdatePlayer()
    DIM  pos_space(3) AS SINGLE

    NodePosition(pbplay.sp, pos_space(0))
    pbplay.posx =  pos_space(0)
    pbplay.posy =  pos_space(1)

    IF ( pbplay.posx>450 ) THEN  pbplay.posx = -450 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
    IF ( pbplay.posx<-450 )THEN   pbplay.posx = 450  : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
    IF ( pbplay.posy>350 ) THEN  pbplay.posy = -350 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
    IF ( pbplay.posy<-350 ) THEN  pbplay.posy = 350 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)

END SUB
' }

'-----------------------------------------

' { update all projectils
SUB UpdateProjectil()
    DIM COL AS LONG, rd AS SINGLE, i AS LONG

    FOR i = 0 TO 16
        IF proj(i).created <> 0  THEN
            proj(i).posx = proj(i).posx + proj(i).transx
            proj(i).posy = proj(i).posy + proj(i).transy
            PositionNode( proj(i).sprite, proj(i).posx, proj(i).posy, 1)
            IF ( proj(i).posx>400 OR  proj(i).posx<-400 ) THEN    DeleteProjectil(i)
            IF ( proj(i).posy>300 OR  proj(i).posy<-300 ) THEN    DeleteProjectil(i)
            COL = CollideProjectil(i)
            IF COL<>-1  THEN
                rd = meteorB(COL).radius
                DeleteProjectil(i)
                IF rd>13  THEN
                    rd = rd / 2.0
                    CreateMeteor(rd, COL)
                    CreateMeteor(rd, COL)
                ELSE
                    ' explosion
                    GenerateExplode(COL)
                END IF
                DeleteMeteor(COL)
            END IF
        END IF
    NEXT
END SUB
' }

' { Create projectils (16 maxi)
SUB CreateProjectil()
    DIM pos_space(3) AS SINGLE
    DIM rot_space(3) AS SINGLE
    DIM i AS LONG

    num_proj = -1
    FOR i = 0 TO 15
        IF proj(i).created = 0 THEN
            num_proj = i
            EXIT FOR
        END IF
    NEXT
    IF num_proj<0 THEN EXIT SUB

    proj(num_proj).sprite = CreateSprite3D(ballmesh, "media/Particle.png", %NULL)
    MaterialTypeNode(proj(num_proj).sprite, %EMT_TRANSPARENT_ALPHA_CHANNEL)

    NodePosition(pbplay.sp, pos_space(0))
    NodeRotation(pbplay.sp, rot_space(0))

    pos_space(0) = pos_space(0) + SIN( -rot_space(2)*0.01745329 ) * 55.0
    pos_space(1) = pos_space(1) + COS( -rot_space(2)*0.01745329 ) * 55.0

    PositionNode(proj(num_proj).sprite, pos_space(0), pos_space(1), pos_space(2))
    proj(num_proj).posx = pos_space(0)
    proj(num_proj).posy = pos_space(1)
    proj(num_proj).transx = SIN( -rot_space(2)*0.01745329) * pbSPEED
    proj(num_proj).transy = COS( -rot_space(2)*0.01745329) * pbSPEED
    proj(num_proj).created = 1
    proj(num_proj).radius = 10.0
END SUB
' }

' { destruct projectil
SUB DeleteProjectil(num AS LONG)
    IF (proj(num).sprite) THEN
        FreeNode(proj(num).sprite)
        proj(num).sprite = %NULL
        proj(num).created = 0
    END IF
END SUB
' }

'-----------------------------------------

' { Create Meteor
SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
    DIM pos_space(3) AS SINGLE
    DIM rot_space(3) AS SINGLE
    DIM i AS LONG
    DIM num_meteor AS LONG, posx AS SINGLE, posy AS SINGLE

    num_meteor = -1
    FOR i = 0 TO 63
        IF meteorB(i).vcreated = 0 THEN
            num_meteor = i
            EXIT FOR
        END IF
    NEXT

    IF num_meteor<0 THEN EXIT SUB

    meteorB(num_meteor).pbmesh = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    ScaleNode(meteorB(num_meteor).pbmesh, rad,rad,rad)
    LoadTextureNode( meteorB(num_meteor).pbmesh, "media/wall.jpg", 0, 0)
    MaterialFlagNode(meteorB(num_meteor).pbmesh,  %EMF_LIGHTING, %False )


    IF numcol<0  THEN
        DO
            posx = RND()*800.0
        LOOP UNTIL (posx<250.0 OR posx>550.0)
        posx = posx -400.0

        DO
            posy = RND()*600.0
        LOOP UNTIL (posy<200.0 OR posy>400.0)
        posy = posy -300.0
    ELSE
        posx = meteorB(numcol).posx
        posy = meteorB(numcol).posy
    END IF
    PositionNode(meteorB(num_meteor).pbmesh, posx, posy, 1 )
    meteorB(num_meteor).posx = posx
    meteorB(num_meteor).posy = posy

    meteorB(num_meteor).transx = -1.5+RND()*3.0
    meteorB(num_meteor).transy = -1.5+RND()*3.0
    meteorB(num_meteor).vcreated = 1
    meteorB(num_meteor).radius = rad

END SUB
' }

' { update all meteor
SUB UpdateMeteor()
    DIM i AS LONG
    FOR i = 0 TO 63
        IF meteorB(i).vcreated<> 0  THEN
            meteorB(i).posx = meteorB(i).posx + meteorB(i).transx
            meteorB(i).posy = meteorB(i).posy + meteorB(i).transy
            PositionNode( meteorB(i).pbmesh, meteorB(i).posx, meteorB(i).posy, 1)

            IF ( meteorB(i).posx>450 ) THEN meteorB(i).posx = -450
            IF ( meteorB(i).posx<-450 )THEN meteorB(i).posx = 450
            IF ( meteorB(i).posy>350 ) THEN meteorB(i).posy = -350
            IF ( meteorB(i).posy<-350 )THEN meteorB(i).posy = 350

            TurnNode(meteorB(i).pbmesh, 0,0,0.5, 0)

            IF CollideMeteor(i)<>0  THEN
                EndPlayer = 11
            END IF
        END IF
    NEXT
END SUB
' }

' { destruct meteor
SUB DeleteMeteor(num AS LONG)
    FreeNode(meteorB(num).pbmesh)
    meteorB(num).pbmesh = %NULL
    meteorB(num).vcreated = 0
END SUB
' }

'-----------------------------------------

' { test collide between palyer spaceship And one meteor
FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG
    DIM dist AS SINGLE, bt AS SINGLE, COL AS SINGLE

    dist = pbplay.radius + meteorB(numMeteor).radius
    ' cal distance
    bt =  (pbplay.posx - meteorB(numMeteor).posx)*(pbplay.posx - meteorB(numMeteor).posx) + (pbplay.posy - meteorB(numMeteor).posy)* _
        (pbplay.posy - meteorB(numMeteor).posy)

    bt = SQR(bt)
    COL = 0
    IF bt<dist THEN  COL = 1
    FUNCTION = COL
END FUNCTION

' }

' { test collide between palyer spaceship And one meteor
FUNCTION CollideProjectil(numProj AS LONG) AS LONG
    DIM dist AS SINGLE, bt AS SINGLE, COL AS LONG
    DIM i AS LONG

    COL = -1
    FOR i = 0 TO 63
        IF meteorB(i).vcreated <> 0  THEN
            dist = proj(numProj).radius + meteorB(i).radius
            ' cal distance
            bt = (proj(numProj).posx - meteorB(i).posx)*(proj(numProj).posx - meteorB(i).posx) + (proj(numProj).posy - meteorB(i).posy)* _
                (proj(numProj).posy - meteorB(i).posy)

            bt = SQR(bt)
            IF bt<dist THEN
                COL = i
                FUNCTION = COL
                EXIT FUNCTION
            END IF
        END IF
    NEXT
    FUNCTION = -1
END FUNCTION
' }

'-----------------------------------------

' { Generate Explode
SUB GenerateExplode(COL AS LONG)
    DIM posx AS SINGLE, posy AS SINGLE
    DIM num_exp AS LONG
    num_exp = -1
    LOCAL i AS LONG

    score = score + 1
    integererval_score = integererval_score + 1
    IF (integererval_score=4) THEN
        integererval_score=0
        CreateMeteor(50.0, -1)
    END IF

    posx = meteorB(COL).posx
    posy = meteorB(COL).posy

    num_exp = -1
    FOR i = 0 TO %MAXEXPLODE-1
        IF exp0(i).sp = %NULL  THEN
            num_exp = i
            EXIT FOR
        END IF
    NEXT
    IF num_exp<0 THEN EXIT SUB

    DIM spmesh AS Mesh
    spmesh = CreateSpriteMesh( 50.0, &h0ffffffff)
    Exp0(num_exp).sp = CreateSprite3D(spmesh, "media/Particle.png", %NULL)
    MaterialTypeNode(Exp0(num_exp).sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)

    ' Create explose sequance texture
    DIM texturelist AS NArray
    texturelist = CreateListTexture("media/explode.png", 64, 64)
    exp0(num_exp).anim = CreateTextureAnimator( texturelist,  130, %False)
    AddAnimatorTexture(exp0(num_exp).sp, exp0(num_exp).anim)

    PositionNode( exp0(num_exp).sp, posx, posy, 1)
    VisibleNode( exp0(num_exp).sp, %TRUE )

END SUB
' }

' { Update Explode
SUB UpdateExplode()
    DIM i AS LONG
    FOR i = 0 TO %MAXEXPLODE-1
        IF(exp0(i).sp)  THEN
            IF ( AnimatorTextureIndex(exp0(i).anim) = AnimatorTextureSize(exp0(i).anim)-1 )  THEN
                FreeNode( exp0(i).sp )
                exp0(i).sp = %NULL
                exp0(i).anim = %NULL
            END IF
        END IF
    NEXT

END SUB
' }

'-----------------------------------------
' { Death Player
SUB DeathPlayer()
    DIM  pos_space(3) AS SINGLE

    NodePosition(pbplay.sp, pos_space(0))
    PositionNode(player_explode, pos_space(0), pos_space(1), 0.1)

END SUB
' }

'-----------------------------------------
' { turn OFF  Or ON 3D elements
SUB Visible3D( flag AS BYTE)
    VisibleNode(light,  flag)
    VisibleNode(sphere, flag)
END SUB
' }

' { turn OFF  Or ON 2D elements
SUB Visible2D( flag AS BYTE)
    DIM i AS LONG
    VisibleNode(pbplay.sp,  flag)
    FOR i = 0 TO 16
        IF ( proj(i).sprite ) THEN  VisibleNode(proj(i).sprite, flag)
    NEXT
    FOR i = 0 TO 63
        IF ( meteorB(i).pbmesh ) THEN VisibleNode(meteorB(i).pbmesh, flag)
    NEXT
    FOR i = 0 TO %MAXEXPLODE-1
        IF ( Exp0(i).sp ) THEN VisibleNode(Exp0(i).sp, flag)
    NEXT
END SUB
  •