Music update
This commit is contained in:
parent
22bee3b9b4
commit
5e077ea186
@ -10,7 +10,6 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class Npc extends Person {
|
public class Npc extends Person {
|
||||||
private MapPainter mapPainter;
|
private MapPainter mapPainter;
|
||||||
private Color color;
|
|
||||||
|
|
||||||
public Npc(int x, int y, Map map, MapPainter mapPainter) {
|
public Npc(int x, int y, Map map, MapPainter mapPainter) {
|
||||||
super(x, y, map);
|
super(x, y, map);
|
||||||
@ -62,7 +61,6 @@ public class Npc extends Person {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
g.setColor(color);
|
|
||||||
g.fillOval(getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE);
|
g.fillOval(getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
package ruscz.game.gameOfProd.Scripts;
|
package ruscz.game.gameOfProd.Scripts;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
UP, DOWN, LEFT, RIGHT, NONE
|
UP, DOWN, LEFT, RIGHT
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java
Normal file
34
src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package ruscz.game.gameOfProd.Sounds;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MusicManager {
|
||||||
|
private String musicName;
|
||||||
|
|
||||||
|
public MusicManager(String name){
|
||||||
|
musicName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playMusic(){
|
||||||
|
AudioInputStream audioIn;
|
||||||
|
try {
|
||||||
|
audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/" + musicName));
|
||||||
|
Clip clip;
|
||||||
|
clip = AudioSystem.getClip();
|
||||||
|
if (clip != null) {
|
||||||
|
clip.open(audioIn);
|
||||||
|
}
|
||||||
|
if (clip != null) {
|
||||||
|
FloatControl gainControl =
|
||||||
|
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
|
||||||
|
gainControl.setValue(-20.0f);
|
||||||
|
clip.loop(1000);
|
||||||
|
clip.start();
|
||||||
|
}
|
||||||
|
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,9 @@ import ruscz.game.gameOfProd.Cells.*;
|
|||||||
import ruscz.game.gameOfProd.Dialog.DialogBar;
|
import ruscz.game.gameOfProd.Dialog.DialogBar;
|
||||||
import ruscz.game.gameOfProd.Map.Map;
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
import ruscz.game.gameOfProd.Map.MapPainter;
|
import ruscz.game.gameOfProd.Map.MapPainter;
|
||||||
|
import ruscz.game.gameOfProd.Sounds.MusicManager;
|
||||||
|
|
||||||
|
import javax.sound.midi.MidiChannel;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -35,6 +37,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
private MapPainter mapPainter;
|
private MapPainter mapPainter;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private Timer inputTimer;
|
private Timer inputTimer;
|
||||||
|
private MusicManager musicManager;
|
||||||
|
|
||||||
private LinkedList<Map> mapLinkedList;
|
private LinkedList<Map> mapLinkedList;
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
camera = new Camera(this, canvas);
|
camera = new Camera(this, canvas);
|
||||||
canvas.setBackground(Color.black);
|
canvas.setBackground(Color.BLACK);
|
||||||
canvas.setPreferredSize(new Dimension(
|
canvas.setPreferredSize(new Dimension(
|
||||||
CELL_SIZE * CANVAS_WIDTH,
|
CELL_SIZE * CANVAS_WIDTH,
|
||||||
CELL_SIZE * CANVAS_HEIGHT));
|
CELL_SIZE * CANVAS_HEIGHT));
|
||||||
@ -206,6 +209,8 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
Npc npc2 = new Npc(startX, startY, m6, mapPainter);
|
Npc npc2 = new Npc(startX, startY, m6, mapPainter);
|
||||||
m6.setNpcs(npc2);
|
m6.setNpcs(npc2);
|
||||||
|
|
||||||
|
musicManager = new MusicManager("Town1.wav");
|
||||||
|
musicManager.playMusic();
|
||||||
Timer timer = new Timer(10, actionEvent -> {
|
Timer timer = new Timer(10, actionEvent -> {
|
||||||
mapPainter.getActualMap().getPerson().move();
|
mapPainter.getActualMap().getPerson().move();
|
||||||
camera.moveCamera();
|
camera.moveCamera();
|
||||||
|
|||||||
BIN
src/main/resources/Town1.wav
Normal file
BIN
src/main/resources/Town1.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user