Exemple #1
0
        public void Draw()
        {
            BeginDrawing();
            ClearBackground(Color.WHITE);
            DrawText(fps.ToString(), 10, 10, 12, Color.RED);
            tankObject1.Draw();
            tankObject2.Draw();
            tankBulletObject1.Draw();
            tankBullet1.Draw(tankBullet1.blankHitBox.Overlaps(tank2.blankHitBox));
            tank1.Draw(tank1.blankHitBox.Overlaps(tank2.blankHitBox));
            tank2.Draw(tank2.blankHitBox.Overlaps(tank1.blankHitBox));

            EndDrawing();
        }
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            int screenWidth  = 800;
            int screenHeight = 450;

            rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

            rl.SetTargetFPS(60);
            //--------------------------------------------------------------------------------------
            MyShape triangle = new MyShape();

            triangle.MyPoints.Add(new Vector2(-20, 20));
            triangle.MyPoints.Add(new Vector2(0, -20));
            triangle.MyPoints.Add(new Vector2(20, 20));
            triangle.MyPoints.Add(new Vector2(-20, 20));
            triangle.position = new Vector2(100, 100);



            //TODO:Create another object with a different shape

            MyShape rectangle = new MyShape();

            rectangle.MyPoints.Add(new Vector2(-20, 20));
            rectangle.MyPoints.Add(new Vector2(-20, -20));
            rectangle.MyPoints.Add(new Vector2(20, -20));
            rectangle.MyPoints.Add(new Vector2(20, 20));
            rectangle.MyPoints.Add(new Vector2(-20, 20));
            rectangle.position = new Vector2(200, 200);


            //float tv = 0.5f;
            //float sv = -0.5f;

            Vector2 tv = new Vector2(0.5f, 0.5f);
            Vector2 sv = new Vector2(-0.5f, -.5f);


            // Main game loop
            while (!rl.WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                // TODO: Update your variables here


                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                rl.BeginDrawing();

                rl.ClearBackground(Color.RAYWHITE);

                rl.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LIGHTGRAY);

                if (triangle.position.x > 800)
                {
                    triangle.position.x = 5;
                }

                if (triangle.position.x < 0)
                {
                    triangle.position.x = 795;
                }

                if (triangle.position.y > 450)
                {
                    triangle.position.y = 5;
                }

                if (triangle.position.y < 0)
                {
                    triangle.position.y = 445;
                }

                if (rectangle.position.x > 800)
                {
                    rectangle.position.x = 5;
                }

                if (rectangle.position.x < 0)
                {
                    rectangle.position.x = 795;
                }

                if (rectangle.position.y > 450)
                {
                    rectangle.position.y = 5;
                }

                if (rectangle.position.y < 0)
                {
                    rectangle.position.y = 445;
                }


                triangle.Draw();
                triangle.myColor = Color.DARKGREEN;

                rectangle.Draw();
                rectangle.myColor = Color.DARKGREEN;

                Vector2 Triangle_Pos_Backup = triangle.position;
                Vector2 Rect_Pos_Backup     = rectangle.position;

                //triangle.position.x += tv;
                //rectangle.position.x += sv;

                triangle.position  += tv;
                rectangle.position += sv;



                triangle.myGlobal.Clear();
                rectangle.myGlobal.Clear();

                foreach (Vector2 v in triangle.MyPoints)
                {
                    triangle.myGlobal.Add(v + triangle.position);
                }
                foreach (Vector2 v in rectangle.MyPoints)
                {
                    rectangle.myGlobal.Add(v + rectangle.position);
                }

                triangle.myBox.Fit(triangle.myGlobal);
                rectangle.myBox.Fit(rectangle.myGlobal);

                if (triangle.myBox.Overlaps(rectangle.myBox))
                {
                    //System.Threading.Thread.Sleep(500);
                    tv *= -1;
                    sv *= -1;

                    rectangle.position = Rect_Pos_Backup;
                    triangle.position  = Triangle_Pos_Backup;

                    triangle.myColor  = Color.RED;
                    rectangle.myColor = Color.RED;
                }


                //TODO:Move the 2nd object so that it is on a collision course with the triangle
                //TODO:Implement AABB Collision detection so you know when they hit.
                //Recommend adding the AABB Functionality to the myshape class.
                //Add a method to the myshape class that causes the Bounding box to be recalculated and
                //stored in the myshape class (with the corners/vectors relative to itself)


                //TODO:Bonus have your AABB Box drawn as a green outline to the shapes, and then turn red
                //When they collide.


                rl.EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            rl.CloseWindow();        // Close window and OpenGL context
                                     //--------------------------------------------------------------------------------------

            return(0);
        }
