Пример #1
0
        private void gameGrid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            //this code can select a block based on the location of a click and then call any method on the block
            int[] clickArrayLoc = Engine.GetArrayLocation(e.GetPosition(gameGrid));

            var distance = Engine.GetDistance(new Point((clickArrayLoc[0] * 25) + 13, (clickArrayLoc[1] * 25) + 13), new Point(world.player.Margin.Left + (world.player.Width / 2), world.player.Margin.Top + (world.player.Height / 2)));

            //isolates the individual block
            var selectedBlock = world.GetBlockAtLocation(e.GetPosition(gameGrid));

            if (distance <= 75)
            {
                if (Engine.GetDrillMiningValidityOfBlocksIfYouBoughtTheRightDrill(world.player.playerDrill, selectedBlock))
                {
                    //this.Title = "";

                    //adds that block to the world.players inventory
                    if (world.player.Cargo < world.player.CargoBayCapacity)
                    {
                        world.player.inventory.Add(selectedBlock.GetType(), 1);
                    }
                    //removes the block from the world

                    //world.TransformToAir(world.blockArray[clickArrayLoc[0], clickArrayLoc[1]], gameGrid);
                    world.PlaceBlock(typeof(Block_air), world.blockArray[clickArrayLoc[0], clickArrayLoc[1]]);
                    cargoHudLabel.Text = world.player.Cargo.ToString() + " / " + world.player.CargoBayCapacity.ToString();
                }
            }
            //else if (mode == interactionMode.Build)
            //{   //place a block
            //    if (world.player.inventory.Items.ContainsKey(selection))
            //    {
            //        if (world.player.inventory.Items[selection] > 0)
            //        {
            //            world.PlaceBlock(selection, selectedBlock);
            //            world.player.inventory.Remove(selection, 1);
            //        }
            //    }
            //}

            //this.Title = "";

            //foreach (var v in world.player.inventory.Items)
            //{
            //    //(testing code) displays the world.player inventory in the title of the window
            //    this.Title += v.Key.ToString() + ": " + v.Value.ToString() + " ";
            //    this.Title = this.Title.Replace("Terrerieh___Culminating.", "");//.Replace("_","");
            //}
        }
Пример #2
0
        //public void Jump(Engine.Direction d) {
        //    if (isMoving != true)
        //    {
        //        int deltaY = GetMaxMovement(Engine.Direction.Up, 30);
        //        switch (d)
        //        {

        //            case Engine.Direction.Left:
        //                break;

        //            case Engine.Direction.Right:
        //                AddToQueue(new Movement(new Vector(0, deltaY * -1), deltaY * 10, 0, 0.999));
        //                AddToQueue(new Movement(new Vector(3,0), 1));
        //                ProcessEntireQueue();
        //                break;

        //            case Engine.Direction.None:

        //                //MessageBox.Show("jump");


        //                StartAnimation(new Movement(new Vector(0, deltaY * -1), deltaY * 10, 0, 0.999));
        //                break;
        //        }
        //    }
        //}

        private int GetMaxMovement(Engine.Direction dir, int maxDistance)
        {
            //returns the max number of pixels that the player can travel in a specific direction, with an upper limit of a specified number of pixels (maxDistance)

            int playerX = Convert.ToInt32(this.Margin.Left);
            int playerY = Convert.ToInt32(this.Margin.Top);

            maxDistance = Math.Abs(maxDistance);

            switch (dir)
            {
            case Engine.Direction.Up:

                int maxL_Up = maxDistance;
                int maxR_Up = maxDistance;

                try
                {
                    for (int l = 0; l <= maxDistance; l++)
                    {
                        if (parentWorld.GetBlockAtLocation(playerX + 2, playerY - l).penetrable == false)
                        {
                            maxL_Up = l;
                            break;
                        }
                    }

                    for (int r = 0; r <= maxDistance; r++)
                    {
                        if (parentWorld.GetBlockAtLocation(Convert.ToInt32(playerX + this.Width - 2), playerY - r).penetrable == false)
                        {
                            maxR_Up = r;
                            break;
                        }
                    }

                    if (maxL_Up <= maxR_Up)
                    {
                        if (maxL_Up == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxL_Up - 1);
                        }
                    }
                    else
                    {
                        if (maxR_Up == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxR_Up - 1);
                        }
                    }
                }
                catch
                {
                    return(0);
                }

            case Engine.Direction.Down:

                int maxL_Down = maxDistance;
                int maxR_Down = maxDistance;
                try
                {
                    for (int l = 0; l <= maxDistance; l++)
                    {
                        if (parentWorld.GetBlockAtLocation(playerX + 2, Convert.ToInt32(playerY + this.Height)).penetrable == false)
                        {
                            maxL_Down = l;
                            break;
                        }
                    }


                    for (int r = 0; r <= maxDistance; r++)
                    {
                        if (parentWorld.GetBlockAtLocation(Convert.ToInt32(playerX + this.Width - 2), Convert.ToInt32(playerY + this.Height) + r).penetrable == false)
                        {
                            maxR_Down = r;
                            break;
                        }
                    }

                    if (maxL_Down <= maxR_Down)
                    {
                        if (maxL_Down == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxL_Down - 1);
                        }
                    }
                    else
                    {
                        if (maxR_Down == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxR_Down - 1);
                        }
                    }
                }
                catch
                {
                    return(0);
                }

            case Engine.Direction.Left:

                int maxU_Left = maxDistance;
                int maxD_Left = maxDistance;
                try
                {
                    for (int u = 0; u <= maxDistance; u++)
                    {
                        if (parentWorld.GetBlockAtLocation(playerX - u + 2, playerY).penetrable == false)
                        {
                            maxU_Left = u;
                            break;
                        }
                    }

                    for (int d = 0; d <= maxDistance; d++)
                    {
                        if (parentWorld.GetBlockAtLocation(playerX - d + 2, Convert.ToInt32((playerY - 1) + this.Height)).penetrable == false)
                        {
                            maxD_Left = d;
                            break;
                        }
                    }

                    if (maxU_Left <= maxD_Left)
                    {
                        if (maxU_Left == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxU_Left - 1);
                        }
                    }
                    else
                    {
                        if (maxD_Left == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxD_Left - 1);
                        }
                    }
                }
                catch
                {
                    return(0);
                }

            case Engine.Direction.Right:
                try
                {
                    int maxU_Right = maxDistance;
                    int maxD_Right = maxDistance;

                    for (int u = 0; u <= maxDistance; u++)
                    {
                        if (parentWorld.GetBlockAtLocation(Convert.ToInt32((playerX - 2) + this.Width + u), playerY).penetrable == false)
                        {
                            maxU_Right = u;
                            break;
                        }
                    }

                    for (int d = 0; d <= maxDistance; d++)
                    {
                        if (parentWorld.GetBlockAtLocation(Convert.ToInt32((playerX - 2) + this.Width + d), Convert.ToInt32((playerY - 1) + this.Height)).penetrable == false)
                        {
                            maxD_Right = d;
                            break;
                        }
                    }

                    if (maxU_Right <= maxD_Right)
                    {
                        if (maxU_Right == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxU_Right - 1);
                        }
                    }
                    else
                    {
                        if (maxD_Right == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(maxD_Right - 1);
                        }
                    }
                }
                catch
                {
                    return(0);
                }
            }
            return(0);
        }