Example #1
0
    public override void Show()
    {
        timePlayedTimer.Start();
        DateTime timeStampFromLastShot   = DateTime.Now;
        DateTime timeStampFromLastDamage = DateTime.Now;

        short centeredCharacterX =
            (short)((GameController.SCREEN_WIDTH / 2) - (Character.Width / 2));
        short centeredCharacterY =
            (short)((GameController.SCREEN_HEIGHT / 2) - (Character.Height / 2));

        Character.Image.MoveTo(centeredCharacterX, centeredCharacterY);
        Character.MoveTo(centeredCharacterX, centeredCharacterY);

        enemyGenerator.InitialiceRound(Round);
        enemyGenerator.SetEnemiesSpawnpoints();

        enemy.MoveTo(0, GameController.SCREEN_HEIGHT);

        short oldX, oldY, oldXMap, oldYMap;

        do
        {
            // 1. Draw everything.
            hardware.ClearScreen();

            hardware.DrawSprite(level.Floor, 0, 0, 0,
                                0, GameController.SCREEN_WIDTH,
                                GameController.SCREEN_HEIGHT);

            level.DrawObstacles(hardware);
            hardware.DrawImage(Character.Image);
            hardware.DrawImage(enemy.EnemyImage);

            foreach (Enemy enemy in enemyGenerator.enemies)
            {
                hardware.DrawImage(enemy.EnemyImage);
            }

            foreach (Bullet bullet in Character.
                     weapons[Character.ActualWeapon].Bullets)
            {
                hardware.DrawImage(bullet.Image);
            }

            drawHud();
            hardware.UpdateScreen();
            // 2. Move character from keyboard input.
            oldX    = Character.X;
            oldY    = Character.Y;
            oldXMap = level.XMap;
            oldYMap = level.YMap;

            hardware.GetEvents(
                out mouseX, out mouseY,
                out mouseClickX, out mouseClickY);

            if (mouseClickX != hardware.GetOldMouseClickX() &&
                mouseClickX != hardware.GetOldMouseClickY())
            {
                Character.weapons[Character.ActualWeapon].
                Bullets.Add(new Bullet(
                                (short)mouseClickX, (short)mouseClickY));
            }

            moveBullets();
            moveCharacter();
            Character.Animate(mouseX, mouseY);

            // 3. Move enemies and objects.
            foreach (Enemy enemy in enemyGenerator.enemies)
            {
                enemy.PonitToCharacter(Character.X, Character.Y);
                enemy.GoToPlayer(Character, level);
            }

            enemy.PonitToCharacter(Character.X, Character.Y);
            enemy.GoToPlayer(Character, level);

            // 4. Check collisions and update game state.
            if (enemy.CharacterIsOnRange(Character))
            {
                enemy.Attack(Character, ref timeStampFromLastDamage);
            }
        }while (Character.Life > 0 && !hardware.IsKeyPressed(Hardware.KEY_ESC));
        timePlayedTimer.Reset();
    }