Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Semester 4 Week 7

Pre-release
Pre-release
Compare
Choose a tag to compare
@LPkkjHD LPkkjHD released this 27 May 18:04
· 110 commits to main since this release

Hello and welcome to this weeks development progress blog for our little game Underwatch 🎮

Code Refactoring

This week we decided to do a humongous refactoring of our code base, which happened to be long overdue and also this weeks task. Taking a look at the core problem we had to work around all this time:

In order for the path finding to work we rasterize the world into a 32x32 Grid and represent each of the cells as a single point in an array only containing information about whether or not this cell shall be considered walkable or not.

We had to use arcane combinations of -1 and +1 to add connections to the neighboring cells.

                     // check if wall is above and below
                     if (getNode(x, y + 1).type == FlatTiledNode.TILE_WALL
                             && getNode(x, y - 1).type == FlatTiledNode.TILE_WALL) {
-                        // W
-                        addConnection(n, -1, 0);
-                        // E
-                        addConnection(n, 1, 0);
+                        addConnection(n, Direction.W, Direction.E);
                         continue;
                     }
                     // check if wall is left and right
                     if (getNode(x + 1, y).type == FlatTiledNode.TILE_WALL
                             && getNode(x - 1, y).type == FlatTiledNode.TILE_WALL) {
-                        // S
-                        addConnection(n, 0, -1);
-                        // N
-                        addConnection(n, 0, 1);
+                        addConnection(n, Direction.N, Direction.S);
                         continue;
                     }
                     // check if wall is above
                     if (getNode(x, y + 1).type == FlatTiledNode.TILE_WALL) {
-                        // W
-                        addConnection(n, -1, 0);
-                        // S
-                        addConnection(n, 0, -1);
-                        // E
-                        addConnection(n, 1, 0);
-                        // N
-                        addConnection(n, 0, 1);
-                        // SE
-                        addConnection(n, 1, -1);
-                        // SW
-                        addConnection(n, -1, -1);
+                        addConnection(n, Direction.N, Direction.E, Direction.S, Direction.W, Direction.SE, Direction.SW);
                         continue;
                     }
         }
     }
     private void addConnection(FlatTiledNode n, int xOffset, int yOffset) {
         FlatTiledNode target = getNode(n.x + xOffset, n.y + yOffset);
-        if (target.type != FlatTiledNode.TILE_WALL) n.getConnections().add(new FlatTiledConnection(this, n, target));
+        if (target.type != FlatTiledNode.TILE_WALL)
+            n.getConnections().add(new FlatTiledConnection(this, n, target));
+    }
 }

This is very prone to errors made by the developer, so we decided to refactor it with the use of a private enum as well as allowing a flexible amount or arguments with the varargs feature of Java.

+    private enum Direction {
+        N, E, S, W, NE, NW, SE, SW
+    }
+
+    private void addConnection(FlatTiledNode n, Direction... directions) // throws Exception
+    {
+        // if (directions.length > 8 || directions.length < 0) {
+        // throw new Exception("Directions are fucked up");
+        // }
+        for (Direction direction : directions) {
+            switch (direction) {
+                case N:
+                    addConnection(n, 0, 1);
+                    break;
+                case E:
+                    addConnection(n, 1, 0);
+                    break;
+                case S:
+                    addConnection(n, 0, -1);
+                    break;
+                case W:
+                    addConnection(n, -1, 0);
+                    break;
+                case NE:
+                    addConnection(n, 1, 1);
+                    break;
+                case NW:
+                    addConnection(n, -1, 1);
+                    break;
+                case SE:
+                    addConnection(n, 1, -1);
+                    break;
+                case SW:
+                    addConnection(n, -1, -1);
+                    break;
+                default:
+                    break;
+            }
+        }
+   }

We took inspiration from the Book Clean Code, Chapter 3.1, "Funktionen sollten klein sein[...]" to make this refactoring and are quite happy with the results it yielded.

Progress on the Game 🎮

  • We added new collectables such as HP potions as well as speed potions
  • The came can now be won by collecting the holy grail
  • New sounds, weapons and assets
  • Some initial efforts on balancing the weapons and enemies
  • A crucial bug responsible for crashing the game after a few seconds of gameplay has been squashed

Bugfixes on the Webpage 🐛

  • Added an apply filter button, so we don't DDOS our backend server

What's Changed

Full Changelog: v0.0.4-alpha...v0.0.5-alpha