Esempio n. 1
0
 private void UpdateLocation(SpriteItem item, Tuple <int, int> location)
 {
     Grid.SetRow(item, location.Item2);
     item.sprite.Y = location.Item2;
     Grid.SetColumn(item, location.Item1);
     item.sprite.X = location.Item1;
 }
Esempio n. 2
0
        private SpriteItem GetSpriteItemFromSprite(Sprite sprite)
        {
            List <SpriteItem> source = Blocks;

            SpriteItem spriteItem = source.Where(x => sprite.X == x.sprite.X && x.sprite.Y == sprite.Y).FirstOrDefault();

            return(spriteItem);
        }
Esempio n. 3
0
 private void AddNewSpriteItem(SpriteItem item, bool addToBlocks = true)
 {
     if (addToBlocks)
     {
         Blocks.Add(item);
     }
     Grid.SetRow(item, item.sprite.Y);
     Grid.SetColumn(item, item.sprite.X);
     main.Children.Add(item);
 }
Esempio n. 4
0
        private void NewGame(int level)
        {
            dispatcherTimer = null;

            main.Children.Clear();

            Blocks = new List <SpriteItem>();

            const int width  = 23;
            const int height = 23;

            gameOver = false;
            lblGameOver.Visibility = Visibility.Hidden;
            //SETUP MAP*****************

            //load levels
            Levels levels = new Levels();
            //create map layer
            Layer layer = new Layer();

            //assign data
            layer.Array = levels.LevelMaps[level - 1];
            //create level model and give it the game engine
            Level _level = new Level(new IsometricTileEngine(width, height));

            //create new game map
            _level.Map = new Map();
            //add the layer to the game map
            _level.Map.Layers.Add(layer);
            //store a copy of the game engine locally for local use
            engine = _level.Engine;

            mouse = new SpriteItem(0, 0, @"./Images/mouse.png", 3);
            engine.characterSprite = mouse.sprite;

            engine.UpdateX_Event      += UpdateX_EventHandler;
            engine.UpdateY_Event      += UpdateY_EventHandler;
            engine.AddNewSprite_Event += AddNewSprite_EventHandler;
            engine.RemoveSprite_Event += RemoveSprite_EventHandler;
            engine.LoseLife_Event     += LoseLife_EventHandler;
            engine.ChangeSprite_Event += ChangeSprite_EventHandler;

            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < height; x++)
                {
                    int value = layer.Array[y, x];
                    switch (value)
                    {
                    case 1:
                        AddNewSpriteItem(new SpriteItem(x, y, false));
                        break;

                    case 2:
                        AddNewSpriteItem(new SpriteItem(x, y, true));
                        break;

                    case 3:
                        mouse.sprite.X = x;
                        mouse.sprite.Y = y;
                        AddNewSpriteItem(mouse, false);
                        break;

                    case 4:
                        SpriteItem cat = new SpriteItem(x, y, @"./Images/cat.png", true, true, mouse.sprite);
                        cat.sprite.Ai.engine = engine;
                        AddNewSpriteItem(cat);
                        break;
                    }
                }
            }

            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            dispatcherTimer.Start();

            engine.Sprites = Blocks.Select(x => x.sprite).ToList();
        }
Esempio n. 5
0
 private void UpdateX(SpriteItem item, int change)
 {
     Grid.SetColumn(item, item.sprite.X + change);
     item.sprite.X = item.sprite.X + change;
 }
Esempio n. 6
0
 private void UpdateY(SpriteItem item, int change)
 {
     Grid.SetRow(item, item.sprite.Y + change);
     item.sprite.Y = item.sprite.Y + change;
 }
Esempio n. 7
0
        private void UpdateX_EventHandler(object sender, UpdateX_EventArgs e)
        {
            SpriteItem spriteItem = GetSpriteItemFromSprite(e.Sprite);

            UpdateX(spriteItem, e.Change);
        }
Esempio n. 8
0
        private void RemoveSprite_EventHandler(object sender, RemoveSprite_EventArgs e)
        {
            SpriteItem spriteItem = GetSpriteItemFromSprite(e.Sprite);

            main.Children.Remove(spriteItem);
        }
Esempio n. 9
0
        private void ChangeSprite_EventHandler(object sender, ChangeSprite_EventArgs e)
        {
            SpriteItem spriteItem = GetSpriteItemFromSprite(e.Sprite);

            spriteItem.image.Source = new BitmapImage(new Uri(@"./Images/sleepingCat.png", UriKind.Relative));
        }