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 cutscene #62

Merged
merged 2 commits into from
Jun 6, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ graph TD;

- [ ] crafting feature

- [ ] cutscenes feature
- [ ] credits

- [ ] improve AI

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/com/gdx/game/map/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ public void clearCurrentSelectedMapEntity() {
currentSelectedEntity = null;
}

public void disableCurrentMapMusic(){
currentMap.unloadMusic();
}

public void setPlayer(Entity entity) {
this.player = entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.gdx.game.entities.player.CharacterRecord;
import com.gdx.game.manager.ResourceManager;
import com.gdx.game.profile.ProfileManager;
import com.gdx.game.screen.cutscene.CreatorIntroScreen;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -99,7 +100,7 @@ public void clicked(InputEvent event, float x, float y) {

gdxGame.setGameScreen(new GameScreen(gdxGame, resourceManager));
LOGGER.info("Character {} selected", playerImage.getEntity().getEntityConfig().getEntityID());
setScreenWithTransition((BaseScreen) gdxGame.getScreen(), gdxGame.getGameScreen(), new ArrayList<>());
setScreenWithTransition((BaseScreen) gdxGame.getScreen(), new CreatorIntroScreen(gdxGame, resourceManager), new ArrayList<>());
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.gdx.game.screen.cutscene;

import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.gdx.game.GdxGame;
import com.gdx.game.animation.AnimatedImage;
import com.gdx.game.entities.Entity;
import com.gdx.game.entities.EntityFactory;
import com.gdx.game.manager.ResourceManager;
import com.gdx.game.map.MapFactory;

public class CreatorIntroScreen extends CutSceneBaseScreen {
private Action setupScene01;
private AnimatedImage creator;

public CreatorIntroScreen(GdxGame game, ResourceManager resourceManager) {
super(game, resourceManager);

creator = getAnimatedImage(EntityFactory.EntityType.THIEF);
creator.setName("Creator");

setupScene01 = new RunnableAction() {
@Override
public void run() {
hideMessage();
mapManager.loadMap(MapFactory.MapType.TOPPLE);
mapManager.disableCurrentMapMusic();
setCameraPosition(17, 10);

creator.setCurrentAnimation(Entity.AnimationType.WALK_UP);
creator.setVisible(true);
creator.setPosition(17, 0);
}
};

getStage().addActor(creator);
}

Action getCutsceneAction() {
setupScene01.reset();
getSwitchScreenAction().reset();

return Actions.sequence(
Actions.addAction(setupScene01),
Actions.delay(1),
Actions.addAction(Actions.moveTo(17, 10, 5, Interpolation.linear), creator),
Actions.delay(Float.parseFloat("2.5")),
Actions.addAction(Actions.run(() -> creator.setCurrentAnimation(Entity.AnimationType.IMMOBILE))),
Actions.run(() -> showMessage(creator, "Hello adventurer! Welcome to my game, or at least my prototype game!")),
Actions.delay(5),
Actions.run(() -> showMessage(creator, "Many thanks for your interest in my project, i hope you will like it.")),
Actions.delay(5),
Actions.run(() -> showMessage(creator, "Do not hesitate to contribute or suggest any idea that you might have. Help is always welcome!")),
Actions.delay(5),
Actions.run(() -> showMessage(creator, "Have fun :)")),
Actions.delay(3),
Actions.after(getSwitchScreenAction())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.gdx.game.screen.cutscene;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.gdx.game.GdxGame;
import com.gdx.game.animation.AnimatedImage;
import com.gdx.game.entities.Entity;
import com.gdx.game.entities.EntityFactory;
import com.gdx.game.manager.ResourceManager;
import com.gdx.game.map.Map;
import com.gdx.game.profile.ProfileManager;
import com.gdx.game.screen.BaseScreen;
import com.gdx.game.screen.GameScreen;
import com.gdx.game.screen.transition.effects.FadeOutTransitionEffect;
import com.gdx.game.screen.transition.effects.TransitionEffect;

import java.util.ArrayList;

public abstract class CutSceneBaseScreen extends GameScreen {
private Stage stage;
private Viewport viewport;
private Stage UIStage;
private Viewport UIViewport;
private Actor followingActor;
private Dialog messageBoxUI;
private Label label;
private boolean isCameraFixed = true;
private Action switchScreenAction;

public CutSceneBaseScreen(GdxGame game, ResourceManager resourceManager) {
super(game, resourceManager);

viewport = new ScreenViewport(camera);
stage = new Stage(viewport);

UIViewport = new ScreenViewport(hudCamera);
UIStage = new Stage(UIViewport);

label = new Label("", ResourceManager.skin);
label.setWrap(true);

messageBoxUI = new Dialog("", ResourceManager.skin);
messageBoxUI.setVisible(false);
messageBoxUI.getContentTable().add(label).width(stage.getWidth()/2).pad(10, 10, 10, 0);
messageBoxUI.pack();
messageBoxUI.setPosition(stage.getWidth() / 2 - messageBoxUI.getWidth() / 2, stage.getHeight() - messageBoxUI.getHeight());

followingActor = new Actor();
followingActor.setPosition(0, 0);

//Actions
switchScreenAction = new RunnableAction(){
@Override
public void run() {
ArrayList<TransitionEffect> effects = new ArrayList<>();
effects.add(new FadeOutTransitionEffect(1f));
setScreenWithTransition((BaseScreen) gdxGame.getScreen(), gdxGame.getGameScreen(), effects);
}
};

UIStage.addActor(messageBoxUI);
}

abstract Action getCutsceneAction();

AnimatedImage getAnimatedImage(EntityFactory.EntityType entityType){
Entity entity = EntityFactory.getInstance().getEntity(entityType);
return setEntityAnimation(entity);
}

private AnimatedImage setEntityAnimation(Entity entity){
final AnimatedImage animEntity = new AnimatedImage();
animEntity.setEntity(entity);
animEntity.setWidth(17);
animEntity.setHeight(17);
animEntity.setSize(animEntity.getWidth() * Map.UNIT_SCALE, animEntity.getHeight() * Map.UNIT_SCALE);
return animEntity;
}

void setCameraPosition(float x, float y){
camera.position.set(x, y, 0f);
isCameraFixed = true;
}

void showMessage(AnimatedImage animatedImage, String message){
label.setText(message);
messageBoxUI.getTitleLabel().setText(animatedImage.getName());
messageBoxUI.pack();
messageBoxUI.setVisible(true);
}

void hideMessage(){
messageBoxUI.setVisible(false);
}

@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

mapRenderer.setView(camera);

mapRenderer.getBatch().enableBlending();
mapRenderer.getBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

if (mapManager.hasMapChanged()) {
mapRenderer.setMap(mapManager.getCurrentTiledMap());
mapManager.setMapChanged(false);
}

mapRenderer.render();

if (!isCameraFixed) {
camera.position.set(followingActor.getX(), followingActor.getY(), 0f);
}
camera.update();

UIStage.act(delta);
UIStage.draw();

stage.act(delta);
stage.draw();
}

@Override
public void show() {
stage.addAction(getCutsceneAction());
ProfileManager.getInstance().removeAllObservers();
if (mapRenderer == null) {
mapRenderer = new OrthogonalTiledMapRenderer(mapManager.getCurrentTiledMap(), Map.UNIT_SCALE);
}
}

@Override
public void hide() {
ProfileManager.getInstance().removeAllObservers();
Gdx.input.setInputProcessor(null);
}

@Override
public Stage getStage() {
return stage;
}

public Action getSwitchScreenAction() {
return switchScreenAction;
}
}
13 changes: 13 additions & 0 deletions core/src/main/resources/scripts/player_cleric.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
},
]
animationConfig: [
{
frameDuration: 0.15
animationType: IMMOBILE
texturePaths: [
sprites/characters/Cleric.png
]
gridPoints: [
{
x: 0
y: 2
}
]
}
{
frameDuration: 0.15
animationType: IDLE
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/resources/scripts/player_grappler.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
},
]
animationConfig: [
{
frameDuration: 0.15
animationType: IMMOBILE
texturePaths: [
sprites/characters/Grappler.png
]
gridPoints: [
{
x: 0
y: 2
}
]
}
{
frameDuration: 0.15
animationType: IDLE
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/resources/scripts/player_mage.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
},
]
animationConfig: [
{
frameDuration: 0.15
animationType: IMMOBILE
texturePaths: [
sprites/characters/Mage.png
]
gridPoints: [
{
x: 0
y: 2
}
]
}
{
frameDuration: 0.15
animationType: IDLE
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/resources/scripts/player_thief.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
},
]
animationConfig: [
{
frameDuration: 0.15
animationType: IMMOBILE
texturePaths: [
sprites/characters/Thief.png
]
gridPoints: [
{
x: 0
y: 2
}
]
}
{
frameDuration: 0.15
animationType: IDLE
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/resources/scripts/player_warrior.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
},
]
animationConfig: [
{
frameDuration: 0.15
animationType: IMMOBILE
texturePaths: [
sprites/characters/Warrior.png
]
gridPoints: [
{
x: 0
y: 2
}
]
}
{
frameDuration: 0.15
animationType: IDLE
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/com/gdx/game/battle/BattleHUDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void add_entity_battle_step(BattleObserver.BattleEvent event, int actorNumber, E
private static Stream<Arguments> addEntitySteps() {
return Stream.of(
Arguments.of(BattleObserver.BattleEvent.PLAYER_ADDED, 0, Entity.AnimationType.WALK_RIGHT),
Arguments.of(BattleObserver.BattleEvent.OPPONENT_ADDED, 1, Entity.AnimationType.IDLE)
Arguments.of(BattleObserver.BattleEvent.OPPONENT_ADDED, 1, Entity.AnimationType.IMMOBILE)
);
}

Expand Down
Loading