Exemplo n.º 1
0
        public ActiveUnit(Animation animation, Vector2 pos, Vector2 vel, Vector2 acc, Color blendColor, float rot = 0.0f, float depth = 1.0f)
            : base(animation, pos, blendColor, rot, depth)
        {
            Vel = vel;
            Acc = acc;

            Input.PressedEvent += InputPressed;
            Input.ReleasedEvent += InputReleased;
            Input.HeldEvent += InputHeld;
        }
Exemplo n.º 2
0
        public BasicUnit(Animation animation, Vector2 pos, Color blendColor, float rot = 0.0f, float depth = 1.0f)
        {
            SetAnimation(animation);

            if (blendColor == null)
                blendColor = Color.White;

            Pos = pos;
            Rot = rot;
            BlendColor = blendColor;

            _frame = 0;
            _animationComplete = false;

            Flip = false;

            Core.UpdateEvent += Update;
            Core.RenderEvent += Render;
            AnimationCompleteEvent += AnimationComplete;
        }
Exemplo n.º 3
0
        public override void SetAnimation(Animation animation, bool useDefaults = true)
        {
            base.SetAnimation(animation, useDefaults);

            Size.X = 42;
            Origin.X = 24;
        }
Exemplo n.º 4
0
        public virtual void SetAnimation(Animation animation, bool useDefaults = true)
        {
            _animation = animation;

            if (_animation == null)
                return;

            _frame = 0;
            Size = _animation.FrameSize;

            if (useDefaults)
            {
                _animationTimeout = _animation.FrameTime;
                Origin = _animation.Origin;
                Animating = _animation.Animating;
                Looping = _animation.Looping;
                _animationComplete = false;
            }
        }
Exemplo n.º 5
0
 public HUD()
 {
     _border = Assets.Animations["hud-border"];
 }
Exemplo n.º 6
0
        public TestRoom()
        {
            _player = new Player(new Vector2(320, 0));
            Viewport.Follow(_player);

            Tilesets = new Dictionary<string, Range>();

            Tilesets.Add("platform-tiles", new Range(1, 64));
            Tilesets.Add("special-tiles", new Range(65, 128));
            Tilesets.Add("indicator-tiles", new Range(129, 192));
            Tilesets.Add("lights-tiles", new Range(193, 256));
            Tilesets.Add("switch-tiles", new Range(257, 320));
            Tilesets.Add("plants-tiles", new Range(321, 384));
            Tilesets.Add("ground-tiles", new Range(385, 500));

            int width = Config.GetInt("Maps", "test", "Width");
            int height = Config.GetInt("Maps", "test", "Height");
            int tileSize = 32;

            _player.Pos = Config.GetVector2("Maps", "test", "Player") * tileSize;

            int[] objectData = Config.GetIntList("Maps", "test", "objects");
            int[] tileData = Config.GetIntList("Maps", "test", "visual-layers", "visual_01");

            _objectLayer = new int[width, height];
            _visibleLayer = new int[width, height];

            int row = 0,
                col = 0;
            for (int i = 0; i < objectData.Length; ++i)
            {
                _objectLayer[col, row] = objectData[i];
                _visibleLayer[col, row] = tileData[i];

                ++col;
                if (col == width)
                {
                    col = 0;
                    ++row;
                }
            }

            _platforms = new List<Platform>();
            _tiles = new List<BasicUnit>();

            for (row = 0; row < height; ++row)
            {
                for (col = 0; col < width; ++col)
                {
                    if (_objectLayer[col, row] != 0)
                        Console.WriteLine(_objectLayer[col, row]);

                    Vector2 pos = new Vector2(col * tileSize, row * tileSize);

                    if (_objectLayer[col, row] == TilePlatform)
                    {
                        _platforms.Add(new Platform(pos, new Vector2(tileSize), false));
                    }
                    else if (_objectLayer[col, row] == TileEastRamp)
                    {
                        _platforms.Add(new Platform(pos, new Vector2(tileSize), Direction.East));
                    }
                    else if (_objectLayer[col, row] == TileWestRamp)
                    {
                        _platforms.Add(new Platform(pos, new Vector2(tileSize), Direction.West));
                    }
                    else if (_objectLayer[col, row] == TilePlayerSpawn)
                    {
                        _player.Pos = pos;
                    }

                    if (_visibleLayer[col, row] != 0)
                    {
                        foreach (KeyValuePair<string, Range> pair in Tilesets)
                        {
                            if (!pair.Value.Contains(_visibleLayer[col, row]))
                                continue;

                            int sheetInd = _visibleLayer[col, row] - pair.Value.Min;

                            Texture2D texture = Assets.Animations[pair.Key].Frame(0).Texture;

                            Vector2 coord = Vector2.Zero;
                            for (int i = 0; i < sheetInd; ++i)
                            {
                                coord.X += tileSize;
                                if (coord.X >= texture.Width)
                                {
                                    coord.X = 0;
                                    coord.Y += tileSize;
                                }
                            }

                            Sprite sprite = new Sprite(texture, new Rectangle((int)coord.X, (int)coord.Y, tileSize, tileSize));
                            List<Sprite> frames = new List<Sprite>();
                            frames.Add(sprite);

                            Animation newAnim = new Animation(frames, new Vector2(tileSize), 0, Vector2.Zero, false);

                            _tiles.Add(new BasicUnit(newAnim, pos, Color.White));
                        }
                    }

                }
            }

            Core.UpdateEvent += Update;
            Core.RenderEvent += Render;
        }