public void Draw(GameTime gameTime)
        {
            // Begin
            _sb.Begin(samplerState: SamplerState.PointClamp, sortMode: SpriteSortMode.FrontToBack,
                      blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix());

            // Draw Entities
            foreach (int entityId in ActiveEntities)
            {
                var renderForm = _renderFormMapper.Get(entityId);
                var transform  = _transform2DMapper.Get(entityId);

                if (string.Compare("Background", renderForm.Name) == 0)
                {
                    var renderer = _rendererMapper.Get(entityId);
                    RenderBackground(renderer, transform);
                }
                else if (string.Compare("Chicken", renderForm.Name) == 0)
                {
                    var animatedSprite = _animatedSpriteMapper.Get(entityId);
                    RenderChicken(animatedSprite, transform);
                }
            }
            // End
            _sb.End();
        }
 public override void Update(GameTime gameTime)
 {
     foreach (int entityId in ActiveEntities)
     {
         ++_components.Get(entityId).Value;
     }
 }
        public override void Process(Entity e)
        {
            Transform transform = transformMapper.Get(e);

            UpdateInput();
            if (moveLeft)
            {
                transform.X += world.Delta * -0.3f;
            }
            if (moveRight)
            {
                transform.X += world.Delta * 0.3f;
            }

            if (shoot)
            {
                Entity missile = EntityFactory.CreateMissile(world);
                missile.GetComponent <Transform>().SetLocation(transform.X + 30, transform.Y - 20);
                missile.GetComponent <Velocity>().Speed = -0.5f;
                missile.GetComponent <Velocity>().Angle = 90;
                missile.Refresh();

                shoot = false;
            }
        }
Beispiel #4
0
        public override void Update(GameTime gameTime)
        {
            foreach (var entity in ActiveEntities)
            {
                var modelComponent = _modelMapper.Get(entity);

                DPModel model;
                if (_loadedModels.ContainsKey(modelComponent.Hash))
                {
                    model = _loadedModels[modelComponent.Hash];
                }
                else
                {
                    if (!Models.ModelList.ContainsKey(modelComponent.Hash))
                    {
                        Console.Error.WriteLine("Failed to find model with hash: " + modelComponent.Hash);
                        _modelMapper.Delete(entity);
                        continue;
                    }

                    model = ConvertDProjectModelFormatToModel(Models.ModelList[modelComponent.Hash].AssetPath, _graphicsDevice);
                    _loadedModels.Add(modelComponent.Hash, model);
                }

                var loadedModelComponent = new LoadedModelComponent()
                {
                    Model = model
                };

                _loadedModelMapper.Put(entity, loadedModelComponent);
                _modelMapper.Delete(entity);
            }
        }
