Ejemplo n.º 1
0
        // Check collisions and apply game logic
        public void CheckCollisions()
        {
            for (int i = 0; i < numEnemies; i++)
            {
                if (enemies[i].CollisionsWith(myShot))
                {
                    enemies[i].Hide();
                    myShot.Hide();
                }
            }

            for (int i = 0; i < numEnemies; i++)
            {
                if (enemies[i].CollisionsWith(player))
                {
                    finished = true;
                }
            }

            if (player.GetX() + player.GetWidth() >= currentLevel.GetMaxX() &&
                level < 3)
            {
                level++;
                player.SetX(currentLevel.GetMinX() + 5);
                currentLevel.SetLevel(level);
                for (int i = 0; i < numEnemies; i++)
                {
                    enemies[i].SetX(currentLevel.GetEnemyX()[i]);
                }
            }

            if (player.GetX() <= currentLevel.GetMinX() && level > 0)
            {
                level--;
                player.SetX(currentLevel.GetMaxX() - player.GetWidth() - 5);
                currentLevel.SetLevel(level);
                for (int i = 0; i < numEnemies; i++)
                {
                    enemies[i].SetX(currentLevel.GetEnemyX()[i]);
                }
            }
        }
Ejemplo n.º 2
0
        public Game()
        {
            font18 = new Font("data/Joystix.ttf", 18);
            player = new Player(this);
            level  = 1;
            Random rnd = new Random();

            numEnemies   = 2;
            enemies      = new Enemy[numEnemies];
            currentLevel = new Level();
            for (int i = 0; i < numEnemies; i++)
            {
                enemies[i] = new Enemy(currentLevel.GetEnemyX()[i], currentLevel.GetEnemyY()[i]);
                enemies[i].SetSpeed(rnd.Next(1, 5), 0);
            }

            finished = false;
            myShot   = new Shot(this, 0, 0, 0);
            myShot.Hide();
            direction = 'R';
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        // Check collisions and apply game logic
        public void CheckCollisions()
        {
            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].CollisionsWith(myShot))
                {
                    enemies[i].SetLife(enemies[i].GetLife() - player.GetAttack());

                    if (enemies[i].GetLife() < 0)
                    {
                        enemies[i].Hide();
                        score += 100;
                    }
                    myShot.Hide();
                }
            }

            // logic generators

            for (int i = 0; i < generators.Count; i++)
            {
                int xInLevel = (generators[i].GetX() - currentLevel.GetLeftMargin()) / currentLevel.GetTileWidth();
                int yInLevel = (generators[i].GetY() - currentLevel.GetTopMargin()) / currentLevel.GetTileHeight();

                if (generators[i].CollisionsWithArround(myShot))
                {
                    generators[i].SetLife(generators[i].GetLife() - player.GetAttack());

                    if (generators[i].GetLife() < 0)
                    {
                        generators[i].Hide();
                        generators[i].DestroiGenerator(currentLevel, generators[i].GetX(), generators[i].GetY());
                        generators.RemoveAt(i);
                        score += 300;
                    }
                    myShot.Hide();
                }

                if (currentLevel.GetLevelDescription(xInLevel, yInLevel) == ' ')
                {
                    doors[i].Hide();
                }
            }

            for (int i = 0; i < keys.Count; i++)
            {
                if (keys[i].CollisionsWithArround(player))
                {
                    player.SetKeys();
                    keys[i].Hide();
                }
            }

            for (int i = 0; i < foods.Count; i++)
            {
                if (foods[i].CollisionsWithArround(player))
                {
                    player.SetLife(player.GetLife() + 100);
                    foods[i].DestroiFood(currentLevel, foods[i].GetX(), foods[i].GetY());
                    foods[i].Hide();
                }

                if (foods[i].CollisionsWithArround(myShot))
                {
                    foods[i].DestroiFood(currentLevel, foods[i].GetX(), foods[i].GetY());
                    foods[i].Hide();
                }
            }

            for (int i = 0; i < doors.Count; i++)
            {
                int xInLevel = (doors[i].GetX() - currentLevel.GetLeftMargin()) / currentLevel.GetTileWidth();
                int yInLevel = (doors[i].GetY() - currentLevel.GetTopMargin()) / currentLevel.GetTileHeight();

                if (doors[i].CollisionsWithArround(player))
                {
                    if (player.GetKeys() > 0)
                    {
                        player.UseKeys();

                        doors[i].OpenDoor(currentLevel, doors[i].GetX(), doors[i].GetY());

                        doors[i].Hide();

                        score += 100;
                    }
                }

                if (currentLevel.GetLevelDescription(xInLevel, yInLevel) == ' ')
                {
                    doors[i].Hide();
                }
            }
        }