Exemplo n.º 1
0
        public void Initialize(Animation itemAnimation, Vector2 position, Maze.State Type)
        {
            this.itemAnimation = itemAnimation;
            this.Position = position;
            this.Type = Type;

            IsActive = true;
        }
Exemplo n.º 2
0
 public void Initialize(Animation playerAnimation, Vector2 position)
 {
     this.playerAnimation = playerAnimation;
     Position = position;
     Steps = 0;
     HasSword = true;
     HasTreasure = false;
     Energy = 480;
     Score = 0;
 }
Exemplo n.º 3
0
 public void Initialize(Animation enemyAnimation, Vector2 position)
 {
     this.enemyAnimation = enemyAnimation;
     Position = position;
 }
Exemplo n.º 4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            #if DEBUG
            bannerAd = adGameComponent.CreateAd("Image480_80", new Rectangle(0, 0, 480, 80), true);
            #else
            bannerAd = adGameComponent.CreateAd("81067", new Rectangle(0, 0, 480, 80), true);
            #endif
            bannerAd.ErrorOccurred += new EventHandler<Microsoft.Advertising.AdErrorEventArgs>(bannerAd_ErrorOccurred);
            bannerAd.AdRefreshed += new EventHandler(bannerAd_AdRefreshed);

            adDuplex = new AdManager(this, "8831");
            #if DEBUG
            adDuplex.IsTest = true;
            #endif
            adDuplex.LoadContent();

            backgroundTexture = Content.Load<Texture2D>("background");
            logoTexture = Content.Load<Texture2D>("logo");
            instructionsTexture1 = Content.Load<Texture2D>("Instructions1");
            instructionsTexture2 = Content.Load<Texture2D>("instructions2");

            pixelTexture = Content.Load<Texture2D>("pixel");

            spriteFont = Content.Load<SpriteFont>("SpriteFont");
            menuFont = Content.Load<SpriteFont>("MenuFont");

            tapScreen = new TextAnimation();
            string text = "Tap the screen to continue";
            Vector2 position = new Vector2(
                               (GraphicsDevice.Viewport.Width / 2) - (spriteFont.MeasureString(text).X / 2),
                               GraphicsDevice.Viewport.Height - (spriteFont.MeasureString(text).Y * 4)
                               );

            tapScreen.Initialize(spriteFont, text, position, Color.White);

            wallTexture = Content.Load<Texture2D>("wall");
            pathTexture = Content.Load<Texture2D>("path");
            solutionTexture = Content.Load<Texture2D>("solution");
            foodTexture = Content.Load<Texture2D>("food");
            swordTexture = Content.Load<Texture2D>("sword");
            prisonerTexture = Content.Load<Texture2D>("prisonerAnimation");

            startTexture = Content.Load<Texture2D>("startAnimation");

            treasureTexture = Content.Load<Texture2D>("treasureAnimation");

            playerAnimation = new Animation();
            playerTexture = Content.Load<Texture2D>("playerAnimation");
            playerAnimation.Initialize(playerTexture, Vector2.Zero, 48, 48, 2, 167, Color.White, 1f, true);

            fightAnimation = new Animation();
            fightTexture = Content.Load<Texture2D>("fightAnimation");
            fightAnimation.Initialize(fightTexture, Vector2.Zero, 48, 48, 6, 300, Color.White, 1f, true);

            winAnimation = new Animation();
            winTexture = Content.Load<Texture2D>("winAnimation");
            winAnimation.Initialize(winTexture, Vector2.Zero, 48, 48, 2, 300, Color.White, 1f, true);

            loseAnimation = new Animation();
            loseTexture = Content.Load<Texture2D>("loseAnimation");
            loseAnimation.Initialize(loseTexture, Vector2.Zero, 48, 48, 2, 300, Color.White, 1f, true);

            enemyTexture = Content.Load<Texture2D>("enemyAnimation");

            energyBarTexture = Content.Load<Texture2D>("energyBar");

            overlayTexture = Content.Load<Texture2D>("overlay");

            playerStep = Content.Load<SoundEffect>("sound/playerStep");
            enemyStep = Content.Load<SoundEffect>("sound/enemyStep");
            playerFight = Content.Load<SoundEffect>("sound/playerFight");
            swordDraw = Content.Load<SoundEffect>("sound/swordDraw");
            foodEating = Content.Load<SoundEffect>("sound/foodEat");
            pickupTreasure = Content.Load<SoundEffect>("sound/treasure");
            releasePrisoner = Content.Load<SoundEffect>("sound/prisoner");
        }
