public bool CheckPlatformCollision(SpriteAccess OtherSprite, float OtherMoreX, float OtherMoreY, ref float OtherCurrX, ref float OtherCurrY)
        {
            bool  HitPlatform     = false;
            float NewOtherSpriteY = 0.0f;

            //See if the sprite hit any of the platforms
            foreach (SpriteAccess CurrPlatform in this.Platforms)
            {
                if (CurrPlatform.CollisionRects.CheckEnvironmentRectAgainst(OtherSprite, CurrPlatform.Frame, CurrPlatform.X, CurrPlatform.Y, ref NewOtherSpriteY, OtherMoreX, OtherMoreY))
                {
                    //The sprite hit, so move its bottom to the top of the platform +1
                    OtherCurrX = OtherSprite.X + OtherMoreX;
                    OtherCurrY = NewOtherSpriteY;

                    HitPlatform = true;
                    break;
                }
            }

            //The sprite hit nothing, so move it normally
            if (HitPlatform == false)
            {
                OtherCurrX = OtherSprite.X + OtherMoreX;
                OtherCurrY = OtherSprite.Y + OtherMoreY;
            }

            return(HitPlatform);
        }
            private void Initialize(Direct3D.Device NewParentDevice, float NewX, float NewY, float NewZ)
            {
                //recreate the master sprites if they dont exist
                if (BubbleAccess.MasterBubbleSprite == null)
                {
                    BubbleAccess.MasterBubbleSprite = new SpriteAccess(NewParentDevice, GameConfig.Files.Bubbles, 0, 0, 0, 32, 32, 64, 64, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
                }

                if (BubbleAccess.MasterItemSprite == null)
                {
                    BubbleAccess.MasterItemSprite = new SpriteAccess(NewParentDevice, GameConfig.Files.Items, 0, 0, 0, 32, 32, 128, 128, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
                }

                this.X = NewX;
                this.Y = NewY;
                this.Z = NewZ;

                //have this bubble sprites refer to the master sprites
                this.BubbleSprite = new SpriteAccess(BubbleAccess.MasterBubbleSprite, this.X, this.Y, this.Z);
                this.ItemSprite   = new SpriteAccess(BubbleAccess.MasterItemSprite, this.X, this.Y, this.Z);

                this._State = BubbleState.NeedsFreshAngle;

                this._Item            = (ItemType)(int)((1.0f + (float)ItemType.Warp) * SpaceAndTime.RandomPercent);
                this.ItemSprite.Frame = (int)this._Item;
            }
        public bool CheckPlatformCollisionAndKillPlatforms(SpriteAccess OtherSprite, float OtherMoreX, float OtherMoreY, ref float OtherCurrX, ref float OtherCurrY)
        {
            bool  HitPlatform     = false;
            float NewOtherSpriteY = 0.0f;

            //See if the sprite hit any of the platforms
            for (int i = 0; i < this.Platforms.Count; i++)
            {
                if (((SpriteAccess)this.Platforms[i]).CollisionRects.CheckEnvironmentRectAgainst(OtherSprite, ((SpriteAccess)this.Platforms[i]).Frame, ((SpriteAccess)this.Platforms[i]).X, ((SpriteAccess)this.Platforms[i]).Y, ref NewOtherSpriteY, OtherMoreX, OtherMoreY))
                {
                    //The sprite hit, so move its bottom to the top of the platform +1
                    OtherCurrX = OtherSprite.X + OtherMoreX;
                    OtherCurrY = NewOtherSpriteY;

                    //remove the platform that was hit
                    this.Platforms.RemoveAt(i);

                    HitPlatform = true;
                    break;
                }
            }

            //The sprite hit nothing, so move it normally
            if (HitPlatform == false)
            {
                OtherCurrX = OtherSprite.X + OtherMoreX;
                OtherCurrY = OtherSprite.Y + OtherMoreY;
            }

            return(HitPlatform);
        }
        public bool CanGrabPoll(SpriteAccess OtherSprite)
        {
            bool HitPoll = false;

            //See if the sprite hit any of the Polls
            foreach (PollAccess CurrPoll in this.Polls)
            {
                //If player close to poll x
                if (OtherSprite.X < CurrPoll.X + 0.1f && OtherSprite.X > CurrPoll.X - 0.1f)
                {
                    float[] OtherSpriteRectSides = OtherSprite.CollisionRects.GetIndex(OtherSprite.Frame);
                    float[] CurrPollRectSides    = CurrPoll.CollisionRects.GetIndex(CurrPoll.Frame);

                    float OtherSpriteTop    = OtherSprite.Y + OtherSpriteRectSides[1];
                    float OtherSpriteBottom = OtherSprite.Y - OtherSpriteRectSides[3];
                    float CurrPollTop       = CurrPoll.Y + CurrPollRectSides[1];
                    float CurrPollBottom    = CurrPoll.Y - CurrPollRectSides[3];

                    //If player close to poll y

                    //poll of type center
                    if (CurrPoll.TypeOfPoll == PollType.Center)
                    {
                        if ((OtherSpriteTop >= CurrPollTop && OtherSpriteBottom <= CurrPollTop) ||
                            (OtherSpriteTop <= CurrPollTop && OtherSpriteBottom >= CurrPollBottom) ||
                            (OtherSpriteTop >= CurrPollBottom && OtherSpriteBottom <= CurrPollBottom)
                            )
                        {
                            HitPoll = true;
                            break;
                        }
                    }
                    //poll of type top
                    else if (CurrPoll.TypeOfPoll == PollType.Top)
                    {
                        if ((OtherSpriteTop <= CurrPollTop && OtherSpriteBottom >= CurrPollBottom) ||
                            (OtherSpriteTop >= CurrPollBottom && OtherSpriteBottom <= CurrPollBottom)
                            )
                        {
                            HitPoll = true;
                            break;
                        }
                    }
                    //poll of type bottom
                    else if (CurrPoll.TypeOfPoll == PollType.Bottom)
                    {
                        if ((OtherSpriteTop >= CurrPollTop && OtherSpriteBottom <= CurrPollTop) ||
                            (OtherSpriteTop <= CurrPollTop && OtherSpriteBottom >= CurrPollBottom)
                            )
                        {
                            HitPoll = true;
                            break;
                        }
                    }
                }
            }

            return(HitPoll);
        }
Пример #5
0
        //Sprite that refernces another sprite's texture
        public SpriteAccess(SpriteAccess NewParentSprite, float NewX, float NewY, float NewZ)
        {
            this.ParentSprite = (SpriteAccess)NewParentSprite;
            this.Image        = null;
            this.ParentDevice = this.ParentSprite.ParentDevice;
            this.MaskColor    = this.ParentSprite.MaskColor;

            this.textures       = this.ParentSprite.textures;
            this.CollisionRects = this.ParentSprite.CollisionRects;

            this.Initialize(NewX, NewY, NewZ, ParentSprite.Width, ParentSprite.Height, ParentSprite.SheetWidth, ParentSprite.SheetHeight);
        }
        public float GetPollCenter(SpriteAccess OtherSprite)
        {
            float RetVal = 0.0f;

            //See if the sprite hit any of the Polls
            foreach (SpriteAccess CurrPoll in this.Polls)
            {
                if (OtherSprite.X <= CurrPoll.X + 0.1 && OtherSprite.X >= CurrPoll.X - 0.1)
                {
                    //The sprite hit, so move it to the center of the poll
                    RetVal = CurrPoll.X;
                    break;
                }
            }

            return(RetVal);
        }
        public static ArrayList AllWeapons = new ArrayList();         //holds refs to all weapons

        //These are used to manage all the weapons in the game
        public static void CreateWeapon(Direct3D.Device ParentDevice, WeaponType NewTypeOfWeapon, float SourceX, float SourceY, float SourceZ, bool SourceFaceLeft)
        {
            //Create master sprites if they dont exist
            if (WeaponManagerAccess.MasterGrenadeSprite == null)
            {
                WeaponManagerAccess.MasterGrenadeSprite = new SpriteAccess(ParentDevice, GameConfig.Files.Grenade, 0, 0, 0, 32, 32, 64, 64, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
            }
            if (WeaponManagerAccess.MasterSlideMineSprite == null)
            {
                WeaponManagerAccess.MasterSlideMineSprite = new SpriteAccess(ParentDevice, GameConfig.Files.SlideMine, 0, 0, 0, 32, 32, 64, 64, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
            }
            if (WeaponManagerAccess.MasterMineSprite == null)
            {
                WeaponManagerAccess.MasterMineSprite = new SpriteAccess(ParentDevice, GameConfig.Files.Mine, 0, 0, 0, 32, 32, 64, 64, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
            }
            if (WeaponManagerAccess.MasterBulletSprite == null)
            {
                WeaponManagerAccess.MasterBulletSprite = new SpriteAccess(ParentDevice, GameConfig.Files.Bullet, 0, 0, 0, 256, 256, 256, 256, Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), 0, 0);
            }

            //Create new weapon
            WeaponAccess NewWeapon = null;

            if (NewTypeOfWeapon == WeaponType.Grenade)
            {
                NewWeapon = new GrenadeAccess(WeaponManagerAccess.MasterGrenadeSprite, SourceX, SourceY, SourceZ, SourceFaceLeft);
            }
            else if (NewTypeOfWeapon == WeaponType.Mine)
            {
                NewWeapon = new MineAccess(WeaponManagerAccess.MasterMineSprite, SourceX, SourceY, SourceZ, SourceFaceLeft);
            }
            else if (NewTypeOfWeapon == WeaponType.SlideMine)
            {
                NewWeapon = new SlideMineAccess(WeaponManagerAccess.MasterSlideMineSprite, SourceX, SourceY, SourceZ, SourceFaceLeft);
            }
            else if (NewTypeOfWeapon == WeaponType.Bullet)
            {
                NewWeapon = new BulletAccess(WeaponManagerAccess.MasterBulletSprite, SourceX, SourceY, SourceZ, SourceFaceLeft);
            }

            //Save ref to new weapon
            WeaponManagerAccess.AllWeapons.Add(NewWeapon);
        }
Пример #8
0
        private void Draw()
        {
            this.Screen.StartDraw();

            this.Background.Draw();
            this.Screen.device.RenderState.CullMode = Microsoft.DirectX.Direct3D.Cull.None;
            SpriteAccess.DrawSpriteArray(this.PlayableCharacters);

            WeaponManagerAccess.DrawWeapons();

            this.BubbleManager.DrawBubbles();

            this.Screen.Particles.Draw();

            this.Writer.WriteScoreLeft("Player One Score: " + this.PlayableCharacters[1].DeathCount.ToString());
            this.Writer.WriteScoreRight("Player Two Score: " + this.PlayableCharacters[0].DeathCount.ToString());

            this.Screen.EndDraw();
        }
        public GrenadeAccess(SpriteAccess ParentSprite, float SourceX, float SourceY, float SourceZ, bool SourceFaceLeft)
            : base(ParentSprite, WeaponType.Grenade, SourceX, SourceY, SourceZ, SourceFaceLeft)
        {
            //Get offset for weapon x, y, and z
            if (SourceFaceLeft == true)
            {
                this.X = SourceX + 0.1f;
            }
            else
            {
                this.X = SourceX - 0.1f;
            }

            this.Y = SourceY;
            this.Z = SourceZ;

            //Get velocity
            this.VelocityX = 0.0f;
            this.VelocityY = 0.1f;
        }
        /// <summary>
        /// Used to detect collisions between the background and a sprite. Checks for collisions
        /// between the bottom of the sprite and the top of the background. Only returns a bool
        /// indicating if there was a collision.
        /// </summary>
        public bool CheckEnvironmentRectAgainst(SpriteAccess OtherSprite, int CurrFrame, float CurrX, float CurrY, ref float NewOtherSpriteY, float OtherSpriteMoreX, float OtherSpriteMoreY)
        {
            bool RetVal = false;

            //Get the locations of our rectange's sides in floats
            float[] RectangleCollisions = (float[])this.RectangleMatrix[CurrFrame];
            float   RectLeft            = CurrX + RectangleCollisions[0];
            float   RectTop             = CurrY + RectangleCollisions[1];
            float   RectRight           = CurrX - RectangleCollisions[2];
            float   RectBottom          = CurrY - RectangleCollisions[3];

            //Get the locations the other rectange's sides in floats
            float[] OtherRectangleCollisions = (float[])OtherSprite.CollisionRects.GetIndex(OtherSprite.Frame);
            float   OtherRectLeft            = OtherSprite.X + OtherRectangleCollisions[0];
            float   OtherRectTop             = OtherSprite.Y + OtherRectangleCollisions[1];
            float   OtherRectRight           = OtherSprite.X - OtherRectangleCollisions[2];
            float   OtherRectBottom          = OtherSprite.Y - OtherRectangleCollisions[3];

            //if this frame's rect is inside the other rect, there is a collision
            if (
                RectTop <= OtherRectBottom &&
                RectTop >= OtherRectBottom + OtherSpriteMoreY &&
                (
                    (OtherRectRight <= RectLeft && OtherRectRight >= RectRight) ||
                    (OtherRectLeft >= RectRight && OtherRectLeft <= RectLeft)
                )
                )
            {
                RetVal = true;

                //The OtherSprite's new Y will be
                // the environment's top + the distance from the
                // sprite's bottom to it's center.
                NewOtherSpriteY = RectTop + OtherRectangleCollisions[3];
            }

            return(RetVal);
        }
 public WeaponAccess(SpriteAccess ParentSprite, WeaponType NewTypeOfWeapon, float SourceX, float SourceY, float SourceZ, bool SourceFaceLeft)
     : base(ParentSprite, SourceX, SourceY, SourceZ)
 {
     this._TypeOfWeapon = NewTypeOfWeapon;
     this._FaceLeft     = SourceFaceLeft;
 }
Пример #12
0
        public BackgroundAccess(Direct3D.Device NewParentDevice)
        {
            float PlatformWidthInFloats = SpaceAndTime.LengthFrom2DTo3D(64.0f);
            float CurrColmn             = 2.0f;

            this.Platforms = new ArrayList();
            SpriteAccess TemplatePlatform = new SpriteAccess(NewParentDevice, GameConfig.Files.Platform, 2.0f - (-1 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation, 64, 64, 64, 64, Color.FromArgb(0x00, 0x00, 0xFF, 0x00), 0, 0);

            this.Platforms.Add(TemplatePlatform);
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (1 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (6 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (7 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (8 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -1.4f, SpaceAndTime.SpriteZLocation));

            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (-1 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (1 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (2.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (3.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (4.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (6 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (8 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), -.1f, SpaceAndTime.SpriteZLocation));

            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (-.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (0.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (1.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (3.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (5.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (6.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));
            this.Platforms.Add(new SpriteAccess(TemplatePlatform, 2.0f - (7.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), 1.2f, SpaceAndTime.SpriteZLocation));

            //Set location of platforms
            foreach (SpriteAccess CurrPlatform in this.Platforms)
            {
                CurrPlatform.Location = GameConfig.Locations.Platforms;
            }

            //polls
            float        CurrPollY  = 0.46f;
            SpriteAccess PollTop    = new SpriteAccess(NewParentDevice, GameConfig.Files.PollTop, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, 64, 64, 64, 64, Color.FromArgb(0x00, 0x00, 0xFF, 0x00), 0, 0);
            SpriteAccess PollCenter = new SpriteAccess(NewParentDevice, GameConfig.Files.PollCenter, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, 64, 64, 64, 64, Color.FromArgb(0x00, 0x00, 0xFF, 0x00), 0, 0);
            SpriteAccess PollBottom = new SpriteAccess(NewParentDevice, GameConfig.Files.PollBottom, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, 64, 64, 64, 64, Color.FromArgb(0x00, 0x00, 0xFF, 0x00), 0, 0);

            this.Polls = new ArrayList();
            this.Polls.Add(new PollAccess(PollTop, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Top));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, CurrColmn, CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollBottom, 2.0f - (0 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Bottom));

            CurrPollY = 0.46f;
            this.Polls.Add(new PollAccess(PollTop, 2.0f - (7 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Top));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (7 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (7 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollBottom, 2.0f - (7 * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Bottom));

            CurrPollY = 1.76f;
            this.Polls.Add(new PollAccess(PollTop, 2.0f - (2.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Top));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (2.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (2.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollBottom, 2.0f - (2.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Bottom));

            CurrPollY = 1.76f;
            this.Polls.Add(new PollAccess(PollTop, 2.0f - (4.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Top));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (4.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollCenter, 2.0f - (4.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Center));

            CurrPollY -= PlatformWidthInFloats;
            this.Polls.Add(new PollAccess(PollBottom, 2.0f - (4.5f * SpaceAndTime.LengthFrom2DTo3D(64.0f)), CurrPollY, SpaceAndTime.SpriteZLocation, PollType.Bottom));

            //Set location of polls
            foreach (SpriteAccess CurrPoll in this.Polls)
            {
                CurrPoll.Location = GameConfig.Locations.Polls;
            }

            Direct3D.Device ParentDevice = NewParentDevice;
        }
Пример #13
0
 public PollAccess(SpriteAccess ParentSprite, float NewX, float NewY, float NewZ, PollType NewTypeOfPoll)
     : base(ParentSprite, NewX, NewY, NewZ)
 {
     this.TypeOfPoll = NewTypeOfPoll;
 }
        /// <summary>
        /// Used to detect if there has been a collision between two objects such as sprites.
        /// </summary>
        public CollisionRectAccess.HitSide CheckObjectRectAgainst(SpriteAccess OtherObject, int CurrFrame, float CurrX, float CurrY)
        {
            CollisionRectAccess.HitSide RetVal = HitSide.None;

            //Get the locations of our rectange's sides in floats
            float[] RectangleCollisions = (float[])this.RectangleMatrix[CurrFrame];
            float   RectLeft            = CurrX + RectangleCollisions[0];
            float   RectTop             = CurrY + RectangleCollisions[1];
            float   RectRight           = CurrX - RectangleCollisions[2];
            float   RectBottom          = CurrY - RectangleCollisions[3];

            //Get the locations the other rectange's sides in floats
            float[] OtherRectangleCollisions = (float[])OtherObject.CollisionRects.GetIndex(OtherObject.Frame);
            float   OtherRectLeft            = OtherObject.X + OtherRectangleCollisions[0];
            float   OtherRectTop             = OtherObject.Y + OtherRectangleCollisions[1];
            float   OtherRectRight           = OtherObject.X - OtherRectangleCollisions[2];
            float   OtherRectBottom          = OtherObject.Y - OtherRectangleCollisions[3];

            //Check each side of the rect to see if it is within the other rect
            bool LeftInBounds   = RectLeft >= OtherRectRight && RectRight <= OtherRectLeft;
            bool TopInBounds    = RectTop >= OtherRectTop && RectBottom <= OtherRectTop;
            bool RightInBounds  = RectRight >= OtherRectLeft && RectRight <= OtherRectRight;
            bool BottomInBounds = RectTop >= OtherRectBottom && RectBottom <= OtherRectBottom;

            //Check to see if both sides are in the rect
            //If they are pick one of the sides only depending on which is deeper
            if (RectTop <= OtherRectTop && RectBottom >= OtherRectBottom)
            {
                if (OtherRectTop - RectTop > RectBottom - OtherRectBottom)
                {
                    BottomInBounds = true;
                }
                else
                {
                    TopInBounds = true;
                }
            }
            if (RectLeft <= OtherRectLeft && RectRight >= OtherRectRight)
            {
                if (OtherRectLeft - RectLeft > RectRight - OtherRectRight)
                {
                    LeftInBounds = true;
                }
                else
                {
                    RightInBounds = true;
                }
            }


            //if this frame's rect is inside the other rect, there is a collision
            if (LeftInBounds && (BottomInBounds || TopInBounds))
            {
                if (BottomInBounds)
                {
                    RetVal = HitSide.BottomLeft;
                }
                else if (TopInBounds)
                {
                    RetVal = HitSide.TopLeft;
                }
            }
            else if (RightInBounds && (BottomInBounds || TopInBounds))
            {
                if (TopInBounds)
                {
                    RetVal = HitSide.TopRight;
                }
                else
                {
                    RetVal = HitSide.BottomRight;
                }
            }

            return(RetVal);
        }
 //Sprite that refernces another sprites texture
 public PlayableCharacterAccess(SpriteAccess ParentSprite, float NewX, float NewY, float NewZ)
     : base(ParentSprite, NewX, NewY, NewZ)
 {
     this.Initialize();
 }