Exemple #1
0
        public TopdownHero(MainGame game, Vector2 position, Vector2 size, Vector2 bounce, float friction, float gravityMultiplier = 1)
        {
            Game          = game;
            Guid          = new Guid();
            SpriteType    = SpriteTypes.TopdownHero;
            FaceDirection = Vector2.UnitX;

            //Default pistol
            CurrentWeapons.Add(new Weapon()
            {
                BulletConfig = MainGame.BulletConfigs[WeaponTypes.Pistol],
                Type         = WeaponTypes.Pistol,
                Ammo         = int.MaxValue
            });

            Body = new Body(this)
            {
                MaxVelocity = new Vector2(3f, 3f),
                Enabled     = true,
                Position    = position,
                Radius      = size.Y / 2,
                Game        = game,
                Gravity     = World.Gravity * gravityMultiplier,
                Bounce      = bounce,
                Friction    = friction,
                Static      = false,
                Shape       = Shape.Circle,
                Mass        = 50
            };
            CurrentNode = new Node()
            {
                Coordinate = new Vector2(position.X / 40, position.Y / 40)
            };
            PreviousNode = new Node()
            {
                Coordinate = new Vector2(position.X / 40, position.Y / 40)
            };
        }
Exemple #2
0
        public override void Collisions()
        {
            Vector2 result   = new Vector2();
            float   distance = 0;

            //Loop through each sprite
            for (var i = 0; i < MainGame.Sprites.Count; i++)
            {
                var s = MainGame.Sprites[i];
                if (!s.Equals(this) && World.Intersects(Body, s.Body, ref result, ref distance))
                {
                    //Customize our behaviour based on different sprite types
                    if (s.SpriteType == SpriteTypes.Portal)
                    {
                        MainGame.SwitchMaps = true;
                    }
                    if (s.SpriteType == SpriteTypes.Powerup)
                    {
                        //Apply the powerup to the player
                        var p = (Powerup)s;
                        CurrentWeapons[SelectedWeapon].Ammo += p.PowerupConfig.Ammo;
                        Health             += p.PowerupConfig.Health;
                        Body.MaxVelocity.X += p.PowerupConfig.Speed;
                        Body.MaxVelocity.Y += p.PowerupConfig.Speed;
                        //add weapons or more ammo
                        if (p.PowerupConfig.PowerupType == PowerupType.RPG)
                        {
                            if (CurrentWeapons.All(x => x.Type != WeaponTypes.RPG))
                            {
                                CurrentWeapons.Add(new Weapon()
                                {
                                    BulletConfig = MainGame.BulletConfigs[WeaponTypes.RPG],
                                    Type         = WeaponTypes.RPG,
                                    Ammo         = p.PowerupConfig.Ammo
                                });
                            }
                            else
                            {
                                CurrentWeapons.First(x => x.Type == WeaponTypes.RPG).Ammo = p.PowerupConfig.Ammo;
                            }
                        }

                        if (p.PowerupConfig.PowerupType == PowerupType.SMG)
                        {
                            if (CurrentWeapons.All(x => x.Type != WeaponTypes.SMG))
                            {
                                CurrentWeapons.Add(new Weapon()
                                {
                                    BulletConfig = MainGame.BulletConfigs[WeaponTypes.SMG],
                                    Type         = WeaponTypes.SMG,
                                    Ammo         = p.PowerupConfig.Ammo
                                });
                            }
                            else
                            {
                                CurrentWeapons.First(x => x.Type == WeaponTypes.SMG).Ammo = p.PowerupConfig.Ammo;
                            }
                        }
                        MainGame.Sprites.Remove(s);
                    }
                    //Take damage from enemy each frame.
                    if (s.SpriteType == SpriteTypes.Enemy)
                    {
                        Health -= 2;
                    }
                }
            }
        }