Skip to content
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
25 changes: 24 additions & 1 deletion src/main/java/dk/sdu/mmmi/modulemon/Interaction/BattleEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dk.sdu.mmmi.modulemon.Interaction;

import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
Expand All @@ -10,10 +11,13 @@
import dk.sdu.mmmi.modulemon.CommonMap.Data.EntityType;
import dk.sdu.mmmi.modulemon.CommonMap.IMapEvent;
import dk.sdu.mmmi.modulemon.CommonMap.IMapView;
import dk.sdu.mmmi.modulemon.common.SettingsRegistry;
import dk.sdu.mmmi.modulemon.common.AssetLoader;
import dk.sdu.mmmi.modulemon.common.data.GameData;
import dk.sdu.mmmi.modulemon.common.data.GameKeys;
import dk.sdu.mmmi.modulemon.common.drawing.Rectangle;
import dk.sdu.mmmi.modulemon.common.drawing.TextUtils;
import dk.sdu.mmmi.modulemon.common.services.IGameSettings;

import java.util.Queue;

Expand All @@ -24,10 +28,13 @@ public class BattleEvent implements IMapEvent {
private Entity aggresor;
private Entity victim;
private IMapView mapView;
private Sound alertSound;
private boolean alertSoundPlayed = false;
private IGameSettings settings;

private BattleState currentState;

public BattleEvent(Queue<String> lines, Entity aggressor, Entity victim, IMapView map) {
public BattleEvent(Queue<String> lines, Entity aggressor, Entity victim, IMapView map, IGameSettings settings) {
if (lines == null || lines.isEmpty()) {
throw new IllegalArgumentException("Argument 'lines' is null or has no elements");
}
Expand All @@ -38,6 +45,8 @@ public BattleEvent(Queue<String> lines, Entity aggressor, Entity victim, IMapVie
this.victim = victim;
this.lines = lines;
this.mapView = map;
alertSound = AssetLoader.getInstance().getSoundAsset("/sounds/alert.ogg", this.getClass());
this.settings = settings;
textBox = new Rectangle(20, 20, -1, -1);
exlamationBox = new Rectangle(-1, -1, -1, -1);
currentState = BattleState.BEFORE_BATTLE;
Expand Down Expand Up @@ -106,6 +115,11 @@ public void draw(GameData gameData, SpriteBatch spriteBatch, ShapeRenderer shape
visualVictimPosition.x + 16,
visualVictimPosition.y + 85);

if(!alertSoundPlayed){
playAlertSound();
}


TextUtils.getInstance().drawNormalRoboto(spriteBatch,
lines.peek(),
Color.BLACK,
Expand All @@ -122,6 +136,15 @@ public void draw(GameData gameData, SpriteBatch spriteBatch, ShapeRenderer shape
spriteBatch.end();
}

private void playAlertSound(){
var volume = settings != null
? (float)settings.getSetting(SettingsRegistry.getInstance().getSoundVolumeSetting()) / 100f
: 0.6f;

alertSound.play(volume);
alertSoundPlayed = true;
}

@Override
public void handleInput(GameData gameData) {
if (gameData.getKeys().isPressed(GameKeys.ACTION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dk.sdu.mmmi.modulemon.CommonMap.Data.EntityParts.InteractPart;
import dk.sdu.mmmi.modulemon.CommonMap.Services.IPostEntityProcessingService;
import dk.sdu.mmmi.modulemon.common.data.GameKeys;
import dk.sdu.mmmi.modulemon.common.services.IGameSettings;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -24,6 +25,8 @@ public class InteractProcessing implements IPostEntityProcessingService {

private InteractPair previousInteractPair = new InteractPair();

private IGameSettings settings;

@Override
public void process(GameData gameData, World world) {
boolean wasAbleToInteract = false;
Expand Down Expand Up @@ -95,9 +98,9 @@ public void process(GameData gameData, World world) {

BattleEvent battle;
if(entity.getType() == EntityType.PLAYER){
battle = new BattleEvent(lines, entity, interactPart.getInteractWith(), mapView);
battle = new BattleEvent(lines, entity, interactPart.getInteractWith(), mapView, settings);
}else{
battle = new BattleEvent(lines, interactPart.getInteractWith(), entity, mapView);
battle = new BattleEvent(lines, interactPart.getInteractWith(), entity, mapView, settings);
}
mapView.addMapEvent(battle);
}
Expand Down
Binary file added src/main/resources/sounds/alert.ogg
Binary file not shown.