Exemple #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("_","");
            //}
        }
Exemple #2
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            //runs when a key is pressed

            switch (e.Key)
            {
            //-------------------------------------------------------
            //Inventory Keys
            //case Key.D1:
            //    selection = world.player.inventory.Items.ElementAt(0).Key;
            //    MessageBox.Show(selection.ToString() + " selected");
            //    break;
            //case Key.D2:
            //    selection = world.player.inventory.Items.ElementAt(1).Key;
            //    MessageBox.Show(selection.ToString() + "selected");
            //    break;
            //case Key.D3:
            //    selection = world.player.inventory.Items.ElementAt(2).Key;
            //    MessageBox.Show(selection.ToString() + "selected");
            //    break;
            //case Key.D4:
            //    selection = world.player.inventory.Items.ElementAt(3).Key;
            //    MessageBox.Show(selection.ToString() + "selected");
            //    break;

            //-------------------------------------------------------
            //Movement Keys

            case Key.A:
            case Key.Left:
                world.player.Move(Engine.Direction.Left);
                moveDir = Engine.Direction.Left;
                //world.player.Background = new ImageBrush(world.textures.assets["playerLeft"]);
                break;

            case Key.D:
            case Key.Right:
                world.player.Move(Engine.Direction.Right);
                moveDir = Engine.Direction.Right;
                //world.player.Background = new ImageBrush(world.textures.assets["playerRight"]);
                break;

            case Key.Space:
            case Key.W:
            case Key.Up:
                //moveDir = Engine.Direction.Up;  //jump
                world.player.Move(Engine.Direction.Up);
                moveDir = Engine.Direction.None;
                break;

            //-------------------------------------------------------
            //Misc Keys

            //case Key.LeftShift:
            //    //switches between placing and destroying blocks
            //    if (mode == interactionMode.Build)
            //    {
            //        mode = interactionMode.Destroy;
            //    }
            //    else
            //    {
            //        mode = interactionMode.Build;
            //    }

            //    break;



            //-------------------------------------------------------
            //debug code

            case Key.T:
                //MessageBox.Show("turtleman");
                world.player.SetPosition(new Point(canvas_shop.Margin.Left, canvas_shop.Margin.Top));
                break;

            case Key.Escape:
                store.Visibility = Visibility.Collapsed;
                break;

            case Key.Enter:
                world.player.Move(Engine.Direction.None);
                Point playerPoint = new Point(world.player.Margin.Left + (world.player.Width / 2), world.player.Margin.Top + (world.player.Height / 2));
                Point storePoint  = new Point(canvas_shop.Margin.Left + (canvas_shop.Width / 2), canvas_shop.Margin.Top + (canvas_shop.Height / 2));
                //MessageBox.Show(Engine.GetDistance(playerPoint, storePoint).ToString());
                if (Engine.GetDistance(playerPoint, storePoint) < 100)
                {
                    store.Visibility = Visibility.Visible;
                    Canvas.SetZIndex(store, 100);
                    moneyLabel.Text = world.player.money.ToString();
                    Store.PopulateList(world.player, lbInventory);
                    //MessageBox.Show(store.Visibility.ToString());

                    UpdateStore();
                }
                break;
            }
        }