Exemple #1
0
        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));
        }
Exemple #2
0
        private void PostProcess()
        {
            float zBufferFlicker = ((float)MainClass.Random.NextDouble() - .5f) / 50f;

            Game.Screen.Fill((x, y) => {
                float r, g, b, a;
                MathUtils3D.GetFloatsFromColor(Game.Screen.Get(x, y), out r, out g, out b, out a);
                float zBuffer = 1f - Game.ZBuffer.Get(x, y);
                zBuffer      *= WallsDisappearAt;
                zBuffer      -= Flash;
                zBuffer      += zBufferFlicker;
                if (zBuffer > 1f)
                {
                    zBuffer = 1f;
                }
                zBuffer = 1f - zBuffer;

                return(MathUtils3D.GetColor(r * zBuffer, g * zBuffer, b * zBuffer, a));
            });
        }
Exemple #3
0
        private void DrawHealthBar()
        {
            // health bar
            float startPosition = MainClass.ScreenWidth / 2 - 15 * 2.5f;

            for (int i = (int)startPosition; i < startPosition + 32f; ++i)
            {
                Game.Game.Screen.Set(i, MainClass.ScreenHeight - 21, MathUtils3D.GetColor(0.5f, 0.5f, 0.5f, 1f));
                Game.Game.Screen.Set(i, MainClass.ScreenHeight - 20, MathUtils3D.GetColor(0.5f, 0.5f, 0.5f, 1f));
                Game.Game.Screen.Set(i, MainClass.ScreenHeight - 19, MathUtils3D.GetColor(0.5f, 0.5f, 0.5f, 1f));
            }
            for (int i = (int)startPosition + 1; i < startPosition + Health * 31f; ++i)
            {
                Game.Game.Screen.Set(i, MainClass.ScreenHeight - 20, MathUtils3D.GetColor(1f, 0f, 0f, 1f));
            }
            for (int i = (int)Math.Ceiling(startPosition + Health * 31f); i < startPosition + 31f; ++i)
            {
                Game.Game.Screen.Set(i, MainClass.ScreenHeight - 20, MathUtils3D.GetColor(.2f, .2f, .2f, 1f));
            }
        }
Exemple #4
0
 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);
             }
         }
     }
 }
Exemple #5
0
        public void DrawPatch(Vector2 corner0, Vector2 corner1, Vector2 corner2, Vector2 corner3, Func <float, float, Color> textureFunc, Func <float, float, float> zBufVal, object calledBy)
        {
            Vector2 topLeft;
            Vector2 topRight;
            Vector2 bottomLeft;
            Vector2 bottomRight;

            Vector2[]             all    = new [] { corner0, corner1, corner2, corner3 };
            IEnumerable <Vector2> sorted = all.OrderBy(x => x.X);

            Vector2[] left  = sorted.Take(2).ToArray();
            Vector2[] right = sorted.Skip(2).Take(2).ToArray();

            if (left [0].Y < left [1].Y)
            {
                topLeft    = left [0];
                bottomLeft = left [1];
            }
            else
            {
                bottomLeft = left [0];
                topLeft    = left [1];
            }

            if (right [0].Y < right [1].Y)
            {
                topRight    = right [0];
                bottomRight = right [1];
            }
            else
            {
                bottomRight = right [0];
                topRight    = right [1];
            }

            float dyDxTop    = (topRight.Y - topLeft.Y) / (topRight.X - topLeft.X);
            float dyDxBottom = (bottomRight.Y - bottomLeft.Y) / (bottomRight.X - bottomLeft.X);

            int startX = (int)Math.Round(topLeft.X);
            int endX   = (int)Math.Round(topRight.X);

            for (int x = startX; x < endX; ++x)
            {
                if (x >= 0 && x < MainClass.ScreenWidth)
                {
                    float xRelative = x - startX;
                    float s         = xRelative / (endX - startX);
                    float yTop      = topLeft.Y + xRelative * dyDxTop;
                    float yBottom   = bottomLeft.Y + xRelative * dyDxBottom;

                    float yDifference = yBottom - yTop;

                    int yTopInt    = (int)Math.Round(yTop);
                    int yBottomInt = (int)Math.Round(yBottom);

                    float z = zBufVal(yTopInt, yDifference);
                    if (z > .1f)
                    {
                        for (int y = yTopInt; y < yBottomInt; ++y)
                        {
                            if (y >= 0 && y < MainClass.ScreenHeight)
                            {
                                float zPrevious = Game.ZBuffer.Get(x, y);
                                if (z > zPrevious)
                                {
                                    float t = (float)(y - yTopInt) / (yBottomInt - yTopInt);
                                    Color color = textureFunc(s, t);
                                    float a, r, g, b;
                                    MathUtils3D.GetFloatsFromColor(color, out r, out g, out b, out a);
                                    if (a != 0)
                                    {
                                        Game.Screen.Set(x, y, color);
                                        Game.ZBuffer.Set(x, y, z);
                                        if (x == MainClass.ScreenWidth / 2 && y == MainClass.ScreenHeight / 2)
                                        {
                                            CurrentPlayer.AtCrossHair = new Tuple <object, float, float>(calledBy, s, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #6
0
        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);
            }
        }