Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            screenController.Initialize();

            BaseClass[] baseClasses = Content.Load <BaseClass[]>("baseClasses");

            characters    = new HumanCharacter[3];
            characters[0] = new HumanCharacter("Harold", new Class(baseClasses[0]));
            characters[1] = new HumanCharacter("Mary", new Class(baseClasses[2]));
            characters[2] = new HumanCharacter("Chester", new Class(baseClasses[1]));

            BaseEquipment[] equipmentsData = Content.Load <BaseEquipment[]>("baseEquipments");
            Equipment[]     equipments     = new Equipment[equipmentsData.Length];
            for (int i = 0; i < equipmentsData.Length; i++)
            {
                equipments[i] = new Equipment(equipmentsData[i]);
            }

            foreach (var equipment in equipments)
            {
                var randomCharacter = characters[RandomController.Instance.Range(0, characters.Length)];
                if (randomCharacter.Inventory.HasSlot(equipment.SlotType))
                {
                    randomCharacter.Inventory.SetEquipmentAt(equipment.SlotType, equipment);
                }
            }

            base.Initialize();
        }
Пример #2
0
        public void Can_write_pixels()
        {
            var c   = ScreenController.Initialize(10, 20);
            var red = new Color(1, 0, 0);

            c.SetPixel(2, 3, red);
            Assert.Equal(red, c.GetPixel(2, 3));
        }
Пример #3
0
    public void ShowScreen(string _name, object _data = null)
    {
        //Проверка с текущим экраном
        if (screens.Count > 0 && screens[screens.Count - 1].ScreenName == _name)
        {
            Debug.LogWarning("[ScreenManager] Trying to re-open the screen: " + _name);
            SplashScreenManager.Instance.HideSplashScreenImmediately();
            return;
        }

        ScreenController screen = null;

        //Проверка со список открытых экранов
        foreach (var item in screens)
        {
            if (item.ScreenName == _name)
            {
                Debug.LogWarning("[ScreenManager] The screen \"" + _name + "\" is in the history of open screens.");

                screen = item;
                screen.gameObject.SetActive(true);

                //...
                //return;
            }
        }

        if (screen == null)
        {
            screen = Instantiate(Resources.Load <GameObject>(string.Format("{0}{1}", ConstantsUiPath.SCREEN, _name)), parentScreens).GetComponent <ScreenController>();
        }

        screen.transform.SetAsLastSibling();
        screen.Initialize(_data);
        screen.SetName(_name);

        //Деактивируем предыдущие экраны
        foreach (var item in screens)
        {
            var itemGO = item.gameObject;

            if (itemGO.activeSelf && item != screen)
            {
                itemGO.SetActive(false);
            }
        }

        screens.Add(screen);
        Debug.Log("<color=#FFD800>[ScreenManager] Screen loaded: " + _name + "</color>");
    }
Пример #4
0
        public void Can_create_a_canvas()
        {
            var c = ScreenController.Initialize(10, 20);

            Assert.Equal(10, c.Width);
            Assert.Equal(20, c.Height);

            for (var y = 0; y < c.Height; y++)
            {
                for (var x = 0; x < c.Width; x++)
                {
                    Assert.Equal(new Color(0, 0, 0), c.GetPixel(x, y));
                }
            }
        }
Пример #5
0
        public void Can_save_a_canvas()
        {
            var c = ScreenController.Initialize(256, 256);

            for (var y = 0; y < c.Height; y++)
            {
                for (var x = 0; x < c.Width; x++)
                {
                    var color = new Color((x ^ y) / 255.0f, (x & y) / 255.0f, (x | y) / 255.0f);
                    c.SetPixel(x, y, color);
                }
            }
            c.Refresh();
            c.Save("test.png");
            Assert.True(File.Exists("test.png"));
        }
Пример #6
0
        public static void Main(string[] args)
        {
            var canvas = ScreenController.Initialize(256, 256);

            var translate_scale = Matrix.Translation(128, 128, 0) * Matrix.Scaling(100, 100, 1);

            for (var hour = 1; hour <= 12; hour++)
            {
                var rotation = Matrix.RotationZ(hour * 2 * MathHelper.PI / 12.0f);
                var p        = translate_scale * rotation * Tuple.Point(0, -1, 0);
                canvas.SetPixel((int)p.X, (int)p.Y, new Color(1, 1, 1));
            }

            canvas.Refresh();
            canvas.Save("clock.png");
        }
Пример #7
0
        public static void Main(string[] args)
        {
            var canvas = ScreenController.Initialize(256, 256);

            var s = new Sphere();

            var ray_origin   = Tuple.Point(0, 0, -5);
            var wall_z       = 10f;
            var wall_size    = 7f;
            var pixel_width  = wall_size / canvas.Width;
            var pixel_height = wall_size / canvas.Height;
            var half         = wall_size / 2;

            for (var y = 0; y < canvas.Height; y++)
            {
                // Compute the world y-coordinate.
                // Y is intentionally inverted from what you may expect (top = +half, bottom = -half).
                var world_y = half - pixel_height * y;

                for (var x = 0; x < canvas.Width; x++)
                {
                    // Compute the world x-coordinate (left = -half, right = +half).
                    var world_x = pixel_width * x - half;

                    var position = Tuple.Point(world_x, world_y, wall_z);

                    var r  = new Ray(ray_origin, (position - ray_origin).Normalize());
                    var xs = s.Intersect(r);
                    if (xs != null)
                    {
                        var hit = new IntersectionList(xs).Hit();
                        if (hit.Object != null)
                        {
                            canvas.SetPixel(x, y, new Color(1, 0, 0));
                        }
                    }
                }
            }

            canvas.Refresh();
            canvas.Save("sphere.png");
        }
Пример #8
0
        private static void ProjectileLauncher()
        {
            var start    = Tuple.Point(0, 1, 0);
            var velocity = Tuple.Vector(1, 1.8f, 0).Normalize() * 11.25f;

            // Projectile starts 1 unit above the origin.
            // Velocity is normalized to 1 unit/tick.
            var p = (position : start, velocity : velocity);

            // Gravity -0.1 units/tick, and wind is -0.01 unit/tick.
            var gravity = Tuple.Vector(0, -0.1f, 0);
            var wind    = Tuple.Vector(-0.01f, 0, 0);
            var e       = (gravity : gravity, wind : wind);

            var c = ScreenController.Initialize(900, 550);

            var numTicks = 0;

            Console.WriteLine($"[{numTicks}]: {p.position}");
            if ((p.position.X >= 0) && (p.position.X < c.Width) && (p.position.Y >= 0) && (p.position.Y < c.Height))
            {
                c.SetPixel((int)p.position.X, c.Height - (int)p.position.Y, new Color(1, 0.5f, 0.5f));
            }
            while (p.position.Y >= 0)
            {
                p = Tick(e, p);
                if ((p.position.X >= 0) && (p.position.X < c.Width) && (p.position.Y >= 0) && (p.position.Y < c.Height))
                {
                    c.SetPixel((int)p.position.X, c.Height - (int)p.position.Y, new Color(1, 0.5f, 0.5f));
                }
                numTicks++;
                Console.WriteLine($"[{numTicks}]: {p.position}");
            }
            c.Refresh();
            c.Save("projectile.png");
        }