Skip to content

Commit

Permalink
Merge branch 'feature/combat' of https://github.com/c272/campus-crawl
Browse files Browse the repository at this point in the history
…into feature/combat

merges menu
  • Loading branch information
Michael-Perdue committed Mar 6, 2022
2 parents 30558fd + 09b1c8f commit 7df377c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 23 deletions.
10 changes: 3 additions & 7 deletions Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public override void Initialize()

public void CreateAndSetWeapon(Weapon weapon)
{
weapon.Scene = Scene;
weapon.SetLayer(Layer);
weapon.SetCharacter(this);
weapon.Spawn(Position);

weapon.PickedUp();
Expand Down Expand Up @@ -178,10 +177,12 @@ public void scanAndPickUpEntities()
{
// This means, we have an entity that we can pick up.
entity.PickedUp();
entity.Initialise(Scene, Layer);

if (entity is Weapon)
{
weapon = (Weapon)entity;
weapon.SetCharacter(this);
}
}
}
Expand Down Expand Up @@ -216,11 +217,6 @@ public override void Update(GameTime delta)
} else
{
attacking = false;
if (!isEnemy)
{
Position = new Vector2(Position.X + (movement.Value.X * time * speed), Position.Y + (movement.Value.Y * time * speed));
doNotPickUp = null;
}
}
}

Expand Down
32 changes: 25 additions & 7 deletions Characters/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ private float clamp(float val, float min, float max)

public void spawnRandomWeapon()
{
Fists e = new Fists(this);
e.Scene = Scene;
e.SetLayer(Layer);
e.Spawn(Position);
Fists e = new Fists();
e.SetCharacter(this);
}

public void respawn()
Expand Down Expand Up @@ -146,6 +144,7 @@ private void handlePrimaryAttack(MouseState mouseState)

private int rightButtonHeld = 0;
private bool rightButtonReleased = false;
private bool isLunging = false;
private void handleSecondaryAttack(MouseState mouseState)
{
if (rightButtonHeld > 0 && mouseState.RightButton == ButtonState.Released)
Expand All @@ -162,6 +161,7 @@ private void handleSecondaryAttack(MouseState mouseState)
float yMovement = prepareDirection[1];

Position = new Vector2(Position.X + xMovement, Position.Y + yMovement);
isLunging = true;
}
}
else if (rightButtonReleased)
Expand All @@ -176,6 +176,7 @@ private void handleSecondaryAttack(MouseState mouseState)
});
attacking = true;
((Fists)weapon).Lunge(clamp(rightButtonHeld / 10, 0, 20),true);
isLunging = false;
}
rightButtonHeld = 0;
rightButtonReleased = false;
Expand Down Expand Up @@ -203,23 +204,40 @@ public override void Update(GameTime delta)
var movement = InputHandler.GetEvent("Movement");
var mouseState = Mouse.GetState();
DiagnosticsHook.DebugMessage(damage.ToString());
Vector2 mousePos = Scene.ToGridLocation(mouseState.Position);
Vector2 deltaPos = new Vector2((mousePos.X - Position.X), -(mousePos.Y - Position.Y));
DiagnosticsHook.DebugMessage(deltaPos.ToString());

if(health <= 0)
double personAngle = Math.Atan2(deltaPos.Y, deltaPos.X);
//double personAngle = Math.Atan(tanAngle);
//DiagnosticsHook.DebugMessage("Tan angle = " + tanAngle);
//DiagnosticsHook.DebugMessage("Person angle = " + personAngle);
float radianAngle = (float)((Math.PI / 180) * personAngle);
DiagnosticsHook.DebugMessage("Radian angle = " + radianAngle);
//sprite.Rotation = radianAngle;

if (health <= 0)
{
respawn();
} else
{
handleAttack(mouseState);
}
if (!pushStats.isPushed()&&attacking)
if (!pushStats.isPushed() && attacking)
{
attacking=false;
}

if (!pushStats.isPushed() && !isLunging)
{
Position = new Vector2(Position.X + (movement.Value.X * time * speed), Position.Y + (movement.Value.Y * time * speed));
doNotPickUp = null;
}

healthBar.Value = health / 100;
healthCount.Text = health.ToString() + " / " + 100;
scoreCount.Text = "Score: " + score.ToString();
Scene.LookAt(Position);
}
}

}
6 changes: 6 additions & 0 deletions Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public Entity(string assetPath)
AddComponent(sprite);
}

public void Initialise(Scene scene, int layer)
{
Scene = scene;
SetLayer(layer);
}

public void SetLocation(int x, int y)
{
Position = Scene.TileToGridLocation(new Point(x, y));
Expand Down
19 changes: 14 additions & 5 deletions Entities/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ public abstract class Weapon : Entity
protected bool isAttacking = false;

protected Character character;
public Weapon(Character character, string assetPath, string name) : base(assetPath)
public Weapon(string assetPath, string name) : base(assetPath)
{
this.name = name;
}

public void SetCharacter(Character character)
{
this.character = character;
this.playerModel = character.playerModelPath;
string modelWithoutExtension = playerModel.Replace(".png", "");
restingModel = modelWithoutExtension + "_" + name + "_Resting.png";
attackedModel = modelWithoutExtension + "_" + name + "_Attacked.png";
if (character != null)
{
Initialise(character.Scene, character.Layer);
playerModel = character.playerModelPath;
string modelWithoutExtension = playerModel.Replace(".png", "");
restingModel = modelWithoutExtension + "_" + name + "_Resting.png";
attackedModel = modelWithoutExtension + "_" + name + "_Attacked.png";
}
}

public override void PickedUp()
Expand Down
2 changes: 1 addition & 1 deletion Entities/Weapons/Fists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace CampusCrawl.Entities.Weapons
internal class Fists : Weapon
{
int lungeSize = 10;
public Fists(Character character) : base(character, "Assets/Fists.png", "Fists")
public Fists() : base("Assets/Fists.png", "Fists")
{
damage = 1;
range = 1;
Expand Down
2 changes: 1 addition & 1 deletion Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void startGame(Point location)
TileEngine.Instance.GetScene().CameraPosition = new Vector2(-320, -320);
mainPlayer.SetLayer("Objects");
BaseScene scene = (BaseScene)TileEngine.Instance.GetScene();
mainPlayer.CreateAndSetWeapon(new Fists(mainPlayer));
mainPlayer.CreateAndSetWeapon(new Fists());
}
public override void Initialize()
{
Expand Down
2 changes: 1 addition & 1 deletion Scenes/BaseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void spawnEnemy(int amount, int[] rangeX, int[] rangeY, int layer,int ene
newEnemy = new EnemySprint(directions[random.Next(directions.Count())], random.Next(30), TileToGridLocation(enemyPos));
TileEngine.Instance.GetScene().AddObject(newEnemy);
newEnemy.SetLayer("Objects");
newEnemy.CreateAndSetWeapon(new Fists(newEnemy));
newEnemy.CreateAndSetWeapon(new Fists());
}
}

Expand Down

0 comments on commit 7df377c

Please sign in to comment.