Exemple #3
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            int screenWidth  = 800;
            int screenHeight = 450;

            rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

            rl.SetTargetFPS(60);
            //--------------------------------------------------------------------------------------

            MyShape triangle = new MyShape();

            triangle.MyPoints.Add(new Vector2(10, 10));
            triangle.MyPoints.Add(new Vector2(20, 30));
            triangle.MyPoints.Add(new Vector2(30, 10));
            triangle.MyPoints.Add(new Vector2(10, 10));
            triangle.MyPoints.Add(new Vector2(40, 30));
            triangle.MyPoints.Add(new Vector2(50, 10));
            triangle.position = new Vector2(100, 100);

            MyShape satan = new MyShape();

            satan.MyPoints.Add(new Vector2(0, 11));
            satan.MyPoints.Add(new Vector2(-10, -10));
            satan.MyPoints.Add(new Vector2(13, 3));
            satan.MyPoints.Add(new Vector2(-13, 3));
            satan.MyPoints.Add(new Vector2(10, -10));
            satan.MyPoints.Add(new Vector2(0, 11));
            satan.position.x = 60;
            satan.position.y = 120;

            //Vector2 satanVector = new Vector2();

            //AABB aabb = new AABB();

            //TODO:Create another object with a different shape


            // Main game loop
            while (!rl.WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                // TODO: Update your variables here
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                rl.BeginDrawing();

                rl.ClearBackground(Color.RAYWHITE);

                rl.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LIGHTGRAY);
                //triangle.Draw();
                //satan.Draw();
                satan.Draw(satan.blankHitBox.Overlaps(triangle.blankHitBox));
                triangle.Draw(triangle.blankHitBox.Overlaps(satan.blankHitBox));

                satan.DrawCircle();
                satan.DrawCircle(satan.blankHitCircle.Overlaps(triangle.blankHitBox));
                satan.DrawCircle(satan.blankHitCircle.Overlaps(triangle.blankHitBox));

                satan.position.x    += .6f;
                triangle.position.x += .2f;

                //rl.DrawCircleLines(1, 1, 1, Color.GREEN);

                //TODO:Move the 2nd object so that it is on a collision course with the triangle
                //TODO:Implement AABB Collision detection so you know when they hit.
                //Recommend adding the AABB Functionality to the myshape class.
                //Add a method to the myshape class that causes the Bounding box to be recalculated and
                //stored in the myshape class (with the corners/vectors relative to itself)


                //TODO:Bonus have your AABB Box drawn as a green outline to the shapes, and then turn red
                //When they collide.


                rl.EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            rl.CloseWindow();        // Close window and OpenGL context
                                     //--------------------------------------------------------------------------------------

            return(0);
        }
