Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/c272/campus-crawl
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj committed Mar 17, 2022
2 parents 0ddf39c + 1f123e8 commit 95a1f97
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 57 deletions.
69 changes: 30 additions & 39 deletions Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,41 @@ public struct Push
{
public Push(int x, int y)
{
X = x;
Y = y;
currX = 1;
currY = 1;
}
public int X { get; set; }
public int Y { get; set; }
public int currX { get; set; }
public int currY { get; set; }
public bool IsPushed() { return !(X == 0 && Y == 0); }
public void Reset() { X = 0; Y = 0; currX = 1; currY = 1; }
Value = new Vector2(x, y);
Current = Vector2.One;
}
public Vector2 Value { get; set; }
public Vector2 Current { get; set; }
public bool IsPushed => !(Value.X == 0 && Value.Y == 0);

public void Reset()
{
Value = Vector2.Zero;
Current = Vector2.One;
}

public void SetPush(int x, int y)
{
X = x;
Y = y;
Value = new Vector2(x, y);
if (x < 0)
{
currX = -1;
}
Current = new Vector2(-1, Current.Y);
if (y < 0)
{
currY = -1;
}
Current = new Vector2(Current.X, -1);
}

public void DoneXPush()
{
if (currX < 0) { currX--; } else { currX++; }
}
public void DoneYPush()
{
if (currY < 0) { currY--; } else { currY++; }
}
public void DoneXPush() => Current = new Vector2(Current.X + Current.X < 0 ? -1 : 1, Current.Y);
public void DoneYPush() => Current = new Vector2(Current.X, Current.Y + Current.Y < 0 ? -1 : 1);
public void CheckPush()
{
if (Math.Abs(currX) == Math.Abs(X))
if (Math.Abs(Current.X) == Math.Abs(Value.X))
{
currX = 1;
X = 0;
Current = new Vector2(1, Current.Y);
Value = new Vector2(0, Value.Y);
}
if (Math.Abs(currY) == Math.Abs(Y))
if (Math.Abs(Current.Y) == Math.Abs(Value.Y))
{
currY = 1;
Y = 0;
Current = new Vector2(Current.X, 1);
Value = new Vector2(Value.X, 0); ;
}
}
}
Expand Down Expand Up @@ -206,7 +197,7 @@ public override void Update(GameTime delta)

