Skip to content

Commit

Permalink
Added code to clear rocks from path. Added code to rotate text and nu…
Browse files Browse the repository at this point in the history
…mbers. Added UI class.
  • Loading branch information
LanceJZ committed Jan 12, 2018
1 parent 6b2d59e commit 596f6fb
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 43 deletions.
3 changes: 2 additions & 1 deletion CFNGamejam2/CFNGamejam2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<AssemblyFileVersionSettings>MMddStamp.DayOfYearStamp.MonthStamp.TimeStamp</AssemblyFileVersionSettings>
<AssemblyInfoVersionSettings>YearStamp.DateStamp.DeltaDayStamp.Increment</AssemblyInfoVersionSettings>
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
<AssemblyVersion>1.560.11.0101</AssemblyVersion>
<AssemblyVersion>1.616.12.0101</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -88,6 +88,7 @@
<Compile Include="Entities\Player.cs" />
<Compile Include="Entities\Rock.cs" />
<Compile Include="Entities\TankShot.cs" />
<Compile Include="Entities\UI.cs" />
<Compile Include="Entities\Wall.cs" />
<Compile Include="Game1.cs" />
<Compile Include="GameLogic.cs" />
Expand Down
7 changes: 6 additions & 1 deletion CFNGamejam2/Engine/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public Camera(Game game, Vector3 position, Vector3 target, Vector3 rotation, boo
else
{
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
(float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height, near, far);
(float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height,
near, far);
}
}
#endregion
Expand Down Expand Up @@ -75,6 +76,10 @@ public override void Update(GameTime gameTime)
cameraRotation = Matrix.CreateFromAxisAngle(cameraRotation.Forward, Rotation.Z)
* Matrix.CreateFromAxisAngle(cameraRotation.Right, Rotation.X)
* Matrix.CreateFromAxisAngle(cameraRotation.Up, Rotation.Y);

//This reads the camera rotation.


// If Orthographic make sure the camera is always pointing forward.
if (Orthographic)
Target = Position + cameraRotation.Forward;
Expand Down
29 changes: 29 additions & 0 deletions CFNGamejam2/Engine/Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Numbers : GameComponent, IUpdateableComponent, ILoadContent, IBegin
XnaModel[] NumberXNAModels = new XnaModel[10];
List<AModel> NumberModels = new List<AModel>();
public Vector3 Position = Vector3.Zero;
public Vector3 Rotation = Vector3.Zero;
float Scale;

public Numbers(Game game) : base(game)
Expand Down Expand Up @@ -42,6 +43,12 @@ public void BeginRun()

}

public void ProcessNumber(int number, Vector3 locationStart, Vector3 rotation, float scale)
{
Rotation = rotation;
ProcessNumber(number, locationStart, scale);
}

public void ProcessNumber(int number, Vector3 locationStart, float scale)
{
Position = locationStart;
Expand Down Expand Up @@ -76,6 +83,7 @@ public void ChangeNumber(int number)
} while (numberIn > 0);

ChangePosition();
ChangeRotation();
}

public void ChangePosition()
Expand All @@ -90,6 +98,27 @@ public void ChangePosition()
}
}

public void Change(Vector3 position, Vector3 rotation)
{
ChangePosition(position);
ChangeRotation(rotation);
}

public void ChangeRotation()
{
foreach(AModel number in NumberModels)
{
number.Rotation = Rotation;
number.MatrixUpdate();
}
}

public void ChangeRotation(Vector3 rotation)
{
Rotation = rotation;
ChangeRotation();
}

public void ChangePosition(Vector3 position)
{
Position = position;
Expand Down
23 changes: 23 additions & 0 deletions CFNGamejam2/Engine/Words.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Words : GameComponent, IUpdateableComponent, ILoadContent, IBeginab
float Scale;
int TextSize;
public Vector3 Position = Vector3.Zero;
public Vector3 Rotation = Vector3.Zero;

public Words (Game game) : base(game)
{
Expand Down Expand Up @@ -90,6 +91,28 @@ public void ChangeWords(string words)
}

ChangePosition();
ChangeRotation();
}

public void Change(Vector3 position, Vector3 rotation)
{
ChangePosition(position);
ChangeRotation(rotation);
}

public void ChangeRotation()
{
foreach (AModel number in WordModels)
{
number.Rotation = Rotation;
number.MatrixUpdate();
}
}

public void ChangeRotation(Vector3 rotation)
{
Rotation = rotation;
ChangeRotation();
}

public void ChangePosition()
Expand Down
10 changes: 1 addition & 9 deletions CFNGamejam2/Entities/EnemyControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@ public void LoadContent()

public void BeginRun()
{
//TheDuck.Position.X = 300;
//TheDuck.Position.Y = 200;
//TheDuck.Position.Z = -600;

int border = RefGameLogic.RefGround.TheBorder;

for (int i = 0; i < 4; i++)
SpawnDuck(new Vector3(Services.RandomMinMax(-border, border), 200, border));

//TheBattery.Position.X = -200;
//TheBattery.Position.Y = 20;
//TheBattery.Position.Z = -400;
SpawnDuck(new Vector3(Services.RandomMinMax(-border, border), 200, border + 500));

TheGateway.Position.Z = -1000;
TheGateway.Position.Y = 20;
Expand Down
144 changes: 114 additions & 30 deletions CFNGamejam2/Entities/Ground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Ground : GameComponent, IBeginable, IUpdateableComponent, ILoadCont
XnaModel MountainTilesModel;
XnaModel WaterTileModel;

Vector3 Position;
int Border;

public int TheBorder { get => Border; }
Expand Down Expand Up @@ -126,45 +127,33 @@ public void BeginRun()
}
}

