Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: NobodysNightmare/BlockDefender
base: 3357fccfc2
...
head fork: NobodysNightmare/BlockDefender
compare: 098000ece3
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  BlockDefender/BlockDefender/BlockDefender.csproj
@@ -114,6 +114,7 @@
</Compile>
<Compile Include="Terrain\DestructibleField.cs" />
<Compile Include="Terrain\Field.cs" />
+ <Compile Include="Terrain\MapGenerator.cs" />
<Compile Include="Terrain\PlainField.cs" />
<Compile Include="Terrain\Map.cs" />
<Compile Include="Net\Data\AssignPlayerPacket.cs" />
View
4 BlockDefender/BlockDefender/BlockDefenderGame.cs
@@ -40,7 +40,7 @@ protected override void Initialize()
{
if (AppSettings.Default.EnableServer)
{
- GameServer server = new GameServer(new Map(16, 9), AppSettings.Default.ListenPort);
+ GameServer server = new GameServer(new MapGenerator().Generate(16, 9), AppSettings.Default.ListenPort);
server.Start();
}
NetworkClient = new NetworkClient();
@@ -115,7 +115,7 @@ private void UpdateInput()
protected override void Draw(GameTime gameTime)
{
- GraphicsDevice.Clear(Color.CornflowerBlue);
+ GraphicsDevice.Clear(Color.Black);
Matrix gameTransform = Matrix.CreateScale(GameScale);
gameTransform.Translation = GameOffset;
GameSprites.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp,
View
2  BlockDefender/BlockDefender/Playground.cs
@@ -69,7 +69,7 @@ public void Draw(SpriteBatch spriteBatch)
public Player SpawnNextPlayer()
{
- return SpawnPlayerAt(Map.Fields[1, 1].Center);
+ return SpawnPlayerAt(Map.Fields[0, new Random().Next(Map.RowCount)].Center);
}
public Player SpawnPlayerAt(Vector2 position)
View
5 BlockDefender/BlockDefender/Terrain/Map.cs
@@ -27,10 +27,7 @@ private void InitializeFields()
{
for (int row = 0; row < RowCount; row++)
{
- if((column % 4 != 2) || (row % 3 != 2))
- Fields[column, row] = new PlainField(column, row);
- else
- Fields[column, row] = new DestructibleField(column, row);
+ Fields[column, row] = new PlainField(column, row);
}
}
}
View
54 BlockDefender/BlockDefender/Terrain/MapGenerator.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BlockDefender.Terrain
+{
+ class MapGenerator
+ {
+ delegate Field SimpleFieldMapper(int column, int row, Field currentValue);
+
+ private Map Map;
+ private Random Random;
+
+ public MapGenerator()
+ : this(Environment.TickCount)
+ { }
+
+ public MapGenerator(int seed)
+ {
+ Random = new Random(seed);
+ }
+
+ public Map Generate(int mapWidth, int mapHeight)
+ {
+ Map = new Map(mapWidth, mapHeight);
+ GenerateBaseTerrain();
+ return Map;
+ }
+
+ private void GenerateBaseTerrain()
+ {
+ ApplyToAllFields(MapBaseTerrain);
+ }
+
+ private void ApplyToAllFields(SimpleFieldMapper mappingFunction)
+ {
+ for (int column = 0; column < Map.ColumnCount; column++)
+ for (int row = 0; row < Map.RowCount; row++)
+ Map.Fields[column, row] = mappingFunction(column, row, Map.Fields[column, row]);
+ }
+
+ private Field MapBaseTerrain(int column, int row, Field currentValue)
+ {
+ double distanceToMid = Math.Abs(column - ((Map.ColumnCount - 1) / 2f));
+ double relativeMidDistance = 2 * distanceToMid / Map.ColumnCount;
+ double wallProbability = (0.5 + Math.Cos(relativeMidDistance * Math.PI) / 2);
+ if (Random.NextDouble() < wallProbability)
+ return new DestructibleField(column, row);
+
+ return currentValue;
+ }
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.