コード例 #1
0
ファイル: Player.cs プロジェクト: antonijn/7dfps
        public override Vector2i Draw(MainGameState game)
        {
            Vector2i v = base.Draw(game);

            toPerformWhileNoPP.Add(() => TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(v.X - TextureTools.MeasureString(Name, 4, 5).X / 2, v.Y - 6), Name, game.Game.Screen));
            return(v);
        }
コード例 #2
0
ファイル: Gun.cs プロジェクト: antonijn/7dfps
        public override bool LeftClick(MainGameState game, float time)
        {
            if (!IsReloading && Ammo == 0 && MagazinesLeft > 0 && !game.Game.MouseClickPrevious)
            {
                if (!MainGameState.IsServer)
                {
                    Sounds.Reload1.Play();
                }
                IsReloading   = true;
                reloadCounter = ReloadTime;
            }

            if (SemiAutomatic)
            {
                roundsCounter += time;
                if (roundsCounter > 1f / RoundsPerSecond)
                {
                    Shoot(game);
                    roundsCounter = 0f;
                }
            }
            else if (!game.Game.MouseClickPrevious)
            {
                Shoot(game);
            }
            return(false);
        }
コード例 #3
0
ファイル: DeathState.cs プロジェクト: antonijn/7dfps
        public DeathState(MainGameState game, bool respawn) : base(game.Game)
        {
            Glfw.Enable(GlfwEnableCap.MouseCursor);

            Label deadLabel = new Label("YOU DEADED", Game);

            deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2;
            Gui.Add(deadLabel);

            if (respawn)
            {
                Button bSP = new Button(Game, "RESPAWN");
                bSP.Position      = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30);
                bSP.MouseClicked += (sender, e) => {
                    CheckPoint.Restore(game);
                    Game.CurrentGameState = game;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                };
                Gui.Add(bSP);
            }
            else
            {
                Button bSP = new Button(Game, "QUIT");
                bSP.Position      = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30);
                bSP.MouseClicked += (sender, e) => {
                    Game.CurrentGameState = new MenuState(Game);
                };
                Gui.Add(bSP);
            }
        }
コード例 #4
0
ファイル: Enemy.cs プロジェクト: antonijn/7dfps
        private bool AreWallsBlockingSight(MainGameState game, float playerDiffX, float playerDiffZ)
        {
            Vector2 vec = new Vector2(playerDiffX, playerDiffZ);
            vec.Normalize();
            vec /= 10f;
            float playerDiffXN = vec.X;
            float playerDiffZN = vec.Y;

            float x = 0;
            float z = 0;
            // thanks SixPairsOfFeet, again!
            // thanks SixPairsOfFeet, again, again!
            while (x * x + z * z < 8 * 8 &&
                   Math.Abs(x) < Math.Abs(playerDiffX) && Math.Abs(z) < Math.Abs(playerDiffZ)) {
                float xAbs = x + X;
                float zAbs = z + Z;

                int xWall = (int)xAbs;
                int zWall = (int)zAbs;
                if (game.BlockGrid [xWall, zWall] != null) {
                    return true;
                }

                x += playerDiffXN;
                z += playerDiffZN;
            }

            return false;
        }
コード例 #5
0
ファイル: Block.cs プロジェクト: antonijn/7dfps
 public virtual void Draw(MainGameState game)
 {
     // TODO: better performance
     Wall1.Draw(game);
     Wall2.Draw(game);
     Wall3.Draw(game);
     Wall4.Draw(game);
 }
