Exemplo n.º 1
0
        public MainForm(GameApplication apseApplication)
        {
            this.application = apseApplication;


            Panel Pul = new Panel();

            Pul.Position = new Point(1, 0);
            Pul.Width    = GameClass.TestWindow.Width - 1;
            Pul.Height   = 30;
            Pul.Anchor   = Aligment.Right | Aligment.Left;
            this.Items.Add(Pul);



            {
                DragDropPanel voxap = new DragDropPanel();
                voxap.Position = new Point(10, 75 + 250);
                voxap.Width    = 200;
                voxap.Height   = 250;
                {
                    int libe_pack = 10;
                    {
                        SelectionName          = new Label();
                        SelectionName.Text     = "(NULL; -1)"; SelectionName.AutoSize();
                        SelectionName.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(SelectionName);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Создать Камаз"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            CarObjectKamaz vs = new CarObjectKamaz();
                            vs.Position = new JVector(0f, 4f, 0f);
                            application.InstanceFromGame.AddObject(vs);
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Создать Пикап"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            CarObjectPickUp vs = new CarObjectPickUp();
                            vs.Position = new JVector(0f, 4f, 0f);
                            application.InstanceFromGame.AddObject(vs);
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Создать куб"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            BoxObject bbox1 = new BoxObject();
                            bbox1.Position = new JVector(2f, 6f, 0f);

                            application.InstanceFromGame.AddObject(bbox1);
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Создать планк"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            WoodPlank bbox1 = new WoodPlank();
                            bbox1.Position = new JVector(2f, 6f, 0f);

                            application.InstanceFromGame.AddObject(bbox1);
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Создать дверь"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            WoodDoor bbox1 = new WoodDoor();
                            bbox1.Position = new JVector(2f, 6f, 0f);

                            application.InstanceFromGame.AddObject(bbox1);
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                }
                this.Items.Add(voxap);
            }


            {
                DragDropPanel voxap = new DragDropPanel();
                voxap.Position = new Point(10, 60);
                voxap.Width    = 300;
                voxap.Height   = 250;
                {
                    int libe_pack = 10;
                    {
                        Button bt = new Button();
                        bt.Text   = "Сохранить карту"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            //if(File.Exists("./map.eemx"))
                            //        File.Delete("./map.eemx");
                            //using (Stream bl = File.OpenWrite("./map.eemx"))
                            //{
                            //    MapLoader.Save(bl, application.InstanceFromGame);
                            //}
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Загрузить карту"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            //using (Stream bl = File.OpenRead("./map.eemx"))
                            //{
                            //    MapLoader.Load(bl, application.InstanceFromGame);
                            //}
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                    {
                        Button bt = new Button();
                        bt.Text   = "Перегрузить шейдер"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            //global::EmyEngine.EE.СurrentResources.GetResource("/shaders/new/shader.vs").Data = File.ReadAllBytes("./bin/shaders/new/shader.vs");
                            //global::EmyEngine.EE.СurrentResources.GetResource("/shaders/new/shader.fs").Data = File.ReadAllBytes("./bin/shaders/new/shader.fs");
                            //application.Shader3DMain = new ShaderNew();
                            //((ShaderNew)application.Shader3DMain).ShadowMapObject = application.FraemBufferMain.DepthTextureObject;
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }

                    {
                        CheckBox bt = new CheckBox();
                        bt.Text          = "Дебуг дравв";
                        bt.ValueChanged += (sender, args) =>
                        {
                            if (bt.Checked)
                            {
                                application.InstanceFromGame.EnableDebugDraweble();
                            }
                            else
                            {
                                application.InstanceFromGame.DisableDebugDraweble();
                            }
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }



                    {
                        CheckBox bt = new CheckBox();
                        bt.Text          = "D* Shader Material";
                        bt.ValueChanged += (sender, args) =>
                        {
                            if (bt.Checked)
                            {
                                ((ShaderNew)application.Shader3DMain).EnableMaterials = false;
                            }
                            else
                            {
                                ((ShaderNew)application.Shader3DMain).EnableMaterials = true;
                            }
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }


                    {
                        Button bt = new Button();
                        bt.Text   = "Закрыть"; bt.AutoSize();
                        bt.Click += (sender, args) =>
                        {
                            GameClass.TestWindow.Close();
                        };
                        bt.Position = new Point(10, libe_pack); libe_pack += 30;
                        voxap.Items.Add(bt);
                    }
                }
                this.Items.Add(voxap);
            }
        }
Exemplo n.º 2
0
    void collisions()
    {
        cLeft   = false;
        cRight  = false;
        cBottom = false;
        cTop    = false;

        float xOffset  = crouchOffset.x + (dim.x / 2.0f) - skin;
        float yOffset  = crouchOffset.y + (dim.y / 2.0f) - skin;
        float ySpacing = (yOffset * 2f) * ((float)1f / (float)xRays);
        float xSpacing = (xOffset * 2f) * ((float)1f / (float)yRays);

        rayVector1 = vel;
        rayVector2 = vel;

        if (dropTimer > 0)
        {
            dropTimer -= Time.deltaTime;
        }


        for (int i = 0; i < xRays; i++)
        {
            // Left-facing collisions.
            rayPos = pos + new Vector2(-xOffset, -yOffset + (i * ySpacing) + (ySpacing / 2.0f));             // Set position of ray start points.
            RaycastHit2D rayLeft = Physics2D.Linecast(rayPos, rayPos + new Vector2(rayVector1.x - skin, 0)); // Make new ray.

            if (rayLeft)                                                                                     // If hit.
            {
                rayVector1 = rayLeft.point - (rayPos);                                                       // Create local vector based on ray path.
                if (rayLeft.collider.tag == "Thin")
                {
                    Debug.DrawRay(rayPos, new Vector2(rayVector1.x - skin, 0), Color.magenta);                       // Debug line.
                }
                else
                {
                    // Begin drill code.
                    if (isDrilling)
                    {
                        if (doubleLeft)
                        {
                            if (rayLeft.collider.gameObject.layer == LayerMask.NameToLayer("Solid"))
                            {
                                if (rayLeft.collider.gameObject.layer != LayerMask.NameToLayer("Unbreakable"))
                                {
                                    GameObject c = rayLeft.collider.gameObject;
                                    GameObject.Destroy(c);
                                }
                            }
                        }
                    }
                    // End drill code.
                    if (rayLeft.collider.tag == "Boulder")
                    {
                        if (rayVector1.x > -skin)                           // If ray length hits, and is less than skin.
                        {
                            if (acc.x < -0.001f)
                            {
                                rayLeft.collider.attachedRigidbody.AddTorque(-acc.x * 200f);
                                vel.x = acc.x;
                                //acc.x = 0;
                            }
                            cLeft = true;                                                            // Officially collided.
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.green); // Debug line.
                        }
                        else
                        {
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.yellow);                               // Debug line.
                        }
                    }
                    else
                    {
                        vel.x = rayVector1.x + skin;                                                 // Make sure not to overshoot.
                        Debug.DrawRay(rayPos, new Vector2(rayVector1.x - skin, 0), Color.cyan);      // Debug line.
                        if (rayVector1.x > -skin)                                                    // If ray length hits, and is less than skin.
                        {
                            cLeft = true;                                                            // Officially collided.
                            vel.x = 0;                                                               // Hit.
                            Debug.DrawRay(rayPos, new Vector2(rayVector1.x - skin, 0), Color.green); // Debug line.
                        }
                        Debug.DrawRay(rayPos, new Vector2(rayVector1.x - skin, 0), Color.yellow);    // Debug line.
                    }
                }
            }
            else                                                                       // If no hit.
            {
                Debug.DrawRay(rayPos, new Vector2(rayVector1.x - skin, 0), Color.red); // Debug line.
            }

            // Right-facing collisions.
            rayPos = pos + new Vector2(xOffset, -yOffset + (i * ySpacing) + (ySpacing / 2.0f));               // Set position of ray start points.
            RaycastHit2D rayRight = Physics2D.Linecast(rayPos, rayPos + new Vector2(rayVector2.x + skin, 0)); // Make new ray.

            if (rayRight)                                                                                     // If hit.
            {
                rayVector2 = rayRight.point - (rayPos);                                                       // Create local vector based on ray path.
                if (rayRight.collider.tag == "Thin")
                {
                    Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.magenta);                       // Debug line.
                }
                else
                {
                    // Begin drill code.
                    if (isDrilling)
                    {
                        if (doubleRight)
                        {
                            if (rayRight.collider.gameObject.layer == LayerMask.NameToLayer("Solid"))
                            {
                                if (rayRight.collider.gameObject.layer != LayerMask.NameToLayer("Unbreakable"))
                                {
                                    GameObject c = rayRight.collider.gameObject;
                                    GameObject.Destroy(c);
                                }
                            }
                        }
                    }
                    // End drill code.
                    if (rayRight.collider.tag == "Boulder")
                    {
                        if (rayVector2.x < skin)                           // If ray length hits, and is less than skin.
                        {
                            if (acc.x > 0.001f)
                            {
                                rayRight.collider.attachedRigidbody.AddTorque(-acc.x * 200f);
                                vel.x = acc.x;
                                //acc.x = 0;
                            }
                            cRight = true;                                                           // Officially collided.
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.green); // Debug line.
                        }
                        else
                        {
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.yellow);                               // Debug line.
                        }
                    }
                    else
                    {
                        vel.x = rayVector2.x - skin;                                                 // Make sure not to overshoot.
                        Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.cyan);      // Debug line.
                        if (rayVector2.x < skin)                                                     // If ray length hits, and is less than skin.
                        {
                            cRight = true;                                                           // Officially collided.
                            vel.x  = 0;                                                              // Hit.
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.green); // Debug line.
                        }
                        else
                        {
                            Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.yellow);                               // Debug line.
                        }
                    }
                }
            }
            else                                                                       // If no hit.
            {
                Debug.DrawRay(rayPos, new Vector2(rayVector2.x + skin, 0), Color.red); // Debug line.
            }
        }

        float sumJumpMultiplier = 0;         // Jump-force summation.

        rayVector1 = vel;
        rayVector2 = vel;

        // Iterate over the head and feet rays.
        for (int i = 0; i < yRays; i++)
        {
            // Upward-facing collisions.
            rayPos = pos + new Vector2(-xOffset + (i * xSpacing) + (xSpacing / 2.0f), yOffset);            // Set position of ray start points.
            RaycastHit2D rayUp = Physics2D.Linecast(rayPos, rayPos + new Vector2(0, rayVector1.y + skin)); // Make new ray.

            if (rayUp)                                                                                     // If hit.
            {
                rayVector1 = rayUp.point - (rayPos);                                                       // Create local vector based on ray path.
                if (vel.y >= -0.1f)                                                                        // Is moving upwards.
                {
                    if (rayUp.collider.tag == "Thin")
                    {
                        Debug.DrawRay(rayPos, new Vector2(0, rayVector1.y + skin), Color.magenta);                           // Debug line.
                    }
                    else
                    {
                        // Begin drill code.
                        if (isDrilling)
                        {
                            if (doubleUp)
                            {
                                if (rayUp.collider.gameObject.layer == LayerMask.NameToLayer("Solid"))
                                {
                                    if (rayUp.collider.gameObject.layer != LayerMask.NameToLayer("Unbreakable"))
                                    {
                                        GameObject c = rayUp.collider.gameObject;
                                        GameObject.Destroy(c);
                                    }
                                }
                            }
                        }
                        // End drill code.
                        vel.y = rayVector1.y - skin;                                            // Make sure not to overshoot.
                        Debug.DrawRay(rayPos, new Vector2(0, rayVector1.y + skin), Color.cyan); // Debug line.
                        if (rayVector1.y < skin)                                                // If ray length hits, and is less than skin.
                        {
                            cTop = true;                                                        // Officially collided.

                            if (rayVector2.y < skin - 0.02f)
                            {
                                vel.y = -0.01f;                                 // Hit.
                            }
                            else
                            {
                                vel.y = 0;
                            }

                            Debug.DrawRay(rayPos, new Vector2(0, rayVector1.y + skin), Color.green);                               // Debug line.
                        }
                        else
                        {
                            Debug.DrawRay(rayPos, new Vector2(0, rayVector1.y + skin), Color.yellow);                               // Debug line.
                        }
                    }
                }
            }
            else                                                                       // If no hit.
            {
                Debug.DrawRay(rayPos, new Vector2(0, rayVector1.y + skin), Color.red); // Debug line.
            }

            // Downward-facing collisions.
            rayPos = pos + new Vector2(-xOffset + (i * xSpacing) + (xSpacing / 2.0f), -yOffset);             // Set position of ray start points.
            RaycastHit2D rayDown = Physics2D.Linecast(rayPos, rayPos + new Vector2(0, rayVector2.y - skin)); // Make new ray.

            if (rayDown)                                                                                     // If hit.
            {
                sumJumpMultiplier += rayDown.collider.bounciness;                                            // Get bounciness of tile.
                rayVector2         = rayDown.point - (rayPos);                                               // Create local vector based on ray path.
                if (vel.y <= 0.1f)                                                                           // Is moving downwards.
                {
                    if (rayDown.collider.tag == "Thin")
                    {
                        WoodPlank p = rayDown.collider.gameObject.GetComponent <WoodPlank> ();
                        p.durability -= 0.003f;
                        if (dropTimer <= 0)                                                         // If timer isn't in effect.
                        {
                            vel.y = rayVector2.y + skin;                                            // Make sure not to overshoot.
                            Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.cyan); // Debug line.
                            if (rayVector2.y > -skin)                                               // If ray length hits, and is less than skin.

                            {
                                cBottom = true;                                 // Officially collided.

                                if (rayVector2.y > -skin + 0.02f)
                                {
                                    vel.y = 0.01f;                                     // Hit.
                                }
                                else
                                {
                                    vel.y = 0;
                                }
                                Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.green);                                   // Debug line.
                                if (rayVector2.y == 0)
                                {
                                    pos.y += 0.01f;
                                }
                            }
                        }
                        else                                                                          // If fall-through timer is still activated.
                        {
                            Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.yellow); // Debug line.
                        }
                    }
                    else
                    {
                        // Begin drill code.
                        if (isDrilling)
                        {
                            if (doubleDown)
                            {
                                if (rayDown.collider.gameObject.layer == LayerMask.NameToLayer("Solid"))
                                {
                                    if (rayDown.collider.gameObject.layer != LayerMask.NameToLayer("Unbreakable"))
                                    {
                                        GameObject c = rayDown.collider.gameObject;
                                        GameObject.Destroy(c);
                                    }
                                }
                            }
                        }
                        // End drill code.
                        vel.y = rayVector2.y + skin;                                            // Make sure not to overshoot.
                        Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.cyan); // Debug line.
                        if (rayVector2.y > -skin)                                               // If ray length hits, and is less than skin.

                        {
                            cBottom = true;                             // Officially collided.

                            if (rayVector2.y > -skin + 0.02f)
                            {
                                vel.y = 0.01f;                                 // Hit.
                            }
                            else
                            {
                                vel.y = 0;
                            }
                            Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.green);                               // Debug line.
                            if (rayVector2.y == 0)
                            {
                                pos.y += 0.01f;
                            }
                        }
                    }
                }
            }
            else                                                                       // If no hit.
            {
                Debug.DrawRay(rayPos, new Vector2(0, rayVector2.y - skin), Color.red); // Debug line.
            }



            jumpMultiplier = sumJumpMultiplier / yRays * 10.0f;
        }
    }