Beispiel #1
0
        public Pilot(int x, int y, string path) : base(x, y)
        {
            isEntered = true;
            _texture  = new Sprite(path);
            bodyTank  = new TankBody(150, 150, "tankBlue.png");
            _hitbox   = new AABB(_texture.Width, _texture.Height);
            AddChild(_texture);
            AddChild(_hitbox);
            AddChild(bodyTank);

            OnUpdate += TurnLeft;
            OnUpdate += TurnRight;

            OnUpdate += MoveUp;
            OnUpdate += MoveDown;
            OnUpdate += MoveLeft;
            OnUpdate += MoveRight;

            OnUpdate += PilotReset;
            OnUpdate += Braking;

            OnUpdate += EnterTank;
            OnUpdate += ExitTank;

            OnUpdate += WrapScreen;

            OnDraw += PositionFinder;
        }
Beispiel #2
0
        // Checks to see if bullets hit the pilot or Pilot's Tank
        public void HitCollision(float deltaTime)
        {
            foreach (Actor checkHit in Parent.GetChildren)
            {
                if (checkHit is Pilot)
                {
                    Pilot pilot = (Pilot)checkHit;

                    foreach (Actor pilotInside in pilot.GetChildren)
                    {
                        if (pilotInside is TankBody)
                        {
                            TankBody bodyTank = (TankBody)pilotInside;
                            if (bodyTank.DetectCollision(_hitboxBullet))
                            {
                                pilot.ExitTank(deltaTime);

                                RemoveChild(_hitboxBullet);
                                RemoveChild(_textureBullet);
                                if (Parent != null)
                                {
                                    Parent.RemoveChild(this);
                                }
                            }
                        }
                    }
                    if (pilot.DetectCollision(_hitboxBullet))
                    {
                        RemoveChild(_hitboxBullet);
                        RemoveChild(_textureBullet);
                        if (Parent != null)
                        {
                            Parent.RemoveChild(this);
                        }
                    }
                }

                if (checkHit is TankBody)
                {
                    TankBody bodyTank = (TankBody)checkHit;
                    if (bodyTank.DetectCollision(_hitboxBullet))
                    {
                        RemoveChild(bodyTank);
                        Rotate(-GetRotation());

                        RemoveChild(_hitboxBullet);
                        RemoveChild(_textureBullet);
                        if (Parent != null)
                        {
                            Parent.RemoveChild(this);
                        }
                    }
                }
            }
        }