Skip to content

Commit

Permalink
Merge pull request #404 from UQcsse3200/team3/Cutscene-Component
Browse files Browse the repository at this point in the history
Cutscene allows for scaling of images and can remove text boxes
  • Loading branch information
Caleb-J-Murphy authored Oct 2, 2024
2 parents 8ca643e + 0d03d70 commit 024a175
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ protected void createEntitiesForScene(Scene scene) {
if (scene.getImagePaths() != null) {
String[] imagePaths = scene.getImagePaths();
Vector2[] imagePositions = scene.getImagePositions();
float[] imageScales = scene.getImageScales();
for (int i = 0; i < imagePaths.length; i++) {
String imagePath = imagePaths[i];
Vector2 imagePosition = imagePositions[i];
float imageScale = imageScales[i];
// Assume that the animation is called idle for now.
Entity image = CutsceneFactory.createImage(imagePath);
Entity image = CutsceneFactory.createImage(imagePath, imageScale);
entities.add(image);
image.setPosition(imagePosition);
ServiceLocator.getEntityService().register(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Entity createAnimation(String animationImgPath, String animName) {
* @param imgPath The file path of the animation image to use.
* @return A new animation entity.
*/
public static Entity createImage(String imgPath) {
public static Entity createImage(String imgPath, float imageScale) {
Entity animation = new Entity();

// Create and add a texture component to the entity for rendering the animation
Expand All @@ -86,6 +86,7 @@ public static Entity createImage(String imgPath) {

// Scale the entity based on the texture size
textureComponent.scaleEntity();
animation.setScale(animation.getScale().x * imageScale, animation.getScale().y * imageScale);

return animation;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.cutscenes;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.components.cutscenes.scenes.Scene;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -25,16 +26,18 @@ public IntroCutscene() {
@Override
protected void setupScenes() {
// Add text to be displayed during the cutscene
cutsceneText.add("First bit of text");
cutsceneText.add("Second bit of text");
cutsceneText.add("Third bit of text");
cutsceneText.add("Hello This is an Example Text");
cutsceneText.add("Wow, we can move forward, I wonder what else this can do :)");
cutsceneText.add("This is a quick check to see if truncation is working correctly or whether it does not " +
"show what it is meant to show or not.");

// Add scenes with background images, animations, text, and duration

Scene scene1 = new Scene("images/Cutscenes/Beastly_Bistro_Background.png");
scene1.setImages(
new String[]{"images/meals/acai_bowl.png"},
new Vector2[] {new Vector2(4, 2)}
new Vector2[] {new Vector2(4, 2)},
new float[] {1.0f}
);

scene1.setSceneText(cutsceneText);
Expand All @@ -45,9 +48,14 @@ protected void setupScenes() {
Scene scene2 = new Scene("images/Cutscenes/Graveyard_Scene.png");
scene2.setImages(
new String[]{"images/meals/acai_bowl.png"},
new Vector2[] {new Vector2(2, 2)}
new Vector2[] {new Vector2(2, 2)},
new float[] {4.0f}
);
scene2.setSceneText(cutsceneText);
Array<String> scene2Text = new Array<>();
scene2Text.add("This is the second scene");
scene2Text.add("We made it");
scene2Text.add("LETS GO!!!!");
scene2.setSceneText(scene2Text);
scene2.setDuration(3.0f);

scenes.add(scene2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Scene {

private String[] imagePaths;
private Vector2[] imagePositions;
private float[] imageScales;

private Array<String> sceneText; // Text dialogue for the scene
private float duration; // Duration the scene will be displayed
Expand Down Expand Up @@ -87,12 +88,22 @@ public Vector2[] getImagePositions() {
return imagePositions;
}

public void setImages(String[] imagePaths, Vector2[] imagePositions) {
/**
* Gets the image scales for the scene.
*
* @return Array of Vector2 positions for the images.
*/
public float[] getImageScales() {
return imageScales;
}

public void setImages(String[] imagePaths, Vector2[] imagePositions, float[] imageScales) {
if (imagePaths.length != imagePositions.length) {
logger.error("Image paths size does not match the position size");
}
this.imagePaths = imagePaths;
this.imagePositions = imagePositions;
this.imageScales = imageScales;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SceneTest {
private Vector2[] animationPositions;
private String[] imagePaths;
private Vector2[] imagePositions;
private float[] imageScales;

private Array<String> sceneText;
private float duration;
Expand All @@ -27,6 +28,7 @@ void setUp() {
animationPositions = new Vector2[]{new Vector2(1, 1), new Vector2(1, 2)};
imagePaths = new String[]{"img1.png", "img2.png"};
imagePositions = new Vector2[]{new Vector2(1, 1), new Vector2(1, 2)};
imageScales = new float[] {1.0f};
sceneText = new Array<>();
sceneText.add("Line 1");
sceneText.add("Line 2");
Expand Down Expand Up @@ -56,10 +58,11 @@ void testGetSetAnimationImagePaths() {

@Test
void testGetSetImagePaths() {
scene.setImages(imagePaths, imagePositions);
scene.setImages(imagePaths, imagePositions, imageScales);
// Test that the animation image paths are correctly returned
assertEquals(imagePaths, scene.getImagePaths(), "Image paths should match");
assertEquals(imagePositions, scene.getImagePositions(), "Image positions should match");
assertEquals(imageScales, scene.getImageScales(), "Image scales should match");
}

@Test
Expand Down

0 comments on commit 024a175

Please sign in to comment.