Example #1
0
 public void RemoveListener(IModelListener varListener)
 {
     if (varListener == null || mListeners == null)
     {
         return;
     }
     mListeners.Remove(varListener);
 }
        public void update(float elapsedTime, IModelListener listener)
        {
            player.update (elapsedTime);

            if (map.playerReachedEnd (player) == true) {
                player.shuttleCenterPosition = map.getPlayerStartPosition (player);
            }
            if (map.playerCollidesRoof (player) || map.playerCollidesFloor(player) ) {
                player.shuttleCenterPosition = map.getPlayerStartPosition (player);
                listener.hitWall ();
            }
        }
Example #3
0
 public void AddListener(IModelListener varListener)
 {
     if (mListeners == null)
     {
         mListeners = new List <IModelListener>();
     }
     if (varListener == null)
     {
         return;
     }
     if (mListeners.Contains(varListener))
     {
         return;
     }
     mListeners.Add(varListener);
 }
Example #4
0
 internal void HitBall(Vector2 mousePosition, IModelListener view)
 {
     foreach (Ball ball in balls)
     {
         if (ball.Alive)
         {
             Vector2 ballPosition = ball.getPosition();
             if (ballPosition.Y >= (mousePosition.Y - aim.Radius) &&
                 ballPosition.Y <= (mousePosition.Y + aim.Radius) &&
                 ballPosition.X >= (mousePosition.X - aim.Radius) &&
                 ballPosition.X <= (mousePosition.X + aim.Radius))
             {
                 ball.Alive = false;
                 view.HitBall(ballPosition.X, ballPosition.Y);
             }
         }
     }
 }
Example #5
0
        public void NotifyListener(IModelListenerEventType varEvtType, params object[] varArgs)
        {
            if (mListeners == null || mListeners.Count == 0)
            {
                return;
            }
            for (int i = 0; i < mListeners.Count; i++)
            {
                IModelListener listener = mListeners[i];
                if (listener == null)
                {
                    continue;
                }
                switch (varEvtType)
                {
                case IModelListenerEventType.OnModelInited:
                    listener.OnModelInited();
                    break;

                case IModelListenerEventType.OnViewAssigned:
                    if (varArgs.Length > 0)
                    {
                        listener.OnViewAssigned(varArgs[0] as GTView);
                    }
                    else
                    {
                        listener.OnViewAssigned(null);
                    }
                    break;

                case IModelListenerEventType.OnModelDestroyed:
                    listener.OnModelDestroyed();
                    break;

                case IModelListenerEventType.OnModelStateChanged:
                    listener.OnModelStateChanged(mModelState);
                    break;

                default:
                    break;
                }
            }
        }
Example #6
0
 public void SetListener(IModelListener listener)
 {
     this.listener = listener;
 }