for (int i = 0; i < 10; i++)
{
ExtraLargeRocks.Add(new Rock(Game, RefGameLogic));
ExtraLargeRocks.Last().SetModel(ExtraLargeRockModel);
SpawnExtraLargeRock(ExtraLargeRocks.Last());
}

for (int i = 0; i < 30; i++)
{
Vector3 loc;
Vector3 rot;
LargeRocks.Add(new Rock(Game, RefGameLogic));
LargeRocks.Last().SetModel(LargeRockModel);
loc = new Vector3(Services.RandomMinMax(-Border - 100, Border - 100),
Services.RandomMinMax(-20, -10), Services.RandomMinMax(-Border - 100, Border - 100));
rot = new Vector3(Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi), Services.RandomMinMax(0, MathHelper.Pi));
LargeRocks.Last().Spawn(loc, rot);
SpawnLargeRock(LargeRocks.Last());

MedRocks.Add(new Rock(Game, RefGameLogic));
MedRocks.Last().SetModel(MedRockModel);
loc = new Vector3(Services.RandomMinMax(-Border - 60, Border - 60),
Services.RandomMinMax(-15, -5), Services.RandomMinMax(-Border - 60, Border - 60));
rot = new Vector3(Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi), Services.RandomMinMax(0, MathHelper.Pi));
MedRocks.Last().Spawn(loc, rot);
SpawnMedRock(MedRocks.Last());

SmallRocks.Add(new Rock(Game, RefGameLogic));
SmallRocks.Last().SetModel(SmallRockModel);
loc = new Vector3(Services.RandomMinMax(-Border, Border),
Services.RandomMinMax(-10, -2), Services.RandomMinMax(-Border, Border));
rot = new Vector3(Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi), Services.RandomMinMax(0, MathHelper.Pi));
SmallRocks.Last().Spawn(loc, rot);
SpawnSmallRock(SmallRocks.Last());
}

for (int i = 0; i < 10; i++)
{
Vector3 loc;
Vector3 rot;
ExtraLargeRocks.Add(new Rock(Game, RefGameLogic));
ExtraLargeRocks.Last().SetModel(ExtraLargeRockModel);
loc = new Vector3(Services.RandomMinMax(-Border / 2, Border / 2),
Services.RandomMinMax(-30, -10), Services.RandomMinMax(-Border / 2, Border / 2));
rot = new Vector3(Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi), Services.RandomMinMax(0, MathHelper.Pi));
ExtraLargeRocks.Last().Spawn(loc, rot);
}
Vector3[] path = new Vector3[2];
path[0] = new Vector3(0, -11, -Border);
path[1] = new Vector3(0, -11, Border);

ClearPath(path);
}

public override void Update(GameTime gameTime)
Expand All @@ -173,9 +162,104 @@ public override void Update(GameTime gameTime)
base.Update(gameTime);
}

public void ClearPath(Vector3 start, Vector3 end)
public void ClearPath(Vector3[] path)
{
bool working = true;
float radius = 200;

while(working)
{
working = false;
Position = path[0];

foreach (Vector3 spot in path)
{
while (!MoveTowardsPoint(spot))
{
foreach (Rock rock in ExtraLargeRocks)
{
if (rock.CirclesIntersect(spot, radius))
{
working = true;
SpawnExtraLargeRock(rock);
}
}

foreach (Rock rock in LargeRocks)
{
if (rock.CirclesIntersect(spot, radius))
{
working = true;
SpawnLargeRock(rock);
}
}

foreach (Rock rock in MedRocks)
{
if (rock.CirclesIntersect(spot, radius))
{
working = true;
SpawnMedRock(rock);
}
}

foreach (Rock rock in SmallRocks)
{
if (rock.CirclesIntersect(spot, radius))
{
working = true;
SpawnSmallRock(rock);
}
}
}
}
}
}

bool MoveTowardsPoint(Vector3 goal)
{
if (Position == goal)
return true;

Vector3 direction = Vector3.Normalize(goal - Position);
Position += direction * 0.1f;

//if (Math.Abs(Vector3.Dot(direction, Vector3.Normalize(goal - Position)) + 1) < 0.1f)
// Position = goal; //Does the same as below, but would take more CPU.

if (Vector3.Distance(direction, Vector3.Normalize(Position - goal)) < 0.1f)
Position = goal;

return Position == goal;
}

void SpawnExtraLargeRock(Rock rock)
{
SpawnRock(rock, -30, -10, Border / 2);
}

void SpawnLargeRock(Rock rock)
{
SpawnRock(rock, -20, -10, Border - 100);
}

void SpawnMedRock(Rock rock)
{
SpawnRock(rock, -15, -5, Border - 60);
}

void SpawnSmallRock(Rock rock)
{
SpawnRock(rock, -10, -2, Border - 20);
}

void SpawnRock(Rock rock, int hightMin, int hightMax, int border)
{
rock.Spawn(new Vector3(Services.RandomMinMax(-border, border),
Services.RandomMinMax(hightMin, hightMax), Services.RandomMinMax(-border, border)),
new Vector3(Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi),
Services.RandomMinMax(0, MathHelper.Pi)));
}
}
}
Loading

0 comments on commit 596f6fb

Please sign in to comment.