コード例 #1
0
        public override void ItemAction(Transform transform, Direction direction, Vector2 position, out int timer)
        {
            var x = 0;
            var y = 0;

            switch (direction)
            {
            case Direction.Right:
                x = _speed;
                y = 0;
                break;

            case Direction.Left:
                x = -_speed;
                y = 0;
                break;

            case Direction.Up:
                x = 0;
                y = -_speed;
                break;

            case Direction.Down:
                x = 0;
                y = _speed;
                break;
            }

            if (ManageInput.playerSpecial)
            {
                _entities.AddEntities(new Projectile(_entities, _owner, new Vector2(x, y), position, 1, new AnimatedSprite(_animationFactory, "Init"), 0));
            }

            timer = 20;
        }
コード例 #2
0
        public CrawlerPrefab(Entities entities, ManageMap manageMap, ContentManager content, Vector2 position, out Entities enemyAdded)
        {
            //add enemy
            var _enemy = new GameObject {
                Id = "Enemy"
            };

            _enemy.AddComponent(new Transform(position));
            _enemy.AddComponent(new SpriteRenderer(content.Load <Texture2D>("Textures/s_crawler"), 16, 16));
            _enemy.AddComponent(new Collision(manageMap, new Rectangle(0, 0, 16, 16), new Vector2(0, 0), content.Load <Texture2D>("Textures/s_pixel")));
            _enemy.AddComponent(new Animation(content.Load <Texture2D>("Textures/s_crawler"), (new SpriteSheetData
                                                                                               (
                                                                                                   16,
                                                                                                   16,
                                                                                                   (new List <string> {
                "Idle", "Walk"
            }),
                                                                                                   (new List <int[]> {
                new[] { 0 }, new[] { 0, 1 }
            }),
                                                                                                   (new List <float> {
                0.2f, 0.2f
            }),
                                                                                                   (new List <bool> {
                true, true
            }

                                                                                                   )))));
            _enemy.AddComponent(new MoveRandomAI(600, 1));
            _enemy.AddComponent(new Damage(entities, _enemy));
            _enemy.AddComponent(new Health(entities, _enemy, 2, 2));
            _enemy.AddComponent(new EfxGenerator(content.Load <Texture2D>("Textures/s_efx")));
            entities.AddEntities(_enemy);
            enemyAdded = entities;
        }
コード例 #3
0
        public override void ItemAction(Transform transform, Direction direction, Vector2 position, out int timer)
        {
            var x = 0;
            var y = 0;

            switch (direction)
            {
            case Direction.Right:
                x = _speed;
                y = 0;
                _adjustPosition = new Vector2(5, -16);
                break;

            case Direction.Left:
                x = -_speed;
                y = 0;
                _adjustPosition = new Vector2(-32, -16);
                break;

            case Direction.Up:
                x = 0;
                y = -_speed;
                break;

            case Direction.Down:
                x = 0;
                y = _speed;
                break;
            }

            position  += _adjustPosition;
            Position   = position;
            _transform = transform;

            if (ManageInput.playerSpecial)
            {
                Velocity = new Vector2(x, y);
                _entities.AddEntities(new Projectile(_entities, _owner, Velocity, Position, 2, new AnimatedSprite(_animationFactory, "Init"), 2, false));
                FireTrail();
                _fireTimer = 5;
                _tailTimer = 20;
                _counter   = 6;
            }

            timer = 120;
        }
コード例 #4
0
        public PlayerPrefab(Entities entities, ManageMap manageMap, ContentManager content, Vector2 position, out Entities outEntities)
        {
            //add player
            var _player = new GameObject {
                Id = "Player"
            };

            //upgrades
            if (PlayerStats.UpgrdStar)
            {
                _player.AddComponent(new Shuriken(entities, _player, content));
            }
            if (PlayerStats.UpgrdFire)
            {
                _player.AddComponent(new FlameStrike(entities, _player, content));
            }


            _player.AddComponent(new Transform(position, (int)HUD.PlayerCurrentDirection));
            _player.AddComponent(new PlayerController(entities, _player));
            _player.AddComponent(new SpriteRenderer(content.Load <Texture2D>("Textures/s_player_atlas"), 54, 35));
            _player.AddComponent(new Animation(content.Load <Texture2D>("Textures/s_player_atlas"), (new SpriteSheetData
                                                                                                     (
                                                                                                         54,
                                                                                                         35,
                                                                                                         (new List <string> {
                "Idle", "Walk", "Jump", "Fall", "Duck", "Attack", "WallJump", "DuckAttack", "WallAttack", "Hurt", "Special", "DuckSpecial", "WallSpecial", "LadderIdle", "Ladder", "LadderAttack", "LadderSpecial"
            }),
                                                                                                         (new List <int[]> {
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 23, 22 }, new[] { 1, 2, 3, 4, 5, 6 }, new[] { 7 }, new[] { 8 }, new[] { 9 }, new[] { 11, 12, 12 }, new[] { 18 }, new[] { 15, 16, 17 }, new[] { 19, 20, 21 }, new[] { 8 }, new[] { 24, 25, 26 }, new[] { 27, 28, 29 }, new[] { 31, 32 }, new[] { 33 }, new[] { 33, 34 }, new[] { 19, 20, 21 }, new[] { 31, 32 }
            }),
                                                                                                         (new List <float> {
                0.1f, 0.1f, 0.2f, 0.2f, 0.2f, 0.1f, 0.2f, 0.1f, 0.1f, 0.3f, 0.06f, 0.06f, 0.06f, 0.2f, 0.2f, 0.1f, 0.06f
            }),
                                                                                                         (new List <bool> {
                true, true, true, true, true, false, true, false, false, false, false, false, false, false, true, false, false
            }

                                                                                                         ))), (int)HUD.PlayerCurrentDirection, true));
            _player.AddComponent(new Collision(manageMap, new Rectangle(0, 0, 13, 24), new Vector2(21, 11), content.Load <Texture2D>("Textures/s_pixel")));
            _player.AddComponent(new Damage(entities, _player));
            _player.AddComponent(new Health(entities, _player, PlayerStats.MaxHealth, HUD.PlayerCurrentHealth));
            _player.AddComponent(new EfxGenerator(content.Load <Texture2D>("Textures/s_efx")));

            entities.AddEntities(_player);

            outEntities = entities;
        }
