コード例 #1
0
        List <TmxLayerTile> GetTilesInView(Layer layer)
        {
            List <TmxLayerTile> inViewTiles = new List <TmxLayerTile>();
            AccuracyAngle       viewAngle   = new AccuracyAngle();
            Vector2             viewOrigin  = (GameMain.mainPlayer.position + GameMain.mainPlayer.getDirectionVector(Direction.Backward, 50));

            viewAngle.EnforceConsistency();
            foreach (var tile in _map.Layers[(int)layer].Tiles)
            {
                Vector2 vecToPoint = new Vector2(tile.X - viewOrigin.X, tile.Y - viewOrigin.Y);
                float   tileAngle  = (3 * MathHelper.PiOver2) - (float)Math.Atan2(vecToPoint.Y, vecToPoint.X);

                if (tileAngle >= MathHelper.TwoPi)
                {
                    tileAngle -= MathHelper.TwoPi;
                }
                else if (tileAngle <= 0)
                {
                    tileAngle += MathHelper.TwoPi;
                }
                if (viewAngle.Contains(tileAngle))
                {
                    inViewTiles.Add(tile);
                }
            }
            return(inViewTiles);
        }
コード例 #2
0
ファイル: Weapon.cs プロジェクト: Stabax/Frozenpizza
        public override bool use(Player player)
        {
            if (!base.use(player))
            {
                return(false);
            }
            if (reloadTimer.isActive() ||
                (fireMode == FireMode.SemiAuto && Options.Config.Bindings[GameAction.UseHands].IsControlHeld(Engine.getDeviceState(), Engine.getPrevDeviceState())))
            {
                return(false);
            }
            if (ammo <= 0)
            {
                Resources.Dryfire.Play(Options.Config.SoundVolume, 0f, 0f);
                return(true);
            }
            ammo--;
            muzzleFlashTimer.Start();
            AccuracyAngle angle = GameMain.mainPlayer.getAimAccuracyAngle(true);

            angle.EnforceComparison();
            float   bulletAngle    = (float)(_randomGenerator.Next((int)(angle.right * 1000000f), (int)(angle.left * 1000000f)) / 1000000f);
            Vector2 bulletPos      = player.position + player.getDirectionVector(Direction.Forward, 15);
            float   bulletVelocity = 400f;

            sounds["use"].Play(Options.Config.SoundVolume, 0f, 0f);
            GameMain.projectiles.Add(new Projectile(player.uid, bulletPos, bulletAngle, bulletVelocity, damage));
            ClientSenderV2.SendProjectile(new ProjectileData(player.uid, bulletPos, bulletAngle, bulletVelocity, damage));
            return(true);
        }
コード例 #3
0
        bool isTileInView(Vector2 tilePos)
        {
            AccuracyAngle viewAngle = new AccuracyAngle();

            viewAngle.EnforceConsistency();
            Vector2 vecToPoint = tilePos - (GameMain.mainPlayer.position + GameMain.mainPlayer.getDirectionVector(Direction.Backward, 50));
            float   tileAngle  = (3 * MathHelper.PiOver2) - (float)Math.Atan2(vecToPoint.Y, vecToPoint.X);

            if (tileAngle >= MathHelper.TwoPi)
            {
                tileAngle -= MathHelper.TwoPi;
            }
            else if (tileAngle <= 0)
            {
                tileAngle += MathHelper.TwoPi;
            }

            if (raycast(tilePos, GameMain.mainPlayer.position, Layer.Wall, RaycastType.Hit))
            {
                return(false);
            }
            return(viewAngle.Contains(tileAngle));
        }