Exemplo n.º 5
0
        private void UpdateLoading(GameTime gameTime)
        {
            if (loadSaveGame == true)
            {
                GameData data = LoadGameData();

                if (data.GameState == GameState.Playing || data.GameState == GameState.Fighting || data.GameState == GameState.Paused ||
                    data.PreviousGameState == GameState.Playing || data.PreviousGameState == GameState.Fighting || data.PreviousGameState == GameState.Paused)
                {
                    pastSteps = data.PastSteps;
                    showPath = data.ShowPath;
                    count = data.Count;
                    fightCounter = data.FightCounter;
                    faith = data.Faith;
                    minimumMoves = data.MinimumMoves;

                    maze = new Maze();
                    maze.Initialize(mazeWidth, mazeHeight, difficulty);

                    items = new Dictionary<Vector2, Item>();

                    MazeData mazeData = new MazeData().Load();

                    int x = 0;
                    int y = 0;

                    for (int i = 0; i < mazeData.CellState.Count; i++)
                    {
                        maze.Cells[i] = new Cell();
                        maze.Cells[i].X = x;
                        maze.Cells[i].Y = y;
                        maze.Cells[i].State = mazeData.CellState[i];

                        if (maze.Cells[i].State == Maze.State.Start)
                        {
                            maze.StartCell = maze.Cells[i];
                        }

                        if (maze.Cells[i].State == Maze.State.Treasure)
                        {
                            maze.GoalCell = maze.Cells[i];
                        }

                        if (x == mazeWidth - 1)
                        {
                            x = 0;
                            y++;
                        }
                        else
                        {
                            x++;
                        }
                    }

                    player = new Player();
                    player.Initialize(playerAnimation, new Vector2(data.PlayerX, data.PlayerY));
                    player.Steps = data.Steps;
                    player.Score = data.Score;
                    player.HasSword = data.HasSword;
                    player.HasTreasure = data.HasTreasure;
                    player.Energy = data.Energy;

                    playerAnimation.newFrameRow = 0;

                    playerAnimation.Active = data.PlayerAnimationActive;
                    fightAnimation.Active = data.FightAnimationActive;
                    winAnimation.Active = data.WinAnimationActive;
                    loseAnimation.Active = data.LoseAnimationActive;

                    playerAnimation.Position = player.Position;
                    fightAnimation.Position = player.Position;
                    winAnimation.Position = player.Position;
                    loseAnimation.Position = player.Position;

                    player.Move(Vector2.Zero, Player.State.Idle);

                    camera = new Camera2D();
                    camera.Position = new Vector2(data.PlayerX + 24, data.PlayerY + 48);

                    if (data.PlayerX < 240)
                    {
                        camera._pos.X = 240 + 24;
                    }
                    else if (data.PlayerX > (mazeWidth * 48) - 288)
                    {
                        camera._pos.X = ((mazeWidth * 48) - 288) + 24;
                    }

                    if (data.PlayerY < 240)
                    {
                        camera._pos.Y = 240 + 48;
                    }
                    else if (data.PlayerY > (mazeHeight * 48) - 288)
                    {
                        camera._pos.Y = ((mazeHeight * 48) - 288) + 48;
                    }

                    int width, height;

                    x = (int)camera.Position.X - (GraphicsDevice.Viewport.Width / 2);
                    y = (int)camera.Position.Y - (GraphicsDevice.Viewport.Height / 2) + 112;
                    width = GraphicsDevice.Viewport.Width + 48;
                    height = GraphicsDevice.Viewport.Height - 272;

                    mazeRectangle = new Rectangle(x, y, width, height);
                    mazeTexture = new RenderTarget2D(GraphicsDevice, mazeRectangle.Width, mazeRectangle.Height);

                    enemies = new Dictionary<Vector2, Enemy>();

                    for (int i = 0; i < data.EnemyX.Count; i++)
                    {
                        Vector2 position = new Vector2(data.EnemyX[i], data.EnemyY[i]);
                        Enemy enemy = new Enemy();

                        Animation enemyAnimation = new Animation();
                        enemyAnimation.Initialize(enemyTexture, Vector2.Zero, 48, 48, 2, 500, Color.White, 1f, true);
                        enemy.Initialize(enemyAnimation, position);
                        enemies.Add(position, enemy);
                    }

                    items = new Dictionary<Vector2, Item>();

                    for (int i = 0; i < data.ItemX.Count; i++)
                    {
                        Item item = new Item();
                        Vector2 position = new Vector2(data.ItemX[i], data.ItemY[i]);

                        switch (data.ItemType[i])
                        {
                            case Maze.State.Prisoner:
                                prisonerAnimation = new Animation();
                                prisonerAnimation.Initialize(prisonerTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                                item.Initialize(prisonerAnimation, position, Maze.State.Prisoner);
                                items.Add(position, item);
                                break;
                            case Maze.State.Sword:
                                swordAnimation = new Animation();
                                swordAnimation.Initialize(swordTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                                item.Initialize(swordAnimation, position, Maze.State.Sword);
                                items.Add(position, item);
                                break;
                            case Maze.State.Food:
                                foodAnimation = new Animation();
                                foodAnimation.Initialize(foodTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                                item.Initialize(foodAnimation, position, Maze.State.Food);
                                items.Add(position, item);
                                break;
                            case Maze.State.Treasure:
                                treasureAnimation = new Animation();
                                treasureAnimation.Initialize(treasureTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                                item.Initialize(treasureAnimation, position, Maze.State.Treasure);
                                items.Add(position, item);
                                break;
                            case Maze.State.Start:
                                startAnimation = new Animation();
                                startAnimation.Initialize(startTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                                item.Initialize(startAnimation, position, Maze.State.Start);
                                items.Add(position, item);
                                break;
                            default:
                                break;
                        }
                    }

                    for (int i = 0; i < maze.Cells.Length; i++)
                    {
                        if (maze.Cells[i].State == Maze.State.Prisoner ||
                            maze.Cells[i].State == Maze.State.Food ||
                            maze.Cells[i].State == Maze.State.Start ||
                            maze.Cells[i].State == Maze.State.Sword ||
                            maze.Cells[i].State == Maze.State.Treasure
                           )
                        {
                            if (items.ContainsKey(new Vector2(maze.Cells[i].X * 48, maze.Cells[i].Y * 48)) == false)
                            {
                                maze.Cells[i].State = Maze.State.Wall;
                            }
                        }
                    }

                    if (showPath == true)
                    {
                        if (player.HasTreasure == true)
                        {
                            maze.BuildDistanceTable(maze.StartCell);
                            maze.FindPath(maze.StartCell, maze.Cells[(int)(player.Position.X / 48) + (int)(player.Position.Y / 48) * mazeWidth]);
                        }
                        else
                        {
                            maze.BuildDistanceTable(maze.GoalCell);
                            maze.FindPath(maze.GoalCell, maze.Cells[(int)(player.Position.X / 48) + (int)(player.Position.Y / 48) * mazeWidth]);
                        }
                    }

                    mazeNeedsRedraw = true;
                    RedrawMaze();

                    loadSaveGame = false;

                    if (data.GameState == GameState.Paused)
                    {
                        if (saveGameAvailable == true)
                        {
                            gameState = data.PreviousGameState;
                        }
                        else
                        {
                            previousGameState = data.PreviousGameState;
                            gameState = data.GameState;
                        }
                    }
                    else if (data.GameState == GameState.Playing)
                    {
                        if (saveGameAvailable == true)
                        {
                            gameState = data.GameState;
                        }
                        else
                        {
                            previousGameState = GameState.Playing;
                            gameState = GameState.Paused;
                        }
                    }
                    else if (data.GameState == GameState.Fighting)
                    {
                        if (saveGameAvailable == true)
                        {
                            gameState = data.GameState;
                        }
                        else
                        {
                            previousGameState = GameState.Fighting;
                            gameState = GameState.Paused;
                        }
                    }
                    else
                    {
                        if (saveGameAvailable == true)
                        {
                            gameState = data.PreviousGameState;
                        }
                        else
                        {
                            //gameState = data.GameState;

                            //if (gameState == GameState.Instructions)
                            //{
                            //    instructionsPage = data.InstructionsPage;
                            //}
                            gameState = GameState.Menu;
                        }
                    }

                    if (saveGameAvailable == true)
                    {
                        saveGameAvailable = false;
                    }
                }
            }
            else
            {
                maze = new Maze();
                player = new Player();
                camera = new Camera2D();

                pastSteps = 0;

                showPath = false;

                count = 0;
                fightCounter = 0;
                energyCounter = 0;

                faith = 0;

                mazeNeedsRedraw = true;

                playerAnimation.Active = true;
                fightAnimation.Active = false;
                winAnimation.Active = false;
                loseAnimation.Active = false;

                items = new Dictionary<Vector2, Item>();

                maze.Initialize(mazeWidth, mazeHeight, difficulty);
                maze.Generate();

                MazeData mazeData = new MazeData();
                mazeData.CellState = new List<Maze.State>();

                foreach (Cell c in maze.Cells)
                {
                    mazeData.CellState.Add(c.State);
                }

                mazeData.Save(mazeData);

                minimumMoves = (maze.StartCell.Distance * 2) - 4;

                int[] dx = { 0, 0, -1, 1 };
                int[] dy = { -1, 1, 0, 0 };

                for (int i = 0; i < 4; i++)
                {
                    if (maze.Cells[(maze.StartCell.X + dx[i]) + (maze.StartCell.Y + dy[i]) * mazeWidth].State == Maze.State.Path)
                    {
                        playerPosition = new Vector2((maze.StartCell.X + dx[i]) * 48, (maze.StartCell.Y + dy[i]) * 48);
                    }
                }

                player.Initialize(playerAnimation, playerPosition);
                playerAnimation.newFrameRow = 0;

                camera.Position = new Vector2(playerPosition.X + 24, playerPosition.Y + 48);

                if (playerPosition.X < 240)
                {
                    camera._pos.X = 240 + 24;
                }
                else if (playerPosition.X > (mazeWidth * 48) - 288)
                {
                    camera._pos.X = ((mazeWidth * 48) - 288) + 24;
                }

                if (playerPosition.Y < 240)
                {
                    camera._pos.Y = 240 + 48;
                }
                else if (playerPosition.Y > (mazeHeight * 48) - 288)
                {
                    camera._pos.Y = ((mazeHeight * 48) - 288) + 48;
                }

                int x, y, width, height;

                x = (int)camera.Position.X - (GraphicsDevice.Viewport.Width / 2);
                y = (int)camera.Position.Y - (GraphicsDevice.Viewport.Height / 2) + 112;
                width = GraphicsDevice.Viewport.Width + 48;
                height = GraphicsDevice.Viewport.Height - 272;

                mazeRectangle = new Rectangle(x, y, width, height);

                mazeTexture = new RenderTarget2D(GraphicsDevice, mazeRectangle.Width, mazeRectangle.Height);

                for (x = 0; x < mazeWidth; x++)
                {
                    for (y = 0; y < mazeHeight; y++)
                    {
                        Cell c = maze.Cells[x + y * mazeWidth];
                        Vector2 position = new Vector2(x * 48, y * 48);
                        Item item = new Item();
                        if (c.State == Maze.State.Prisoner)
                        {
                            prisonerAnimation = new Animation();
                            prisonerAnimation.Initialize(prisonerTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                            item.Initialize(prisonerAnimation, position, Maze.State.Prisoner);
                            items.Add(position, item);
                        }

                        if (c.State == Maze.State.Sword)
                        {
                            swordAnimation = new Animation();
                            swordAnimation.Initialize(swordTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                            item.Initialize(swordAnimation, position, Maze.State.Sword);
                            items.Add(position, item);
                        }

                        if (c.State == Maze.State.Food)
                        {
                            foodAnimation = new Animation();
                            foodAnimation.Initialize(foodTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                            item.Initialize(foodAnimation, position, Maze.State.Food);
                            items.Add(position, item);
                        }

                        if (c.State == Maze.State.Treasure)
                        {
                            treasureAnimation = new Animation();
                            treasureAnimation.Initialize(treasureTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                            item.Initialize(treasureAnimation, position, Maze.State.Treasure);
                            items.Add(position, item);
                        }

                        if (c.State == Maze.State.Start)
                        {
                            startAnimation = new Animation();
                            startAnimation.Initialize(startTexture, Vector2.Zero, 48, 48, 2, 400, Color.White, 1f, true);
                            item.Initialize(startAnimation, position, Maze.State.Start);
                            items.Add(position, item);
                        }
                    }
                }

                enemies = new Dictionary<Vector2, Enemy>();

                for (int i = 0; i < GameSettings.Maziacs[difficulty]; i++)
                {
                    Animation enemyAnimation = new Animation();
                    enemyAnimation.Initialize(enemyTexture, Vector2.Zero, 48, 48, 2, 500, Color.White, 1f, true);

                    Vector2 enemyPosition = Vector2.Zero;
                    bool found = false;

                    while (found == false)
                    {
                        x = random.Next(0, mazeWidth - 1);
                        y = random.Next(0, mazeHeight - 1);

                        if (x % 2 == 0)
                        {
                            x++;
                        }

                        if (y % 2 == 0)
                        {
                            y++;
                        }

                        if (maze.Cells[x + y * mazeWidth].State == Maze.State.Path && enemies.ContainsKey(new Vector2(x * 48, y * 48)) == false)
                        {
                            if (x < (player.Position.X / 48) - 5 || x > (player.Position.X / 48) + 5)
                            {
                                if (y < (player.Position.Y / 48) - 5 || y > (player.Position.Y / 48) + 5)
                                {
                                    enemyPosition = new Vector2(x * 48, y * 48);
                                    found = true;
                                }
                            }
                        }
                    }

                    Enemy enemy = new Enemy();
                    enemy.Initialize(enemyAnimation, enemyPosition);

                    enemies.Add(enemyPosition, enemy);
                }

                gameState = GameState.Playing;
            }
        }
Exemplo n.º 6
0
        private Collisions UpdateCollisions(UserInput input)
        {
            Collisions test = Collisions.None;

            int[] dx = { 0, 1, 0, -1, 0, 0 };
            int[] dy = { -1, 0, 1, 0, 0, 0 };

            int x = (int)player.Position.X / 48;
            int y = (int)player.Position.Y / 48;

            int d = (int)input;

            Cell c = maze.Cells[(x + dx[d]) + (y + dy[d]) * mazeWidth];

            if (c.State != Maze.State.Path)
            {
                test = Collisions.Wall;

                if (c.State == Maze.State.Prisoner)
                {
                    test = Collisions.Prisoner;
                    c.State = Maze.State.Wall;
                    items[new Vector2(c.X * 48, c.Y * 48)].IsActive = false;
                    items.Remove(new Vector2(c.X * 48, c.Y * 48));
                    //items[c.X, c.Y].IsActive = false;

                    if (soundEnabled == true)
                    {
                        releasePrisoner.Play();
                    }

                    player.Score += GameSettings.PrisonerPoints;

                    return test;
                }

                if (c.State == Maze.State.Sword)
                {
                    test = Collisions.Sword;

                    if (player.HasSword == false)
                    {
                        c.State = Maze.State.Wall;
                        items[new Vector2(c.X * 48, c.Y * 48)].IsActive = false;
                        items.Remove(new Vector2(c.X * 48, c.Y * 48));
                        player.HasSword = true;

                        if (soundEnabled == true)
                        {
                            swordDraw.Play();
                        }

                        if (player.HasTreasure == true)
                        {
                            c.State = Maze.State.Treasure;
                            player.HasTreasure = false;

                            items.Remove(new Vector2(c.X * 48, c.Y * 48));

                            Vector2 position = new Vector2(c.X * 48, c.Y * 48);
                            Item item = new Item();

                            Animation treasureAnimation = new Animation();
                            treasureAnimation.Initialize(treasureTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                            item.Initialize(treasureAnimation, position, Maze.State.Sword);
                            items.Add(position, item);

                            maze.GoalCell = c;
                        }
                    }

                    return test;
                }

                if (c.State == Maze.State.Food)
                {
                    test = Collisions.Food;
                    c.State = Maze.State.Wall;
                    items[new Vector2(c.X * 48, c.Y * 48)].IsActive = false;
                    items.Remove(new Vector2(c.X * 48, c.Y * 48));

                    return test;
                }

                if (c.State == Maze.State.Treasure)
                {
                    test = Collisions.Treasure;
                    c.State = Maze.State.Wall;
                    items[new Vector2(c.X * 48, c.Y * 48)].IsActive = false;
                    items.Remove(new Vector2(c.X * 48, c.Y * 48));
                    player.HasTreasure = true;

                    if (soundEnabled == true)
                    {
                        pickupTreasure.Play();
                    }

                    if (player.HasSword == true)
                    {
                        c.State = Maze.State.Sword;
                        player.HasSword = false;

                        items.Remove(new Vector2(c.X * 48, c.Y * 48));

                        Vector2 position = new Vector2(c.X * 48, c.Y * 48);
                        Item item = new Item();

                        Animation swordAnimation = new Animation();
                        swordAnimation.Initialize(swordTexture, Vector2.Zero, 48, 48, 1, 400, Color.White, 1f, true);
                        item.Initialize(swordAnimation, position, Maze.State.Sword);
                        items.Add(position, item);
                    }

                    return test;
                }

                if (c.State == Maze.State.Start)
                {
                    test = Collisions.Start;
                }
            }

            return test;
        }