コード例 #5
0
ファイル: Health.cs プロジェクト: Keatsotic/KeatsoticEngine
        public override void Update(GameTime gameTime)
        {
            if (_owner.Id == "Player")
            {
                return;
            }

            var transform = GetComponent <Transform>(ComponentType.Transform);

            if (CurrentHealth <= 0)
            {
                var animation = GetComponent <EfxGenerator>(ComponentType.EfxGenerator).ObjectAnimated;
                var sprite    = GetComponent <SpriteRenderer>(ComponentType.SpriteRenderer);

                _entities.AddEntities(new EnemyDeathAnimation(_entities, transform.Position, animation, sprite.Width, sprite.Height));
                _entities.RemoveEntities(_owner);
            }
        }
コード例 #6
0
        public override void Update(GameTime gameTime)
        {
            //access components
            var sprite    = GetComponent <SpriteRenderer>(ComponentType.SpriteRenderer);
            var transform = GetComponent <Transform>(ComponentType.Transform);
            var collision = GetComponent <Collision>(ComponentType.Collision);
            var animation = GetComponent <Animation>(ComponentType.Animation);
            var damage    = GetComponent <Damage>(ComponentType.Damage);

            if (transform == null || sprite == null || collision == null)
            {
                return;
            }


            Camera.Update(new Vector2(GetComponent <Transform>(ComponentType.Transform).Position.X + sprite.Width / 2,
                                      GetComponent <Transform>(ComponentType.Transform).Position.Y));

            //sword attack
            if (ManageInput.playerAttack && _attackTimer <= 0)
            {
                switch (CurrentState)
                {
                case State.Duck:
                    CurrentState = State.DuckAttack;
                    break;

                case State.WallJump:
                    CurrentState = State.WallAttack;
                    break;

                case State.Ladder:
                    CurrentState = State.LadderAttack;
                    break;

                case State.LadderIdle:
                    CurrentState = State.LadderAttack;
                    break;

                default:
                    CurrentState = State.Attack;
                    break;
                }
                _attackTimer = _attackTimerMax;
            }

            //special attack
            if (ManageInput.playerSpecial && _specialTimer <= 0 && _equipedItem != null)
            {
                switch (CurrentState)
                {
                case State.Duck:
                    CurrentState = State.DuckSpecial;
                    break;

                case State.WallJump:
                    CurrentState = State.WallSpecial;
                    break;

                case State.Ladder:
                    CurrentState = State.LadderSpecial;
                    break;

                case State.LadderIdle:
                    CurrentState = State.LadderSpecial;
                    break;

                default:
                    CurrentState = State.Special;
                    break;
                }
                _canSpecial = true;
            }

            if (_attackTimer > 0)
            {
                _attackTimer--;
            }

            if (_specialTimer > 0)
            {
                _specialTimer--;
            }

            if (isOnLadder)
            {
                CurrentState = State.Ladder;
                isOnLadder   = false;
            }

            //animation stuff
            if (animation.AnimationFinished == true)
            {
                CurrentState = ReturnState;
            }
            if (damage.IstakingDamage)
            {
                CurrentState = State.Hurt;
            }
            animation.CurrentState = CurrentState;

            if (CurrentState == State.WallJump)
            {
                var smokeAnimation = GetComponent <EfxGenerator>(ComponentType.EfxGenerator).ObjectTexture;
                if (_smokeTimer <= 0)
                {
                    if (Direction == Direction.Left)
                    {
                        _entities.AddEntities(new WallSmoke(_entities, smokeAnimation, new Vector2(transform.Position.X + 3, transform.Position.Y + 4), sprite.Width, sprite.Height));
                    }
                    else
                    {
                        _entities.AddEntities(new WallSmoke(_entities, smokeAnimation, new Vector2(transform.Position.X + 15, transform.Position.Y + 4), sprite.Width, sprite.Height));
                    }
                    _smokeTimer = 15;
                }
                _smokeTimer--;
            }

            StateMachine(CurrentState, transform, collision);
        }