예제 #1
0
파일: MapState.cs 프로젝트: Babelz/jamipeli
        public void Update(GameTime gameTime)
        {
            if (Started)
            {
                elapsed += gameTime.ElapsedGameTime.Milliseconds;
                MonsterWave nextWave = waves.FirstOrDefault(w => elapsed > w.ReleaseTime);

                // Vapautetaan seuraava aalto hirviöitä.
                if (nextWave != null)
                {
                    if (OnNextWave != null)
                    {
                        OnNextWave(this, new MapStateEventArgs(nextWave, elapsed));
                    }

                    waves.Remove(nextWave);

                    Random random = new Random();
                    foreach (Monster monster in nextWave.ReleaseMonsters())
                    {
                        Game.Instance.AddGameObject(monster);
                        releasedMonsters.Add(monster);

                        int height = (int)(monster.Animation.Scale * 256);
                        int max_X  = Game.Instance.ScreenWidth + 200;
                        int max_Y  = Game.Instance.ScreenHeight;

                        // Vetää monsterin positionin randomilla jonkin verran ulos ruudusta ja kertoo sen pos modifierillä
                        // jotta se saadaan tulemaan oikeasta paikasta (vasen, oikea, ylä ja ala)
                        monster.Position = new Vector2(
                            random.Next(Game.Instance.ScreenWidth, max_X) * nextWave.PositionModifier.X,
                            random.Next(Game.Instance.ScreenHeight / 2, max_Y) * nextWave.PositionModifier.Y);
                    }
                }

                // Jos kaikki wavet on lähetetty, katsotaan onko hirviöitä vielä elossa.
                // Jos kaikki hirviöt on jo tapettu, state on suoritettu.
                if (!HasWaves)
                {
                    Finished = true;
                    foreach (Monster releasedMonster in releasedMonsters)
                    {
                        if (Game.Instance.ContainsGameObject(releasedMonster))
                        {
                            Finished = false;
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
파일: MapState.cs 프로젝트: Jntz/jamipeli
 public MapStateEventArgs(MonsterWave nextWave, int elapsed)
 {
     NextWave = nextWave;
     NewWave = nextWave != null;
     Elapsed = elapsed;
 }
예제 #3
0
파일: MapState.cs 프로젝트: Babelz/jamipeli
 public MapStateEventArgs(MonsterWave nextWave, int elapsed)
 {
     NextWave = nextWave;
     NewWave  = nextWave != null;
     Elapsed  = elapsed;
 }