Пример #1
0
        public Projectile(InputAction inputAction, float angle, Vector2 location, ContentManager content, GraphicsDeviceManager graphics, PlayerIndex playerIndex, Rectangle boundary, int playerChoice, bool fromSkull)
        {
            this.content      = content;
            this.graphics     = graphics;
            this.playerChoice = playerChoice;
            originalOwner     = playerChoice;
            collisionLocation = CollidedWith.None;
            this.inputAction  = inputAction;
            this.fromSkull    = fromSkull;
            if (this.inputAction == InputAction.Shoot)
            {
                chargeShot            = false;
                originalSpeed         = 4;
                speed                 = 4;
                fireball              = new Animation(skullBulletT, 1, 1, angle);
                fireball.currentFrame = 1;
            }

            wallBounce = new Animation(wallBounceT, 2, 6);
            wallBounce.currentFrame = 10;

            reversing    = false;
            accelerating = false;

            this.location    = new Vector2(location.X, location.Y);
            this.angle       = angle;
            this.playerIndex = playerIndex;

            if (location.X + fireball.width > boundary.Right)
            {
                this.location.X = boundary.Right - fireball.width;
            }
            else if (location.X < boundary.Left)
            {
                this.location.X = boundary.Left;
            }
            bounds        = new Rectangle((int)this.location.X, (int)this.location.Y, (int)fireball.width, (int)fireball.height);
            this.boundary = boundary;

            if (playerIndex == PlayerIndex.One)
            {
                direction = new Vector2((float)Math.Cos(angle + (Math.PI / -2f)), (float)Math.Sin(angle + (Math.PI / -2f)));
            }
            else if (playerIndex == PlayerIndex.Two)
            {
                direction = new Vector2((float)Math.Cos(angle + (Math.PI / 2)), (float)Math.Sin(angle + (Math.PI / 2)));
            }
            direction.Normalize();
            recentlyReflected = 0;

            aiMark      = false;
            removalPing = false;
        }
Пример #2
0
 public void CollisionSwitch()
 {
     collisionLocation = CollidedWith.None;
     if (bounds.Top <= boundary.Top)
     {
         collisionLocation = CollidedWith.TopGoal;
     }
     if (bounds.Bottom >= boundary.Bottom)
     {
         collisionLocation = CollidedWith.BottomGoal;
     }
     if (bounds.Left <= boundary.Left)
     {
         leftOrRight       = new Vector2(bounds.Left, bounds.Center.Y - wallBounce.width / 2);
         collisionLocation = CollidedWith.Left;
     }
     if (bounds.Right >= boundary.Right)
     {
         leftOrRight       = new Vector2(bounds.Right - wallBounce.width, bounds.Center.Y - wallBounce.width / 2);
         collisionLocation = CollidedWith.Right;
     }
 }
Пример #3
0
Файл: Game.cs Проект: tilpner/hp
        public BBAA ResolveCollision(BBAA o, out CollidedWith flags) {
            flags = 0;
            o.Check();
            // mutation of a BBAA without explicit copy is acceptable, it's a struct.
            // iterate tiles that overlap with "o"

            // TODO: Check less tiles. s/2/1/ or s/2/0/ might do.
            int ULy = (int)(o.UL.Y - 2).Clamp(0, Height);
            int ULx = (int)(o.UL.X - 2).Clamp(0, Width);
            int LRy = (int)(o.LR.Y + 2).Clamp(0, Height);
            int LRx = (int)(o.LR.X + 2).Clamp(0, Width);
            
            for (int y = ULy; y < LRy; y++) {
                for (int x = ULx; x < LRx; x++) {
                    
                    var tile = this[x, y];
                    if (tile.Type != null && tile.Type.Collider) {
                        // TODO: less checks
                        var intersection = o.Check().Intersect(new BBAA(v2f(x, y), v2f(x + 1, y + 1))).Check();
                        Vector2f iSize = intersection.Size, oSize = o.Size;
                        Vector2f iCenter = intersection.Center, oCenter = o.Center;

                        if (iSize.Len() > 0) {
                            // only respond to force on the shallow axis
                            if (iSize.X < iSize.Y) {
                                if (iCenter.X < oCenter.X) {
                                    flags |= CollidedWith.Left;
                                    o.Position = v2f(intersection.LR.X, o.UL.Y);
                                } else {
                                    flags |= CollidedWith.Right;
                                    o.Position = v2f(intersection.UL.X - o.Size.X, o.UL.Y);
                                }
                            } else {
                                if (iCenter.Y < oCenter.Y) {
                                    flags |= CollidedWith.Top;
                                    o.Position = v2f(o.UL.X, intersection.LR.Y);
                                } else {
                                    flags |= CollidedWith.Bottom;
                                    o.Position = v2f(o.UL.X, intersection.UL.Y - o.Size.Y);
                                }
                            }
                        }
                    }
                }
            }

            return o;
        }