// Code to move/push
pushStats.CheckPush();
if (pushStats.IsPushed())
if (pushStats.IsPushed)
{
PushEffect(time);
} else
Expand All @@ -218,18 +209,18 @@ public override void Update(GameTime delta)
public void PushEffect(float time)
{
pushStats.CheckPush();
if (pushStats.IsPushed() == true)
if (pushStats.IsPushed)
{
float xPushAmt = 0;
float yPushAmt = 0;
if (pushStats.X != 0)
if (pushStats.Value.X != 0)
{
xPushAmt = pushStats.currX * time * speed;
xPushAmt = pushStats.Current.X * time * speed;
pushStats.DoneXPush();
}
if (pushStats.Y != 0)
if (pushStats.Value.Y != 0)
{
yPushAmt = pushStats.currY * time * speed;
yPushAmt = pushStats.Current.Y * time * speed;
pushStats.DoneYPush();
}
if (attacking)
Expand Down
26 changes: 14 additions & 12 deletions Scenes/AlexandraSquare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,29 @@ public class AlexandraSquare : BaseScene
public override void Initialize()
{
base.Initialize();

//Load background sound.
SoundReference loadedSound = TileEngine.Instance.Sound.LoadSound("Sound/birdSound.mp3");
SoundInstance soundInstance = TileEngine.Instance.Sound.PlaySound(loadedSound);
soundInstance.Looping = true;
soundInstance.Volume = 0.3f;

//Set up the spawn cooldown.
spawnCooldown = new Timer(10f);
spawnCooldown.OnTick += spawnReset;
spawnCooldown.OnTick += SpawnReset;
spawnCooldown.Loop = true;
spawnCooldown.Start();

//Add wave information for the scene.
waveInfo = new Label();
waveInfo.FontSize = 32;
waveInfo.Colour = Color.Black;
waveInfo.Anchor = UIAnchor.Right | UIAnchor.Top;
timeStart = (int)(DateTime.UtcNow - new DateTime(1000, 1, 1)).TotalSeconds;
UI.AddElement(waveInfo);
//...
}

public void spawnReset()
public void SpawnReset()
{
timeStart = (int)(DateTime.UtcNow - new DateTime(1000, 1, 1)).TotalSeconds;
if (player != null && timed)
Expand All @@ -52,7 +57,7 @@ public void spawnReset()
}
}

public void waveReset()
public void WaveReset()
{
if(waveCounter != 1)
TileEngine.Instance.Sound.PlaySound(TileEngine.Instance.Sound.LoadSound("Sound/waveDone.mp3"));
Expand All @@ -66,9 +71,9 @@ public void waveReset()
player.health = 100;
else
player.health += 30;
spawnEnemy(waveCounter *2, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer,0);
spawnEnemy((int)waveCounter /2, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer, 1);
spawnEnemy((int)waveCounter/3, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer, 2);
SpawnEnemy(waveCounter *2, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer,0);
SpawnEnemy((int)waveCounter /2, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer, 1);
SpawnEnemy((int)waveCounter/3, new int[] { -10, 69 }, new int[] { -8, 6 }, player.Layer, 2);
timeStart = (int)(DateTime.UtcNow - new DateTime(1000, 1, 1)).TotalSeconds;
}

Expand All @@ -78,20 +83,17 @@ public override void Update(GameTime delta)
if (!paused)
{
if (player == null)
{
player = (Player)this.GameObjects.Where(x => x is Player).FirstOrDefault();
}
player = (Player)GameObjects.Where(x => x is Player).FirstOrDefault();

var enemies = this.GameObjects.Where(x => x is Enemy);
waveInfo.Text = "Wave " + waveCounter.ToString() + " Enemies left: " + enemies.Count().ToString();
if (this.GameObjects.Where(x => x is Enemy).FirstOrDefault() == null && TileEngine.Instance.GetScene() != null)
{
waveCounter++;
waveReset();
WaveReset();
}
spawnCooldown.Update(delta);
}
//...
}

[EventFunction("OnShelteredArea")]
Expand Down
13 changes: 7 additions & 6 deletions Scenes/BaseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@ namespace CampusCrawl.Scenes
{
public abstract class BaseScene : Scene
{
//Static random to avoid re-seeding unnecessarily.
private static Random random = new Random();

public int waveCounter = 0;
public Boolean paused = false;
public override void Initialize()
{
base.Initialize();
//...
}

public override void Update(GameTime delta)
{
base.Update(delta);
//...
}

public void spawnEnemy(int amount, int[] rangeX, int[] rangeY, int layer,int enemyType)
public void SpawnEnemy(int amount, Point rangeX, Point rangeY, int layer,int enemyType)
{
if (amount != 0)
{
string[] directions = new string[] { "up", "down", "left", "right" };
List<Point> spawnableTiles = new List<Point>();
for (int x = rangeX[0]; x < rangeX[1]; x++)
for (int x = rangeX.X; x < rangeX.Y; x++)
{
for (int y = rangeY[0]; y < rangeY[1]; y++)
for (int y = rangeY.X; y < rangeY.Y; y++)
{
if (!Map.Layers.Where(a => a.ID == layer).FirstOrDefault().CollisionHull.ContainsKey(new Point(x, y)))
{
spawnableTiles.Add(new Point(x, y));
}
}
}
Random random = new Random();

for (int x = 0; x < amount; x++)
{
var index = random.Next(spawnableTiles.Count);
Expand Down

0 comments on commit 95a1f97

Please sign in to comment.