コード例 #6
0
ファイル: HealthPack.cs プロジェクト: antonijn/7dfps
        public void Update(MainGameState game, float time)
        {
            if (!Enabled)
            {
                differentlyAbledCounter -= time;
                if (differentlyAbledCounter <= 0f)
                {
                    Enabled = true;

                    if (MainGameState.IsServer)
                    {
                        foreach (Player p in Server.Current.PlayerList)
                        {
                            Server.Current.SendAddHealthPack(p.Client, X, Z);
                        }
                    }
                }
            }
            else
            {
                lock (Server.playerMutex) {
                    List <Player> toScrollThrough = new List <Player> {
                        game.CurrentPlayer
                    };
                    if (MainGameState.IsServer)
                    {
                        toScrollThrough = (Server.Current.PlayerList);
                    }
                    foreach (Player p in toScrollThrough)
                    {
                        float playerDeltaX = p.X - X;
                        float playerDeltaZ = p.Z - Z;
                        if (playerDeltaX * playerDeltaX + playerDeltaZ * playerDeltaZ < 1f)
                        {
                            p.Health = 1f;
                            if (MainGameState.IsServer)
                            {
                                Server.Current.SendUpdateHealthMessage(p.Client, p.Health);
                            }
                            else
                            {
                                Sounds.PickupCrate.Play();
                            }
                            Enabled = false;
                            differentlyAbledCounter = 60f;

                            if (MainGameState.IsServer)
                            {
                                foreach (Player p1 in Server.Current.PlayerList)
                                {
                                    Server.Current.SendRemoveHealthPack(p1.Client, X, Z);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
            public override void Update(MainGameState game, float time)
            {
                fuse -= time;
                if (fuse <= 0f)
                {
                    if (!MainGameState.IsServer && !game.IsMultiplayer)
                    {
                        Vector2 movement      = new Vector2(Direction.X * .5f, Direction.Y * .5f);
                        Vector2 finalPosition = new Vector2(X, Z) + movement;
                        Door    d             = game.BlockGrid [(int)finalPosition.X, (int)finalPosition.Y] as Door;
                        if (d != null)
                        {
                            d.Open();
                        }
                    }
                    if (MainGameState.IsServer)
                    {
                        Server.Current.PlayerList.ForEach(x => {
                            float relativeX = -x.X + X;
                            float relativeZ = -x.Z + Z;
                            float distSqr   = relativeX * relativeX + relativeZ * relativeZ;
                            x.Health       -= Math.Max(0, 1.5f - distSqr);
                            if (distSqr > 0f)
                            {
                                Server.Current.SendUpdateHealthMessage(x.Client, x.Health);
                            }
                        });
                    }
                    game.Enemies.ForEach(x => {
                        float relativeX = -x.X + X;
                        float relativeZ = -x.Z + Z;
                        float distSqr   = relativeX * relativeX + relativeZ * relativeZ;
                        x.Health       -= Math.Max(0, 1.5f - distSqr);
                    });
                    game.Projectiles.Add(new Explosion(X, Z));
                    if (!MainGameState.IsServer)
                    {
                        Sounds.Grenade.Play();
                    }
                    ShouldBeRemoved = true;

                    return;
                }

                UpdateGravity(time);
                if (Altitude != 0f)
                {
                    Vector2 movement      = new Vector2(Direction.X * time * 6f, Direction.Y * time * 6f);
                    Vector2 finalPosition = new Vector2(X, Z) + movement;
                    Block   b             = game.BlockGrid[(int)finalPosition.X, (int)finalPosition.Y];
                    if (b == null || !b.CollidesWithVector(finalPosition))
                    {
                        X = finalPosition.X;
                        Z = finalPosition.Y;
                    }
                }
            }
コード例 #8
0
ファイル: Player.cs プロジェクト: antonijn/7dfps
 public Player(MainGameState game, float x, float z, string name) : base(TextureTools.TextureEnemy, x, z, .65f, 0f)
 {
     Name   = name;
     Health = 1f;
     Game   = game;
     SetInventoryItem(0, new DefaultPistol());
     SetInventoryItem(1, new ButterKnife());
     SetInventoryItem(2, new Grenade());
 }
コード例 #9
0
ファイル: MultiplayerClient.cs プロジェクト: antonijn/7dfps
        public MultiplayerClient(MainGameState _game, string ip, int port)
        {
            game   = _game;
            client = new TcpClient();
            IPEndPoint server = new IPEndPoint(IPAddress.Parse(ip), port);

            client.Connect(server);
            serverHandler = new Thread(HandleServer);
            serverHandler.Start(client);
        }
コード例 #10
0
ファイル: Enemy.cs プロジェクト: antonijn/7dfps
 public void Update(MainGameState game, float time)
 {
     if (gotKilled) {
         ShouldBeRemoved = UpdateAnimation(TextureTools.EnemyDeathAnimation, 4f, time);
         if (ShouldBeRemoved) {
             Drop(game);
         }
     } else {
         UpdateAI(game, time);
     }
 }
コード例 #11
0
 public override bool LeftClick(MainGameState game, float time)
 {
     if (!game.Game.MouseClickPrevious)
     {
         bool result = GetItem().LeftClick(game, time);
         if (result)
         {
             --Amount;
         }
     }
     return(Amount == 0);
 }
コード例 #12
0
ファイル: CheckPoint.cs プロジェクト: antonijn/7dfps
        public override void Update(MainGameState game, float time)
        {
            float xPlayerDiff = game.CurrentPlayer.X - X;
            float zPlayerDiff = game.CurrentPlayer.Z - Z;

            if (xPlayerDiff * xPlayerDiff + zPlayerDiff * zPlayerDiff < 1f)
            {
                last            = this;
                ShouldBeRemoved = true;
                Sounds.PickupCrate.Play();
                CopyWorld(game);
            }
        }
コード例 #13
0
 public override void Draw(MainGameState game)
 {
     if (!IsOpen)
     {
         base.Draw(game);
         if (timeToOpen != -1f)
         {
             wallLower1.Draw(game);
             wallLower2.Draw(game);
             wallLower3.Draw(game);
             wallLower4.Draw(game);
         }
     }
 }
コード例 #14
0
ファイル: Enemy.cs プロジェクト: antonijn/7dfps
        private void UpdateAI(MainGameState game, float time)
        {
            // idea of super amazing AI with more randomness conceived by SixPairsOfFeet
            keepWalkingFor -= time;
            stopFor -= time;
            if (keepWalkingFor >= 0f && stopFor <= 0f) {
                float playerDiffX = game.CurrentPlayer.X - X;
                float playerDiffZ = game.CurrentPlayer.Z - Z;
                float playerDist = playerDiffX * playerDiffX + playerDiffZ * playerDiffZ;
                if (playerDist < MainGameState.WallsDisappearAt * MainGameState.WallsDisappearAt / (2 * 2)) {
                    shootCounter -= time;
                    if (shootCounter <= 0f) {
                        if (!AreWallsBlockingSight(game, playerDiffX, playerDiffZ)) {
                            game.CurrentPlayer.Health -= ((float)MainClass.Random.NextDouble() * .5f + .5f) * .05f;
                            shootCounter = ((float)MainClass.Random.NextDouble() * .5f + .5f) * 1f;
                            Sounds.Shoot1.Play();
                        }
                    }

                    Vector2 movement = Vector2.Normalize(new Vector2(playerDiffX, playerDiffZ));
                    movement = Vector3.Transform(new Vector3(movement.X, 0f, movement.Y), Matrix.CreateRotationY(angle)).Xz;
                    // thanks killraptor for the suggestion!
                    Vector2 movement1 = new Vector2(movement.X, 0f);
                    Vector2 movement2 = new Vector2(0f, movement.Y);
                    Vector2 finalPosition1 = new Vector2(X, Z) + movement1 * time * speed;
                    Vector2 finalPosition2 = new Vector2(X, Z) + movement2 * time * speed;
                    {
                        Block collidingWithPlayer = game.BlockGrid [(int)finalPosition1.X, (int)finalPosition1.Y];
                        if (collidingWithPlayer == null || !collidingWithPlayer.CollidesWithVector(finalPosition1)) {
                            X = finalPosition1.X;
                        }
                    }
                    {
                        Block collidingWithPlayer = game.BlockGrid [(int)finalPosition2.X, (int)finalPosition2.Y];
                        if (collidingWithPlayer == null || !collidingWithPlayer.CollidesWithVector(finalPosition2)) {
                            Z = finalPosition2.Y;
                        }
                    }
                }
            } else {
                if (stopFor <= 0f) {
                    stopFor = ((float)MainClass.Random.NextDouble() * .5f + .5f) * 2f;
                }
                keepWalkingFor = ((float)MainClass.Random.NextDouble() * .5f + .5f) * 5f;
                angle = ((float)MainClass.Random.NextDouble() * 2f - 1f) * MathHelper.TauOver4;
            }
        }
コード例 #15
0
ファイル: BillBoard.cs プロジェクト: antonijn/7dfps
        public virtual Vector2i Draw(MainGameState game)
        {
            float x = X - game.CurrentPlayer.X;
            float z = Z - game.CurrentPlayer.Z;

            float zBackup = z;

            z = game.CurrentPlayer.CosWorldRotation * z - game.CurrentPlayer.SinWorldRotation * x;
            x = game.CurrentPlayer.CosWorldRotation * x + game.CurrentPlayer.SinWorldRotation * zBackup;

            float aspect = Texture.Width / (float)Texture.Height;

            float leftRightOffset = aspect * Scale / 2f;

            Tuple <float, float> y = MathUtils3D.GetYForZ(z);

            int xResult = (int)MathUtils3D.GetXForX(x, y.Item1);

            float xPoss0 = MathUtils3D.GetXForX(x - leftRightOffset, y.Item1);
            float xPoss1 = MathUtils3D.GetXForX(x + leftRightOffset, y.Item1);

            float oringalZ       = MathUtils3D.GetZForY(y.Item1);
            float yDifference    = y.Item1 - y.Item2;
            float altitudeOffset = Altitude * yDifference;

            yDifference *= 1f - Scale;
            y            = new Tuple <float, float>(y.Item1 - altitudeOffset, y.Item2 + yDifference - altitudeOffset);
            int pixelsDrawn = 0;

            if (z > .1f && z < MainGameState.WallsDisappearAt)
            {
                game.DrawPatch(new Vector2(xPoss0, y.Item1), new Vector2(xPoss0, y.Item2), new Vector2(xPoss1, y.Item1), new Vector2(xPoss1, y.Item2),
                               (s, t) => {
                    ++pixelsDrawn;
                    Color texColor = Texture.Get((int)(s * Texture.Width), (int)(t * Texture.Height));
                    return(texColor);
                }, (f, unused) => AlwaysBright ? 1 : oringalZ, this);
            }

            if (pixelsDrawn > 0 && z < MainGameState.WallsDisappearAt)
            {
                return(new Vector2i(xResult, (int)y.Item2));
            }

            return(new Vector2i(short.MinValue, short.MinValue));
        }
コード例 #16
0
ファイル: Enemy.cs プロジェクト: antonijn/7dfps
        private void Drop(MainGameState game)
        {
            DroppedWeapon toDrop = null;

            int rand = MainClass.Random.Next(6);
            switch (rand) {
            case 0:
                toDrop = new DroppedWeapon<Grenade>(X, Z);
                break;
            case 1:
                toDrop = new DroppedWeapon<Rifle>(X, Z);
                break;
            case 2:
                toDrop = new DroppedWeapon<SemiAuto>(X, Z);
                break;
            }

            if (toDrop != null) {
                game.DroppedWeapons.Add(toDrop);
            }
        }
コード例 #17
0
ファイル: Server.cs プロジェクト: antonijn/7dfps
        public Server(int port)
        {
            Current = this;

            MouseStates         = new Dictionary <Player, bool>();
            PreviousMouseStates = new Dictionary <Player, bool>();

            Clients = new List <TcpClient>();
            Players = new Dictionary <TcpClient, Player>();

            Port        = port;
            tcpListener = new TcpListener(IPAddress.Any, port);
            Console.WriteLine("INFO: Opened server on {0}", port);

            listenThread = new Thread(ListenForClients);
            listenThread.Start();

            ServerSideProgram      = new MainClass();
            MainGameState.IsServer = true;
            World = new MainGameState(ServerSideProgram);
        }
コード例 #18
0
ファイル: Gun.cs プロジェクト: antonijn/7dfps
 public void Shoot(MainGameState game)
 {
     if (Ammo > 0)
     {
         --Ammo;
         game.Flash = FlashTime;
         if (!MainGameState.IsServer)
         {
             Shot.Play();
         }
         Tuple <object, float, float> crossHairWall = game.CurrentPlayer.AtCrossHair as Tuple <object, float, float>;
         if (crossHairWall != null)
         {
             Wall   wall = crossHairWall.Item1 as Wall;
             Enemy  e    = crossHairWall.Item1 as Enemy;
             Player p    = crossHairWall.Item1 as Player;
             if (wall != null)
             {
                 Door door = wall.Owner as Door;
                 if (OpensDoors && door != null)
                 {
                     door.Open();
                 }
                 int s = (int)(crossHairWall.Item2 * wall.DecalTexture.Width);
                 int t = (int)(crossHairWall.Item3 * wall.DecalTexture.Width);
                 wall.DecalTexture.Set(s, t, MathUtils3D.GetColor(0f, 0f, 0f, .25f));
             }
             else if (e != null)
             {
                 e.Health -= Damage;
             }
             else if (p != null)
             {
                 p.Health -= Damage / 5f;
                 Server.Current.SendUpdateHealthMessage(p.Client, p.Health);
             }
         }
     }
 }
コード例 #19
0
ファイル: AreYouSure.cs プロジェクト: antonijn/7dfps
        public AreYouSure(MainGameState maingame) : base(maingame.Game)
        {
            Glfw.Enable(GlfwEnableCap.MouseCursor);

            Label deadLabel = new Label("ARE YOU SURE YOU WANT TO QUIT?", Game);

            deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2;
            Gui.Add(deadLabel);

            Button yes = new Button(Game, "YES");

            yes.Position      = new Vector2i(Game.Screen.Width / 2 - yes.Image.Width - 15, Game.Screen.Height / 2 + 30);
            yes.MouseClicked += (sender, e) => { Game.CurrentGameState = new MenuState(Game); };
            Gui.Add(yes);

            Button no = new Button(Game, "NO");

            no.Position      = new Vector2i(Game.Screen.Width / 2 + 15, Game.Screen.Height / 2 + 30);
            no.MouseClicked += (sender, e) => { Game.CurrentGameState = maingame; Glfw.Disable(GlfwEnableCap.MouseCursor); };
            Gui.Add(no);

            mainGame = maingame;
        }
コード例 #20
0
ファイル: ButterKnife.cs プロジェクト: antonijn/7dfps
 public override bool LeftClick(MainGameState game, float time)
 {
     if (!game.Game.MouseClickPrevious)
     {
         Tuple <object, float, float> atCrossHair = game.CurrentPlayer.AtCrossHair as Tuple <object, float, float>;
         if (atCrossHair != null)
         {
             Enemy  enemy = atCrossHair.Item1 as Enemy;
             Player plyr  = atCrossHair.Item1 as Player;
             if (enemy != null)
             {
                 float enemyDeltaX = game.CurrentPlayer.X - enemy.X;
                 float enemyDeltaZ = game.CurrentPlayer.Z - enemy.Z;
                 if (enemyDeltaX * enemyDeltaX + enemyDeltaZ * enemyDeltaZ < Range * Range)
                 {
                     enemy.Health -= damageDealt;
                 }
             }
             else if (plyr != null)
             {
                 float enemyDeltaX = game.CurrentPlayer.X - plyr.X;
                 float enemyDeltaZ = game.CurrentPlayer.Z - plyr.Z;
                 if (enemyDeltaX * enemyDeltaX + enemyDeltaZ * enemyDeltaZ < Range * Range)
                 {
                     plyr.Health -= damageDealt;
                     Server.Current.SendUpdateHealthMessage(plyr.Client, plyr.Health);
                 }
             }
         }
         if (!MainGameState.IsServer)
         {
             Sounds.Squeak.Play();
         }
     }
     return(false);
 }
コード例 #21
0
ファイル: InventoryItem.cs プロジェクト: antonijn/7dfps
 /// <returns><c>true</c>, if item should be removed from inventory, <c>false</c> otherwise.</returns>
 public abstract bool LeftClick(MainGameState game, float time);
コード例 #22
0
 public override bool LeftClick(MainGameState game, float time)
 {
     game.Projectiles.Add(new Grenade.GenadeProjectile(game.CurrentPlayer.X, game.CurrentPlayer.Z, new Vector2(-game.CurrentPlayer.SinWorldRotation, game.CurrentPlayer.CosWorldRotation)));
     return(true);
 }
コード例 #23
0
        public override void Update(MainGameState game, float time)
        {
            float playerPosRelX = game.CurrentPlayer.X - X;
            float playerPosRelZ = game.CurrentPlayer.Z - Z;

            if (Altitude == 0f && playerPosRelX * playerPosRelX + playerPosRelZ * playerPosRelZ < .5f * .5f)
            {
                Weapon drop = GetDropped();
                if (drop.MaxStack <= 1)
                {
                    for (int i = 0; i < Player.InventorySize; ++i)
                    {
                        if (game.CurrentPlayer.GetInventoryItem(i) == null)
                        {
                            game.CurrentPlayer.SetInventoryItem(i, drop);
                            Sounds.PickupWeapon.Play();
                            ShouldBeRemoved = true;
                            return;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < Player.InventorySize; ++i)
                    {
                        InventoryStack iStack = game.CurrentPlayer.GetInventoryItem(i) as InventoryStack;
                        // thanks novynn for pointing out the silly != / == mistake!
                        if (iStack != null && iStack.GetItemType() == drop.GetType() && iStack.Amount != iStack.MaxValue)
                        {
                            ++iStack.Amount;
                            Sounds.PickupWeapon.Play();
                            ShouldBeRemoved = true;
                            return;
                        }
                    }
                    for (int i = 0; i < Player.InventorySize; ++i)
                    {
                        if (game.CurrentPlayer.GetInventoryItem(i) == null)
                        {
                            game.CurrentPlayer.SetInventoryItem(i, new DroppedItemInventoryStack(drop.GetType(), drop.MaxStack));
                            Sounds.PickupWeapon.Play();
                            ShouldBeRemoved = true;
                            return;
                        }
                    }
                }
            }

            UpdateGravity(time);
            if (Altitude != 0f)
            {
                Vector2 movement      = new Vector2(XDir * time * 3f, ZDir * time * 3f);
                Vector2 finalPosition = new Vector2(X, Z) + movement;
                Block   b             = game.BlockGrid[(int)finalPosition.X, (int)finalPosition.Y];
                if (b == null || !b.CollidesWithVector(finalPosition))
                {
                    X = finalPosition.X;
                    Z = finalPosition.Y;
                }
            }
        }
コード例 #24
0
ファイル: Wall.cs プロジェクト: antonijn/7dfps
        public static void DrawWall(MainGameState game, float x, float z, float rotation, Texture2D texture)
        {
            Wall wall = new Wall(x, z, rotation, texture);

            wall.Draw(game);
        }
コード例 #25
0
 public override void Update(MainGameState game, float time)
 {
     ShouldBeRemoved = UpdateAnimation(TextureTools.ExplosionAnimation, 10f, time);
 }
コード例 #26
0
        public void Update(MainGameState game, float time)
        {
            if (!Enabled)
            {
                differentlyAbledCounter -= time;
                if (differentlyAbledCounter <= 0f)
                {
                    Enabled = true;

                    if (MainGameState.IsServer)
                    {
                        foreach (Player p in Server.Current.PlayerList)
                        {
                            Server.Current.SendAddAmmoCrates(p.Client, X, Z);
                        }
                    }
                }
            }
            else
            {
                lock (Server.playerMutex) {
                    List <Player> toScrollThrough = new List <Player> {
                        game.CurrentPlayer
                    };
                    if (MainGameState.IsServer)
                    {
                        toScrollThrough = (Server.Current.PlayerList);
                    }
                    foreach (Player p in toScrollThrough)
                    {
                        float playerDeltaX = p.X - X;
                        float playerDeltaZ = p.Z - Z;
                        if (playerDeltaX * playerDeltaX + playerDeltaZ * playerDeltaZ < 1f)
                        {
                            for (int i = 0; i < Player.InventorySize; ++i)
                            {
                                Gun g = p.GetInventoryItem(i) as Gun;
                                if (g != null)
                                {
                                    g.Ammo          = g.DefaultAmmo;
                                    g.MagazinesLeft = g.MagazineSize - 1;
                                    if (MainGameState.IsServer)
                                    {
                                        Server.Current.SendSetInventoryItemMessage(p.Client, i, g);
                                    }
                                }
                            }

                            if (!MainGameState.IsServer)
                            {
                                Sounds.PickupCrate.Play();
                            }
                            Enabled = false;
                            differentlyAbledCounter = 60f;
                            if (MainGameState.IsServer)
                            {
                                foreach (Player p1 in Server.Current.PlayerList)
                                {
                                    Server.Current.SendRemoveAmmoCrates(p1.Client, X, Z);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #27
0
ファイル: Wall.cs プロジェクト: antonijn/7dfps
        public void Draw(MainGameState game)
        {
            float x = X - game.CurrentPlayer.X;
            float z = Z - game.CurrentPlayer.Z;

            float zBackup = z;

            z = game.CurrentPlayer.CosWorldRotation * z - game.CurrentPlayer.SinWorldRotation * x;
            x = game.CurrentPlayer.CosWorldRotation * x + game.CurrentPlayer.SinWorldRotation * zBackup;
            float rotation = Rotation + game.CurrentPlayer.WorldRotation;

            float cosRot      = (float)Math.Cos(rotation);
            float sinRot      = (float)Math.Sin(rotation);
            float secondEdgeZ = cosRot;
            float secondEdgeX = sinRot;

            Tuple <float, float> yPoss0 = MathUtils3D.GetYForZ(z);
            Tuple <float, float> yPoss1 = MathUtils3D.GetYForZ(z + secondEdgeZ);

            float xPoss0 = MathUtils3D.GetXForX(x, yPoss0.Item1);
            float xPoss1 = MathUtils3D.GetXForX(secondEdgeX + x, yPoss1.Item1);

            {
                float yDifference    = yPoss0.Item1 - yPoss0.Item2;
                float altitudeOffset = Altitude * yDifference;
                yPoss0 = new Tuple <float, float>(yPoss0.Item1 - altitudeOffset, yPoss0.Item2 - altitudeOffset);
            }
            {
                float yDifference    = yPoss1.Item1 - yPoss1.Item2;
                float altitudeOffset = Altitude * yDifference;
                yPoss1 = new Tuple <float, float>(yPoss1.Item1 - altitudeOffset, yPoss1.Item2 - altitudeOffset);
            }

            if (z > 0f && z + secondEdgeZ > 0f && z < MainGameState.WallsDisappearAt)
            {
                game.DrawPatch(new Vector2(xPoss0, yPoss0.Item1), new Vector2(xPoss0, yPoss0.Item2), new Vector2(xPoss1, yPoss1.Item1), new Vector2(xPoss1, yPoss1.Item2),
                               (s, t) => {
                    Color texColor   = Texture.Get((int)(s * Texture.Width), (int)(t * Texture.Height));
                    Color decalColor = DecalTexture.Get((int)(s * DecalTexture.Width), (int)(t * DecalTexture.Height));
                    float dR, dG, dB, dA;
                    MathUtils3D.GetFloatsFromColor(decalColor, out dR, out dG, out dB, out dA);
                    float tR, tG, tB, tA;
                    MathUtils3D.GetFloatsFromColor(texColor, out tR, out tG, out tB, out tA);

                    float fR, fG, fB, fA;
                    fA = dA + tA * (1f - dA);
                    fR = (dR * dA + tR * tA * (1f - dA)) / fA;
                    fG = (dG * dA + tG * tA * (1f - dA)) / fA;
                    fB = (dB * dA + tB * tA * (1f - dA)) / fA;

                    return(MathUtils3D.GetColor32(fR, fG, fB, fA));
                }, (yTop, yDifference) => {
                    if (Altitude == 0f)
                    {
                        return(MathUtils3D.GetZForY(yTop));
                    }

                    // should be just a bit different... they probably won't notice because the doors rise so fast
                    return(MathUtils3D.GetZForY(yDifference * Altitude + yTop));
                }, this);
            }
        }
コード例 #28
0
ファイル: Block.cs プロジェクト: antonijn/7dfps
        public static void DrawBlock(MainGameState game, int x, int z, Texture2D texture)
        {
            Block b = new Block(x, z, texture);

            b.Draw(game);
        }
コード例 #29
0
ファイル: Projectile.cs プロジェクト: antonijn/7dfps
 public abstract void Update(MainGameState game, float time);
コード例 #30
0
ファイル: CheckPoint.cs プロジェクト: antonijn/7dfps
        public static void Restore(MainGameState world)
        {
            if (last == null)
            {
                world.CurrentPlayer = null;
                world.LoadLevel(world.CurrentLevel);
            }
            else
            {
                world.Enemies.Clear();
                foreach (Enemy e in last.enemies)
                {
                    world.Enemies.Add(new Enemy(e.X, e.Z));
                }

                world.HealthPacks.Clear();
                // TODO: take healthpack timer into account
                foreach (HealthPack hp in last.healthPack)
                {
                    world.HealthPacks.Add(new HealthPack(hp.X, hp.Z));
                }

                world.Crates.Clear();
                // TODO: idem
                foreach (AmmoCrate ac in last.crates)
                {
                    world.Crates.Add(new AmmoCrate(ac.X, ac.Z));
                }

                world.Blocks.Clear();
                world.BlockGrid = new Block[world.WorldWidth, world.WorldHeight];
                for (int x = 0; x < world.WorldWidth; ++x)
                {
                    for (int z = 0; z < world.WorldWidth; ++z)
                    {
                        Block oldBlock = last.blockGrid [x, z];
                        Door  oldDoor  = oldBlock as Door;
                        if (oldBlock != null)
                        {
                            Block newBlock = null;
                            if (oldDoor != null)
                            {
                                // TODO: take full door texture into account
                                Door newDoor = new Door(oldDoor.X, oldDoor.Z, TextureTools.TextureDoor1, oldDoor.Upper, oldDoor.Lower);
                                if (oldDoor.IsOpen)
                                {
                                    newDoor.Open();
                                }
                                newBlock = newDoor;
                            }
                            else
                            {
                                newBlock = new Block(oldBlock.X, oldBlock.Z, oldBlock.Wall1.Texture);
                            }
                            world.BlockGrid [x, z] = newBlock;
                            world.Blocks.Add(newBlock);
                        }
                    }
                }

                world.DroppedWeapons.Clear();
                foreach (DroppedWeapon weapon in last.dropped)
                {
                    Weapon droppedWeapon = weapon.GetDropped();
                    world.DroppedWeapons.Add(new InventoryDroppedWeapon(droppedWeapon, weapon.X, weapon.Z, 0f, 0f));
                }

                for (int i = 0; i < world.CurrentPlayer.Inventory.Length; ++i)
                {
                    InventoryItem current = last.playerInventory [i];
                    if (current != null)
                    {
                        InventoryStack stack = current as InventoryStack;
                        if (stack != null)
                        {
                            DroppedItemInventoryStack newStack = new DroppedItemInventoryStack(stack.GetItemType(), stack.MaxValue);
                            newStack.Amount = stack.Amount;
                            world.CurrentPlayer.Inventory [i] = newStack;
                        }
                        else
                        {
                            world.CurrentPlayer.Inventory [i] = (InventoryItem)Activator.CreateInstance(current.GetType());
                            Gun g = current as Gun;
                            if (g != null)
                            {
                                ((Gun)world.CurrentPlayer.Inventory [i]).Ammo          = g.Ammo;
                                ((Gun)world.CurrentPlayer.Inventory [i]).MagazinesLeft = g.MagazinesLeft;
                            }
                        }
                    }
                }

                world.CurrentPlayer.X      = last.xPlayer;
                world.CurrentPlayer.Z      = last.zPlayer;
                world.CurrentPlayer.Health = last.healthPlayer;
            }
        }