Пример #1
0
        public Tile(TVec2 ID, TVec3 scale, TVec3 position, TMesh cube, TMesh ball, bool walkable)
        {
            this.ID       = ID;
            this.cube     = LE.CopyEntity(cube);
            this.ball     = LE.CopyEntity(ball);
            this.walkable = walkable;
            LE.ShowEntity(this.cube);

            //set position and scale
            LE.ScaleEntity(this.cube, scale);
            LE.PositionEntity(this.cube, position);

            LE.ScaleEntity(this.ball, new TVec3(scale.X / 2, scale.Y / 2, scale.Z / 2));
            LE.PositionEntity(this.ball, new TVec3(position.X, position.Y + 1, position.Z));

            //Set a different Color when the tile is non walkable
            if (!this.walkable)
            {
                LE.EntityColor(this.cube, Tile.BLACK);
            }
            else
            {
                LE.EntityColor(this.cube, Tile.PINK);
                LE.EntityColor(this.ball, Tile.YELLOW);
            }
        }
Пример #2
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();
            }
        }
Пример #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();

                //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();
            }
        }