Exemplo n.º 1
0
 public virtual void Tick(TickContext context)
 {
     foreach (var child in Children)
     {
         child.Tick(context);
     }
 }
Exemplo n.º 2
0
        public void Tick(TickContext context)
        {
            _partTimer.Tick(context.DeltaTime);
            _shiftMovetimer.Tick(context.DeltaTime);
            if (_partTimer.Completed)
            {
                _partTimer.Restart();
                _shiftMovetimer.Restart();
                Generate();
            }
            else
            {
                //Console.WriteLine($"Next in {_partTimer.RemainingTime.TotalMilliseconds} ms");
            }

            var keys = Keyboard.GetState();

            if (_redrawCooldownTimer.Completed && keys.IsKeyDown(Keys.Q))
            {
                Shuffle();
            }
            else
            {
                _redrawCooldownTimer.Tick(context.DeltaTime);
            }
        }
 protected override void UpdatePosition(TickContext context)
 {
     this.Update(() =>
     {
         Transform.Location = _parent.GloalLocation;
     });
 }
Exemplo n.º 4
0
        public void Execute()
        {
            var gameTime    = GameTime;
            var tickContext = new TickContext
            {
                DeltaTime        = (uint)gameTime.ElapsedGameTime.Ticks,
                DeltaTimeSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds,
                TimeSeconds      = (float)gameTime.TotalGameTime.TotalSeconds,
                ServiceProvider  = null,
                TimeStamp        = (uint)gameTime.TotalGameTime.Ticks
            };

            foreach (var component in _entityManager.GetAll <IPreTick>())
            {
                component.PreTick(tickContext);
            }
            foreach (var component in _entityManager.GetAll <ITick>())
            {
                component.Tick(tickContext);
            }
            foreach (var component in _entityManager.GetAll <IPostTick>())
            {
                component.PostTick(tickContext);
            }
        }