Example #7
0
        public void Update(GameTime gameTime, IModelListener view)
        {
            // If player and boss is alive update the player
            if (player.Alive && BossAlive)
            {
                KeyboardState keyState = Keyboard.GetState();
                doesPlayerMove((float)gameTime.ElapsedGameTime.TotalSeconds);

                if (keyState.IsKeyDown(Keys.Space))
                {
                    player.shoot(gameTime);
                    view.PlayerShoots(gameTime);
                }
                else
                {
                    player.UpdateShootDelay((float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }

            player.UpdateBullets(gameTime);

            //If player is dead, display the animation and end the game
            if (!player.Alive)
            {
                elapsedPlayerDeath += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (elapsedPlayerDeath >= 2.0f)
                {
                    GameEnds = true;
                }

                if (!playerDeathAnimation)
                {
                    view.PlayerDied(player.Position.X, player.Position.Y);
                    playerDeathAnimation = true;
                }
            }

            foreach (Levels l in levelsystem.LevelList)
            {
                if (l.Active && !l.Completed)
                {
                    if (l.EnemyAmount >= enemiesDown)
                    {
                        //spawn enemies if there´s enemy on the level
                        if (l.Enemies)
                        {
                            l.spawnEnemies(gameTime);

                            foreach (Enemy e in l.EnemyList)
                            {
                                //updates the enemy and thier bullets and lloks for collision with the player
                                e.Update(gameTime);

                                foreach (Bullet eb in e.BulletList)
                                {
                                    if (eb.Position.X >= player.Position.X - player.Radius &&
                                        eb.Position.X <= player.Position.X + player.Radius &&
                                        eb.Position.Y + 1.0f >= player.Position.Y - (player.Radius * 2) &&
                                        eb.Position.Y <= player.Position.Y + (player.Radius * 2))
                                    {
                                        eb.Invisible = false;
                                        view.BeenHit();
                                        player.Health = 1;
                                    }
                                }

                                //Looks for collisino between playerbullets and the enemy and playerbullets and enemybullets
                                foreach (Bullet pb in player.BulletList)
                                {
                                    if (e.IsAlive)
                                    {
                                        if (pb.Position.X <= e.Position.X + e.Radius &&
                                            pb.Position.X >= e.Position.X - e.Radius &&
                                            pb.Position.Y - 0.5f <= e.Position.Y + (e.Radius * 2) &&
                                            pb.Position.Y >= e.Position.Y - (e.Radius * 2))
                                        {
                                            e.IsAlive = false;
                                            pb.Invisible = false;
                                            view.HitEnemy(e.Position.X, e.Position.Y);
                                            enemiesDown++;
                                        }
                                    }

                                    foreach (Bullet eb in e.BulletList)
                                    {
                                        if (pb.Position.X <= eb.Position.X + 0.08f &&
                                            pb.Position.X >= eb.Position.X - 0.08f &&
                                            pb.Position.Y - 0.5f <= eb.Position.Y + 1.0f)
                                        {
                                            pb.Invisible = false;
                                            eb.Invisible = false;
                                        }
                                    }
                                }

                                //Player can collide with enemy just if it´s alive
                                if (e.IsAlive)
                                {
                                    if (e.Position.X + e.Radius >= player.Position.X - player.Radius &&
                                        e.Position.X - e.Radius <= player.Position.X + player.Radius &&
                                        e.Position.Y + (e.Radius * 2) >= player.Position.Y - (player.Radius * 2) &&
                                        e.Position.Y - (e.Radius * 2) <= player.Position.Y + (player.Radius * 2))
                                    {
                                        e.IsAlive = false;
                                        view.HitEnemy(e.Position.X, e.Position.Y);
                                        player.Health = 1;
                                    }
                                }
                            }
                        }

                        //Spawsn asteroids if there´s any on the level
                        if (l.Asteroid)
                        {
                            l.spawnAsteroids(gameTime);

                            foreach (Asteroid a in l.AsteroidList)
                            {
                                if (a.Visible)
                                {
                                    //Updates asteroids and looks for collision with the player and with player bullets
                                    a.Update(gameTime);

                                    if (a.Position.X + a.Radius >= player.Position.X - player.Radius &&
                                        a.Position.X - a.Radius <= player.Position.X + player.Radius &&
                                        a.Position.Y + (a.Radius * 2) >= player.Position.Y - (player.Radius * 2) &&
                                        a.Position.Y - (a.Radius * 2) <= player.Position.Y + (player.Radius * 2))
                                    {
                                        a.Visible = false;
                                        player.Health = 1;
                                        view.HitAsteroid(a.Position.X, a.Position.Y);
                                    }

                                    foreach (Bullet pb in player.BulletList)
                                    {
                                        if (pb.Position.X <= a.Position.X + a.Radius &&
                                            pb.Position.X >= a.Position.X - a.Radius &&
                                            pb.Position.Y <= a.Position.Y + (a.Radius * 2) &&
                                            pb.Position.Y >= a.Position.Y - (a.Radius * 2))
                                        {
                                            a.Visible = false;
                                            pb.Invisible = false;
                                            view.HitAsteroid(a.Position.X, a.Position.Y);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (l.Boss)
                        {
                            //spawns boss
                            if (l.TheBoss == null)
                            {
                                l.spawnBoss(gameTime);
                            }

                            //Updates boss
                            if (l.TheBoss.IsAlive)
                            {
                                l.TheBoss.Update(gameTime);
                            }

                            //If boss is above 0 health, watch for collisions
                            if (l.TheBoss.Health != 0)
                            {
                                if (l.TheBoss.Position.X + l.TheBoss.Radius >= player.Position.X - player.Radius &&
                                l.TheBoss.Position.X - l.TheBoss.Radius <= player.Position.X + player.Radius &&
                                l.TheBoss.Position.Y + l.TheBoss.Radius >= player.Position.Y &&
                                l.TheBoss.Position.Y - l.TheBoss.Radius <= player.Position.Y + player.Radius)
                                {
                                    player.Alive = false;
                                }

                                foreach (Bullet b in l.TheBoss.BulletList)
                                {
                                    if (b.Position.X >= player.Position.X - player.Radius &&
                                        b.Position.X <= player.Position.X + player.Radius &&
                                        b.Position.Y + 1.0f >= player.Position.Y - (player.Radius * 2) &&
                                        b.Position.Y <= player.Position.Y + (player.Radius * 2))
                                    {
                                        view.BeenHit();
                                        b.Invisible = false;
                                        player.Health = 1;
                                    }
                                }

                                //When the boss is in position, start shoot
                                if (l.TheBoss.AnimationDone())
                                {
                                    foreach (Bullet pb in player.BulletList)
                                    {
                                        if (pb.Position.X <= l.TheBoss.Position.X + l.TheBoss.Radius &&
                                            pb.Position.X >= l.TheBoss.Position.X - l.TheBoss.Radius &&
                                            pb.Position.Y <= l.TheBoss.Position.Y + l.TheBoss.Radius &&
                                            pb.Position.Y >= l.TheBoss.Position.Y - l.TheBoss.Radius)
                                        {
                                            view.BossHit();
                                            l.TheBoss.Health = 1;
                                            pb.Invisible = false;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //If boss dies, display explosion effects every 0.7 seconds
                                elapsedAnimationBoss += (float)gameTime.ElapsedGameTime.TotalSeconds;
                                elapsedBossEndsGame += (float)gameTime.ElapsedGameTime.TotalSeconds;
                                l.TheBoss.IsAlive = false;
                                BossAlive = false;

                                if (elapsedAnimationBoss >= 0.5f && elapsedBossEndsGame <= 10.0f)
                                {
                                    //random on boss position
                                    view.BossDies(l.TheBoss.Position.X + (float)random.NextDouble() * 2.0f - 1.0f,
                                                  l.TheBoss.Position.Y + (float)random.NextDouble() - 0.5f);
                                    elapsedAnimationBoss = 0;
                                }

                                //And after 10 seconds move player out of the screen and finish the game
                                if (elapsedBossEndsGame >= 10.2f)
                                {
                                    l.TheBoss.Visible = false;
                                    if (player.FinishMove())
                                    {
                                        GameEnds = true;
                                    }
                                }
                            }

                        }
                        else
                        {
                            elapsedChangeLevel += (float)gameTime.ElapsedGameTime.TotalSeconds;

                            if (elapsedChangeLevel >= 1.5f)
                            {
                                if (!levelsystem.completeAndActivate())
                                {
                                    ChangeLevel = true;
                                    elapsedChangeLevel = 0;

                                }
                                player.MaxHealth();
                                enemiesDown = 1;
                            }
                        }
                    }
                }
            }
        }