Browse Source

bug fixes, added no sound mode

Kajetan Johannes Hammerle 6 years ago
parent
commit
996ac768b2

+ 10 - 10
levels/00.map

@@ -24,19 +24,19 @@
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, 21, -1, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, 181, -1, 180, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, 180, -1, 180, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, 179, -1, 179, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 161, -1
 -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 160, -1
--1, -1, 15, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, -1, -1, -1, -1, -1, -1, -1, 64, 64, 64, 64, 64, 64, 64, -1, -1, -1, -1, -1, -1, 64, 64, -1, -1, 64, 64, 64, 64, 64, 64, 64, -1, -1
-112, -1, -1, -1, -1, 32, -1, -1, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1
--1, -1, 48, -1, 64, -1, 64, 64, -1, -1, -1, -1, -1, -1, -1, -1, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 32, -1
-20, 20, 20, 148, 148, 148, 148, 20, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 20, 20, 20, 20, 20, 20, 23, -1, -1, 32, -1, -1, -1, -1, -1, -1
+-1, -1, 15, -1, -1, 15, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, -1, -1, 15, 64, 64, 64, 64, 64, 64, 64, -1, -1, -1, -1, -1, -1, 64, 64, -1, -1, 64, 64, 64, 64, 64, 64, 64, -1, -1
+112, -1, -1, -1, -1, 32, -1, 15, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1
+-1, -1, -1, -1, -1, -1, 64, 64, -1, -1, -1, -1, -1, -1, -1, -1, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 32, -1
+20, 20, 148, 148, 148, 148, 148, 20, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 20, 20, 20, 20, 20, 20, 23, -1, -1, 32, -1, -1, -1, -1, -1, -1
 -1,  2,  0,  0,  0,  0,  0,  0,  1, 97, 97,  97,  97, 97, 97, -1, -1, -1,  2,  0,  0,  0,  0,  0,  0,  1, 97, 97,  6,  5, 80, 80, -1, -1, -1
  4,  0,  0,  0,  0,  0,  0,  0,  0,  4,  4,  0,  0,  0,  0,  4,  4,  4,  0,  0,  0,  0,  0,  0,  0,  0,  4,  4,  0,  0,  0,  0,  4,  4,  4
 #

+ 1 - 1
savegame.txt

@@ -1,2 +1,2 @@
 level.00=true
-level.01=false
+sound=false

+ 6 - 2
src/me/hammerle/supersnuvi/gamelogic/Level.java

@@ -345,8 +345,12 @@ public final class Level
         if(worldLoaded)
         {
             // setting the right view center
-            double centerX = Math.max(0, hero.getX() - (renderer.getWidth() / 2));
-            double centerY = Math.max(0, hero.getY() - (renderer.getHeight() / 2));
+            double rWidth = renderer.getWidth();
+            double rHeight = renderer.getHeight();
+            
+            double centerX = Math.min(Math.max(0, hero.getX() - rWidth / 2), width * 32 - rWidth);
+            double centerY = Math.min(Math.max(0, hero.getY() - rHeight / 2), height * 32 - rHeight);
+            
             renderer.setViewCenter(centerX, centerY);
             
             // end

+ 5 - 1
src/me/hammerle/supersnuvi/gamelogic/StateRenderer.java

@@ -3,7 +3,6 @@ package me.hammerle.supersnuvi.gamelogic;
 import java.io.File;
 import java.util.Arrays;
 import java.util.HashMap;
-import javafx.scene.image.Image;
 import javafx.scene.input.KeyCode;
 import javafx.scene.paint.Color;
 import me.hammerle.supersnuvi.input.IKeyHandler;
@@ -29,6 +28,8 @@ public class StateRenderer
     private int levelIndex;
     private final SimpleConfig config;
     
+    public static boolean noSound;
+    
     public StateRenderer(IGameRenderer renderer)
     {
         this.renderer = renderer;
@@ -46,6 +47,9 @@ public class StateRenderer
         config = new SimpleConfig("savegame.txt");
         config.load();
         
+        noSound = !config.getBoolean("sound", false);
+        SoundUtils.loadSounds();
+        
         registerTiles();
     }    
 

+ 0 - 5
src/me/hammerle/supersnuvi/rendering/GameRenderer.java

@@ -1,6 +1,5 @@
 package me.hammerle.supersnuvi.rendering;
 
-import java.io.File;
 import me.hammerle.supersnuvi.gamelogic.StateRenderer;
 import javafx.animation.AnimationTimer;
 import javafx.scene.Scene;
@@ -8,8 +7,6 @@ import javafx.scene.canvas.Canvas;
 import javafx.scene.canvas.GraphicsContext;
 import javafx.scene.image.Image;
 import javafx.scene.input.KeyEvent;
-import javafx.scene.media.Media;
-import javafx.scene.media.MediaPlayer;
 import javafx.scene.paint.Color;
 import javafx.scene.paint.Paint;
 import me.hammerle.supersnuvi.input.KeyHandler;
@@ -67,8 +64,6 @@ public class GameRenderer extends AnimationTimer implements IGameRenderer
         registerEvents();
         
         this.state = new StateRenderer(this);
-        
-        SoundUtils.loadSounds();
     }
     
     private void registerEvents()

+ 1 - 0
src/me/hammerle/supersnuvi/rendering/GameWindow.java

@@ -1,5 +1,6 @@
 package me.hammerle.supersnuvi.rendering;
 
+import java.util.Arrays;
 import javafx.application.Application;
 import javafx.scene.Group;
 import javafx.scene.Scene;

+ 14 - 0
src/me/hammerle/supersnuvi/util/SoundUtils.java

@@ -3,6 +3,8 @@ package me.hammerle.supersnuvi.util;
 import java.io.File;
 import javafx.scene.media.Media;
 import javafx.scene.media.MediaPlayer;
+import me.hammerle.supersnuvi.gamelogic.StateRenderer;
+import me.hammerle.supersnuvi.rendering.GameWindow;
 
 public class SoundUtils 
 {
@@ -22,6 +24,10 @@ public class SoundUtils
     
     public static MediaPlayer getMedia(String path, boolean loop)
     {
+        if(StateRenderer.noSound)
+        {
+            return null;
+        }
         Media sound = new Media(new File("sounds/" + path + ".wav").toURI().toString());
         MediaPlayer mp = new MediaPlayer(sound);
         if(loop)
@@ -49,6 +55,10 @@ public class SoundUtils
     
     public static void playSound(MediaPlayer mp, boolean reset)
     {
+        if(StateRenderer.noSound)
+        {
+            return;
+        }
         if(reset)
         {
             mp.seek(mp.getStartTime());
@@ -63,6 +73,10 @@ public class SoundUtils
     
     public static void stopSound(MediaPlayer mp)
     {
+        if(StateRenderer.noSound)
+        {
+            return;
+        }
         mp.stop();
     }
 }