Exemplo n.º 5
0
        private void CheckSpawn(TickContext context)
        {
            // Don't spawn when within 5 of target.
            var remaining = _distanceTarget?.Remaining;

            if (remaining.HasValue && (-remaining.Value) < 40)
            {
                return;
            }
            if (_running && _entities.Count() < 200)
            {
                // Locks spawn to once ever 3 units is moved.
                if (_lastZ > _flightShipTransform.Location.Z)
                {
                    _lastZ -= (int)Math.Ceiling((100 - _difficult) / 10.0);
                    for (var i = 0; i < _spawnPerWave; i++)
                    {
                        var ent = Entity.Create();
                        ent.Add(new Transform()
                        {
                            Location = _flightShipTransform.Location + Vector3.Forward * 40 + new Vector3((float)(Random.NextDouble() - 0.5f) * 50, 0f, (float)Random.NextDouble() * 20)
                        });
                        var asteroidComponent = Activator.CreateInstance(_distribution.Sample());
                        (asteroidComponent as IVelocity).Velocity = new Vector3((float)Random.NextDouble() - 0.5f, 0f, (float)(0.8f + Random.NextDouble())) * 0.3f;
                        ent.Add(asteroidComponent as IComponent);
                        _entities.Add(ent);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override void Tick(TickContext context)
        {
            _deathRunBehaviour.Tick(context);

            _pos += context.DeltaTimeSeconds * (float)(Math.PI / 10f);
            _positionChaserBehaviour.Target = _playerShip.Entity.Get <Transform>().Location + new Vector3(
                (float)Math.Cos(_pos) * _circleRadius,
                0f,
                (float)Math.Sin(_pos) * _circleRadius
                ) + _playerOffset;
            _positionChaserBehaviour.Tick(context);
            _takeAimBehaviour.Tick(context);

            _fireTimer.Tick(context.DeltaTime);
            if (_fireTimer.Completed)
            {
                WeaponCapability.StandardFire();
                _fireTimer.Restart();
            }
            _changeAimTimer.Tick(context.DeltaTime);
            if (_changeAimTimer.Completed)
            {
                _oscillateMode = !_oscillateMode;
                _changeAimTimer.Restart();
                _takeAimBehaviour.SetRandomAimOffset((float)Math.PI / 3);
            }
        }
Exemplo n.º 7
0
 public void Tick(TickContext context)
 {
     if (Remaining > 0)
     {
         _phase.Ended = true;
     }
 }
Exemplo n.º 8
0
 public void Tick(TickContext context)
 {
     if (Remaining <= _allowedRemaining)
     {
         _phase.Ended = true;
     }
 }
Exemplo n.º 9
0
        public void Tick(TickContext context)
        {
            if (!_playerShip.GetNodes().Any())
            {
                return;
            }
            var displacement = (_playerShip.GetNodes().First().GloalLocation - _transform.Location);
            var rotation     = -RotationHelper.GetAngle(displacement.X, displacement.Z) - (float)Math.PI / 2 + aimOffset;
            var rotVel       = 0f;

            if (_flightShip.Rotation > rotation + RotationRate)
            {
                rotVel -= 0.01f;
            }
            else if (_flightShip.Rotation < rotation - 0.01f)
            {
                rotVel = 0.01f;
            }
            _flightShip.Update(() =>
            {
                _flightShip.RotationalSpeed = rotVel;
                if (rotVel == 0)
                {
                    _flightShip.Rotation = rotation;
                }
            });
        }
Exemplo n.º 10
0
        public void Tick(TickContext context)
        {
            var mouse = Mouse.GetState();

            _lastState    = _currentState;
            _currentState = mouse;
        }
Exemplo n.º 11
0
        public void Tick(TickContext context)
        {
            var speed    = new Vector3(0, 0, 0);
            var keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.A))
            {
                speed += Vector3.Left;
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                speed += Vector3.Right;
            }

            speed = Vector3.Transform(speed, Camera.Position.Rotation);
            if (keyboard.IsKeyDown(Keys.W))
            {
                speed += Vector3.Forward;
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                speed += Vector3.Backward;
            }
            speed *= MoveSpeed;

            Transform.Update(() =>
            {
                Transform.Location += speed * context.DeltaTimeSeconds;
                Camera?.Recalculate();
            });
        }
Exemplo n.º 12
0
        public void Tick(TickContext context)
        {
            var keys  = Keyboard.GetState();
            var mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed || keys.IsKeyDown(Keys.Space))
            {
                WeaponCapability?.StandardFire();
            }
            if (mouse.RightButton == ButtonState.Pressed || keys.IsKeyDown(Keys.Enter))
            {
                WeaponCapability?.HeavyFire();
            }

            if (KeyControls.HasBeenPressed(Keys.D1))
            {
                WeaponCapability?.ShieldDeploy();
            }
            if (KeyControls.HasBeenPressed(Keys.D2))
            {
                WeaponCapability?.BombardFire();
            }
            if (KeyControls.HasBeenPressed(Keys.D6))
            {
                WeaponCapability?.RocketBlast();
            }
        }
Exemplo n.º 13
0
 public void Tick(TickContext context)
 {
     _lightweightCooldown.Tick(context.DeltaTime);
     _heavyweightCooldown.Tick(context.DeltaTime);
     _bubbleShieldCooldown.Tick(context.DeltaTime);
     _blastRocketCooldown.Tick(context.DeltaTime);
     _bombardCooldown.Tick(context.DeltaTime);
 }
Exemplo n.º 14
0
 public void Tick(TickContext context)
 {
     _fadeTimer.Tick(context.DeltaTime);
     if (_fading && _fadeTimer.Completed)
     {
         Entity.Delete();
     }
 }
Exemplo n.º 15
0
        public void Tick(TickContext context)
        {
            var keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.Escape))
            {
                System.Environment.Exit(0);
            }
        }
Exemplo n.º 16
0
 protected virtual void UpdatePosition(TickContext context)
 {
     //var spin = _spin * context.DeltaTimeSeconds;
     Transform.Update(() =>
     {
         //Transform.Rotation *= Quaternion.CreateFromYawPitchRoll(spin.X, spin.Y, spin.Z);
         Transform.Location += Velocity * context.DeltaTimeSeconds;
     });
 }
Exemplo n.º 17
0
        public override void Tick(TickContext context)
        {
            base.Tick(context);

            if (_dragAndDropCapatility.CurrentlyDragging != null)
            {
                Reevaluate();
            }
        }
Exemplo n.º 18
0
 public void Tick(TickContext context)
 {
     foreach (var element in _templates.Keys.ToArray())
     {
         element.Tick(
             context
             );
     }
 }
Exemplo n.º 19
0
        public void Tick(TickContext context)
        {
            var spin = _spin * context.DeltaTimeSeconds;

            Transform.Update(() =>
            {
                Transform.Rotation *= Quaternion.CreateFromYawPitchRoll(spin.X, spin.Y, spin.Z);
                Transform.Location += Velocity * context.DeltaTimeSeconds;
            });
        }
