Beispiel #1
0
        public Game()
        {
            font18  = new Font("data/Joystix.ttf", 18);
            player  = new Player();
            shoting = false;

            Hardware.ScrollTo((short)(512 - (player.GetX())), (short)(384 - player.GetY()));
            //Centering scroll to the character

            Random rnd = new Random();

            numEnemies = 2;

            Enemy enemy;

            for (int i = 0; i < numEnemies; i++)
            {
                enemy = new Enemy(rnd.Next(200, 800), rnd.Next(50, 600), this);
                enemies.Add(enemy);
            }

            currentLevel = new Level();
            finished     = false;

            myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 0, 0);
            myShot.Hide();
            direction = 'R';

            score = 0;

            //create object into level
            Door      newDoor;
            Key       newKey;
            Food      newFood;
            Generator newGenerator;


            for (int row = 0; row < currentLevel.GetlevelHeight(); row++)
            {
                for (int col = 0; col < currentLevel.GetLevelWidth(); col++)
                {
                    int xPos = currentLevel.GetLeftMargin() + col * currentLevel.GetTileWidth();
                    int yPos = currentLevel.GetTopMargin() + row * currentLevel.GetTileHeight();

                    switch (currentLevel.GetLevelDescription(col, row))
                    {
                    // Q = key

                    case 'Q':
                        newKey = new Key(xPos, yPos);
                        currentLevel.SetSpacePosition(row, col);
                        keys.Add(newKey);
                        break;

                    case '[':
                        newDoor = new Door(xPos, yPos, 'V');
                        doors.Add(newDoor);
                        break;

                    case '_':
                        newDoor = new Door(xPos, yPos, 'H');
                        doors.Add(newDoor);
                        break;

                    case 'F':
                        newFood = new Food(xPos, yPos);
                        foods.Add(newFood);
                        break;

                    case 'G':
                        newGenerator = new Generator(xPos, yPos, this);
                        generators.Add(newGenerator);
                        break;
                    }
                }
            }
            start = DateTime.Now;
        }
Beispiel #2
0
 // Change enemy status to in bubble
 public void InBubble(Shot shot)
 {
     isInBubble = true;
     myShot     = shot;
 }
Beispiel #3
0
        // Check input by the user
        public void CheckKeys()
        {
            if ((Hardware.KeyPressed(Hardware.KEY_RIGHT)) &&
                (currentLevel.IsValidMove(
                     player.GetX() + player.GetSpeedX(),
                     player.GetY(),
                     player.GetX() + player.GetWidth() + player.GetSpeedX(),
                     player.GetY() + player.GetHeight())))
            {
                player.MoveRight();
                Hardware.ScrollHorizontally((short)-player.GetSpeedX());
                direction = 'R';
            }


            if ((Hardware.KeyPressed(Hardware.KEY_LEFT)) &&
                (currentLevel.IsValidMove(
                     player.GetX() - player.GetSpeedX(),
                     player.GetY(),
                     player.GetX() + player.GetWidth() - player.GetSpeedX(),
                     player.GetY() + player.GetHeight())))
            {
                player.MoveLeft();
                Hardware.ScrollHorizontally((short)player.GetSpeedX());
                direction = 'L';
            }


            if ((Hardware.KeyPressed(Hardware.KEY_DOWN)) &&
                (currentLevel.IsValidMove(
                     player.GetX(),
                     player.GetY() + player.GetSpeedY(),
                     player.GetX() + player.GetWidth(),
                     player.GetY() + player.GetHeight() + player.GetSpeedY())))
            {
                player.MoveDown();
                Hardware.ScrollVertically((short)-player.GetSpeedY());
                direction = 'D';
            }


            if ((Hardware.KeyPressed(Hardware.KEY_UP)) &&
                (currentLevel.IsValidMove(
                     player.GetX(),
                     player.GetY() - player.GetSpeedY(),
                     player.GetX() + player.GetWidth(),
                     player.GetY() + player.GetHeight() - player.GetSpeedY())))
            {
                player.MoveUp();
                Hardware.ScrollVertically((short)player.GetSpeedY());
                direction = 'U';
            }

            if ((Hardware.KeyPressed(Hardware.KEY_SPC)) && (!myShot.IsVisible()) && (!shoting))
            {
                if (direction == 'R')
                {
                    myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 10, 0);
                }
                if (direction == 'L')
                {
                    myShot = new Shot(currentLevel, player.GetX(), player.GetY(), -10, 0);
                }
                if (direction == 'U')
                {
                    myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 0, -10);
                }
                if (direction == 'D')
                {
                    myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 0, 10);
                }
            }


            if (Hardware.KeyPressed(Hardware.KEY_ESC))
            {
                finished = true;
            }
        }