Ejemplo n.º 1
0
 public void Move(MovebleObj obj, int delta)
 {
     if (obj.OldX < obj.X)
     {
         mapGraphics.FillRectangle(Brushes.Black, obj.OldX * TanksForm.sizeCell + delta - 5, obj.OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         mapGraphics.DrawImage(obj.Img, obj.OldX * TanksForm.sizeCell + delta, obj.OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         return;
     }
     if (obj.OldX > obj.X)
     {
         mapGraphics.FillRectangle(Brushes.Black, obj.OldX * TanksForm.sizeCell - delta + 5, obj.OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         mapGraphics.DrawImage(obj.Img, obj.OldX * TanksForm.sizeCell - delta, obj.OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         return;
     }
     if (obj.OldY < obj.Y)
     {
         mapGraphics.FillRectangle(Brushes.Black, obj.OldX * TanksForm.sizeCell, obj.OldY * TanksForm.sizeCell + delta - 5, TanksForm.sizeCell, TanksForm.sizeCell);
         mapGraphics.DrawImage(obj.Img, obj.OldX * TanksForm.sizeCell, obj.OldY * TanksForm.sizeCell + delta, TanksForm.sizeCell, TanksForm.sizeCell);
         return;
     }
     if (obj.OldY > obj.Y)
     {
         mapGraphics.FillRectangle(Brushes.Black, obj.OldX * TanksForm.sizeCell, obj.OldY * TanksForm.sizeCell - delta + 5, TanksForm.sizeCell, TanksForm.sizeCell);
         mapGraphics.DrawImage(obj.Img, obj.OldX * TanksForm.sizeCell, obj.OldY * TanksForm.sizeCell - delta, TanksForm.sizeCell, TanksForm.sizeCell);
         return;
     }
     if (obj.OldY == obj.Y && obj.OldX > obj.X)
     {
         mapGraphics.FillRectangle(Brushes.Black, obj.OldX * TanksForm.sizeCell, obj.Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         mapGraphics.DrawImage(obj.Img, obj.X * TanksForm.sizeCell, obj.Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell);
         return;
     }
 }
Ejemplo n.º 2
0
        public void CreateShotKolobok(MovebleObj sender)
        {
            switch (sender.DirectionTo)
            {
            case (int)Direction.Down:
            {
                ShotsKolobok.Add(new Shot(sender.X, sender.Y + 1, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Left:
            {
                ShotsKolobok.Add(new Shot(sender.X - 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Right:
            {
                ShotsKolobok.Add(new Shot(sender.X + 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Up:
            {
                ShotsKolobok.Add(new Shot(sender.X, sender.Y - 1, sender.DirectionTo, sender));
                break;
            }

            default:
                break;
            }
            for (int i = 0; i < ShotsKolobok.Count - 1; i++)
            {
                if (ShotsKolobok.Last().CollidesWith(ShotsKolobok[i]))
                {
                    ShotsKolobok.RemoveAt(ShotsKolobok.Count - 1);
                    return;
                }
            }
            if (ShotsKolobok.Last().CollidesWithWalls(Walls))
            {
                ShotsKolobok.RemoveAt(ShotsKolobok.Count - 1);
                return;
            }
        }
Ejemplo n.º 3
0
        public void CreateShotTank(MovebleObj sender)
        {
            switch (sender.DirectionTo)
            {
            case (int)Direction.Down:
            {
                ShotsTanks.Add(new Shot(sender.X, sender.Y + 1, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Left:
            {
                ShotsTanks.Add(new Shot(sender.X - 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Right:
            {
                ShotsTanks.Add(new Shot(sender.X + 1, sender.Y, sender.DirectionTo, sender));
                break;
            }

            case (int)Direction.Up:
            {
                ShotsTanks.Add(new Shot(sender.X, sender.Y - 1, sender.DirectionTo, sender));
                break;
            }

            default:
                break;
            }
            if (ShotsTanks.Last().CollidesWithWalls(Walls))
            {
                ShotsTanks.RemoveAt(ShotsTanks.Count - 1);
            }
        }
Ejemplo n.º 4
0
 public Shot(int x, int y, int direction, MovebleObj sender) : base(x, y, direction)
 {
     OldX   = x;
     OldY   = y;
     Sender = sender;
 }