Ejemplo n.º 1
0
    private void createAsteroids()
    {
        CAsteroid asteroid;

        for (int i = 0; i < 10; i++)
        {
            asteroid = new CAsteroid(CAsteroid.TYPE_BIG, CMath.randomIntBetween(1, 3));
            asteroid.setXY(CMath.randomIntBetween(0, CGameConstants.SCREEN_WIDTH), CMath.randomIntBetween(0, CGameConstants.SCREEN_HEIGHT));
            asteroid.setVelX(CMath.randomFloatBetween(-500, 500));
            asteroid.setVelY(CMath.randomFloatBetween(-500, 500));
            CEnemyManager.inst().add(asteroid);
        }
    }
Ejemplo n.º 2
0
    // Se llama desde CPlayerBullet cuando una bala nos toca.
    public void hit()
    {
        setDead(true);

        int t = 0;

        // Si es un asteroide grande, se crean asteroides medianos.
        if (getType() == TYPE_BIG)
        {
            t = TYPE_MEDIUM;
        }
        // Si el asteroide es mediano, se crean asteroides chicos.
        else if (getType() == TYPE_MEDIUM)
        {
            t = TYPE_SMALL;
        }

        // Si el asteroide es chico, se saltea esta parte.
        // No se crean asteroides.
        if (getType() != TYPE_SMALL)
        {
            for (int i = 0; i < 2; i++)
            {
                // Crear los asteroides: se le pasa como parámetro el tipo y color (el color es el mismo).
                CAsteroid asteroid = new CAsteroid(t, mColor);
                asteroid.setXY(getX(), getY());
                asteroid.setVelX(CMath.randomFloatBetween(-500, 500));
                asteroid.setVelY(CMath.randomFloatBetween(-500, 500));
                CEnemyManager.inst().add(asteroid);
            }
        }

        CExplosion explosion = new CExplosion();

        explosion.setXY(getX(), getY());
        CParticleManager.inst().add(explosion);
    }