DEADSOFTWARE

One GameProc object for everything
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameSaver.java
index a4e314b465273705b1cc404d44918080ef0b7f26..5f8743dc8710a3f054b597fea29a9be5a19e6538 100644 (file)
@@ -23,10 +23,10 @@ public class GameSaver {
         out.write(intToBytes(VERSION));
         out.write(intToBytes(width));
         out.write(intToBytes(height));
-        for (int y = 0; y < map[0].length; y++) {
+        for (int y = 0; y < height; y++) {
             bl = map[0][y];
             rl = 0;
-            for (int x = 0; x < map.length; x++) {
+            for (int x = 0; x < width; x++) {
                 if (map[x][y] != bl) {
                     out.write(intToBytes(rl));
                     out.write(intToBytes(bl));
@@ -78,7 +78,7 @@ public class GameSaver {
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
             );
-            gameProc.physics = new GamePhysics(gameProc);
+            gameProc.physics = new GamePhysics();
             gameProc.resetRenderer();
         } catch (Exception e) {
             Gdx.app.error("GameSaver", e.getMessage(), e);
@@ -87,17 +87,17 @@ public class GameSaver {
         return gameProc;
     }
 
-    public static void save(GameProc gameProc) {
+    public static void save(GameProc gp) {
         FileHandle file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/");
         file.mkdirs();
         file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/game.sav");
         try {
             ObjectOutputStream out = new ObjectOutputStream(file.write(false));
             out.writeInt(VERSION);
-            out.writeObject(gameProc);
+            out.writeObject(gp);
             out.close();
-            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav"), gameProc.world.getFullForeMap());
-            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"), gameProc.world.getFullBackMap());
+            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav"), gp.world.getFullForeMap());
+            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"), gp.world.getFullBackMap());
         } catch (Exception e) {
             e.printStackTrace();
         }