Exemplo n.º 1
0
  @Override
  public void create() {
    // load the images for the droplet and the bucket, 48x48 pixels each
    dropImage = new Texture(Gdx.files.internal("data/droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("data/bucket.png"));

    // load the drop sound effect and the rain background "music"
    dropSound = Gdx.audio.newSound(Gdx.files.internal("data/drop.wav"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("data/rain.mp3"));

    // start the playback of the background music immediately
    rainMusic.setLooping(true);
    rainMusic.play();

    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    batch = new SpriteBatch();

    // create a Rectangle to logically represent the bucket
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 48 / 2; // center the bucket horizontally
    bucket.y = 20; // bottom left corner of the bucket is 20 pixels above the bottom screen edge
    bucket.width = 48;
    bucket.height = 48;

    // create the raindrops array and spawn the first raindrop
    raindrops = new Array<Rectangle>();
    spawnRaindrop();
  }
Exemplo n.º 2
0
 // Metodo que devuelve una textura de un Arraylist cada X tiempo (intervalTime).
 private Texture SwapTextureFromArray(
     ArrayList<Texture> list, int startIndex, long startTime, float intervalTime) {
   Texture img = null;
   if (startIndex < list.size()) {
     Music sound = soundsList.get(startIndex);
     if (TimeUtils.timeSinceMillis(startTime) < intervalTime * 1000) {
       img = list.get(startIndex);
       if (startIndex < titlesList.size()) {
         imageTitle.ChangeFontText(titlesList.get(startIndex));
       }
       if (!soundPlayed) {
         System.out.println("Playing music");
         sound.play();
         soundPlayed = true;
       }
     } else {
       if (!sound.isPlaying()) {
         actualImgIndex++;
         beginTime = TimeUtils.millis();
         img = list.get(startIndex);
         imageTitle.ChangeFontText(titlesList.get(startIndex));
         System.out.println("Music finished");
         soundPlayed = false;
       }
     }
   } else {
     img = list.get(texturesList.size() - 1);
   }
   return img;
 }
Exemplo n.º 3
0
  private GameScreen() {
    this.superflu = SuperFlu.getInstance();
    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    groupZones = new Group();
    groupVilles = new GroupVilles();
    groupTransferts = new Group();

    Texture backgroundTexture = superflu.manager.get("images/fond_carte.png", Texture.class);
    TextureRegion backgroundTextureRegion =
        new TextureRegion(backgroundTexture, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
    Image imgBackground = new Image(backgroundTextureRegion);
    imgBackground.touchable = false;
    stage.addActor(imgBackground);

    Texture carteTexture = superflu.manager.get("images/carte.png", Texture.class);
    TextureRegion carteTextureRegion =
        new TextureRegion(carteTexture, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
    Image carte = new Image(carteTextureRegion);
    carte.touchable = false;
    stage.addActor(carte);

    stage.addActor(groupZones);
    stage.addActor(groupVilles);
    stage.addActor(groupTransferts);

    stage.addActor(TransfertCreator.getInstance());

    Music softMusic = superflu.manager.get("music/soft.mp3", Music.class);
    softMusic.play();

    createEntities();
    Gdx.input.setInputProcessor(stage);

    stage.addActor(new GlobalStatsActor(gameLogic));
  }
Exemplo n.º 4
0
  private void randomizeMusic() {
    int random;
    // If its not the first time randomizing
    if (currentMusic != -1) {
      random = rand.nextInt(musicFileNames.length - 1);

      // To make sure the same music dosen't play twice
      if (currentMusic <= random) {
        random++;
      }
    } else {
      random = rand.nextInt(musicFileNames.length);
    }

    if (music != null) {
      music.stop();
      music.dispose();
    }

    currentMusic = random;
    music = Gdx.audio.newMusic(Gdx.files.internal("audio/" + musicFileNames[random]));
    music.play();
    music.setVolume(1);

    music.setOnCompletionListener(
        new OnCompletionListener() {
          @Override
          public void onCompletion(Music music) {
            randomizeMusic();
            music.dispose();
          }
        });
  }
 public void playMusic() {
   music.setVolume(1);
   music.setLooping(true);
   if (music != null && !music.isPlaying()) {
     music.play();
   }
 }
Exemplo n.º 6
0
  @Override
  public void create() {
    music = Gdx.audio.newMusic(Gdx.files.internal("res/racerx.mp3"));
    music.setLooping(true);
    music.play();

    splashScreen = new SplashScreen(this);
    setScreen(splashScreen);
  }
Exemplo n.º 7
0
 public static void play(String newKey) {
   if (!enabled) return;
   if (music != null) {
     music.stop();
   }
   key = newKey;
   music = musics.get(key);
   music.setLooping(true);
   music.play();
 }
Exemplo n.º 8
0
  private void initMusic() {
    music = AssetsLoader.getMusic();

    boolean musicOn = preferences.getBoolean("musicOn", true);
    float musicVolume = preferences.getFloat("musicVolume", 1);
    music.setLooping(true);
    if (musicOn) {
      music.play();
    }
    music.setVolume(musicVolume);
  }
Exemplo n.º 9
0
 public static void reloadMusic() {
   if (MiningAdventure.PREF_AUDIO) {
     aud.stop();
     aud.dispose();
     aud = null;
     if (!MiningAdventure.sanic) {
       aud = Gdx.audio.newMusic(Gdx.files.internal("music/Game.mp3"));
     } else {
       aud = Gdx.audio.newMusic(Gdx.files.internal("music/SANIC.mp3"));
     }
     aud.play();
     aud.setLooping(true);
   }
 }
Exemplo n.º 10
0
  private void mainInit() {
    Image logo;

    logo = new Image(new Texture("resources/logo.png"));
    logo.setPosition(16, 300);
    logo.setOrigin(logo.getWidth() / 2, logo.getHeight() / 2);
    RepeatAction twinkleForever = new RepeatAction();
    twinkleForever.setAction(new SequenceAction(CustomActions.twinkle(), new DelayAction(1.3f)));
    twinkleForever.setCount(RepeatAction.FOREVER);

    logo.addAction(twinkleForever);
    music = Gdx.audio.newMusic(Gdx.files.internal("resources/music/main.mp3"));
    music.play();
    stage.addActor(logo);
  }
Exemplo n.º 11
0
  /**
   * Plays the given music (starts the streaming).
   *
   * <p>If there is already a music being played it is stopped automatically.
   */
  public void play(Music music) {
    // check if the music is enabled
    if (!enabled) return;

    // stop any music being played

    //        stop(); // removing this solves the restart problem (if menu-music is added, maybe
    // it's needed again)

    // start streaming the new music
    musicBeingPlayed = music;
    musicBeingPlayed.setVolume(volume);
    musicBeingPlayed.setLooping(true);
    musicBeingPlayed.play();
  }
Exemplo n.º 12
0
  // constructor donde se inicializa los elementos de pantallaJuego y donde cargamos los recursos a
  // la memoria ram
  public PantallaJuego(Arcanoid arcanoid) {
    this.arcanoid = arcanoid;

    ManejadorDeRecursos.cargarTodasLasTexturas();
    batch = new SpriteBatch();
    manejadorDeSprite = new ManejadorDeSprite(arcanoid.spriteBatch);
    manejadorDeNiveles = new ManejadorDeNiveles(manejadorDeSprite);
    manejadorDeNiveles.cargarNivelActual();
    musicaFondo = ManejadorDeRecursos.getMusica("musicaFondo");
    musicaFondo.play();
    fondoPantalla = ManejadorDeRecursos.getTextura("fondoJuego");

    camara = new OrthographicCamera();
    camara.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    jugador = new Jugador();
  }
  @Override
  public void create() {
    shapeRenderer = new ShapeRenderer();
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    uiCamera = new OrthographicCamera();
    uiCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    uiCamera.update();

    font = new BitmapFont(Gdx.files.internal("arial.fnt"));

    background = new Texture("background.png");
    ground = new TextureRegion(new Texture("ground.png"));
    ceiling = new TextureRegion(ground);
    ceiling.flip(true, true);

    rock = new TextureRegion(new Texture("rock.png"));
    rockDown = new TextureRegion(rock);
    rockDown.flip(false, true);

    Texture frame1 = new Texture("plane1.png");
    frame1.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    Texture frame2 = new Texture("plane2.png");
    Texture frame3 = new Texture("plane3.png");

    ready = new TextureRegion(new Texture("ready.png"));
    gameOver = new TextureRegion(new Texture("gameover.png"));

    plane =
        new Animation(
            0.05f,
            new TextureRegion(frame1),
            new TextureRegion(frame2),
            new TextureRegion(frame3),
            new TextureRegion(frame2));
    plane.setPlayMode(PlayMode.LOOP);

    music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
    music.setLooping(true);
    music.play();

    explode = Gdx.audio.newSound(Gdx.files.internal("explode.wav"));

    resetWorld();
  }
Exemplo n.º 14
0
  /*
   *  The create() method initializes our all of our resources and loads them into memory before the rest of the game is run
   *  This method is the first called after the entry point(based on platform) and is only called once.
   *  This is also a convenient place to put boiler plate code for the rest of the game that we only want ran once on startup.
   *
   *  NOTE: Gdx.files.internal() defaults to the assets put into the Android project folder and takes String "filename.filetype" as a parameter.
   */
  @Override
  public void create() {
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    dropSound = Gdx.audio.newSound(Gdx.files.internal("droplet.mp3"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));

    rainMusic.setLooping(true); // set rainMusic (rain.mp3) to play over and over again
    rainMusic.play(); // starts the rainMusic audio

    camera = new OrthographicCamera(); // initialize camera, part of opengl/opengl-es.

    /*
     * sets the camera to 2 dimensional plane. Seems redundant since we are using OrthographicCamera() object.
     * Note: investigate camera settings
     */
    camera.setToOrtho(false, 800, 400);

    batch = new SpriteBatch(); // new sprite batch used in render() ie.Draws images.

    /*
     * set bucket properties. Use Rectangle object to represent bucket, track position and set size
     * used for collision detection with raindrop objects
     *
     */
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2;
    bucket.y = 20;
    bucket.width = 64;
    bucket.height = 64;

    /*
     * initializes Libgdx Array.
     * Note: Investigate how  Libgdx Array is different than regular Java Array.
     */
    raindrops = new Array<Rectangle>();

    /*
     * creates new raindrops to be drawn for our game. This method is called here to
     * start the first raindrop.
     */
    spawnRaindrop();
  }
Exemplo n.º 15
0
  private void startLevel(String filename) {
    level = Level.loadLevel(filename);
    nextFootstep = 0;
    music = Gdx.audio.newMusic(Gdx.files.internal(level.getMusicFiles().poll()));
    music.play();
    final GameScreen thisGameScreen = this;
    music.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(Music music) {
            music.dispose();
            level.incrementCurrentSection();

            String nextMusicName = level.getMusicFiles().poll();
            if (!endingLevel) {
              if (nextMusicName != null) {
                Music nextMusic = Gdx.audio.newMusic(Gdx.files.internal(nextMusicName));
                nextMusic.play();
                nextMusic.setOnCompletionListener(this);
                thisGameScreen.music = nextMusic;
              } else {
                // End of level!
                // Play end of level sound
                // After it ends, load level 2
                Music endSound = Gdx.audio.newMusic(Gdx.files.internal("endOfLevel.ogg"));
                endSound.play();
                // final OnCompletionListener thisCompletionListener =
                // this;
                // this;
                endSound.setOnCompletionListener(
                    new OnCompletionListener() {

                      @Override
                      public void onCompletion(Music music) {
                        music.dispose();
                        startLevel("theme2.txt");
                      }
                    });
              }
            }
          }
        });
  }
Exemplo n.º 16
0
  public BaseLevel(GameScreen gameScreen) {
    m_GameScreen = gameScreen;
    m_Entities = new ArrayList<IEntity>();

    m_BackgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("music/background.mp3"));
    m_BackgroundMusic.setVolume(gameScreen.m_Settings.m_BackgroundMusicVolume * 0.75f);
    m_BackgroundMusic.setLooping(true);
    m_BackgroundMusic.play();

    m_ClockTick = Gdx.audio.newSound(Gdx.files.internal("music/tick.mp3"));
    m_Powerup = Gdx.audio.newSound(Gdx.files.internal("music/powerup.wav"));
    m_Crash = Gdx.audio.newSound(Gdx.files.internal("music/crash.mp3"));
    m_Wind = Gdx.audio.newSound(Gdx.files.internal("music/wind.mp3"));

    // title
    m_BorderTexture = new Texture(Gdx.files.internal("map/border.png"));
    m_BorderTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    TextureRegion borderRegion = new TextureRegion(m_BorderTexture, 0, 0, 800, 600);
    m_BorderSprite = new Sprite(borderRegion);
    m_BorderSprite.setColor(1, 1, 1, 0.5f);
  }
Exemplo n.º 17
0
  @Override
  public void show() {
    buttonRenderer = new SpriteBatch();

    if (aud != null && !MiningAdventure.PREF_AUDIO) {
      aud.stop();
      aud.dispose();
      aud = null;
    }

    if (aud == null && MiningAdventure.PREF_AUDIO) {
      if (!MiningAdventure.sanic) {
        aud = Gdx.audio.newMusic(Gdx.files.internal("music/Game.mp3"));
      } else {
        aud = Gdx.audio.newMusic(Gdx.files.internal("music/SANIC.mp3"));
      }
      aud.play();
      aud.setLooping(true);
    }

    Gdx.input.setInputProcessor(this);
  }
Exemplo n.º 18
0
  @Override
  public void create() {
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    // img = new Texture("badlogic.jpg");
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2;
    bucket.y = 20;
    bucket.width = 64;
    bucket.width = 64;

    raindrops = new Array<Rectangle>();
    spawnRaindrop();

    dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));

    rainMusic.setLooping(true);
    rainMusic.play();
  }
