예제 #1
0
 public void Initialize(Level level)
 {
     // monster
     {
         RealCharacter monster = _gameState.CreateCharacter(false);
         //monster.MoveBehavior = new MonsterMoveAStar(monster, level);
         monster.Position = new Vector2(1300, 1500);
         monster.Speed = 200;
     }
     //// monster
     //{
     //    RealCharacter monster = _gameState.CreateCharacter(false);
     //    //monster.moveBehavior = new StupidMonsterMove(monster);
     //    monster.MoveBehavior = new EmptyBehavior(monster);
     //    monster.Position = new Vector2(200, 170);
     //    monster.Speed = 25;
     //}
     _shouldContinue = true;
     Start();
 }
예제 #2
0
 private int[,] GetSimplifiedGrid(Level level)
 {
     var height = (int)Math.Ceiling((double)level.Height / _tileSize);
     var width = (int)Math.Ceiling((double)level.Width / _tileSize);
     var solids = new int[width, height];
     foreach (var solid in level.Solids)
     {
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 if (CollisionHelper.Intersects(new Rectangle(x * _tileSize, y * _tileSize, _tileSize, _tileSize), solid))
                 {
                     solids[x, y] = 1;
                 }
             }
         }
     }
     return solids;
 }
예제 #3
0
파일: Grid.cs 프로젝트: virvar/StillAlive
 /// <summary>
 /// Формирует сетку и добавляем объекты карты в соответствующие ячейки.
 /// </summary>
 /// <param name="level">Карта</param>
 public void SetLevel(Level level)
 {
     foreach (var solid in level.Solids)
     {
         solid.InitAxes();
     }
     // создаём карты зон
     Height = (int)Math.Ceiling((double)level.Height / Level.ZoneSize);
     Width = (int)Math.Ceiling((double)level.Width / Level.ZoneSize);
     Solids = new List<List<HashSet<Solid>>>(Width);
     Characters = new List<List<HashSet<Character>>>(Width);
     for (int i = 0; i < Width; i++)
     {
         Solids.Add(new List<HashSet<Solid>>(Height));
         Characters.Add(new List<HashSet<Character>>(Height));
         for (int j = 0; j < Height; j++)
         {
             Solids[i].Add(new HashSet<Solid>());
             Characters[i].Add(new HashSet<Character>());
         }
     }
     // добавляем каждое тело на карте в зоны, которые оно пересекает
     foreach (var solid in level.Solids)
     {
         for (int i = 0; i < Width; i++)
         {
             for (int j = 0; j < Height; j++)
             {
                 if (solid.CollisionRect.Intersects(new Rectangle(i * Level.ZoneSize, j * Level.ZoneSize, Level.ZoneSize, Level.ZoneSize)))
                 {
                     Solids[i][j].Add(solid);
                 }
             }
         }
     }
 }
예제 #4
0
 public MonsterMoveAStar(Character character, Level level, params Character[] targets)
     : base(character, targets)
 {
     _grid = GetSimplifiedGrid(level);
     _AStar = new AStar();
 }
예제 #5
0
 public void SetLevel(Level level)
 {
     this.Level = level;
     Grid.SetLevel(level);
 }
예제 #6
0
        public void LoadGame()
        {
            //Load UserInterface.
            //Load Debugger.
            //PopulateLists
            //gameObject.GetSprite.LoadContent.
            //gameObject.PostSetSpriteFram().
            //Set Starting gamestate
            // pass gametime.

            PlayingField = new Rectangle(0, 25, 1380, 775);

            randomGenerator = new Random();

            // EnemyTimeToSpawn = randomGenerator.Next(7000, 15000);

            mRedTimeElapsed = 0f;
            mBlueTimeElapsed = 0f;
            mGreenTimeElapsed = 0f;
            mYellowTimeElapsed = 0f;
            mPurpleTimeElapsed = 0f;

            Graveyard = new JLinkedList();
            mInPlayItemDropList = new JLinkedList();
            mInPlayObjectList = new JLinkedList();
            mInPlayProjectileList = new JLinkedList();

            mDebugGridState = DebugGrid.GRID_DISABLED;
            Debug.EnableGrid = DisplayGrid;
            Debug.EnableGodModeFunction = EnableGodMode;
            LoadDebugger();

            PopulateLists();

            UserInterfaceController.mCastle = mCastle;
            UserInterfaceController.mHero = mHero;
            UserInterfaceController.LoadUserInterface(gameTime, content, spriteBatch);
            InitializeInPlayStructures(ref  InPlayStructures);
            InitializeStructurePool(ref StructurePool);
            InitializeFriendlyPool(ref FriendlyPool);

            // Create Castle
            mCastle.Sprite.LoadContent();
            mCastle.PostSetSpriteFrame();
            //mCastleHealthBarTexture = content.Load<Texture2D>("Sprites/Castle/HealthBar");
            mRedBar = content.Load<Texture2D>("Sprites/PixelTextures/solidred");
            source = new Rectangle(1565, 450, 50, 300);
            mCastleHealthBarRectangle = new Rectangle(1565, 450, 50, 300);
            // Populate Enemies Menus, and Levels.
            mHero.Sprite.LoadContent();

            // Create HERO
            mHero.PostSetSpriteFrame();
            mHero.PlayingField = PlayingField;

            // Create Level
            mDirtLevel = new Level(new Rectangle(0, 0, screenWidth, screenHeight), mLevelTexture, "Audio/Songs/Battle Music", content);
            WaveController.Castle = mCastle;
            WaveController.Content = content;
            WaveController.InitializeWaveController();

            PassGameTime();

            Notification.LoadNotificationFont(content);
            Notification.LoadLevelUpRibbon(content);

            ChangeGameState(GameState.LOAD);
        }
예제 #7
0
 private Level ParseLevel(string name)
 {
     using (StreamReader sr = new StreamReader(name))
     {
         string line;
         line = sr.ReadLine();
         int width = int.Parse(line.Split('=')[1]);
         line = sr.ReadLine();
         int height = int.Parse(line.Split('=')[1]);
         Level level = new Level(width, height);
         while ((line = sr.ReadLine()) != null)
         {
             // respawn points
             if (line == "[RespawnPoint]")
             {
                 line = sr.ReadLine();
                 int pX = int.Parse(line.Split('=')[1]);
                 line = sr.ReadLine();
                 int pY = int.Parse(line.Split('=')[1]);
                 level.RespawnPoints.Add(new Vector2(pX, pY));
             }
             // map objects
             if (line == "[Solid]")
             {
                 DrawableSolid solid = new DrawableSolid();
                 line = sr.ReadLine();
                 int w = int.Parse(line.Split('=')[1]);
                 line = sr.ReadLine();
                 int h = int.Parse(line.Split('=')[1]);
                 solid.Size = new Point(w, h);
                 line = sr.ReadLine();
                 int pX = int.Parse(line.Split('=')[1]);
                 line = sr.ReadLine();
                 int pY = int.Parse(line.Split('=')[1]);
                 solid.Position = new Vector2(pX, pY);
                 line = sr.ReadLine();
                 solid.Angle = float.Parse(line.Split('=')[1]);
                 level.Solids.Add(solid);
             }
         }
         if (level.RespawnPoints.Count == 0)
         {
             level.CreateDefaultRespawnPositions();
         }
         return level;
     }
 }