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

Feature/storyy #585

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions source/core/assets/images/npc/Astronaut.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ Astro_Right
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/core/assets/levels/cryoheim/main_area/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"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"
],
"textureAtlasPaths": [
Expand All @@ -35,6 +36,7 @@
"images/boss_enemy.atlas",
"images/botanist.atlas",
"images/weapons/wrench.atlas",
"images/npc/Astronaut.atlas",
"images/npc/astronaut_npc.atlas",
"images/botanist.atlas"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}