From aa253c4af037ddebf7c8c47eb4990c614afd71d4 Mon Sep 17 00:00:00 2001 From: Ahmad Abu-Aysha <111224176+The-AhmadAA@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:09:31 +1000 Subject: [PATCH 1/2] added music to story screen --- .../csse3200/game/screens/StoryScreen.java | 15 + .../game/input/BuildInputComponentTest.java | 307 +++++++++--------- 2 files changed, 174 insertions(+), 148 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/screens/StoryScreen.java b/source/core/src/main/com/csse3200/game/screens/StoryScreen.java index d294730be..398a9b352 100644 --- a/source/core/src/main/com/csse3200/game/screens/StoryScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/StoryScreen.java @@ -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; @@ -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. @@ -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. * @@ -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 @@ -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 @@ -201,5 +215,6 @@ public void dispose() { boldFont.dispose(); stage.dispose(); shapeRenderer.dispose(); + music.dispose(); } } diff --git a/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java b/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java index f5f7fe1cc..3cd427659 100644 --- a/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java +++ b/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java @@ -1,148 +1,159 @@ -package com.csse3200.game.input; - -import com.badlogic.gdx.math.Vector2; -import com.csse3200.game.extensions.GameExtension; -import com.csse3200.game.services.ServiceLocator; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -@ExtendWith(GameExtension.class) -class BuildInputComponentTest { - - @BeforeEach - void setup() { - - } - - @AfterEach - void tearDown() { - - } - - @Test - void shouldUpdatePriority() { - int newPriority = 100; - InputComponent inputComponent = spy(InputComponent.class); - - inputComponent.setPriority(newPriority); - verify(inputComponent).setPriority(newPriority); - - int priority = inputComponent.getPriority(); - verify(inputComponent).getPriority(); - - assertEquals(newPriority, priority); - } - - @Test - void shouldRegisterOnCreate() { - InputService inputService = spy(InputService.class); - ServiceLocator.registerInputService(inputService); - - InputComponent inputComponent = spy(InputComponent.class); - inputComponent.create(); - verify(inputService).register(inputComponent); - } - - @Test - void shouldHandleKeyDown(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.keyDown(1)); - } - - @Test - void shouldHandleKeyTyped() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.keyTyped('a')); - } - - @Test - void shouldHandleKeyUp() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.keyUp(1)); - } - - @Test - void shouldHandleMouseMoved() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.mouseMoved( 5, 6)); - } - - @Test - void shouldHandleScrolled() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.scrolled( 5f, 6f)); - } - - @Test - void shouldHandleTouchDown() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.touchDown( 5, 6, 7, 8)); - } - - @Test - void shouldHandleTouchDragged() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.touchDragged(5, 6, 7)); - } - - @Test - void shouldHandleTouchUp() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.touchUp( 5, 6, 7, 8)); - } - - @Test - void shouldHandleFling(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.fling( 5f, 6f, 7)); - } - - @Test - void shouldHandleLongPress(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.longPress(5f, 6f)); - } - - @Test - void shouldHandlePan(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.pan( 5f, 6f, 7f, 8f)); - } - - @Test - void shouldHandlePanStop(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.panStop( 5f, 6f, 7, 8)); - } - - @Test - void shouldHandlePinch(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.pinch(Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero)); - } - - @Test - void shouldHandleTap() { - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.tap(5f, 6f, 7, 8)); - } - - @Test - void shouldHandleTouchDownGesture(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.touchDown(5f, 6f, 7, 8)); - } - - @Test - void shouldHandleZoom(){ - InputComponent inputComponent = spy(InputComponent.class); - assertFalse(inputComponent.zoom(5f, 6f)); - } -} +//package com.csse3200.game.input; +// +//import com.badlogic.gdx.graphics.g2d.TextureAtlas; +//import com.badlogic.gdx.maps.tiled.TiledMap; +//import com.badlogic.gdx.math.Vector2; +//import com.csse3200.game.components.CameraComponent; +//import com.csse3200.game.currency.Currency; +//import com.csse3200.game.entities.Entity; +//import com.csse3200.game.entities.EntityService; +//import com.csse3200.game.entities.factories.TowerFactory; +//import com.csse3200.game.extensions.GameExtension; +//import com.csse3200.game.physics.PhysicsService; +//import com.csse3200.game.rendering.DebugRenderer; +//import com.csse3200.game.rendering.RenderService; +//import com.csse3200.game.services.*; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertFalse; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(GameExtension.class) +//class BuildInputComponentTest { +// +// private BuildInputComponent buildInputComponent; +// private Entity baseTower; +// private Entity weaponTower; +// private Entity wallTower; +// private Entity stunTower; +// private Entity fireTower; +// private Entity tntTower; +// private Entity droidTower; +// private String[] texture = { +// "images/towers/turret_deployed.png", +// "images/towers/turret01.png", +// "images/towers/wall_tower.png", +// "images/towers/fire_tower_atlas.png", +// "images/towers/stun_tower.png", +// "images/towers/DroidTower.png", +// "images/towers/TNTTower.png" +// }; +// private String[] atlas = { +// "images/towers/turret01.atlas", +// "images/towers/stun_tower.atlas", +// "images/towers/fire_tower_atlas.atlas", +// "images/towers/DroidTower.atlas", +// "images/towers/TNTTower.atlas", +// "images/towers/barrier.atlas" +// }; +// private static final String[] sounds = { +// "sounds/towers/gun_shot_trimmed.mp3", +// "sounds/towers/deploy.mp3", +// "sounds/towers/stow.mp3" +// }; +// +// @BeforeEach +// void setup() { +// GameTime gameTime = mock(GameTime.class); +// CameraComponent camera = mock(CameraComponent.class); +// when(gameTime.getDeltaTime()).thenReturn(0.02f); +// ServiceLocator.registerTimeSource(gameTime); +// ServiceLocator.registerPhysicsService(new PhysicsService()); +// RenderService render = new RenderService(); +// render.setDebug(mock(DebugRenderer.class)); +// ServiceLocator.registerRenderService(render); +// +// CurrencyService currencyService = new CurrencyService(); +// ResourceService resourceService = new ResourceService(); +// MapService mapService = new MapService(camera); +// EntityService entityService = new EntityService(); +// +// ServiceLocator.registerResourceService(resourceService); +// ServiceLocator.registerCurrencyService(currencyService); +// ServiceLocator.registerMapService(mapService); +// ServiceLocator.registerEntityService(entityService); +// +// resourceService.loadTextures(texture); +// resourceService.loadTextureAtlases(atlas); +// resourceService.loadSounds(sounds); +// resourceService.loadAll(); +// +// ServiceLocator.getResourceService() +// .getAsset("images/towers/turret01.atlas", TextureAtlas.class); +// baseTower = TowerFactory.createBaseTower(); +// weaponTower = TowerFactory.createWeaponTower(); +// wallTower = TowerFactory.createWallTower(); +// fireTower = TowerFactory.createFireTower(); +// stunTower = TowerFactory.createFireTower(); +// tntTower = TowerFactory.createTNTTower(); +// droidTower = TowerFactory.createDroidTower(); +// +// buildInputComponent = new BuildInputComponent(camera.getCamera()); +// } +// +// @Test +// void shouldUpdatePriority() { +// int newPriority = 100; +// InputComponent inputComponent = spy(InputComponent.class); +// +// inputComponent.setPriority(newPriority); +// verify(inputComponent).setPriority(newPriority); +// +// int priority = inputComponent.getPriority(); +// verify(inputComponent).getPriority(); +// +// assertEquals(newPriority, priority); +// } +// +// @Test +// void shouldRegisterOnCreate() { +// InputService inputService = spy(InputService.class); +// ServiceLocator.registerInputService(inputService); +// +// InputComponent inputComponent = spy(InputComponent.class); +// inputComponent.create(); +// verify(inputService).register(inputComponent); +// } +// +// @Test +// void shouldHandleTouchDown() { +// BuildInputComponent inputComponent = spy(BuildInputComponent.class); +// assertFalse(inputComponent.touchDown( 5, 6, 7, 8)); +// } +// +// @Test +// void shouldRejectOccupiedTile() { +// Vector2 tile = ServiceLocator.getMapService().getComponent().tileToWorldPosition(0, 0); +// tntTower.setPosition(0,0); +// assertFalse(buildInputComponent.touchDown(0,0, 7,8)); +// } +// +// @Test +// void shouldRejectInvalidTile() { +// +// } +// +// @Test +// void shouldHandleMissingMapService() { +// +// } +// +// @Test +// void shouldHandleMissingCurrencyService() { +// +// } +// +// @Test +// void shouldHandleInvalidTower() { +// +// } +// +// @Test +// void shouldHandleMissingEntityService() { +// +// } +//} From bb5a7f8a59c303b4fed26d33375ef12701671781 Mon Sep 17 00:00:00 2001 From: Ahmad Abu-Aysha <111224176+The-AhmadAA@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:18:56 +1000 Subject: [PATCH 2/2] added music to level select and turret select screens --- .../game/screens/LevelSelectScreen.java | 17 +++++++++++++++++ .../game/screens/TurretSelectionScreen.java | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java index 4db4580f7..a14208b54 100644 --- a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java @@ -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; @@ -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; @@ -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 @@ -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 @@ -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(); } /** @@ -174,5 +190,6 @@ public void resize(int width, int height) { public void dispose() { stage.dispose(); batch.dispose(); + music.dispose(); } } \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java index 357ab0fd6..eb3df9e70 100644 --- a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java @@ -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; @@ -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; @@ -52,6 +54,10 @@ public class TurretSelectionScreen extends ScreenAdapter { private static final String TEXTURE = "planets/background.png"; private Set 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) { @@ -59,6 +65,11 @@ public TurretSelectionScreen(GdxGame 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); @@ -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) { @@ -304,6 +319,7 @@ private void updateDescriptionText() { @Override public void dispose() { stage.dispose(); + music.dispose(); } }