/*/////////////////////////////////////////
         * GRAPHICAL DATA & RESOURCE LOADING
         */
        ////////////////////////////////////////
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            this.sprite_batch = new SpriteBatch(this.GraphicsDevice);

            // Load game logo:
            this.logo = this.Content.Load<Texture2D>("Textures/Interface/UI_Logo");
            this.logo_pos = new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width - this.logo.Width) / 2.0),
                                        (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height - this.logo.Height) / 2.0));

            // Create Kinect manager:
            this.kinect_manager = new KinectManager(ColorImageFormat.RgbResolution640x480Fps30,
                                                    DepthImageFormat.Resolution640x480Fps30,
                                                    this);

            // Create player cursors:
            this.player_1_cursor = new Cursor(this.Content.Load<Texture2D>("Textures/Interface/UI_CursorHand"),
                                              this.Content.Load<Texture2D>("Textures/Interface/UI_CursorColourIcon"),
                                              this.Content.Load<SpriteFont>("Fonts/Segoe16"),
                                              JointType.HandLeft,
                                              1.0f,
                                              0);
            this.player_2_cursor = new Cursor(this.Content.Load<Texture2D>("Textures/Interface/UI_CursorHand"),
                                              this.Content.Load<Texture2D>("Textures/Interface/UI_CursorColourIcon"),
                                              this.Content.Load<SpriteFont>("Fonts/Segoe16"),
                                              JointType.HandRight,
                                              1.0f,
                                              1);

            // Create main-menu/player-selection buttons (with offset):
            this.mainmenu_button_1player = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_SinglePlayer"),
                                                      1.2f,
                                                      new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) - 270),
                                                                  (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height - 360) / 2.0f)),
                                                      GestureType.NONE);

            this.mainmenu_button_2player = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_MultiPlayer"),
                                                      1.2f,
                                                      new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) + 10),
                                                                  (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height - 360) / 2.0f)),
                                                      GestureType.NONE);

            // Create hand selection buttons (with offset):
            this.mainmenu_lefthand_1 = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_LeftHand"),
                                                  1.2f,
                                                  new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) - 270),
                                                              (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height / 2.0f) - 160)),
                                                  GestureType.NONE);

            this.mainmenu_lefthand_2 = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_LeftHand"),
                                                  1.2f,
                                                  new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) + 110),
                                                              (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height / 2.0f) - 160)),
                                                  GestureType.NONE);

            this.mainmenu_righthand_1 = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_RightHand"),
                                                   1.2f,
                                                   new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) - 270),
                                                               (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height / 2.0f))),
                                                   GestureType.NONE);

            this.mainmenu_righthand_2 = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_RightHand"),
                                                   1.2f,
                                                   new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width / 2.0f) + 110),
                                                               (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height / 2.0f))),
                                                   GestureType.NONE);

            // Create start game button (with offset):
            this.mainmenu_startgame = new Button(this.Content.Load<Texture2D>("Textures/Interface/UI_StartGame"),
                                                 1.2f,
                                                 new Vector2((float)Math.Ceiling((this.GraphicsDevice.Viewport.Width - 160) / 2.0f),
                                                             (float)Math.Ceiling((this.GraphicsDevice.Viewport.Height / 2.0f) + 100)),
                                                 GestureType.NONE);

            this.player_1_cursor.selected_colour = Color.Red;
        }
