示例#1
0
 void ClearAll()
 {
     foreach (GameObject TLight in TLights)
     {
         TLight.SetActive(false);
     }
 }
示例#2
0
 public void TrafficManager()
 {
     foreach (GameObject TLight in TLights)
     {
         if (TLight.activeSelf)
         {
             TLight.GetComponent <TraficLight>().Invoker();
         }
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            try
            {
                // Initialize
                LE.Initialize();
                LE.SetAppTitle(AppTitle);
                LE.RegisterAbstractPath(MediaDir);

                // Set graphics mode
                if (LE.Graphics(ScreenWidth, ScreenHeight) == 0)
                {
                    ErrOut("Failed to set graphics mode.");
                    return;
                }

                // Create framework object and set it to a global object so other scripts can access it
                TFramework fw = LE.CreateFramework();
                if (!fw.IsValid)
                {
                    ErrOut("Failed to initialize engine.");
                    return;
                }

                // Set Lua framework object
                LE.SetGlobalObject("fw", fw.Handle);

                // Set Lua framework variable
                IntPtr lua = LE.GetLuaState();
                LE.lua_pushobject(lua, fw.Handle);
                LE.lua_setglobal(lua, "fw");
                LE.lua_pop(lua, 1);

                // Get framework main camera
                TCamera camera = LE.GetLayerCamera(LE.GetFrameworkLayer(0));
                LE.PositionEntity(camera, new TVec3(7, 6, -6));
                LE.RotateEntity(camera, new TVec3(20, 0, 0));
                LE.CameraRange(camera, 1, 10000);

                // Add some light
                TLight light = LE.CreateDirectionalLight();
                LE.RotateEntity(light, new TVec3(45, 90, 0));

                //Create a plane
                TMesh plane = LE.CreatePlane();
                LE.PositionEntity(plane, new TVec3(0, 0, 0));
                LE.ScaleEntity(plane, new TVec3(1000, 0, 1000));

                //mouse variables
                float mx          = 0;
                float my          = 0;
                TVec3 camRotation = new TVec3(0);
                LE.HideMouse();

                // Spin cube until user hits Escape
                while (!LE.KeyHit() && !LE.AppTerminate())
                {
                    if (!LE.AppSuspended())
                    {
                        #region camera and movement
                        //cam keyboard movement
                        float sideways = LE.KeyDown(Keys.KEY_D) - LE.KeyDown(Keys.KEY_A);
                        float forward  = LE.KeyDown(Keys.KEY_W) - LE.KeyDown(Keys.KEY_S);
                        LE.MoveEntity(camera, new TVec3(sideways * LE.AppSpeed(), 0, forward * LE.AppSpeed()), 0);

                        //cam mouse movement
                        mx = LE.MouseX() - LE.GraphicsWidth() / 2;
                        my = LE.MouseY() - LE.GraphicsHeight() / 2;
                        LE.MoveMouse((int)(LE.GraphicsWidth() / 2), (int)(LE.GraphicsHeight() / 2));

                        //rotate the camera
                        camRotation = new TVec3(camRotation.X + (my / 10), camRotation.Y - (mx / 10), 0);
                        LE.RotateEntity(camera, camRotation);
                        #endregion

                        LE.UpdateFramework();
                        LE.RenderFramework();

                        //Drawing a cursos
                        LE.DrawRect(LE.GraphicsWidth() / 2 - 2, LE.GraphicsHeight() / 2 - 2, 4, 4);
                        LE.Flip(0);
                    }
                }
            }

            //  Catch Exceptions
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //  Terminate
            finally
            {
                LE.Terminate();
            }
        }
示例#4
0
    public void GenerateMesh()
    {
        for (int x = 0; x < chunkSize; x++)
        {
            for (int y = 0; y < chunkSize; y++)
            {
                for (int z = 0; z < chunkSize; z++)
                {
                    //This code will run for every block in the chunk

                    if (Block(x, y, z) != 0)
                    {
                        //If the block is solid
                        if (Block(x, y + 1, z) == 0)
                        {
                            //Block above is air
                            CubeTop(x, y, z, Block(x, y, z));
                        }

                        if (Block(x, y - 1, z) == 0)
                        {
                            //Block below is air
                            CubeBottom(x, y, z, Block(x, y, z));
                        }

                        if (Block(x + 1, y, z) == 0)
                        {
                            //Block east is air
                            CubeEast(x, y, z, Block(x, y, z));
                        }

                        if (Block(x - 1, y, z) == 0)
                        {
                            //Block west is air
                            CubeWest(x, y, z, Block(x, y, z));
                        }

                        if (Block(x, y, z + 1) == 0)
                        {
                            //Block north is air
                            CubeNorth(x, y, z, Block(x, y, z));
                        }

                        if (Block(x, y, z - 1) == 0)
                        {
                            //Block south is air
                            CubeSouth(x, y, z, Block(x, y, z));
                        }
                    }

                    if (Block(x, y, z) == 9)
                    {
                        if (lights[x, y, z] == null)
                        {
                            GameObject lightGO = Instantiate(lightPrefab, transform.position, transform.rotation);
                            lightGO.transform.parent = transform;

                            lights[x, y, z]            = lightGO;
                            lightGO.transform.position = new Vector3(lightGO.transform.position.x + x, lightGO.transform.position.y + y, lightGO.transform.position.z + z);
                        }

                        TLight light = lights[x, y, z].GetComponent <TLight>();

                        if (Block(x, y + 1, z) == 0)
                        {
                            //Block above is air
                            light.SetFace(TLight.Face.Top, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.Top, false);
                        }

                        if (Block(x, y - 1, z) == 0)
                        {
                            //Block below is air
                            light.SetFace(TLight.Face.Bottom, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.Bottom, false);
                        }

                        if (Block(x + 1, y, z) == 0)
                        {
                            //Block east is air
                            light.SetFace(TLight.Face.East, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.East, false);
                        }

                        if (Block(x - 1, y, z) == 0)
                        {
                            //Block west is air
                            light.SetFace(TLight.Face.West, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.West, false);
                        }

                        if (Block(x, y, z + 1) == 0)
                        {
                            //Block north is air
                            light.SetFace(TLight.Face.North, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.North, false);
                        }

                        if (Block(x, y, z - 1) == 0)
                        {
                            //Block south is air
                            light.SetFace(TLight.Face.South, true);
                        }
                        else
                        {
                            light.SetFace(TLight.Face.South, false);
                        }
                    }
                    else
                    {
                        Destroy(lights[x, y, z]);
                        lights[x, y, z] = null;
                    }
                }
            }
        }

        UpdateMesh();
    }
示例#5
0
        static void Main(string[] args)
        {
            try
            {
                // Initialize
                LE.Initialize();
                LE.SetAppTitle(AppTitle);
                LE.RegisterAbstractPath(MediaDir);

                // Set graphics mode
                if (LE.Graphics(ScreenWidth, ScreenHeight) == 0)
                {
                    ErrOut("Failed to set graphics mode.");
                    return;
                }

                // Create framework object and set it to a global object so other scripts can access it
                TFramework fw = LE.CreateFramework();
                if (!fw.IsValid)
                {
                    ErrOut("Failed to initialize engine.");
                    return;
                }

                // Set Lua framework object
                LE.SetGlobalObject("fw", fw.Handle);

                // Set Lua framework variable
                IntPtr lua = LE.GetLuaState();
                LE.lua_pushobject(lua, fw.Handle);
                LE.lua_setglobal(lua, "fw");
                LE.lua_pop(lua, 1);

                // Get framework main camera
                TCamera camera = LE.GetLayerCamera(LE.GetFrameworkLayer(0));
                LE.PositionEntity(camera, new TVec3(7, 6, -6));
                LE.RotateEntity(camera, new TVec3(20, 0, 0));
                LE.CameraRange(camera, 1, 10000);

                // Add some light
                TLight light = LE.CreateDirectionalLight();
                LE.RotateEntity(light, new TVec3(45, 90, 0));

                //Create a plane
                TMesh plane = LE.CreatePlane();
                LE.PositionEntity(plane, new TVec3(0, 0, 0));
                LE.ScaleEntity(plane, new TVec3(1000, 0, 1000));

                //mouse variables
                float mx          = 0;
                float my          = 0;
                TVec3 camRotation = new TVec3(0);
                LE.HideMouse();

                //Making our grid
                Tile[,] grid = new Tile[AStartTest.gridWidth, AStartTest.gridHeight];
                TMesh cube = LE.CreateCube();
                TMesh ball = LE.CreateSphere(8);
                LE.HideEntity(cube);
                LE.HideEntity(ball);
                Random rand = new Random(62346);

                for (int i = 0; i < AStartTest.gridWidth; i++)
                {
                    for (int j = 0; j < AStartTest.gridHeight; j++)
                    {
                        //To walk or not to walk
                        if (rand.Next(0, 100) < 25)
                        {
                            //make a new tile
                            grid[i, j] = new Tile(new TVec2(i, j), new TVec3(0.8f), new TVec3(i * 1.3f, 0, j * 1.3f), cube, ball, false);
                        }
                        else
                        {
                            //make a new tile
                            grid[i, j] = new Tile(new TVec2(i, j), new TVec3(0.8f), new TVec3(i * 1.3f, 0, j * 1.3f), cube, ball, true);
                        }
                    }
                }

                //make a new Pathfinder
                Pathfinder path1 = new Pathfinder(grid);
                path1.SearchPath(new TVec2(0, 0), new TVec2(99, 98));

                Pathfinder path2 = new Pathfinder(grid);
                path2.SearchPath(new TVec2(0, 80), new TVec2(60, 12));

                // Spin cube until user hits Escape
                while (!LE.KeyHit() && !LE.AppTerminate())
                {
                    if (!LE.AppSuspended())
                    {
                        #region camera and movement
                        //cam keyboard movement
                        float sideways = LE.KeyDown(Keys.KEY_D) - LE.KeyDown(Keys.KEY_A);
                        float forward  = LE.KeyDown(Keys.KEY_W) - LE.KeyDown(Keys.KEY_S);
                        LE.MoveEntity(camera, new TVec3(sideways * LE.AppSpeed(), 0, forward * LE.AppSpeed()), 0);

                        //cam mouse movement
                        mx = LE.MouseX() - LE.GraphicsWidth() / 2;
                        my = LE.MouseY() - LE.GraphicsHeight() / 2;
                        LE.MoveMouse((int)(LE.GraphicsWidth() / 2), (int)(LE.GraphicsHeight() / 2));

                        //rotate the camera
                        camRotation = new TVec3(camRotation.X + (my / 10), camRotation.Y - (mx / 10), 0);
                        LE.RotateEntity(camera, camRotation);
                        #endregion

                        LE.UpdateFramework();
                        LE.RenderFramework();

                        //Drawing a cursos
                        LE.DrawRect(LE.GraphicsWidth() / 2 - 2, LE.GraphicsHeight() / 2 - 2, 4, 4);
                        LE.Flip(0);
                    }
                }
            }

            //  Catch Exceptions
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //  Terminate
            finally
            {
                LE.Terminate();
            }
        }