Ejemplo n.º 1
0
        private bool CanDamage(ref Decoration toHitDecoration, short damage)
        {
            if (toHitDecoration == null)return false;
            if (!toHitDecoration.Visible) return false;

            if(toHitDecoration.MyType == DecorHelper.Tree && _attackRect.Intersects(toHitDecoration.HitRect))
            {
                toHitDecoration.IsHit(damage);
                _woodChop.Play();
                return true;
            }
            return false;
        }
Ejemplo n.º 2
0
        internal void LoadData()
        {
            _tileCollWidth = TileManager.TileColls.GetLength(0);
            _tileCollHeight = TileManager.TileColls.GetLength(1);
            _decorPool = new Decoration[_tileCollWidth*_tileCollHeight];
            _decorSprites = new Decoration[_tileCollWidth,_tileCollHeight];
            DecorSprites = _decorSprites;
            _tileColls = TileManager.TileColls;
            var count = 0;

            for (var i = 0; i < _tileCollWidth; i++)
            {
                for (var j = 0; j < _tileCollHeight; j++)
                {
                    var s = new Decoration(this, ref _tileRegions);
                    DecorPool[count++] = s;
                    DecorSprites[i, j] = s;
                    s.SectorX = _tileColls[i, j].SectorX;
                    s.SectorY = _tileColls[i, j].SectorY;
                    s.MySectorSpotX = _tileColls[i, j].MySectorSpotX;
                    s.MySectorSpotY = _tileColls[i, j].MySectorSpotY;
                    s.MyVectorSpotX = _tileColls[i, j].MyVectorSpotX;
                    s.MyVectorSpotY = _tileColls[i, j].MyVectorSpotY;
                    s.UpdatePosition(_tileColls[i, j].HitRect.X, _tileColls[i, j].HitRect.Y);
                    var ld = _tileColls[i, j].MyLoaderBase;
                    CreateLightForTile(s, ld);
                }
            }
            SortPool();
        }
Ejemplo n.º 3
0
 private void CreateLightForTile(Decoration s, LoaderBase ld)
 {
     if (!s.SetInfo(this, ld.SectorData.DecorData[s.MySectorSpotX, s.MySectorSpotY])) return;
     //_tileColls[s.MyVectorSpotX, s.MyVectorSpotY].StarterLight(ref _tileColls, _tileCollWidth, _tileCollHeight);
 }
Ejemplo n.º 4
0
        public void Update(Decoration[] decorPool)
        {
            Decoration hitX = null;
            Decoration hitY = null;
            //var speed = isReversed ? HeroSpeed/2 : HeroSpeed;
            var movX = Inputs.MyInputs.MovX;
            var movY = Inputs.MyInputs.MovY;
            movX *= HeroSpeed;
            movY *= HeroSpeed;

            for (var i = 0; i < decorPool.Length; i++)
            {
                if (!decorPool[i].Visible)
                    break;

                if (movX != 0 && hitX == null)
                {
                    var rect = MyHero.HitRect;
                    rect.X += movX;
                    if (decorPool[i].HitRect.Intersects(rect))
                        hitX = decorPool[i];
                }
                if (movY != 0 && hitY == null)
                {
                    var rect = MyHero.HitRect;
                    rect.Y += movY;
                    if (decorPool[i].HitRect.Intersects(rect))
                        hitY = decorPool[i];
                }
                if (hitX != null && hitY != null)
                    break;
            }

            var campos = Camera2D.MyCam.Position;
            if (movX != 0)
            {
                if (hitX == null)
                    campos.X += movX;
                else
                {
                    campos.X += movX > 0
                                    ? (MyHero.HitRect.X - (hitX.HitRect.X - MyHero.HitRect.Width))
                                    : ((hitX.HitRect.X + hitX.HitRect.Width) - MyHero.HitRect.X);
                }
            }

            if (movY != 0)
            {
                if (hitY == null)
                    campos.Y += movY;
                else
                {
                    campos.Y += movY > 0
                                    ? (MyHero.HitRect.Y - (hitY.HitRect.Y - MyHero.HitRect.Height))
                                    : ((hitY.HitRect.Y + hitY.HitRect.Height) - MyHero.HitRect.Y);
                }
            }

            var isMoving = campos != Camera2D.MyCam.Position;
            Camera2D.MyCam.Position = campos;
            MyHero.Update(isMoving);
        }