예제 #2
0
        /*/////////////////////////////////////////
          * GRAPHICAL RESOURCE LOADING
          */
        ///////////////////////////////////////
        public void load(ContentManager p_content,
                         GraphicsDevice p_gfx_device)
        {
            // Load the puzzle game:
            this.marker_texture = p_content.Load<Texture2D>("Textures/Game/PuzzleMarkers");
            Rectangle[,] temp_rects = new Rectangle[across, down];

            // Divide image into sections:
            for (int i = 0; i < this.across; i++)
            {
                for (int j = 0; j < this.down; j++)
                {
                    temp_rects[i, j] = new Rectangle(i * this.width,
                                                     j * this.height,
                                                     this.width,
                                                     this.height);
                }
            }

            // Create puzzle-piece lists:
            if (this.is_two_player)
            {
                // Setup both lists of puzzle pieces:
                this.p1_pieces = new List<PuzzlePiece>();
                this.p2_pieces = new List<PuzzlePiece>();

                for (int i = 0; i < this.across; i++)
                {
                    for (int j = 0; j < this.down; j++)
                    {
                        var temp = temp_rects[i, j];
                        var temp2 = temp;

                        temp2.X = this.image_rect.X + i * this.width;
                        temp2.Y = this.image_rect.Y + j * this.height;

                        if(temp.X < 256)
                        {
                            // Give piece to player 1:
                            this.p1_pieces.Add(new PuzzlePiece(temp, temp2));
                        }
                        else
                        {
                            // Give piece to player 2:
                            this.p2_pieces.Add(new PuzzlePiece(temp, temp2));
                        }
                    }
                }
            }
            else
            {
                // Setup player 1's list of puzzle pieces:
                this.p1_pieces = new List<PuzzlePiece>();
                this.p2_pieces = null;

                for (int i = 0; i < this.across; i++)
                {
                    for (int j = 0; j < this.down; j++)
                    {
                        var temp = temp_rects[i, j];
                        var temp2 = temp;

                        temp2.X = this.image_rect.X + i * this.width;
                        temp2.Y = this.image_rect.Y + j * this.height;

                        // Give piece to player 1:
                        this.p1_pieces.Add(new PuzzlePiece(temp, temp2));
                    }
                }
            }

            this.p1_current_piece = 0;
            this.p2_current_piece = 0;
            this.p1_new_piece = false;
            this.p2_new_piece = false;

            // Create buttons for player 1:
            Vector2 temp_p1_pos = new Vector2(this.image_rect.X - 270.0f,
                                              (float)Math.Ceiling((p_gfx_device.Viewport.Height - 750) / 2.0f) - 10.0f);

            this.p1_next_piece = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonUp"),
                                            1.2f,
                                            temp_p1_pos,
                                            GestureType.NONE);

            temp_p1_pos.Y += 150;

            // Position player 1's pieces;
            foreach(var piece in this.p1_pieces)
            {
                piece.destination_rect.X = (int)temp_p1_pos.X + 50;
                piece.destination_rect.Y = (int)temp_p1_pos.Y + 100;
            }

            temp_p1_pos.Y += 150 * 3;

            this.p1_prev_piece = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonDown"),
                                            1.2f,
                                            temp_p1_pos,
                                            GestureType.NONE);

            // Create buttons for player 2:
            Vector2 temp_p2_pos = new Vector2(this.image_rect.X + this.image_rect.Width + 60.0f,
                                              (float)Math.Ceiling((p_gfx_device.Viewport.Height - 750) / 2.0f) - 10.0f);

            this.p2_next_piece = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonUp"),
                                            1.2f,
                                            temp_p2_pos,
                                            GestureType.NONE);
            temp_p2_pos.Y += 150;

            // Positions player 2's pieces:
            if (this.is_two_player &&
                this.p2_pieces != null)
            {
                foreach (var piece in this.p2_pieces)
                {
                    piece.destination_rect.X = (int)temp_p2_pos.X + 40;
                    piece.destination_rect.Y = (int)temp_p2_pos.Y + 100;
                }
            }

            temp_p2_pos.Y += 150 * 3;

            this.p2_prev_piece = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonDown"),
                                            1.2f,
                                            temp_p2_pos,
                                            GestureType.NONE);
        }
        /*/////////////////////////////////////////
          * GRAPHICAL RESOURCE LOADING
          */
        ///////////////////////////////////////
        public void load(ContentManager p_content,
                         GraphicsDevice p_gfx_device)
        {
            int current_image = this.rand.Next(0, this.valid_pictures.Length);

            // Load the image:
            Texture2D image_base = p_content.Load<Texture2D>("Textures/Game/" + this.valid_pictures[current_image] + "_Sections");
            int base_size = image_base.Width * image_base.Height;

            Color[] image_colours = new Color[base_size];

            for (int i = 0; i < image_colours.Length; i++)
            {
                image_colours[i] = Color.White;
            }

            // Load image outline, setup blank white paintable image, position with offset:
            this.image_outlines = p_content.Load<Texture2D>("Textures/Game/" + this.valid_pictures[current_image] + "_Outline");
            this.image_rect = new Rectangle((int)Math.Ceiling((p_gfx_device.Viewport.Width - image_base.Width) / 2.0f),
                                            (int)Math.Ceiling(((p_gfx_device.Viewport.Height - image_base.Height) / 2.0f) - 60),
                                            image_base.Width,
                                            image_base.Height);

            this.image_paintable = new Texture2D(p_gfx_device, image_base.Width, image_base.Height);
            this.image_paintable.SetData(image_colours);

            // Convert base image to paint sections:
            image_base.GetData(image_colours);
            Color[] unique_colours = this.findUniqueColours(image_colours);
            this.image_sections = new PaintSection[unique_colours.Length]; // create a paint section for each unique colour

            for (int i = 0; i < image_sections.Length; i++)
            {
                this.image_sections[i] = new PaintSection(base_size,
                                                          unique_colours[i],
                                                          1.2f,
                                                          GestureType.NONE);
                this.image_sections[i].createSectionMask(image_colours);
            }

            this.paint_colours = image_colours;
            for (int i = 0; i < this.paint_colours.Length; i++) this.paint_colours[i] = Color.White;

            // Create finish minigame button (positioned from the bottom of the base image with offset):
            this.finish_confirm = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonConfirm"),
                                             1.2f,
                                             new Vector2((float)Math.Ceiling((p_gfx_device.Viewport.Width - 210) / 2.0f),
                                                         this.image_rect.Y + this.image_rect.Height + 20),
                                             GestureType.NONE);

            // Create colour selection & scroll buttons for player 1:
            Vector2 temp_p1_pos = new Vector2(this.image_rect.X - 270.0f,
                                              (float)Math.Ceiling((p_gfx_device.Viewport.Height - 750) / 2.0f) - 10.0f);

            this.p1_next_col = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonUp"),
                                          1.2f,
                                          temp_p1_pos,
                                          GestureType.NONE);

            this.p1_cbuttons = new ColourButton[3];
            temp_p1_pos.Y += 150;

            for (int i = 0; i < this.p1_cbuttons.Length; i++)
            {
                this.p1_cbuttons[i] = new ColourButton(p_content.Load<Texture2D>("Textures/Interface/UI_ColourButton"),
                                                       1.2f,
                                                       temp_p1_pos,
                                                       GestureType.NONE,
                                                       this.valid_button_colours[this.p1_colours[i]]);

                // Next button position:
                temp_p1_pos.Y += 150;
            }

            this.p1_prev_col = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonDown"),
                                          1.2f,
                                          temp_p1_pos,
                                          GestureType.NONE);

            // Create colour selection & scroll buttons for player 2:
            Vector2 temp_p2_pos = new Vector2(this.image_rect.X + this.image_rect.Width + 60.0f,
                                              (float)Math.Ceiling((p_gfx_device.Viewport.Height - 750) / 2.0f) - 10.0f);

            this.p2_next_col = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonUp"),
                                          1.2f,
                                          temp_p2_pos,
                                          GestureType.NONE);

            this.p2_cbuttons = new ColourButton[3];
            temp_p2_pos.Y += 150;

            for (int i = 0; i < this.p2_cbuttons.Length; i++)
            {
                this.p2_cbuttons[i] = new ColourButton(p_content.Load<Texture2D>("Textures/Interface/UI_ColourButton"),
                                                       1.2f,
                                                       temp_p2_pos,
                                                       GestureType.NONE,
                                                       this.valid_button_colours[this.p1_colours[i]]);

                // Next button position:
                temp_p2_pos.Y += 150;
            }

            this.p2_prev_col = new Button(p_content.Load<Texture2D>("Textures/Interface/UI_ButtonDown"),
                                          1.2f,
                                          temp_p2_pos,
                                          GestureType.NONE);
        }