コード例 #1
0
        private void CoreWindow_PointerPressed(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
        {
            // create a new food
            Superfood superfood = new Superfood();

            // set location with mouse position
            superfood.LocationX = args.CurrentPoint.Position.X - superfood.Width / 2;
            superfood.LocationY = args.CurrentPoint.Position.Y - superfood.Height / 2;
            // add to game canvas
            MyCanvas.Children.Add(superfood);
            // set food location in canvas
            superfood.SetLocation();
            // add to foods list (for collision checking)
            superfoods.Add(superfood);
        }
コード例 #2
0
        public MainPage()
        {
            this.InitializeComponent();

            // initialize list of food
            foods = new List <Food>();

            // initialize list of superfood
            superfoods = new List <Superfood>();

            // initialize wall list
            walls = new List <Wall>();



            // MapMatrix
            int[,] array2D = new int[25, 25]

            {
                { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
                { 3, 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 3 },
                { 3, 1, 3, 3, 3, 3, 1, 1, 1, 3, 1, 3, 3, 3, 1, 3, 1, 3, 1, 3, 3, 3, 3, 1, 3 },
                { 3, 1, 3, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3 },
                { 3, 1, 3, 1, 3, 3, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3 },
                { 3, 1, 3, 1, 3, 1, 1, 3, 3, 1, 3, 3, 1, 1, 1, 1, 3, 1, 3, 3, 3, 1, 3, 1, 3 },
                { 3, 1, 1, 1, 3, 1, 3, 3, 1, 1, 1, 3, 1, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3 },
                { 3, 1, 3, 1, 3, 1, 1, 2, 1, 3, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3 },
                { 3, 1, 3, 1, 1, 1, 3, 1, 3, 3, 1, 3, 1, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3 },
                { 3, 1, 3, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 3, 3, 3, 1, 3, 1, 3 },
                { 3, 1, 1, 1, 1, 1, 3, 1, 3, 3, 3, 4, 3, 3, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 3 },
                { 3, 3, 3, 1, 3, 1, 3, 1, 3, 4, 4, 4, 4, 4, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3 },
                { 3, 2, 1, 1, 3, 1, 1, 1, 3, 4, 4, 4, 4, 4, 3, 1, 1, 1, 3, 1, 3, 1, 3, 2, 3 },
                { 3, 1, 3, 1, 3, 1, 3, 1, 3, 4, 4, 4, 4, 4, 3, 1, 3, 1, 1, 1, 3, 1, 3, 1, 3 },
                { 3, 1, 1, 1, 1, 1, 3, 1, 3, 3, 3, 4, 3, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3, 1, 3 },
                { 3, 1, 3, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 },
                { 3, 1, 3, 1, 1, 1, 3, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3 },
                { 3, 1, 3, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 },
                { 3, 1, 1, 1, 3, 1, 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3, 3, 1, 3 },
                { 3, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 1, 3, 1, 1, 3, 1, 3 },
                { 3, 1, 1, 1, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 3, 1, 3, 1, 3 },
                { 3, 1, 3, 1, 1, 1, 2, 3, 1, 1, 1, 3, 1, 3, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 3 },
                { 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 1, 3, 1, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3, 1, 3 },
                { 3, 2, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 3 },
                { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
            };

            // Create the map by using matrix

            for (int i = 0; i < 25; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    if (array2D[j, i] == 0)
                    {
                        Player player = new Player();

                        player.LocationX = i * 40;
                        player.LocationY = j * 40;
                        MyCanvas.Children.Add(player);
                        player.SetLocation();
                    }

                    else if (array2D[j, i] == 1)
                    {
                        // create a new food
                        Food food = new Food();
                        // set location with mouse position
                        food.LocationX = i * 40;
                        food.LocationY = j * 40;
                        // add to game canvas
                        MyCanvas.Children.Add(food);
                        // set food location in canvas
                        food.SetLocation();
                        // add to foods list (for collision checking)
                        foods.Add(food);
                    }

                    else if (array2D[j, i] == 2)
                    {
                        // create a new superfood
                        Superfood superfood = new Superfood();
                        // set location
                        superfood.LocationX = i * 40;
                        superfood.LocationY = j * 40;
                        // add to game canvas
                        MyCanvas.Children.Add(superfood);
                        // set food location in canvas
                        superfood.SetLocation();
                        // add to foods list (for collision checking)
                        superfoods.Add(superfood);
                    }

                    else if (array2D[j, i] == 3)
                    {
                        // create a new wall
                        Wall wall = new Wall();
                        // set location
                        {
                            wall.LocationX = i * 40;
                            wall.LocationY = j * 40;
                        };
                        MyCanvas.Children.Add(wall);
                        // set wall location in canvas
                        wall.SetLocation();
                        // add to walls list (for collision checking)
                        walls.Add(wall);
                    }
                }
            }

            //CreateWalls();

            // add player
            player = new Player
            {
                LocationX = MyCanvas.Width / 2,
                LocationY = MyCanvas.Height / 2 + 100
            };
            MyCanvas.Children.Add(player);


            // Add Ghost
            ghost = new Ghost
            {
                LocationX = MyCanvas.Width / 2 - 55,
                LocationY = MyCanvas.Height / 2
            };
            MyCanvas.Children.Add(ghost);

            Up = true;

            // key Listener

            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;


            // Timer

            timer          = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / 60);
            timer.Tick    += Timer_Tick;
            timer.Start(); //startgame


            // Mouse listener (to test object creation
            Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
        }