Exemplo n.º 19
0
 public void resumeMusic() {
   if (music != null && isMusicPaused) {
     music.play();
     isMusicPaused = false;
   }
 }
Exemplo n.º 20
0
 public static void enable() {
   enabled = true;
   if (music != null) {
     music.play();
   }
 }
Exemplo n.º 21
0
 public static void startMusic(Music music) {
   music.play();
   music.setLooping(true);
 }
Exemplo n.º 22
0
 public void musicResume() {
   preferences.putBoolean("musicOn", true);
   preferences.flush();
   music.play();
 }
Exemplo n.º 23
0
  @Override
  public void show() {
    openingtheme.play();
    openingtheme.setLooping(true);
    // openingtheme.setVolume(game.state.volume);
    batch = new SpriteBatch();

    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    // Straight up stolen from https://www.pinterest.comore
    //        img = new Texture("menubackground1.png");
    img = new Texture("menu_background_fix.png");
    titleimg = new Texture("SlashHeroesTitle.png");
    img.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    // change these numbers around so it looks good on the presentation phone
    TextureRegion region = new TextureRegion(img, 0, 0, 600, 400);
    sprite = new Sprite(region);
    sprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    sprite.setOrigin(0, 0);

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(320, 75, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.GREEN);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    // create the custom font
    FreeTypeFontGenerator generator =
        new FreeTypeFontGenerator(Gdx.files.internal("fonts/slkscre.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 80;
    BitmapFont OurFont = generator.generateFont(parameter);
    generator.dispose(); // don't forget to dispose to avoid memory leaks!

    // add ourfont to the skin for our buttons.
    skin.add("default", OurFont);

    // textbuttonstyle wont overwrite the font
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");

    skin.add("default", textButtonStyle);

    // Create a button with the "default" TextButtonStyle.
    final TextButton PlayButton = new TextButton("PLAY", textButtonStyle);
    // final TextButton ContinueButton = new TextButton("Continue",textButtonStyle);
    final TextButton SettingsButton = new TextButton("Mute", textButtonStyle);
    final TextButton QuitButton = new TextButton("Quit", textButtonStyle);
    PlayButton.setPosition(Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 150);
    // ContinueButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2 - 85);
    //        SettingsButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2
    // - 165);
    SettingsButton.setPosition(
        Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 300);
    //        QuitButton.setPosition(Gdx.graphics.getWidth()/2 - 160, Gdx.graphics.getHeight()/2 -
    // 245);
    QuitButton.setPosition(Gdx.graphics.getWidth() / 2 - 160, Gdx.graphics.getHeight() / 2 - 450);
    stage.addActor(PlayButton);
    // stage.addActor(ContinueButton);
    stage.addActor(SettingsButton);
    stage.addActor(QuitButton);

    PlayButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            select.play();
            PlayButton.setText("Starting new game");
            openingtheme.stop();
            game.setScreen(game.introscreen);
          }
        });
    SettingsButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            // System.out.println("Clicked! Is checked: " + button.isChecked());
            select.play();
            if (game.state.volume == 0f) {
              game.state.volume = .7f;
              openingtheme.play();
              openingtheme.setVolume(game.state.volume);
              SettingsButton.setText("Mute");
            } else {
              game.state.volume = 0f;
              openingtheme.stop();
              SettingsButton.setText("Unmute");
            }

            // TODO make this mute and unmute the non existant sound
            // mute and unmute;
          }
        });
    QuitButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            select.play();
            openingtheme.stop();
            QuitButton.setText("Quitting");
            // TODO make this quit the correct way
            System.exit(0);
          }
        });
  }
Exemplo n.º 24
0
 public void playMusic() {
   if (music != null && !music.isPlaying()) {
     music.play();
     music.setLooping(loopMusic);
   }
 }
Exemplo n.º 25
0
 @Override
 public void show() {
   // start the playback of the background music
   // when the screen is shown
   rainMusic.play();
 }