Skip to content

Commit

Permalink
some sound effects added!
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Sharifi committed Jul 8, 2019
1 parent e5e37ec commit 60bfa90
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/json/accounts/a.json
Original file line number Diff line number Diff line change
Expand Up @@ -673253,6 +673253,6 @@
],
"wins": 2,
"losses": 5,
"authToken": "0"
"authToken": null
}
}
38 changes: 13 additions & 25 deletions src/models/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import models.card.*;
import network.Client;
import network.message.Request;
import view.BattleView;
import view.MainMenuView;
import view.Message;
import view.View;
import view.*;

import java.io.Serializable;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -268,6 +265,7 @@ public int attack(String oppID) {
attacker.setCannotAttack();
attacker.setCannotMove();
System.out.println("attacked.");
VoicePlay.attack();

if (attacker instanceof Minion) {
Minion minion = (Minion) attacker;
Expand Down Expand Up @@ -404,6 +402,7 @@ public void useSpell(int x, int y) {
battleView.drawMana();
battleView.drawHand();
battleView.drawSpellEffect(spell, x, y);
VoicePlay.spell();
}

public void useCollectable(int x, int y) {
Expand Down Expand Up @@ -500,6 +499,7 @@ public void insertCard(String cardName, int x, int y) {
battleView.drawHand();
battleView.drawAttackers();
battleView.drawMana();
VoicePlay.insert();
}

private void goOnCell(Attacker attacker, Cell cell) {
Expand Down Expand Up @@ -564,32 +564,19 @@ private void swapTurn() {
private void aiPlay() {
System.out.println("AI playing...");
try {
selectedCard = info[1].getHero();
moveCard(2, info[1].getHero().getCurrentCell().getY() - 1);

battleView.getSelect().setX(2);
battleView.getSelect().setY(info[1].getHero().getCurrentCell().getY() + 1);
TranslateTransition t = battleView.moveAnimation(2, info[1].getHero().getCurrentCell().getY());
if (t != null)
t.setOnFinished(event -> battleView.drawAttackers());
battleView.updateAttackers();

attack(info[0].getHero().getCardIDInGame());
selectedCard = info[1].getHero();
battleView.setSelect(new view.Cell(selectedCard.getCurrentCell().getX(), selectedCard.getCurrentCell().getY()));
battleView.attackAnimation(info[0].getHero().getCurrentCell().getX(), info[0].getHero().getCurrentCell().getY());
Hero hero = info[1].getHero();
if (hero != null) {
selectAttacker(hero.getCardIDInGame(), hero.getCurrentCell().getX(), hero.getCurrentCell().getY());
moveCard(2, info[1].getHero().getCurrentCell().getY() - 1);
}

for (Attacker attacker : info[1].getGroundedAttackers()) {
if (attacker == null)
continue;
if (attacker.canMove()) {
selectedCard = attacker;
selectAttacker(attacker.getCardIDInGame(), attacker.getCurrentCell().getX(), attacker.getCurrentCell().getY());
int random = new Random().nextInt(2) * 2 - 1;
moveCard(attacker.getCurrentCell().getX() + random, attacker.getCurrentCell().getY());
battleView.getSelect().setX(attacker.getCurrentCell().getX() - random);
battleView.getSelect().setY(attacker.getCurrentCell().getY());
TranslateTransition t1 = battleView.moveAnimation(attacker.getCurrentCell().getX(), attacker.getCurrentCell().getY());
if (t1 != null)
t1.setOnFinished(event -> battleView.drawAttackers());
battleView.updateAttackers();
}
}

Expand Down Expand Up @@ -841,6 +828,7 @@ public void endTurn() {
aiPlay();
System.out.println("turn ended.");
battleView.drawMana();
VoicePlay.endturn();
}

private void prepareNextRound() {
Expand Down
36 changes: 29 additions & 7 deletions src/view/CreateMatchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private Group makePanel(String imagePath, String name) {
label.setStyle("-fx-text-fill: rgba(255, 255, 255, 0.8)");
label.setFont(Font.font(20));
label.relocate(transparent.getWidth() / 2 - fontLoader.computeStringWidth(label.getText(), label.getFont()) / 2, transparent.getLayoutY() + 15);
View.giveGlowEffect(label);
group.getChildren().addAll(image, transparent, trimPlate, label);
} catch (IOException e) {
View.printThrowable(e);
Expand All @@ -248,17 +247,20 @@ private void setOnActions() {
single.setOnMouseClicked(event -> {
MainMenu.getInstance().setSingle();
boxes.push(gameType);
VoicePlay.select();
});
multiplayer.setOnMouseClicked(event -> {
MainMenu.getInstance().setMultiplayer();
boxes.push(goalMode);
VoicePlay.select();
});
Group[] groups = {single, multiplayer, story, custom, story1, story2, story3, killHero,
holdFlag, gatherFlag};
for (Group g : groups) {
g.setOnMouseEntered(event -> {
g.setScaleX(1.07);
g.setScaleY(1.07);
VoicePlay.hover();
});
g.setOnMouseExited(event -> {
g.setScaleX(1);
Expand All @@ -268,20 +270,38 @@ private void setOnActions() {
killHero.setOnMouseClicked(event -> {
MainMenu.getInstance().setKillHero();
goalModeAction();
VoicePlay.select();
});
holdFlag.setOnMouseClicked(event -> {
MainMenu.getInstance().setHoldFlag(flagCount.getText());
goalModeAction();
VoicePlay.select();
});
gatherFlag.setOnMouseClicked(event -> {
MainMenu.getInstance().setGatherFlag(flagCount.getText());
goalModeAction();
VoicePlay.select();
});
story.setOnMouseClicked(event -> {
boxes.push(storyMode);
VoicePlay.select();
});
story1.setOnMouseClicked(event -> {
MainMenu.getInstance().startStoryMatch(1);
VoicePlay.select();
});
story2.setOnMouseClicked(event -> {
MainMenu.getInstance().startStoryMatch(2);
VoicePlay.select();
});
story3.setOnMouseClicked(event -> {
MainMenu.getInstance().startStoryMatch(3);
VoicePlay.select();
});
custom.setOnMouseClicked(event -> {
boxes.push(customMode);
VoicePlay.select();
});
story.setOnMouseClicked(event -> boxes.push(storyMode));
story1.setOnMouseClicked(event -> MainMenu.getInstance().startStoryMatch(1));
story2.setOnMouseClicked(event -> MainMenu.getInstance().startStoryMatch(2));
story3.setOnMouseClicked(event -> MainMenu.getInstance().startStoryMatch(3));
custom.setOnMouseClicked(event -> boxes.push(customMode));
}

private void goalModeAction() {
Expand All @@ -296,8 +316,10 @@ private void back() {
if (!boxes.isEmpty())
boxes.pop();
View.back();
} else
} else {
root.getChildren().remove(boxes.pop());
VoicePlay.back();
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/view/MainMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void draw() {
if (node1 instanceof Button) {
Button button = (Button) node1;
button.setFont(Font.font(17));
View.giveGlowEffect(button);
View.buttonEffect(button);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/view/View.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package view;

import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.ImageCursor;
import javafx.scene.Node;
Expand Down Expand Up @@ -60,11 +61,13 @@ public static void setScene(Scene scene) {
primaryStage.setScene(scene);
scenes.push(scene);
setCursor(scene);
VoicePlay.setScene();
}

public static void back() {
scenes.pop();
primaryStage.setScene(scenes.peek());
VoicePlay.back();
}

static void setCursor(Scene scene) {
Expand Down Expand Up @@ -180,4 +183,19 @@ static void giveGlowEffect(Node node) {
node.setOnMouseEntered(event -> glow.setLevel(1));
node.setOnMouseExited(event -> glow.setLevel(0));
}

static void buttonEffect(Button button) {
Glow glow = new Glow();
button.setEffect(glow);
button.setOnMouseClicked(event -> {
Platform.runLater(VoicePlay::select);
});
button.setOnMouseEntered(event -> {
glow.setLevel(1);
VoicePlay.hover();
});
button.setOnMouseExited(event -> {
glow.setLevel(0);
});
}
}
53 changes: 47 additions & 6 deletions src/view/VoicePlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

import java.io.File;

class VoicePlay {
public class VoicePlay {
private static final double backgroundVolume = 0.3;
private static File file = new File("src\\assets\\mainMenu.m4a");
private static File file1 = new File("src\\assets\\shop.m4a");
private static File file2 = new File("src\\assets\\matchHistory.m4a");
private static File file = new File("src/assets/mainMenu.m4a");
private static File file1 = new File("src/assets/shop.m4a");
private static File file2 = new File("src/assets/matchHistory.m4a");

private static MediaPlayer mainMenu = new MediaPlayer(new Media(file.toURI().toString()));
private static MediaPlayer shop = new MediaPlayer(new Media(file1.toURI().toString()));
private static MediaPlayer matchHistory = new MediaPlayer(new Media(file2.toURI().toString()));

private static String thisMenu = "main menu";

static {
Expand All @@ -28,17 +30,56 @@ class VoicePlay {
}

static void buttonPlay() {
File file = new File("src\\assets\\button.m4a");
File file = new File("src/assets/button.m4a");
MediaPlayer click = new MediaPlayer(new Media(file.toURI().toString()));
click.play();
}

static void notification() {
File file = new File("src\\assets\\notification.m4a");
File file = new File("src/assets/notification.m4a");
MediaPlayer click = new MediaPlayer(new Media(file.toURI().toString()));
click.play();
}

static void hover() {
playSoundEffect("hover");
}

static void select() {
playSoundEffect("select");
}

static void setScene() {
playSoundEffect("scene_change");
}

static void back() {
playSoundEffect("back");
}

public static void attack() {
playSoundEffect("attack");
}

public static void endturn() {
playSoundEffect("endturn");
}

public static void insert() {
playSoundEffect("insert");
}

public static void spell() {
playSoundEffect("spell");
}

private static void playSoundEffect(String name) {
File file = new File("src/assets/sounds/" + name + ".m4a");
MediaPlayer mediaPlayer = new MediaPlayer(new Media(file.toURI().toString()));
mediaPlayer.setVolume(1);
mediaPlayer.play();
}

static void setThisMenu(String n) {
switch (n) {
case "main menu":
Expand Down

0 comments on commit 60bfa90

Please sign in to comment.