|
5 | 5 | import com.redomar.game.entities.Player; |
6 | 6 | import com.redomar.game.entities.Vendor; |
7 | 7 | import com.redomar.game.entities.trees.Spruce; |
| 8 | +import com.redomar.game.event.InputHandler; |
| 9 | +import com.redomar.game.event.MouseHandler; |
8 | 10 | import com.redomar.game.gfx.Screen; |
9 | 11 | import com.redomar.game.gfx.SpriteSheet; |
10 | 12 | import com.redomar.game.level.LevelHandler; |
| 13 | +import com.redomar.game.lib.Either; |
11 | 14 | import com.redomar.game.lib.Font; |
12 | 15 | import com.redomar.game.lib.Time; |
13 | | -import com.redomar.game.script.PrintTypes; |
14 | | -import com.redomar.game.script.Printer; |
| 16 | +import com.redomar.game.log.PrintTypes; |
| 17 | +import com.redomar.game.log.Printer; |
15 | 18 | import org.apache.commons.text.WordUtils; |
16 | 19 |
|
17 | 20 | import javax.swing.*; |
@@ -68,10 +71,10 @@ public class Game extends Canvas implements Runnable { |
68 | 71 | private final BufferedImage image2 = new BufferedImage(WIDTH, HEIGHT - 30, BufferedImage.TYPE_INT_RGB); |
69 | 72 | private final Font font = new Font(); // Font object capable of displaying 2 fonts: Arial and Segoe UI |
70 | 73 | private final Printer printer = new Printer(); |
| 74 | + boolean musicPlaying = false; |
71 | 75 | private int tickCount = 0; |
72 | 76 | private Screen screen; |
73 | 77 | private LevelHandler level; // Loads and renders levels along with tiles, entities, projectiles and more. |
74 | | - |
75 | 78 | //The entities of the game |
76 | 79 | private Player player; |
77 | 80 | private Dummy dummy; // Dummy NPC follows the player around |
@@ -385,9 +388,17 @@ public void run() { |
385 | 388 | */ |
386 | 389 | public void tick() { |
387 | 390 | setTickCount(getTickCount() + 1); |
| 391 | + Either<Exception, Boolean> musicKeyAction = input.toggleActionWithCheckedRunnable(input.getM_KEY(), musicPlaying, () -> Game.getBackgroundMusic().play(), () -> Game.getBackgroundMusic().stop()); |
| 392 | + musicKeyAction.either(exception -> { |
| 393 | + printer.cast().print("Failed to play music", PrintTypes.MUSIC); |
| 394 | + printer.exception(exception.toString()); |
| 395 | + musicPlaying = false; |
| 396 | + }, isPlaying -> musicPlaying = isPlaying); |
| 397 | + |
388 | 398 | level.tick(); |
389 | 399 | } |
390 | 400 |
|
| 401 | + |
391 | 402 | /** |
392 | 403 | * This method displays the current state of the game. |
393 | 404 | */ |
|
0 commit comments