Exemplo n.º 20
0
 public override void Tick(TickContext context)
 {
     base.Tick(context);
     _refreshCount++;
     if (_refreshCount % 1000 == 0)
     {
         _modelViews.Clear();
     }
     Reevaluate();
 }
Exemplo n.º 21
0
        public void PostTick(TickContext context)
        {
            var keyboard = Keyboard.GetState();

            _lastState    = _currentState;
            _currentState = new Dictionary <Keys, bool>();
            foreach (Keys key in Enum.GetValues(typeof(Keys)))
            {
                _lastState[key] = keyboard.IsKeyDown(key);
            }
        }
Exemplo n.º 22
0
        public void Tick(TickContext context)
        {
            var state = Mouse.GetState();

            if (_previousState == null)
            {
                _previousState = state;
            }
            var position = state.Position;

            if (state.LeftButton == ButtonState.Pressed &&
                _previousState.LeftButton == ButtonState.Released)
            {
                foreach (var layer in UserInterfaceManager.TemplateLayers.ToArray())
                {
                    // new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height)
                    HitCheckRecurse(layer, layer.Position, position.ToVector2(), (pos) => new MouseDownEvent(pos));
                }
            }
            else if (state.LeftButton == ButtonState.Released &&
                     _previousState.LeftButton == ButtonState.Pressed)
            {
                foreach (var layer in UserInterfaceManager.TemplateLayers.ToArray())
                {
                    HitCheckRecurse(layer, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), position.ToVector2(), (pos) => new MouseUpEvent(pos));
                }
            }

            // Get all elements currently being hovered.
            var hoveringNow = new List <IElement>();

            foreach (var layer in UserInterfaceManager.TemplateLayers.ToArray())
            {
                HoverCheckRecurse(layer, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), position.ToVector2(), hoveringNow);
            }
            foreach (var el in hoveringNow.Except(_hoverElements))
            {
                if (el.Events.Handles <MouseHoverEvent>())
                {
                    el.Events.Handle(new MouseHoverEvent(position.ToVector2()));
                }
            }
            foreach (var el in _hoverElements.Except(hoveringNow))
            {
                if (el.Events.Handles <MouseUnhoverEvent>())
                {
                    el.Events.Handle(new MouseUnhoverEvent(position.ToVector2()));
                }
            }

            _hoverElements = hoveringNow;

            _previousState = state;
        }
Exemplo n.º 23
0
        //private (Point point, BuildNode buildNode) GetSelectedGridPoint()
        //{
        //}

        public void Tick(TickContext context)
        {
            var mouse     = Mouse.GetState();
            var screenPos = new Vector2(
                mouse.X / (float)GraphicsDevice.Viewport.Width,
                1.0f - (mouse.Y / (float)GraphicsDevice.Viewport.Height)
                ) * 2 - new Vector2(1, 1);
            //Console.WriteLine($"screen {screenPos}");

            //Console.WriteLine(screenPos);
            //Console.WriteLine(worldDirectionVector);
            var ray = Camera.CreateRay(screenPos);
            var res = RayCollider.RayCast(ray, (byte)HitLayers.BuildTile);
            // Console.WriteLine($"Location: {res.location}");

            var buildNode = res.entity?.Get <BuildNode>();

            if (buildNode != null)
            {
                //Console.WriteLine($"{buildNode.GridLocation}");
            }
            this.Update(() => HoverNode = buildNode);

            if (PlacingSection != null)
            {
                if (KeyControls.HasBeenPressed(Keys.R))
                {
                    PlacingSection.Rotate(1);
                }
                if (MouseControls.RightClicked)
                {
                    CancelPlacing();
                }
                else if (buildNode != null && MouseControls.LeftClicked)
                {
                    var gridLocation = buildNode.GridLocation;
                    if (_shipTopology.SectionAt(gridLocation) == null &&
                        _shipTopology.LegalSectionCheck(PlacingSection, gridLocation))
                    {
                        this.Update(() =>
                        {
                            _shipTopology.SetSection(gridLocation, PlacingSection);
                            _productionLine.Remove(PlacingSection);
                            PlacingSection = null;
                            SoundEffects.Get("Hammer")?.Play();
                        });
                    }
                    else
                    {
                        SoundEffects.Get("Click")?.Play();
                    }
                }
            }
        }
Exemplo n.º 24
0
        public void Tick(TickContext context)
        {
            var mag = Ship.Velocity.Length();

            if (mag > Limit)
            {
                Ship.Update(() =>
                {
                    Ship.Velocity *= 0.98f;
                });
            }
        }
