Beispiel #1
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;
            }
        }
Beispiel #2
0
 private void Window_KeyUp(object sender, KeyEventArgs e)
 {
     moveDir = Engine.Direction.None;
     //previousMoveDir = Engine.Direction.None;
     world.player.Move(Engine.Direction.None);
 }
Beispiel #3
0
        //private bool VerifyMovement(Movement m) 
        //{

        //    int[] newLocL = Engine.GetArrayLocation(this.Margin.Left + m.Displacement.X, this.Margin.Top + m.Displacement.Y);
        //    int[] newLocR = Engine.GetArrayLocation((this.Margin.Left + this.Width) + m.Displacement.X, this.Margin.Top + m.Displacement.Y);
        //    try
        //    {
        //        if (parentWorld.blockArray[newLocL[0], newLocL[1]].penetrable && parentWorld.blockArray[newLocL[0], newLocL[1] + 1].penetrable)
        //        {
        //            if (parentWorld.blockArray[newLocR[0], newLocR[1]].penetrable && parentWorld.blockArray[newLocR[0], newLocR[1] + 1].penetrable)
        //            {
        //                return true;
        //            }
        //        }
        //    }
        //    catch { }

        //    return false;
        //}

        //public void CheckGravity()
        //{

        //    int floor = parentWorld.GetFloor(this);    //location in the array of the next lower solidblock
        //    int[] playerFloor = Engine.GetArrayLocation(this.Margin.Left + 1, this.Margin.Top + this.Height); //location in the array of the bottom left corner of the world.player

        //    if (playerFloor[1] < floor)
        //    {

        //        int deltaY = ((floor * 25) - Convert.ToInt32((this.Margin.Top + this.Height - 1)) - 1);
        //        Movement m = new Movement(new Vector(0, deltaY), 3 * deltaY, mAcceleration: 0.999);
        //        this.StartAnimation(m);

        //    }
        //}

        public void Move(Engine.Direction d) 
        { 
            currentMoveDir = d;
        }