Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 2 Sound #219

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
Expand All @@ -23,6 +24,7 @@
import com.csse3200.game.screens.text.AnimatedText;
import com.csse3200.game.screens.Planets;
import com.csse3200.game.services.GameEndService;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -45,6 +47,10 @@ public class LevelSelectScreen extends ScreenAdapter {
private BitmapFont font;

private Sprite background;
private String[] bgm = {
"sounds/background/pre_game/Sci-Fi8Loop_story.ogg"
};
private Music music;

// Stores a time to determine the frame of the planet
// TODO: Account for integer overflow
Expand Down Expand Up @@ -77,6 +83,12 @@ public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, f
table1.pad(20); // Add padding to the top-right corner
table1.add(buttonTable).row(); // Add button table and move to the next row
stage.addActor(table1);

ServiceLocator.registerResourceService(new ResourceService());
ServiceLocator.getResourceService().loadMusic(bgm);
ServiceLocator.getResourceService().loadAll();
music = ServiceLocator.getResourceService().getAsset(bgm[0], Music.class);

}

@Override
Expand All @@ -85,6 +97,10 @@ public void show() {
background = new Sprite(new Texture(BG_PATH));
ServiceLocator.registerGameEndService(new GameEndService());
Gdx.input.setInputProcessor(stage);

music.setVolume(0.4f);
music.setLooping(true);
music.play();
}

/**
Expand Down Expand Up @@ -174,5 +190,6 @@ public void resize(int width, int height) {
public void dispose() {
stage.dispose();
batch.dispose();
music.dispose();
}
}
15 changes: 15 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/StoryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
Expand All @@ -17,6 +18,8 @@
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.csse3200.game.GdxGame;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;

/**
* Screen that displays a story with images and text.
Expand Down Expand Up @@ -67,6 +70,10 @@ public class StoryScreen extends ScreenAdapter {
"all seems perfect until we picked up on a looming threat that maybe we aren't alone......",
// Add more text as needed
};
private String[] bgm = {
"sounds/background/pre_game/Sci-Fi8Loop_story.ogg"
};
private Music music;
/**
* Creates a new StoryScreen.
*
Expand All @@ -83,6 +90,10 @@ public StoryScreen(GdxGame game) {
for (int i = 0; i < IMAGE_PATHS.length; i++) {
images[i] = new Texture(IMAGE_PATHS[i]);
}
ServiceLocator.registerResourceService(new ResourceService());
ServiceLocator.getResourceService().loadMusic(bgm);
ServiceLocator.getResourceService().loadAll();
music = ServiceLocator.getResourceService().getAsset(bgm[0], Music.class);
}

@Override
Expand Down Expand Up @@ -128,6 +139,9 @@ public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, f
table.pad(20); // Add padding to the top-right corner
table.add(buttonTable).row(); // Add button table and move to the next row
stage.addActor(table);
music.setVolume(0.4f);
music.setLooping(true);
music.play();
}

@Override
Expand Down Expand Up @@ -201,5 +215,6 @@ public void dispose() {
boldFont.dispose();
stage.dispose();
shapeRenderer.dispose();
music.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
Expand All @@ -21,6 +22,7 @@
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -52,13 +54,22 @@ public class TurretSelectionScreen extends ScreenAdapter {
private static final String TEXTURE = "planets/background.png";
private Set<TowerType> selectedTurrets = new HashSet<>();
private TextButton backButton;
private String[] bgm = {
"sounds/background/pre_game/Sci-Fi7Loop.ogg"
};
private Music music;
private static final Logger logger = LoggerFactory.getLogger(MainMenuScreen.class);

public TurretSelectionScreen(GdxGame game) {
this.game = game;
stage = new Stage(new ScreenViewport());
table = new Table();

ServiceLocator.registerResourceService(new ResourceService());
ServiceLocator.getResourceService().loadMusic(bgm);
ServiceLocator.getResourceService().loadAll();
music = ServiceLocator.getResourceService().getAsset(bgm[0], Music.class);

// Set up the background
batch = new SpriteBatch();
Texture backgroundImage = new Texture(TEXTURE);
Expand Down Expand Up @@ -218,6 +229,10 @@ public void clicked(InputEvent event, float x, float y) {
table.setFillParent(true);
Gdx.input.setInputProcessor(stage);

music.setVolume(0.4f);
music.setLooping(true);
music.play();

}
@Override
public void render(float delta) {
Expand Down Expand Up @@ -304,6 +319,7 @@ private void updateDescriptionText() {
@Override
public void dispose() {
stage.dispose();
music.dispose();
}

}
Loading