Pandaqi / In-the-Same-Boat

Jackbox-style game where you try to sail a ship together - discovering treasures and battling your friends.
2 stars 0 forks source link

Create basic structure for the map #12

Closed Pandaqi closed 5 years ago

Pandaqi commented 5 years ago

IMPORTANT: Test all the map algorithms and systems on my local WAMP installation, before putting it on the server. Should be much faster and easier. (I don't need to start an online game again every time.)

Server (game creation) stuff

The server needs to:

Client (game displaying) stuff

Then it needs to send this information to the clients:

Important optimization!

During the game, we will be searching through tiles A LOT. (Checking if they are within viewing range, checking if the bullet hit them, etc.)

It would be very expensive (server-side) to search through all those lists time and time again.

Example: Want to know if we hit a monster on tile A? Well, check all monsters. No hit; the cannonball flies to tile B. Well ... we need to check all the monsters again! Doing this for all tiles within range, for every cannonball, for each ship, etc. is very expensive.)

Instead! There is a (slightly larger) map variable on the server. This doesn't just save the current value of the tile (sea or island), but also any units (or special things) that are on this tile.

At the end of turn, when everything moves, we update their own object AND we update this map. This costs a little extra at that moment, but saves many operations in the long run.

Example (again): Want to know if we hit something on tile A? Fetch the tile, see if there are more than 0 units on the tile. Simple! We go to tile B, perform the same quick operation.

(As an extra optimization, all tiles where there are NO units/specialties, can just reduce back to their number. To check if we hit something, we just check if this tile's value is a number or not. If so, we don't hit anything. If not, the tile's value is an object, and we can "damage" everything within that object.)

Another important note: We don't actually need to save what's there. We just need to save the index/id of the "thing" that is on the tile. Once we know that, we can look up the information in the corresponding list. (You hit monster number 3? Let me check my monsters Array at position 3.)

Pandaqi commented 5 years ago

Did all of this! (Except for some slight optimizations, which might not even be needed.)