City Walls: Placement and Design - UQdeco2800/2022-studio-3 GitHub Wiki
Introduction
In Sprint 3, the walls of Atlantis' city have been revamped to make Atlantis feel more like fortress, or a bastion that can potentially withstand the divine forces that seek to destroy it. In this process, the design of the City Walls, as well as their placement function have been modified. AtlantisGameArea has a new spawnCityWalls() function, which will spawn a set of city walls around the outskirts of the city, in reference to a constant wall size.
Wall Placement Function goals
It was intended to produce a modular function that could generate a set of walls that would meet the following criteria:
- The walls will be aligned (texture-wise) to the edge of the city, along all city edges no matter their size
- The walls can be scaled to different tile lengths, to increase the perceived size in game
- Increasing the size will vary the number of wall/pillar entities present, to allow it to look more realistic
The placement function as it exists in game achieves these goals, as modifying a single constant - Tile Width of a Wall, will scale and place all the walls in the desired position. e.g City with wall length of 1 tile:
VS
e.g City with wall length of 5 tiles:
Each wall entity also has a correspondingly scaled and placed hitbox, meaning that this function is largely scalable to set wall sizes to any reasonable size in future. Note that in the larger wall size example, there are fewer turrets/joining walls - which is intuitive, as maintaining a constant number would mean the textures would have to be squished at higher scales.
How to modify wall scale
If it is desired to change the size of the walls, it is only necessary to modify the CORNER_SCALE constant defined in entities/factories/BuildingFactory.java. NOTE: It is important to only specify integer values for CORNER_SCALE, even though the data type is a float (used for convenience as scaling in game is done using floats)
e.g Changing the wall size to be 3 tiles long (Each pillar will be 3 tiles wide, and the connecting wall will be 6 tiles wide)
public static final float CORNER_SCALE = 3f;
Implications of modifying wall scale
As the wall placement is done assuming walls will have a set tile length in their textures, a specific amount of tiles are required to fill a row of the city with walls. To accommodate for this, MapGenerator has been added to dynamically ensure that the provided cityWidth and cityHeight are large enough to fit a minimum-sized wall along its borders. The downside of this is that, when setting a CORNER_SCALE (wall size) that is too large, it is possible to allocate a city size that is too large to fit within the given map, causing the run to fail. If you wish to increase wall size significantly (past the 5 tiles example shown above) it is recommended you ensure the map size is big enough to fit a city that is enclosed with walls of that size.
Future directions
The logic applied to scale and place CityWalls can and should be extrapolated to the rest of the game, as entities are currently being scaled orthogonally and placed relative to the bottom left corner of their texture. The code implemented in spawnCityBuildings() provides a proven framework that can precisely place entities on tiles relative to their texture, so entities may now be placed exactly at the desired tile, not simply close to it. This is significant for scaled entities, as the more it is scaled, the further away the entity's visual start point is from its position.