Пример #4
0
        public Projectile(InputAction inputAction, float angle, Vector2 location, GraphicsDeviceManager graphics, PlayerIndex playerIndex, Rectangle boundary, int playerChoice)
        {
            this.graphics     = graphics;
            this.playerChoice = playerChoice;
            originalOwner     = playerChoice;
            collisionLocation = CollidedWith.None;
            this.inputAction  = inputAction;
            if (this.inputAction == InputAction.Shoot)
            {
                chargeShot    = false;
                originalSpeed = 2;
                speed         = 2;
                fireball      = new Animation(fireballT, 2, 3, angle);
                trails.Add(new Animation(fireballTrailT1, 2, 3, angle));
                trails.Add(new Animation(fireballTrailT1, 2, 3, angle));
                fireball.currentFrame  = 2;
                trails[0].currentFrame = 1;
                trails[1].currentFrame = 0;
            }
            if (this.inputAction == InputAction.ChargeShot)
            {
                chargeShot = true;
                if (originalOwner == 1)
                {
                    fireball = new Animation(buffWizardChargeShotT, 2, 3, angle);
                }
                if (originalOwner == 2)
                {
                    fireball = new Animation(tiredWizardChargeShotT, 2, 3, angle);
                }
                originalSpeed = 4;
                speed         = 4;
            }

            wallBounce = new Animation(wallBounceT, 2, 6);
            wallBounce.currentFrame = 10;

            reversing    = false;
            accelerating = false;

            this.location    = location;
            this.angle       = angle;
            this.playerIndex = playerIndex;

            if (playerIndex == PlayerIndex.One)
            {
                this.location.Y -= fireball.height;
                this.location.X -= fireball.width / 2;
            }
            else if (playerIndex == PlayerIndex.Two)
            {
                this.location.X -= fireball.width / 2;
            }

            if (location.X + fireball.width > boundary.Right)
            {
                this.location.X = boundary.Right - fireball.width;
            }
            else if (location.X < boundary.Left)
            {
                this.location.X = boundary.Left;
            }
            bounds        = new Rectangle((int)this.location.X, (int)this.location.Y, (int)fireball.width, (int)fireball.height);
            this.boundary = boundary;

            if (playerIndex == PlayerIndex.One)
            {
                direction = new Vector2((float)Math.Cos(angle + (Math.PI / -2f)), (float)Math.Sin(angle + (Math.PI / -2f)));
            }
            else if (playerIndex == PlayerIndex.Two)
            {
                direction = new Vector2((float)Math.Cos(angle + (Math.PI / 2)), (float)Math.Sin(angle + (Math.PI / 2)));
            }
            direction.Normalize();
            recentlyReflected = 0;

            aiMark         = false;
            removalPing    = false;
            tempNoCollison = false;
        }
 public override void ApplyMotion(float deltaTime, Vector3 additionalLinearVelocity)
 {
     Position.Value = Position.Value + (LinearVelocity + additionalLinearVelocity) * deltaTime;
     Rotation.Value = Quaternion.Euler(Rotation.Value.eulerAngles + AngularVelocity * deltaTime);
     CollidedWith.ObserveEveryValueChanged(value => value.Value).Subscribe(OnCollidedWith).AddTo(_disposables);
 }