コード例 #1
0
ファイル: Tile.cs プロジェクト: kralle333/TankGame
        public void SetType(BlockName type)
        {
            ClearAnimationStates();
            AddAnimationState(new SpriteState("Idle", _tileSpriteMap[type], 0));
            SetCurrentAnimationState("Idle");

            _name = type;
            _type = _tileBlockTypes[type];
            switch (_type)
            {
            case BlockType.Solid:
                _depth  = SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.High);
                _health = 2;
                break;

            case BlockType.WalkableCovering:
                _depth = SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.High);
                break;

            case BlockType.Walkable: _depth = SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.Low); break;
            }
        }
コード例 #2
0
        public Tank(int playerIndex, Vector2 position, int team, ControlScheme controlScheme, Rectangle screenBounds)
            : base("Sprites", position, Map.TileSize, Map.TileSize, true, SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.Middle))
        {
            _playerIndex       = playerIndex;
            _team              = team;
            _screenBounds      = screenBounds;
            _usedControlScheme = controlScheme;
            if ((int)_usedControlScheme > 2)
            {
                _gamePadIndex = (PlayerIndex)_usedControlScheme - 3;
            }

            //Cannon
            SetOrigin(16, 16);
            cannon = new Sprite("Sprites", position, 26, 16, false, SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.Middle) + 0.1f);
            cannon.SetTextureRectangle(new Rectangle(96 + (32 * _team), 64, 26, 16));
            cannon.SetOrigin(8f, 8f);
            cannon.position = position;
            _spriteOverlays.Add(cannon);

            //Animation
            AddAnimationState(new SpriteState("MovingHorizontal", SpriteHelper.GetSpriteRectangleStrip(32, 32, 0, 3 + _team, 3 + _team, 0, 2), _animationSpeed));
            _orientation           = new Vector2(1, 0);
            _currentAnimationState = "MovingHorizontal";
            SetCurrentAnimationState(_currentAnimationState);
            InitiateAnimationStates();

            //Statbar
            statsBarPosition = new Vector2(20 + (playerIndex * 290), 24);
            if (playerIndex > 1)
            {
                statsBarPosition.X += 200;
            }
            tankSprite       = new Sprite("Sprites", (int)statsBarPosition.X, (int)statsBarPosition.Y, new Rectangle(96 + (32 * team), 112, 32, 32), 1);
            _healthBar       = new HealthBar((int)statsBarPosition.X + 42, (int)statsBarPosition.Y, 116, 30, Color.Green, Color.Red, Color.Black);
            powerupRectangle = new Sprite("Sprites", _healthBar.x + 100 + 32, 21, 1);
            powerupRectangle.SetTextureRectangle(new Rectangle(0, 176, 36, 36));
        }