Exemple #4
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            int screenWidth  = 800;
            int screenHeight = 450;

            rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

            rl.SetTargetFPS(60);
            //--------------------------------------------------------------------------------------
            MyShape triangle = new MyShape();

            triangle.MyPoints.Add(new Vector2(0, 20));
            triangle.MyPoints.Add(new Vector2(20, -20));
            triangle.MyPoints.Add(new Vector2(-20, -20));
            triangle.MyPoints.Add(new Vector2(0, 20));
            triangle.position = new Vector2(100, 100);

            MyShape square = new MyShape();

            square.MyPoints.Add(new Vector2(20, -20));
            square.MyPoints.Add(new Vector2(20, 20));
            square.MyPoints.Add(new Vector2(-20, 20));
            square.MyPoints.Add(new Vector2(-20, -20));
            square.MyPoints.Add(new Vector2(20, -20));
            square.position = new Vector2(220, 100);

            foreach (Vector2 v in triangle.MyPoints)
            {
                triangle.Global.Add(v + triangle.position);
            }

            foreach (Vector2 v in square.MyPoints)
            {
                square.Global.Add(v + square.position);
            }

            triangle.box.Fit(triangle.Global);
            square.box.Fit(square.Global);

            //TODO:Create another object with a different shape
            float tv = .3f;
            float sv = -.3f;

            // Main game loop
            while (!rl.WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                // TODO: Update your variables here
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                rl.BeginDrawing();

                rl.ClearBackground(Color.RAYWHITE);

                rl.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LIGHTGRAY);
                triangle.Draw();
                triangle.position.x += tv;

                square.Draw();
                square.position.x += sv;

                foreach (Vector2 v in triangle.MyPoints)
                {
                    triangle.Global.Add(v + triangle.position);
                }

                foreach (Vector2 v in square.MyPoints)
                {
                    square.Global.Add(v + square.position);
                }

                triangle.box.Fit(triangle.Global);
                square.box.Fit(square.Global);

                if (triangle.box.Overlaps(square.box))
                {
                    tv = -.2f;
                    sv = .2f;
                    triangle.myColor = Color.RED;
                    square.myColor   = Color.RED;
                }

                //TODO:Move the 2nd object so that it is on a collision course with the triangle
                //TODO:Implement AABB Collision detection so you know when they hit.
                //Recommend adding the AABB Functionality to the myshape class.
                //Add a method to the myshape class that causes the Bounding box to be recalculated and
                //stored in the myshape class (with the corners/vectors relative to itself)


                //TODO:Bonus have your AABB Box drawn as a green outline to the shapes, and then turn red
                //When they collide.


                rl.EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            rl.CloseWindow();        // Close window and OpenGL context
                                     //--------------------------------------------------------------------------------------

            return(0);
        }
Exemple #5
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            int screenWidth  = 800;
            int screenHeight = 450;

            InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

            SetTargetFPS(60);
            //--------------------------------------------------------------------------------------
            MyShape triangle = new MyShape();

            triangle.MyPoints.Add(new Vector2(10, 10));
            triangle.MyPoints.Add(new Vector2(20, 30));
            triangle.MyPoints.Add(new Vector2(30, 10));
            triangle.MyPoints.Add(new Vector2(10, 10));
            triangle.position = new Vector2(100, 100);
            triangle.color    = Color.GREEN;

            MyShape star = new MyShape();

            star.MyPoints.Add(new Vector2(5, 40));
            star.MyPoints.Add(new Vector2(20, 0));
            star.MyPoints.Add(new Vector2(35, 40));
            star.MyPoints.Add(new Vector2(-5, 20));
            star.MyPoints.Add(new Vector2(45, 20));
            star.MyPoints.Add(new Vector2(5, 40));
            star.position = new Vector2(200, 100);
            star.color    = Color.GOLD;

            Circle circleCol = new Circle(new Vector2(300, 300), 20);

            // Main game loop
            while (!WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                // TODO: Update your variables here
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                BeginDrawing();

                ClearBackground(Color.RAYWHITE);

                DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LIGHTGRAY);

                if (IsKeyDown(KeyboardKey.KEY_W))
                {
                    star.position.y -= star.Swooce;
                }
                if (IsKeyDown(KeyboardKey.KEY_A))
                {
                    star.position.x -= star.Swooce;
                }
                if (IsKeyDown(KeyboardKey.KEY_S))
                {
                    star.position.y += star.Swooce;
                }
                if (IsKeyDown(KeyboardKey.KEY_D))
                {
                    star.position.x += star.Swooce;
                }

                if (triangle.collisionBox.Overlaps(star.collisionBox))
                {
                    triangle.color = Color.RED;
                }
                else
                {
                    triangle.color = Color.GREEN;
                }

                if (circleCol.Overlaps(star.collisionBox))
                {
                    star.color = Color.SKYBLUE;
                }
                else
                {
                    star.color = Color.GOLD;
                }

                DrawCircle(300, 300, 20, Color.PURPLE);

                triangle.Update();
                triangle.Draw();
                triangle.position.x += triangle.Swooce;
                if (triangle.position.x <= 99 || triangle.position.x >= 300)
                {
                    triangle.Swooce = -triangle.Swooce;
                }

                star.Update();
                star.Draw();


                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            CloseWindow();
            // Close window and OpenGL context
            //--------------------------------------------------------------------------------------

            return(0);
        }