// Update is called once per frame
    void Update()
    {
        float deltaTime = Time.deltaTime;

        if (deltaTime > 0.050f)
        {
            deltaTime = 0.050f;
        }
        //Debug.Log(deltaTime);
        game.Tick(deltaTime);
        drawQueue.Clear();

        timeleft -= Time.deltaTime;
        accum    += Time.timeScale / Time.deltaTime;
        ++frames;

        // Interval ended - update GUI text and start new interval
        if (timeleft <= 0.0)
        {
            // display two fractional digits (f2 format)
            fps = accum / frames;

            //  DebugConsole.Log(format,level);
            timeleft = updateInterval;
            accum    = 0.0F;
            frames   = 0;
        }
    }
Пример #2
0
        public void VerifyThatListOfItemsIsSuitablyAdjustedWhenGameObjectMovesFromAnAdditionalOccupiedSpaceToAnotherOccupiedSpace()
        {
            var instructions = new[]
                {
                new PlayerController.TimedInstruction(TimeSpan.Zero, new PlayerController.Instruction(Direction.Right, FiringState.None, FiringState.None)),
                new PlayerController.TimedInstruction(TimeSpan.FromMilliseconds(100), new PlayerController.Instruction(Direction.Right, FiringState.None, FiringState.None))
                };

            var pc = new PlayerController(instructions);
            var wl = new WorldLoaderForTest();
            var g = new Game1(pc, wl);
            g.Components.Add(new SuppressDrawComponent(g));
            g.LoadLevel("pg");
            var w = g.World;
            w.AddGrave(new TilePos(0, 0));

            while (!pc.HasFinishedQueue || w.IsAnythingMoving())
                {
                g.Tick();
                }

            var list = w.GameObjects.GetItemsOnTile(new TilePos(0, 0)).ToList();
            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Grave);

            list = w.GameObjects.GetItemsOnTile(new TilePos(1, 0)).ToList();
            Assert.NotNull(list);
            Assert.AreEqual(2, list.Count);
            Assert.IsTrue(list[0] is Grave);
            Assert.IsTrue(list[1] is Player);
        }
Пример #3
0
        public void TestPlayerShootsAdjacentBoulder()
        {
            var instructions = new[]
                {
                new PlayerController.TimedInstruction(TimeSpan.Zero, new PlayerController.Instruction(Direction.None, FiringState.Pulse, FiringState.None)),
                new PlayerController.TimedInstruction(TimeSpan.Zero, PlayerController.Instruction.DoNothingInstruction())
                };

            var pc = new PlayerController(instructions);
            var wl = new WorldLoaderForTest();
            var g = new Game1(pc, wl);
            g.Components.Add(new SuppressDrawComponent(g));
            g.LoadLevel("# bp ");
            var w = g.World;

            while (!pc.HasFinishedQueue || w.IsAnythingMoving())
                {
                g.Tick();
                }

            var list = w.GameObjects.GetItemsOnTile(new TilePos(1, 0)).ToList();
            Assert.IsNotEmpty(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Boulder);
        }
Пример #4
0
        public void TestPlayerCannotShootBoulder2()
        {
            var instructions = new[]
                {
                new PlayerController.TimedInstruction(TimeSpan.Zero, new PlayerController.Instruction(Direction.None, FiringState.Pulse, FiringState.None)),
                new PlayerController.TimedInstruction(TimeSpan.Zero, PlayerController.Instruction.DoNothingInstruction())
                };

            var pc = new PlayerController(instructions);
            var wl = new WorldLoaderForTest();
            var g = new Game1(pc, wl);
            g.Components.Add(new SuppressDrawComponent(g));
            g.LoadLevel("# bbp ");
            var w = g.World;

            while (!pc.HasFinishedQueue)
                {
                g.Tick();
                }

            Assert.IsFalse(w.GameObjects.DoesShotExist());
        }
Пример #5
0
        public void TestPlayerBouncesOneBoulderAndEndsUpPushingAnother()
        {
            var instructions = new[]
                {
                new PlayerController.TimedInstruction(TimeSpan.Zero, new PlayerController.Instruction(Direction.Left, FiringState.None, FiringState.None)),
                new PlayerController.TimedInstruction(TimeSpan.FromMilliseconds(200), PlayerController.Instruction.DoNothingInstruction())
                };

            var pc = new PlayerController(instructions);
            var wl = new WorldLoaderForTest();
            var g = new Game1(pc, wl);
            g.Components.Add(new SuppressDrawComponent(g));
            g.LoadLevel("#bpb #");
            var w = g.World;

            while (!pc.HasFinishedQueue || w.IsAnythingMoving())
                {
                g.Tick();
                }

            var list = w.GameObjects.GetItemsOnTile(new TilePos(1, 0)).ToList();
            Assert.NotNull(list);
            Assert.IsEmpty(list);

            list = w.GameObjects.GetItemsOnTile(new TilePos(2, 0)).ToList();
            Assert.NotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Boulder);

            list = w.GameObjects.GetItemsOnTile(new TilePos(3, 0)).ToList();
            Assert.NotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Player);

            list = w.GameObjects.GetItemsOnTile(new TilePos(4, 0)).ToList();
            Assert.NotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0] is Boulder);
        }
Пример #6
0
        public void VerifyThatTheListOfItemsMovesWhenGameObjectMovesToAnAdjacentEmptySpace()
        {
            var instructions = new[]
                {
                new PlayerController.TimedInstruction(TimeSpan.Zero, new PlayerController.Instruction(Direction.Right, FiringState.None, FiringState.None)),
                new PlayerController.TimedInstruction(TimeSpan.FromMilliseconds(100), new PlayerController.Instruction(Direction.Right, FiringState.None, FiringState.None))
                };

            var pc = new PlayerController(instructions);
            var wl = new WorldLoaderForTest();
            var g = new Game1(pc, wl);
            g.Components.Add(new SuppressDrawComponent(g));
            g.LoadLevel("p ");
            var w = g.World;

            while (!pc.HasFinishedQueue || w.IsAnythingMoving())
                {
                g.Tick();
                }

            Assert.IsEmpty(w.GameObjects.GetItemsOnTile(new TilePos(0, 0)));
            var list = w.GameObjects.GetItemsOnTile(new TilePos(1, 0)).ToList();
            Assert.IsNotEmpty(list);
            Assert.IsTrue(list.SequenceEqual(new List<StaticItem> {w.Player}));
        }