feat(gameplay): large zoomable map, neighborhood layout, tagging fix
Major changes: - Map: 80x40 (was 38x18) - requires zoom/pan to navigate - CameraController: pinch-to-zoom, drag-to-pan, scroll wheel zoom - Neighborhood layout: streets grid with house rows, backyards, fences - All gaps minimum 2.5 units wide for unit passage - Streets visible on ground (gray paths) Bug fixes: - Tagging: only captured unit goes to jail, never the instigator - Collision handled once (by lower instance ID) - Respawn offset fixed for landscape mode New constants: - CameraMinZoom/MaxZoom/StartZoom - MinGapSize, StreetWidth - VisionRadius increased to 6 (larger map) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -24,9 +24,10 @@ public class Game : MonoBehaviour
|
||||
public const float UnitSpeed = 5f;
|
||||
public const float UnitSize = 1f;
|
||||
public const float UnitColliderRadius = 0.5f;
|
||||
public const float MinGapSize = 2f; // Minimum gap between obstacles
|
||||
|
||||
// Vision & Detection
|
||||
public const float VisionRadius = 4f;
|
||||
public const float VisionRadius = 6f;
|
||||
public const float TagRadius = 0.75f;
|
||||
public const float FlagPickupRadius = 0.75f;
|
||||
|
||||
@@ -37,17 +38,24 @@ public class Game : MonoBehaviour
|
||||
// Scoring
|
||||
public const int WinScore = 3;
|
||||
|
||||
// Map - 19:9 aspect ratio for smartphone (landscape)
|
||||
public const float MapWidth = 38f;
|
||||
public const float MapHeight = 18f;
|
||||
// Map - Large neighborhood (19:9 landscape, requires zoom)
|
||||
public const float MapWidth = 80f;
|
||||
public const float MapHeight = 40f;
|
||||
|
||||
// Camera
|
||||
public const float CameraMinZoom = 8f;
|
||||
public const float CameraMaxZoom = 22f;
|
||||
public const float CameraStartZoom = 15f;
|
||||
|
||||
// Bases
|
||||
public const float BaseSize = 5f;
|
||||
public const float BaseInset = 4f; // Distance from map edge
|
||||
public const float BaseSize = 6f;
|
||||
public const float BaseInset = 6f;
|
||||
|
||||
// Houses
|
||||
public const float HouseMinSize = 2f;
|
||||
public const float HouseMaxSize = 4f;
|
||||
// Neighborhood layout
|
||||
public const float StreetWidth = 4f;
|
||||
public const float HouseWidth = 5f;
|
||||
public const float HouseDepth = 4f;
|
||||
public const float YardDepth = 3f;
|
||||
|
||||
// References set during setup
|
||||
public static Game Instance { get; private set; }
|
||||
@@ -73,6 +81,9 @@ public class Game : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Seed random for consistent neighborhood layout
|
||||
Random.InitState(42);
|
||||
|
||||
SetupCamera();
|
||||
CreateGround();
|
||||
CreateObstacles();
|
||||
@@ -89,101 +100,163 @@ public class Game : MonoBehaviour
|
||||
if (cam != null)
|
||||
{
|
||||
cam.orthographic = true;
|
||||
cam.orthographicSize = MapHeight / 2f + 2f;
|
||||
cam.orthographicSize = CameraStartZoom;
|
||||
cam.transform.position = new Vector3(0, 0, -10);
|
||||
|
||||
// Add camera controller for zoom/pan
|
||||
var controller = cam.gameObject.AddComponent<CameraController>();
|
||||
controller.minZoom = CameraMinZoom;
|
||||
controller.maxZoom = CameraMaxZoom;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateGround()
|
||||
{
|
||||
var ground = CreateSprite("Ground", new Color(0.2f, 0.4f, 0.2f), MapWidth, MapHeight);
|
||||
// Grass background
|
||||
var ground = CreateSprite("Ground", new Color(0.2f, 0.35f, 0.15f), MapWidth, MapHeight);
|
||||
ground.transform.position = Vector3.zero;
|
||||
var sr = ground.GetComponent<SpriteRenderer>();
|
||||
sr.sortingOrder = -10;
|
||||
|
||||
// Create streets (darker gray paths)
|
||||
Color streetColor = new Color(0.3f, 0.3f, 0.32f);
|
||||
|
||||
// Main horizontal street (center)
|
||||
var mainStreet = CreateSprite("MainStreet", streetColor, MapWidth - 20f, StreetWidth);
|
||||
mainStreet.transform.position = new Vector3(0, 0, 0);
|
||||
mainStreet.GetComponent<SpriteRenderer>().sortingOrder = -9;
|
||||
|
||||
// Upper horizontal street
|
||||
var upperStreet = CreateSprite("UpperStreet", streetColor, MapWidth - 30f, StreetWidth);
|
||||
upperStreet.transform.position = new Vector3(0, 10f, 0);
|
||||
upperStreet.GetComponent<SpriteRenderer>().sortingOrder = -9;
|
||||
|
||||
// Lower horizontal street
|
||||
var lowerStreet = CreateSprite("LowerStreet", streetColor, MapWidth - 30f, StreetWidth);
|
||||
lowerStreet.transform.position = new Vector3(0, -10f, 0);
|
||||
lowerStreet.GetComponent<SpriteRenderer>().sortingOrder = -9;
|
||||
|
||||
// Vertical cross streets
|
||||
float[] crossStreetX = { -20f, -8f, 8f, 20f };
|
||||
int streetIndex = 0;
|
||||
foreach (float x in crossStreetX)
|
||||
{
|
||||
var crossStreet = CreateSprite($"CrossStreet_{streetIndex++}", streetColor, StreetWidth, MapHeight - 10f);
|
||||
crossStreet.transform.position = new Vector3(x, 0, 0);
|
||||
crossStreet.GetComponent<SpriteRenderer>().sortingOrder = -9;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateObstacles()
|
||||
{
|
||||
// Dense house layout for landscape 38x18 map
|
||||
// Bases on left/right, houses create horizontal lanes with cross-routes
|
||||
// Create realistic neighborhood layout for 80x40 map
|
||||
// Pattern: horizontal streets with house rows, vertical cross-streets
|
||||
// All gaps minimum 2.5 units for unit passage
|
||||
|
||||
Vector2[] housePositions = {
|
||||
// Left section (near player base) - create 3 exit lanes
|
||||
new(-14f, 5f),
|
||||
new(-12f, -4f),
|
||||
new(-10f, 0f),
|
||||
var obstacles = new List<(Vector2 pos, Vector2 size, Color color)>();
|
||||
|
||||
// Left-mid section - force route decisions
|
||||
new(-6f, 6f),
|
||||
new(-4f, 2f),
|
||||
new(-7f, -3f),
|
||||
new(-3f, -5f),
|
||||
// Street grid creates the main routes
|
||||
// Houses line the streets with backyards creating sneaky routes
|
||||
|
||||
// Center section - dense, creates cat-and-mouse area
|
||||
new(2f, 5f),
|
||||
new(0f, 1f),
|
||||
new(-2f, -2f),
|
||||
new(3f, -4f),
|
||||
new(-1f, -6f),
|
||||
new(1f, 6f),
|
||||
// === ROW 1 (Top) - y around 12-16 ===
|
||||
CreateHouseRow(obstacles, y: 14f, xStart: -32f, xEnd: 32f, houseWidth: 5f, gapWidth: 3f, yardSide: -1);
|
||||
|
||||
// Right-mid section - mirror complexity
|
||||
new(6f, 5f),
|
||||
new(4f, -2f),
|
||||
new(7f, -5f),
|
||||
new(5f, 2f),
|
||||
// === ROW 2 (Upper-mid) - y around 4-8 ===
|
||||
CreateHouseRow(obstacles, y: 6f, xStart: -28f, xEnd: 28f, houseWidth: 6f, gapWidth: 3.5f, yardSide: 1);
|
||||
|
||||
// Right section (near enemy base) - create 3 approach lanes
|
||||
new(14f, 4f),
|
||||
new(12f, -3f),
|
||||
new(10f, 0f),
|
||||
};
|
||||
// === ROW 3 (Center) - y around -2 to 2 ===
|
||||
// Staggered houses creating interesting chokepoints
|
||||
CreateHouseRow(obstacles, y: -1f, xStart: -25f, xEnd: 25f, houseWidth: 5f, gapWidth: 4f, yardSide: -1);
|
||||
|
||||
Vector2[] houseSizes = {
|
||||
// Left section
|
||||
new(2.5f, 3f),
|
||||
new(3f, 2.5f),
|
||||
new(2f, 2f),
|
||||
// === ROW 4 (Lower-mid) - y around -8 to -4 ===
|
||||
CreateHouseRow(obstacles, y: -8f, xStart: -28f, xEnd: 28f, houseWidth: 6f, gapWidth: 3.5f, yardSide: 1);
|
||||
|
||||
// Left-mid
|
||||
new(3f, 2.5f),
|
||||
new(2f, 3f),
|
||||
new(2.5f, 2f),
|
||||
new(2.5f, 2.5f),
|
||||
// === ROW 5 (Bottom) - y around -12 to -16 ===
|
||||
CreateHouseRow(obstacles, y: -14f, xStart: -32f, xEnd: 32f, houseWidth: 5f, gapWidth: 3f, yardSide: 1);
|
||||
|
||||
// Center - varied sizes for interesting gaps
|
||||
new(2f, 3f),
|
||||
new(3f, 2f),
|
||||
new(2f, 2.5f),
|
||||
new(2.5f, 2f),
|
||||
new(2f, 2f),
|
||||
new(2.5f, 2.5f),
|
||||
// === Add some fences/hedges in backyards for extra cover ===
|
||||
// These create the sneaky backyard routes
|
||||
AddBackyardObstacles(obstacles);
|
||||
|
||||
// Right-mid
|
||||
new(2.5f, 2.5f),
|
||||
new(3f, 2f),
|
||||
new(2.5f, 3f),
|
||||
new(2f, 2f),
|
||||
|
||||
// Right section
|
||||
new(3f, 2.5f),
|
||||
new(2f, 3f),
|
||||
new(2.5f, 2f),
|
||||
};
|
||||
|
||||
for (int i = 0; i < housePositions.Length; i++)
|
||||
// Create all obstacles
|
||||
int houseIndex = 0;
|
||||
foreach (var (pos, size, color) in obstacles)
|
||||
{
|
||||
var house = CreateSprite($"House_{i}", new Color(0.35f, 0.35f, 0.4f), houseSizes[i].x, houseSizes[i].y);
|
||||
house.transform.position = new Vector3(housePositions[i].x, housePositions[i].y, 0);
|
||||
var house = CreateSprite($"House_{houseIndex++}", color, size.x, size.y);
|
||||
house.transform.position = new Vector3(pos.x, pos.y, 0);
|
||||
|
||||
var collider = house.AddComponent<BoxCollider2D>();
|
||||
collider.size = Vector2.one; // Local space - scale handles actual size
|
||||
collider.size = Vector2.one;
|
||||
|
||||
var sr = house.GetComponent<SpriteRenderer>();
|
||||
sr.sortingOrder = -5;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateHouseRow(List<(Vector2, Vector2, Color)> obstacles, float y, float xStart, float xEnd,
|
||||
float houseWidth, float gapWidth, int yardSide)
|
||||
{
|
||||
Color houseColor = new Color(0.4f, 0.35f, 0.3f); // Brown-ish houses
|
||||
float houseDepth = 4f;
|
||||
float x = xStart;
|
||||
|
||||
while (x < xEnd - houseWidth)
|
||||
{
|
||||
// Vary house sizes slightly for visual interest
|
||||
float w = houseWidth + Random.Range(-0.5f, 0.5f);
|
||||
float h = houseDepth + Random.Range(-0.3f, 0.3f);
|
||||
|
||||
// Skip houses near bases (leave clear zones)
|
||||
if (Mathf.Abs(x) > 12f || Mathf.Abs(y) < 10f)
|
||||
{
|
||||
obstacles.Add((new Vector2(x + w / 2f, y), new Vector2(w, h), houseColor));
|
||||
}
|
||||
|
||||
x += w + gapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void AddBackyardObstacles(List<(Vector2, Vector2, Color)> obstacles)
|
||||
{
|
||||
Color fenceColor = new Color(0.5f, 0.4f, 0.3f); // Fence brown
|
||||
Color hedgeColor = new Color(0.15f, 0.35f, 0.15f); // Hedge green
|
||||
|
||||
// Fences between yards (vertical) - create backyard maze
|
||||
float[] fenceXPositions = { -22f, -14f, -6f, 6f, 14f, 22f };
|
||||
foreach (float fx in fenceXPositions)
|
||||
{
|
||||
// Upper backyard fences
|
||||
if (Random.value > 0.3f)
|
||||
obstacles.Add((new Vector2(fx, 10f), new Vector2(0.5f, 3f), fenceColor));
|
||||
// Lower backyard fences
|
||||
if (Random.value > 0.3f)
|
||||
obstacles.Add((new Vector2(fx, -10f), new Vector2(0.5f, 3f), fenceColor));
|
||||
}
|
||||
|
||||
// Hedges along some property lines (horizontal)
|
||||
float[] hedgeYPositions = { 10f, 2.5f, -4f, -11f };
|
||||
foreach (float hy in hedgeYPositions)
|
||||
{
|
||||
float hx = Random.Range(-20f, 20f);
|
||||
if (Mathf.Abs(hx) > 8f) // Not too close to center
|
||||
{
|
||||
obstacles.Add((new Vector2(hx, hy), new Vector2(4f, 1f), hedgeColor));
|
||||
}
|
||||
}
|
||||
|
||||
// Some sheds/garages in backyards
|
||||
Color shedColor = new Color(0.45f, 0.4f, 0.35f);
|
||||
Vector2[] shedPositions = {
|
||||
new(-18f, 10f), new(-10f, -10f), new(8f, 10f), new(16f, -10f),
|
||||
new(-26f, 2f), new(26f, -3f)
|
||||
};
|
||||
foreach (var pos in shedPositions)
|
||||
{
|
||||
if (Random.value > 0.4f)
|
||||
obstacles.Add((pos, new Vector2(2.5f, 2.5f), shedColor));
|
||||
}
|
||||
}
|
||||
|
||||
void CreateBases()
|
||||
{
|
||||
// Player base - left side
|
||||
|
||||
Reference in New Issue
Block a user