diff --git a/source/core/assets/images/npc/Astronaut.atlas b/source/core/assets/images/npc/Astronaut.atlas index 808357651..58146d283 100644 --- a/source/core/assets/images/npc/Astronaut.atlas +++ b/source/core/assets/images/npc/Astronaut.atlas @@ -3,115 +3,122 @@ size: 512, 32 format: RGBA8888 filter: Nearest, Nearest repeat: none -Astro_Up +row-1-column-1 rotate: false xy: 0, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Up +row-1-column-2 rotate: false xy: 32, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Up +row-1-column-3 rotate: false xy: 64, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Up +row-1-column-4 rotate: false xy: 96, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Left +row-2-column-1 rotate: false xy: 128, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Left +row-2-column-2 rotate: false xy: 160, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Left +row-2-column-3 rotate: false xy: 192, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Left +row-2-column-4 rotate: false xy: 224, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Down +row-3-column-1 rotate: false xy: 256, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Down +row-3-column-2 rotate: false xy: 288, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Down +row-3-column-3 rotate: false xy: 320, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Down +row-3-column-4 rotate: false xy: 352, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Right +row-4-column-1 rotate: false xy: 384, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Right +row-4-column-2 rotate: false xy: 416, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Right +row-4-column-3 rotate: false xy: 448, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 -Astro_Right +row-4-column-4 rotate: false xy: 480, 0 size: 32, 32 orig: 32, 32 offset: 0, 0 index: -1 +Astro_Stand + rotate: false + xy: 256, 0 + size: 32, 32 + orig: 32, 32 + offset: 0, 0 + index: -1 diff --git a/source/core/assets/kenney-rpg-expansion/kenneyrpg.json b/source/core/assets/kenney-rpg-expansion/kenneyrpg.json index a72f36ad6..427f3991d 100644 --- a/source/core/assets/kenney-rpg-expansion/kenneyrpg.json +++ b/source/core/assets/kenney-rpg-expansion/kenneyrpg.json @@ -253,7 +253,7 @@ "titleFont": "thick_white" }, "dialogue_7": { - "background": "dialogue_6", + "background": "dialogue_7", "titleFont": "thick_white" } } diff --git a/source/core/assets/levels/cryoheim/main_area/entities/astronaut.json b/source/core/assets/levels/cryoheim/main_area/entities/astronaut.json index 42973ee08..eac0856d5 100644 --- a/source/core/assets/levels/cryoheim/main_area/entities/astronaut.json +++ b/source/core/assets/levels/cryoheim/main_area/entities/astronaut.json @@ -3,7 +3,7 @@ "entities": [ { "class": "com.csse3200.game.entities.configs.AstronautConfig", - "spritePath": "images/npc/astronaut_npc.atlas", + "spritePath": "images/npc/Astronaut.atlas", "position" : { "x": 15, "y": 38 diff --git a/source/core/assets/levels/cryoheim/main_area/main.json b/source/core/assets/levels/cryoheim/main_area/main.json index 9a3fda795..6f1e0b482 100644 --- a/source/core/assets/levels/cryoheim/main_area/main.json +++ b/source/core/assets/levels/cryoheim/main_area/main.json @@ -26,8 +26,11 @@ "map/heatzone.png", "particle-effects/explosion/particle.png", "images/npc/astronaut_npc.png", + "images/npc/Astronaut.png", + "images/space_navigation_planet_2.png","images/upgradetree/sword.png", "images/space_navigation_planet_2.png","images/upgradetree/sword.png", "images/companion/Laboratorycryoheim.png" + ], "textureAtlasPaths": [ "images/troll_enemy.atlas", @@ -36,6 +39,7 @@ "images/boss_enemy.atlas", "images/botanist.atlas", "images/weapons/wrench.atlas", + "images/npc/Astronaut.atlas", "images/npc/astronaut_npc.atlas", "images/botanist.atlas" ], diff --git a/source/core/assets/levels/flora_haven/main_area/entities/astro.json b/source/core/assets/levels/flora_haven/main_area/entities/astro.json index 485c5b7da..6e83155fa 100644 --- a/source/core/assets/levels/flora_haven/main_area/entities/astro.json +++ b/source/core/assets/levels/flora_haven/main_area/entities/astro.json @@ -3,7 +3,7 @@ "entities": [ { "class": "com.csse3200.game.entities.configs.AstronautConfig", - "spritePath": "images/npc/astronaut_npc.atlas", + "spritePath": "images/npc/Astronaut.atlas", "position" : { "x": 13, "y": 40 diff --git a/source/core/src/main/com/csse3200/game/components/npc/AstronautAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/AstronautAnimationController.java index 9787481f9..dda06448a 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/AstronautAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/AstronautAnimationController.java @@ -28,7 +28,7 @@ public void create() { animator = entity.getComponent(AnimationRenderComponent.class); // Start with the default animation. - animator.startAnimation("row-1-column-1"); + animator.startAnimation("Astro_Stand"); } @Override @@ -48,25 +48,11 @@ public void update() { // Switch between animations. switch (animator.getCurrentAnimation()) { - case "row-1-column-1" -> animator.startAnimation("row-1-column-2"); - case "row-1-column-2" -> animator.startAnimation("row-1-column-3"); - case "row-1-column-3" -> animator.startAnimation("row-1-column-4"); - case "row-1-column-4" -> animator.startAnimation("row-2-column-1"); - case "row-2-column-1" -> animator.startAnimation("row-2-column-2"); - case "row-2-column-2" -> animator.startAnimation("row-2-column-3"); - case "row-2-column-3" -> animator.startAnimation("row-2-column-4"); - case "row-2-column-4" -> animator.startAnimation("row-3-column-1"); - case "row-3-column-1" -> animator.startAnimation("row-3-column-2"); - case "row-3-column-2" -> animator.startAnimation("row-3-column-3"); - case "row-3-column-3" -> animator.startAnimation("row-3-column-4"); - case "row-3-column-4" -> animator.startAnimation("row-4-column-1"); - case "row-4-column-1" -> animator.startAnimation("row-4-column-2"); - case "row-4-column-2" -> animator.startAnimation("row-4-column-3"); - case "row-4-column-3" -> animator.startAnimation("row-4-column-4"); - case "row-4-column-4" -> animator.startAnimation("row-1-column-1"); + case "Astro_Left" -> animator.startAnimation("Astro_Left"); + case "Astro_Right" -> animator.startAnimation("Astro_Right"); default -> // Default to the bottom animation if not in any specific state. - animator.startAnimation("row-1-column-1"); + animator.startAnimation("Astro_Stand"); } } } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index d70deaee9..29d1f0e2f 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -95,7 +95,6 @@ public static Entity createBotanist(BotanistConfig config) { "{SLOW}I will give you all the Knowledge I have, \nto find a suitable planet for your Journey "}; String[] titletext= {"",""}; String[] window = {"dialogue_7", "dialogue_7"}; - TitleBox titleBox = new TitleBox(game, titletext, storytext, skin, window); titleBox.showDialog(ServiceLocator.getRenderService().getStage()); },10f)); @@ -175,10 +174,12 @@ public static Entity createTutnpc(TutnpcConfig tutnpcConfig) { tutnpc.getComponent(ColliderComponent.class).setDensity(1.5f); tutnpc.scaleHeight(0.7f); - String[] storytext = {"I am your Tutorial Guide", "I am here to teach you how to play!"}; - String[] titletext = {"", ""}; tutnpc.addComponent(new InteractableComponent(entity -> { - tutnpc.getComponent(DialogComponent.class).showdialogue(storytext, titletext); + String[] storytext = {"I am your Tutorial Guide", "I am here to teach you how to play!"}; + String[] titletext = {"", ""}; + String[] window = {"dialogue_5", "dialogue_5"}; + TitleBox titleBox = new TitleBox(game, titletext, storytext, skin, window); + titleBox.showDialog(ServiceLocator.getRenderService().getStage()); }, 3f)); animator.startAnimation("Tut_StandDown"); return tutnpc; @@ -221,10 +222,12 @@ public static Entity createHellman(HellmanConfig hellmanConfig) { Hellman.getComponent(ColliderComponent.class).setDensity(1.5f); Hellman.scaleHeight(2.0f); - String[] storytext = {"If you defeat this boss,\n I will help you find a suitable planet", "You will find the boss on the \nother side of the portal."}; - String[] titletext = {"", ""}; Hellman.addComponent(new InteractableComponent(entity -> { - Hellman.getComponent(DialogComponent.class).showdialogue(storytext, titletext); + String[] storytext = {"If you defeat this boss,\n I will help you find a suitable planet", "You will find the boss on the \nother side of the portal."}; + String[] titletext = {"", ""}; + String[] window = {"dialogue_6", "dialogue_6"}; + TitleBox titleBox = new TitleBox(game, titletext, storytext, skin, window); + titleBox.showDialog(ServiceLocator.getRenderService().getStage()); }, 3f)); return Hellman; } @@ -258,23 +261,10 @@ public static Entity createAstronaut(AstronautConfig astronautConfig) { AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService().getAsset(astronautConfig.spritePath, TextureAtlas.class)); - animator.addAnimation("row-1-column-1", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-1-column-2", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-1-column-3", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-1-column-4", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-2-column-1", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-2-column-2", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-2-column-3", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-2-column-4", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-3-column-1", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-3-column-2", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-3-column-3", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-3-column-4", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-4-column-1", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-4-column-2", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-4-column-3", 0.01f, Animation.PlayMode.LOOP); - animator.addAnimation("row-4-column-4", 0.01f, Animation.PlayMode.LOOP); - + animator.addAnimation("Astro_Stand", 1f, Animation.PlayMode.NORMAL); + animator.addAnimation("Astro_Down", 1f, Animation.PlayMode.LOOP); + animator.addAnimation("Astro_Left", 1f, Animation.PlayMode.LOOP); + animator.addAnimation("Astro_Right", 1f, Animation.PlayMode.LOOP); Entity astronaut = new Entity() @@ -293,12 +283,10 @@ public static Entity createAstronaut(AstronautConfig astronautConfig) { astronaut.addComponent(new InteractableComponent(entity -> { String[] storytext= {"Hello, I've been stuck here for weeks","Can I please come with you?"}; String[] titletext= {"",""}; - astronaut.getComponent(DialogComponent.class).showdialogue(storytext,titletext); - // Since Dialogue Box does not show up on screen, cannot 'exit' dialogue box therefore - // the 'resumeGame' function is never called. This code is to ensure gameplay can continue - for (Entity mainGame : ServiceLocator.getEntityService().getEntitiesByComponent(MainGameActions.class)) { - mainGame.getEvents().trigger("resumeGame"); - } + String[] window = {"dialogue_4", "dialogue_4"}; + TitleBox titleBox = new TitleBox(game, titletext, storytext, skin, window); + titleBox.showDialog(ServiceLocator.getRenderService().getStage()); + },1f)); astronaut.scaleHeight(1f); @@ -329,7 +317,6 @@ public static Entity createJail(JailConfig jailConfig) { ,"{SLOW}Player: We can handle it. \n Let me Lead the way!"}; String[] titletext= {"","",""}; String[] window = {"dialogue_1", "dialogue_1","dialogue_3"}; - TitleBox titleBox = new TitleBox(game, titletext, storytext, skin, window); titleBox.showDialog(ServiceLocator.getRenderService().getStage()); diff --git a/source/core/src/test/com/csse3200/game/components/npc/AstronautAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/npc/AstronautAnimationControllerTest.java index fb5930180..1d9779121 100644 --- a/source/core/src/test/com/csse3200/game/components/npc/AstronautAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/npc/AstronautAnimationControllerTest.java @@ -32,7 +32,8 @@ class AstronautAnimationControllerTest { void setUp() { MockitoAnnotations.openMocks(this); - when(assetManager.get("images/npc/astronaut_npc.atlas")).thenReturn(atlas); +// when(assetManager.get("images/npc/astronaut_npc.atlas")).thenReturn(atlas); + when(assetManager.get("images/npc/Astronaut.atlas")).thenReturn(atlas); controller = new AstronautAnimationController(); @@ -49,7 +50,7 @@ void setUp() { void testCreate() { controller.create(); - verify(animator).startAnimation("row-1-column-1"); + verify(animator).startAnimation("Astro_Stand"); } diff --git a/source/core/src/test/com/csse3200/game/entities/factories/NPCFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/NPCFactoryTest.java new file mode 100644 index 000000000..e69de29bb diff --git a/source/core/src/test/com/csse3200/game/screens/TutorialScreenTest.java b/source/core/src/test/com/csse3200/game/screens/TutorialScreenTest.java new file mode 100644 index 000000000..6494952ce --- /dev/null +++ b/source/core/src/test/com/csse3200/game/screens/TutorialScreenTest.java @@ -0,0 +1,71 @@ +package com.csse3200.game.screens; + +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.backends.headless.HeadlessApplication; +import com.badlogic.gdx.graphics.Texture; +import com.csse3200.game.GdxGame; +import com.csse3200.game.services.ResourceService; +import com.csse3200.game.services.ServiceLocator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Unit tests for the {@link TutorialScreen} class. + */ +public class TutorialScreenTest { + + private Set loadedAssets; + private GdxGame game; + + @BeforeEach + void setUp() { + // Mock the LibGDX application + Gdx.app = mock(Application.class); + when(Gdx.app.getType()).thenReturn(Application.ApplicationType.HeadlessDesktop); + + // Initialize the LibGDX headless application + game = new GdxGame(); + new HeadlessApplication(game); + + // Initialize the set of loaded assets + loadedAssets = new HashSet<>(); + } + + /** + * Test asset loading in {@link TutorialScreen}. + */ + @Test + void testTutorialScreenAssetLoading() { + Gdx.app.postRunnable(() -> { + TutorialScreen tutorialScreen = createTutorialScreen(); + + // Simulate rendering and resizing + tutorialScreen.render(0.1f); + tutorialScreen.resize(800, 600); + + // Verify that a specific asset has been loaded + verifyAssetLoaded("images/structure-icons/wall.png"); + + // Dispose of the screen + tutorialScreen.dispose(); + }); + } + + private TutorialScreen createTutorialScreen() { + return new TutorialScreen(game, "TutorialScreenName"); + } + + private void verifyAssetLoaded(String assetPath) { + ResourceService resourceService = ServiceLocator.getResourceService(); + boolean isLoaded = resourceService.containsAsset(assetPath, Texture.class); + assertTrue(isLoaded, "Asset not loaded: " + assetPath); + } +}