Exemplo n.º 25
0
 private void CheckClear(TickContext context)
 {
     foreach (var asteroidEntity in _entities.ToArray())
     {
         var transform = asteroidEntity.Get <Transform>();
         if (transform.Location.Z > _flightShipTransform.Location.Z + 25)
         {
             asteroidEntity.Delete();
             _entities.Remove(asteroidEntity);
         }
     }
 }
Exemplo n.º 26
0
 public void Tick(TickContext context)
 {
     //var keyboard = Keyboard.GetState();
     //this.Update(() =>
     //{
     //    if (keyboard.IsKeyDown(Keys.T))
     //    {
     //        Transform.Rotation *= Quaternion.CreateFromYawPitchRoll(0, (float)(Math.PI * context.DeltaTimeSeconds), 0);
     //    }
     //    //Transform.Location += Vector3.Up * context.DeltaTimeSeconds * 0.1f;
     //});
 }
Exemplo n.º 27
0
        public void Tick(TickContext context)
        {
            _intoTimer.Tick(context.DeltaTime);
            var keyboard = Keyboard.GetState();

            if (keyboard.GetPressedKeys().Length > 0 ||
                MouseControls.LeftClicked ||
                _intoTimer.Completed)
            {
                FadeTransition.StartTransition(() => SceneManager.SetScene(new MenuScene()));
            }
        }
Exemplo n.º 28
0
 public void Tick(TickContext context)
 {
     if (FlightShip.Health < 1)
     {
         _completionTimer.Tick(context.DeltaTime);
         if (_completionTimer.Completed)
         {
             FadeTransition.StartTransition(() => SceneManager.SetScene(new DeathScene()));
             _completionTimer.Restart();
         }
     }
 }
Exemplo n.º 29
0
            public void Tick(TickContext context)
            {
                _nextTimer.Tick(context.DeltaTime);
                if (!_finished && _nextTimer.Completed)
                {
                    _finished = true;
                    _runAfter?.Invoke();
                }

                _camera.LookAt(_flightShip.GetNodes().First().GlobalLocation);
                _camera.Recalculate();
            }
Exemplo n.º 30
0
 public override void Tick(TickContext context)
 {
     if (_target.Remaining == 2 && _wave == 0)
     {
         _wave = 1;
         _enemyBrains[1].Active = true;
     }
     if (_target.Remaining == 1 && _wave == 1)
     {
         _wave = 2;
         _enemyBrains[2].Active = true;
     }
 }
Exemplo n.º 31
0
Arquivo: Game.cs Projeto: andy-uq/Echo
        public double Update()
        {
            _tick++;
            var context = new TickContext(_tick);

            var index = 0;
            long remaining = TicksPerSlice;

            var tickTimer = Stopwatch.StartNew();
            while (remaining > 0 && _updateFunctions.Count > index)
            {
                var tickMethod = _updateFunctions[index];
                if (tickMethod.Due > _tick)
                {
                    break;
                }

                context.ElapsedTicks = _tick - tickMethod.Due;
                var nextTick = tickMethod.Tick(context);
                if (nextTick != 0)
                {
                    context.Requeue(tickMethod, nextTick);
                }

                remaining = TicksPerSlice - tickTimer.ElapsedTicks;
                index++;
            }

            _updateFunctions = _updateFunctions
                .Skip(index)
                .Concat(context.Registrations)
                .OrderBy(x => x.Due)
                .ToList();

            _idle.Enqueue(remaining/(double) TicksPerSlice);
            return remaining;
        }
Exemplo n.º 32
0
        public void EarthOrbit()
        {
            var world = new MockUniverse();
            var universe = Universe.Builder.Build(world.Universe).Materialise();

            var sol = universe.StarClusters
                .SelectMany(x => x.SolarSystems)
                .Single(x => x.Id == world.SolarSystem.ObjectId);

            var earth = sol.Satellites
                .Single(x => x.Id == world.Earth.ObjectId);

            var context = new TickContext(0) { ElapsedTicks = 60 * 60 * 5 };
            var orbiter = new Orbiter(sol);
            var orbitRadius = earth.Position.LocalCoordinates.Magnitude;

            for (var i = 0; i < 12*21; i++)
            {
                orbiter.Orbit(context);
                Console.WriteLine("{0}: {1:n}", i, earth.Position.LocalCoordinates * 1e-5);

                earth.Position.LocalCoordinates.Magnitude.ShouldBe(orbitRadius, Units.Tolerance*100);
            }
        }