Beispiel #5
0
        protected override void ProcessEntities(Dictionary <int, Entity> entities)
        {
            Bag <Entity> bullets = world.GetGroupManager().getEntities("BULLETS");
            Bag <Entity> ships   = world.GetGroupManager().getEntities("SHIPS");

            if (bullets != null && ships != null)
            {
                for (int a = 0; ships.Size() > a; a++)
                {
                    Entity ship = ships.Get(a);
                    for (int b = 0; bullets.Size() > b; b++)
                    {
                        Entity bullet = bullets.Get(b);

                        if (CollisionExists(bullet, ship))
                        {
                            Transform tb = transformMapper.Get(bullet);
                            EntityFactory.CreateBulletExplosion(world, tb.GetX(), tb.GetY()).Refresh();
                            world.DeleteEntity(bullet);

                            Health health = healthMapper.Get(ship);
                            health.AddDamage(4);

                            if (!health.IsAlive())
                            {
                                Transform ts = transformMapper.Get(ship);
                                EntityFactory.CreateShipExplosion(world, ts.GetX(), ts.GetY()).Refresh();
                                world.DeleteEntity(ship);
                                break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public override void Update(GameTime gameTime)
        {
            // unknown => inprocess
            if (_state == state.Unknown)
            {
                foreach (var entity in ActiveEntities)
                {
                    _battle = _battleMapper.Get(entity);

                    if (_battle != null)
                    {
                        setInProcessState(entity); return;
                    }
                }
            }
            else // inprocess => won/lose => unknown
            if (_state == state.InProcess)
            {
                if (isAllEnemiesDead())
                {
                    setWinState();
                }
                else
                if (isPlayerDead())
                {
                    setLoseState();
                }
            }
        }
Beispiel #7
0
 public void Update(GameTime gameTime)
 {
     foreach (var entity in ActiveEntities)
     {
         updateListenerMapper.Get(entity).RegisterUpdate(gameTime);
     }
 }
        public override void Process(GameTime gameTime, int entityId)
        {
            var unitType = _unitMapper.Get(entityId).Type;

            if (unitType != UnitType.Miner)
            {
                return;
            }

            var productionUnit = _productionUnitMapper.Get(entityId);
            var tilePosition   = _tilePositionMapper.Get(entityId);

            var activeMineableResources = GetActiveMineableResources(tilePosition);

            SetProductionUnitActive(productionUnit, activeMineableResources);

            if (productionUnit.ProductionActive)
            {
                productionUnit.CurrentProductionTime += gameTime.ElapsedGameTime;
            }
            if (productionUnit.CurrentProductionTime >= productionUnit.ProductionSpeed)
            {
                productionUnit.CurrentProductionTime -= productionUnit.ProductionSpeed;
                Produce(productionUnit, activeMineableResources.ToList());
            }
        }
Beispiel #9
0
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);

            //spriteBatch.Draw(background, new Microsoft.Xna.Framework.Rectangle(0, 0, 1280, 720), Color.White);

            foreach (var entity in ActiveEntities)
            {
                var healthPoints = healthMapper.Has(entity) ? healthMapper.Get(entity) : null;
                if (healthPoints != null)
                {
                    var maxHealthPoints = 3;
                    for (int i = 0; i < maxHealthPoints; i++)
                    {
                        Vector2 position = new Vector2(32 + (i * 32), 32f);
                        spriteBatch.Draw(grayHeartSprite, new Transform2(position, 0f, Vector2.One));
                    }

                    for (int i = 0; i < healthPoints.LifePoints; i++)
                    {
                        Vector2 position = new Vector2(32 + (i * 32), 32f);
                        spriteBatch.Draw(redHeartSprite, new Transform2(position, 0f, Vector2.One));
                    }
                }
            }

            spriteBatch.End();
        }
        public override void Process(GameTime gameTime, int entityId)
        {
            var productionUnit = _productionUnitMapper.Get(entityId);
            var tilePosition   = _tilePositionMapper.Get(entityId);

            if (!productionUnit.OutputBuffer.Any())
            {
                return;
            }

            var outputDirection = _alignableMapper.Get(entityId)?.Direction ?? Direction.NorthEast;

            var outputPosition = GetOutputPosition(tilePosition, outputDirection);

            if (OutputPositionIsOccupied(outputPosition))
            {
                return;
            }

            int outputProductEntityId = productionUnit.OutputBuffer[0];

            productionUnit.OutputBuffer.RemoveAt(0);
            var outputProductEntity = GetEntity(outputProductEntityId);

            outputProductEntity.Attach(outputPosition);
            outputProductEntity.Attach(new Transportable());
        }
        public override void Process(Entity entity)
        {
            VelocityComponent v = _velocityMapper.Get(entity);
            PositionComponent p = _positionMapper.Get(entity);

            if (v.ForceActive)
            {
                if (v.ForceAge <= v.ForceDuration)
                {
                    v.ForceAge += World.ElapsedTime;
                    v.Velocity  = v.ForceVelocity * (float)Math.Pow((1 - .99), v.ForceAge);
                }
                else
                {
                    v.Velocity    = Vector2.Zero;
                    v.ForceActive = false;
                    v.ForceAge    = 0;
                }
            }

            //Clamp velocity
            //if (v.Velocity.Length() > v.MaxSpeed)
            //{
            //    v.Velocity = Vector2.Normalize(v.Velocity) * v.MaxSpeed;
            //}
            //Clamp angular velocity
            v.AngularVelocity = MathHelper.Clamp(v.AngularVelocity, -v.MaxAngularVelocity, v.MaxAngularVelocity);

            //Adjust position and rotation based on velocities and time.
            if (p != null && v != null)
            {
                p.Position  = new Vector2(p.Position.X + v.Velocity.X * World.ElapsedTime, p.Position.Y + v.Velocity.Y * World.ElapsedTime);
                p.Rotation += v.AngularVelocity * World.ElapsedTime;
            }
        }
Beispiel #12
0
        public override void Process(GameTime gameTime, int entityId)
        {
            var direction          = _alignableMapper.Get(entityId).Direction;
            var directionalTexture = _directionalTextureMapper.Get(entityId);
            var texture            = direction switch
            {
                Direction.NorthEast => directionalTexture.NorthEastTexture,
                Direction.SouthEast => directionalTexture.SouthEastTexture,
                Direction.SouthWest => directionalTexture.SouthWestTexture,
                Direction.NorthWest => directionalTexture.NorthWestTexture,
                _ => directionalTexture.NorthEastTexture,
            };

            var sprite = _spriteMapper.Get(entityId);

            if (sprite != null)
            {
                sprite.TextureRegion = textureManager.GetRandomTexture(texture);
            }
            else
            {
                sprite = new Sprite(textureManager.GetRandomTexture(texture));
                GetEntity(entityId).Attach(sprite);
            }

            sprite.Alpha = directionalTexture.Alpha;
        }
Beispiel #13
0
        public override void Process(GameTime gameTime, int entityId)
        {
            var player     = _playerMapper.Get(entityId);
            var gameObject = _gameObjectMapper.Get(entityId);

            player.InputHandler.Update();
        }
Beispiel #14
0
    private void RenderSprite(int entity, Sprite sprite)
    {
        var transform = transformMapper.Get(entity);

        // playerMapper.TryGet(entity).IfSome(player => {
        //     sprite.Color = player.PlayerNumber switch {
        //         1 => new Color(128, 128, 255),
        //         2 => new Color(255, 128, 128),
        //         3 => Color.Yellow,
        //         4 => Color.Green,
        //         _ => Color.White
        //     };
        //     healthMapper.TryGet(entity).IfSome(health => { transform.Scale = Vector2.One * health.CurrentHealth / health.MaxHealth; });
        // });

        spriteBatch.Draw(sprite, transform);
        // spriteBatch.DrawRectangle(sprite.GetBoundingRectangle(transform), Color.Beige);

        movableMapper.TryGet(entity).IfSome(movable => {
            if (movable.LevelBoundsBehavior == LevelBoundsBehavior.Wrap)
            {
                DrawLevelWrapping(sprite, transform);
            }
        });
    }
Beispiel #15
0
    public override void Process(GameTime gameTime, int entityId)
    {
        // Accelerator holds intended acceleration
        // TODO: Use acceleration in some way to calculate new acceleration
        var player  = playerMapper.Get(entityId);
        var movable = movableMapper.Get(entityId);
        var input   = playerInputMapper.Get(entityId);
        // TODO: How to handle keyboard keys (WASD) vs Controller inputs? How to know which to use?
        var intendedAcceleration = input.DirectionalInputs.AccelerationDirection;

        movable.Acceleration = player.StandingOn switch {
            // StandingOn.Nothing => ResultAcceleration(intendedAcceleration, movable.Velocity, player.IsBoosting),
            StandingOn.Nothing => Vector2.Zero,
            StandingOn.Planet => GetPlanetMovement(intendedAcceleration),
            _ => Vector2.Zero
        };

        movable.BrakingForce = player.IsBraking &&
                               (movable.Acceleration == Vector2.Zero || gameSettings.BrakeWhileJetpacking)
                ? variables.Global[GlobalVariable.BrakePower]
                : 0;

        // Testing no brakes;
        movable.BrakingForce = 0;
    }
Beispiel #16
0
        // TODO: Add action points restrictions.
        public override void Update(GameTime gameTime)
        {
            if (_entity == null)
            {
                foreach (var entity in ActiveEntities)
                {
                    _turn = _turnMapper.Get(entity);

                    if (_turn != null)
                    {
                        initTurn(entity); return;
                    }
                }
            }
            else
            {
                foreach (var entity in ActiveEntities)
                {
                    var turnEnd = _turnEndMapper.Get(entity);
                    if (turnEnd != null)
                    {
                        _turnEndMapper.Delete(entity);
                        toggleTurn();
                        return;
                    }
                }
            }
        }
Beispiel #17
0
        protected bool IsWithinEntity(int entity, Vector2 pointerLocation)
        {
            var body      = pointerInputBodyMapper.Get(entity).Body;
            var transform = transformMapper.Get(entity);

            return(body.IsPointWithin(pointerLocation - transform.Position));
        }
Beispiel #18
0
        public override void Draw(GameTime gameTime)
        {
            _graphicsDevice.SetRenderTarget(null);
            _graphicsDevice.Clear(ClearOptions.DepthBuffer, Color.White, 1, 0);

            foreach (var entity in ActiveEntities)
            {
                var transform  = _transformMapper.Get(entity);
                var waterPlane = _waterPlaneMapper.Get(entity);

                var effect = ShaderManager.Instance.WaterEffect;
                effect.World = transform.WorldMatrix;

                //TODO: This only needs to happen once and not every draw-call.
                _vertexBuffer.SetData(waterPlane.VertexList);

                _graphicsDevice.SetVertexBuffer(_vertexBuffer);

                foreach (var pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    _graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
                }
            }
        }
Beispiel #19
0
        public override void Update(GameTime gameTime)
        {
            //Debug.WriteLine($"Running Movement Update on {ActiveEntities.Count} active entities.");
            foreach (var entity in ActiveEntities)
            {
                Player       player       = _playerComponentMapper.Get(entity);
                Velocity     velocity     = _velocityComponentMapper.Get(entity);
                FreePosition freeposition = _freePositionComponentMapper.Get(entity);

                KeyboardState kstate = Keyboard.GetState();

                //Player Movement Logic
                if (kstate.IsKeyDown(_keybinds.PlayerMoveUp))
                {
                    freeposition.position.Y -= velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveDown))
                {
                    freeposition.position.Y += velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveLeft))
                {
                    freeposition.position.X -= velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveRight))
                {
                    freeposition.position.X += velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }
Beispiel #20
0
        private void DrawAllModels(IEffectMatrices effect)
        {
            foreach (var entity in ActiveEntities)
            {
                if (_modelMapper.Has(entity))
                {
                    var model     = _modelMapper.Get(entity).Model;
                    var transform = _transformMapper.Get(entity);

                    if (model.VertexBuffer != null && model.IndexBuffer != null & model.PrimitiveCount != 0)
                    {
                        var sphere = BoundingSphere.CreateFromBoundingBox(model.BoundingBox);

                        if (CameraSystem.ActiveLens.BoundingFrustum.Intersects(sphere.Transform(transform.WorldMatrix)))
                        {
                            effect.World = transform.WorldMatrix;
                            DrawMesh((Effect)effect, model, _graphicsDevice);
                        }
                    }
                }
                else if (_primitiveMapper.Has(entity))
                {
                    var primitive = _primitiveMapper.Get(entity);
                    var transform = _transformMapper.Get(entity);

                    effect.World = transform.WorldMatrix;
                    Primitives.Instance.Draw((Effect)effect, primitive.Type);
                }
            }
        }
Beispiel #21
0
        public override void Process(GameTime gameTime, int entityId)
        {
            var transform = _transformMapper.Get(entityId);
            var body      = _bodyMapper.Get(entityId);

            transform.Position = body.Position;
        }
Beispiel #22
0
    public override void Process(GameTime gameTime, int entityId)
    {
        var transform    = transformMapper.Get(entityId);
        var movable      = movableMapper.Get(entityId);
        var elapsedTicks = gameTime.GetElapsedTicks(variables);
        var oldPosition  = transform.Position;

        if (playerStateMapper.Get(entityId) is { StandingOn : StandingOn.Planet } playerState&& playerState.StandingOnEntity != null)
        {
            var planetTransform = transformMapper.Get(playerState.StandingOnEntity.Value);
            var normal          = transform.Position - planetTransform.Position;

            const float planetSpeed = 2f;

            var newNormal = normal.Rotate(planetSpeed * elapsedTicks * movable.Acceleration.X / normal.Length());

            transform.Position = planetTransform.Position + newNormal;

            const float planetJumpVelocity = 10f;

            if (playerState.IsBoosting)
            {
                // Jump off planet
                var playerInput = GetEntity(entityId).Get <PlayerInput>();

                movable.Velocity             = playerInput.DirectionalInputs.AimDirection.NormalizedCopy() * planetJumpVelocity;
                transform.Position          += movable.Velocity;
                playerState.StandingOnEntity = null;
                playerState.StandingOn       = StandingOn.Nothing;
            }
        }
Beispiel #23
0
        private void doTurn(int entityId)
        {
            var entity = GetEntity(entityId);
            var battle = _battleMapper.Get(entity);
            var queue  = _queueManager.Get(entity);

            // TODO: adv ai with bunch of ifelses, oh yeah
            foreach (var enemy in battle.Enemies)
            {
                _l.Info("Enemy decides what to do");

                var status  = _statusManager.Get(enemy);
                var actions = _actionsManager.Get(enemy);

                if (status.Health >= 3)
                {
                    _l.Info("Enemy throwing a stepler");
                    queue.Add(new ActionQueueItem(actions.ThrowStaper, battle.Player, enemy));
                }
                else
                {
                    _l.Info("Enemy health is low, time to drink some COFFEE");
                    queue.Add(new ActionQueueItem(actions.DrinkCoffee, battle.Player, enemy));
                }
            }

            entity.Attach(new TurnEndComponent());
        }
Beispiel #24
0
        public override void Process(GameTime gameTime, int entityId)
        {
            var keyboardState = KeyboardExtended.GetState();
            var body          = _bodyMapper.Get(entityId);
            var player        = _playerMapper.Get(entityId);

            if (keyboardState.IsKeyDown(Keys.Right) && player.Name == "mikze")
            {
                body.ApplyForceToCenter(new System.Numerics.Vector2(10, 0));
            }
            if (keyboardState.IsKeyDown(Keys.Left) && player.Name == "mikze")
            {
                body.ApplyForceToCenter(new System.Numerics.Vector2(-10, 0));
            }
            if (keyboardState.IsKeyDown(Keys.Up) && player.Name == "mikze")
            {
                body.ApplyLinearImpulseToCenter(new System.Numerics.Vector2(0, -0.1f));
            }

            if (keyboardState.IsKeyDown(Keys.D) && player.Name == "mikze2")
            {
                body.ApplyForceToCenter(new System.Numerics.Vector2(10, 0));
            }
            if (keyboardState.IsKeyDown(Keys.A) && player.Name == "mikze2")
            {
                body.ApplyForceToCenter(new System.Numerics.Vector2(-10, 0));
            }
            if (keyboardState.IsKeyDown(Keys.W) && player.Name == "mikze2")
            {
                body.ApplyLinearImpulseToCenter(new System.Numerics.Vector2(0, -0.1f));
            }
        }
Beispiel #25
0
 public override void Update(GameTime gameTime)
 {
     foreach (int entityId in ActiveEntities)
     {
         _xs.Get(entityId).Value += (_as.Get(entityId).Value + _bs.Get(entityId).Value) * Time;
     }
 }
Beispiel #26
0
        public override void Process(Entity e)
        {
            Health    health       = healthMapper.Get(e);
            Transform transform    = transformMapper.Get(e);
            Vector2   textPosition = new Vector2((float)transform.X - 10, (float)transform.Y - 30);

            spriteBatch.DrawString(font, health.HealthPercentage + "%", textPosition, Color.White);
        }
Beispiel #27
0
        private void Shoot()
        {
            // Animation
            int ammoId = _ammoEntities[AmmoCapacity - _currentAmmo];
            var sprite = _animatedSpriteMapper.Get(ammoId);

            sprite.Play("explode");

            // Sound
            Assets.SfxGunBlast.Play();

            // Shot
            _currentAmmo--;

            // Event
            _eventManager.Publish(new ShootEvent(_currentMouseState.Position));
        }
Beispiel #28
0
 public override void Update(GameTime gameTime)
 {
     _tileOccupationManager.RemoveAllItems();
     foreach (var entity in ActiveEntities)
     {
         _tileOccupationManager.AddItem(entity, _tilePositionMapper.Get(entity));
     }
 }
Beispiel #29
0
        /// <summary>
        /// Renders the provided <see cref="Entity"/> instance.
        /// </summary>
        /// <param name="entity"><see cref="Entity"/> instance to render.</param>
        public override void Process(Entity entity)
        {
            ImageComponent imageComponent = _imageMapper.Get(entity);

            if ((imageComponent == null) && !imageComponent.IsVisible)
            {
                return;
            }

            Vector2 position = imageComponent.Position;

            if (imageComponent.PositionMode == PositionMode.External)
            {
                PositionComponent positionComponent = _positionMapper.Get(entity);
                if (positionComponent != null)
                {
                    position += positionComponent.Position;
                }
            }

            float rotation = imageComponent.Rotation;

            if (imageComponent.RotationMode == RotationMode.External)
            {
                PositionComponent positionComponent = _positionMapper.Get(entity);
                if (positionComponent != null)
                {
                    rotation += positionComponent.Rotation;
                }
            }

            Director.SharedDirector.SpriteBatch.Draw(imageComponent.Texture,
                                                     position,
                                                     imageComponent.Source,
                                                     imageComponent.Tint,
                                                     rotation,
                                                     imageComponent.Origin,
                                                     imageComponent.Scale,
                                                     imageComponent.Effects,
                                                     imageComponent.Layer);
#if DEBUG
            ++ImagesRendered;
            ++ImagesProcessed;
#endif
        }
Beispiel #30
0
        public override void Process(GameTime gameTime, int entityId)
        {
            var mineableResource = _mineableResourceMapper.Get(entityId);

            if (mineableResource.Amount <= 0)
            {
                DestroyEntity(entityId);
            }
        }
Beispiel #31
0
        public MoveAction(float expiration, int priority, Entity entity, Vector2 goal)
            : base(expiration, priority)
        {
            _entity = entity;
            _goal = goal;

            ComponentMapper<PositionComponent> positionMapper = new ComponentMapper<PositionComponent>(Director.SharedDirector.EntityWorld);
            _position = positionMapper.Get(entity);

            ComponentMapper<VelocityComponent> velocityMapper = new ComponentMapper<VelocityComponent>(Director.SharedDirector.EntityWorld);
            _velocity = velocityMapper.Get(entity);
        }
        public void TestDerivedComponents()
        {
            EntityWorld entityWorld = new EntityWorld();
            TestDerivedComponent derived = new TestDerivedComponent();
            Entity entity = entityWorld.CreateEntity();

            entity.AddComponent(derived);
            Assert.IsNull(entity.GetComponent<TestDerivedComponent>(), "Should be null because the component should be added as if it was a base component");
            Assert.IsNotNull(entity.GetComponent<TestBaseComponent>());
            Assert.IsTrue(entity.GetComponent<TestBaseComponent>().IsDerived());

            #pragma warning disable 612,618
            ComponentMapper<TestBaseComponent> baseMapper = new ComponentMapper<TestBaseComponent>(entityWorld);
            ComponentMapper<TestDerivedComponent> derivedMapper = new ComponentMapper<TestDerivedComponent>(entityWorld);
            #pragma warning restore 612,618

            Assert.IsNull(derivedMapper.Get(entity));
            Assert.IsNotNull(baseMapper.Get(entity));
            Assert.AreEqual(baseMapper.Get(entity), entity.GetComponent<TestBaseComponent>());
        }