Skip to content

Commit

Permalink
made it so enemies can dash
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Perdue committed Mar 8, 2022
1 parent 3dba851 commit 268fa9d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
11 changes: 6 additions & 5 deletions Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Character : GameObject
protected SpriteComponent sprite;
protected float speed;
public float health;
protected bool attacking;
public bool attacking;
public Push pushStats = new Push(0, 0);
public float[] attackDirection;
public float damage;
Expand Down Expand Up @@ -156,7 +156,6 @@ public float[] mouseDirection()

public void PushSelf(int x, int y)
{
DiagnosticsHook.DebugMessage("Pushing self");
pushStats.setPush(x, y);
}

Expand Down Expand Up @@ -202,15 +201,16 @@ public override void Update(GameTime delta)
pushStats.checkPush();
if (pushStats.isPushed())
{
DiagnosticsHook.DebugMessage("a");
if (attacking)
{

/*
if(!weapon.Attack(true,!isEnemy))
{

DiagnosticsHook.DebugMessage("b");
attacking = false;
pushStats.reset();
}
}*/
}

pushEffect(time);
Expand Down Expand Up @@ -241,6 +241,7 @@ public void pushEffect(float time)
{
if (!weapon.checkAttack(new Vector2(Position.X + xPushAmt, Position.Y + yPushAmt),!isEnemy))
{
DiagnosticsHook.DebugMessage("d");
attacking = false;
pushStats.reset();
}
Expand Down
25 changes: 13 additions & 12 deletions Characters/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Enemy(string directionName, float distance, Vector2 location)
AddComponent(sprite);
heavyAttackCooldown = new Timer(5f);
heavyAttackCooldown.OnTick += heavyAttack;
heavyAttackCooldown.Loop = true;
attackCooldown = new Timer(0.5f);
attackCooldown.OnTick += attack;
attackCooldown.Loop = true;
Expand Down Expand Up @@ -328,7 +329,7 @@ public float[] playerDirection()

private void attack()
{
if (playerInView(40,true) && player.pushStats.isPushed() == false && player.attacking == false)
if (playerInView(40,true) && player.pushStats.isPushed() == false && player.attacking == false && !attacking)
{
//attacking = true;
if (weapon != null)
Expand All @@ -342,14 +343,19 @@ private void attack()

private void heavyAttack()
{
if (playerInView(90, true) && player.pushStats.isPushed() == false && player.attacking == false)

if (playerInView(120, true) && player.pushStats.isPushed() == false && player.attacking == false)
{
attacking = true;
if (weapon != null)
{
attackDirection = playerDirection();
((Fists)weapon).Lunge(1f, false);
heavyAttackCooldown.Reset();
attacking = true;
float[] prepareDirection = playerDirection();
float xMovement = -prepareDirection[0];
float yMovement = -prepareDirection[1];
Position = new Vector2(Position.X + xMovement, Position.Y + yMovement);
attackDirection = prepareDirection;
((Fists)weapon).Lunge(0.04f, false);
//heavyAttackCooldown.Reset();

}
}
Expand All @@ -372,13 +378,8 @@ public override void Update(GameTime delta)
if (!pushStats.isPushed() && attacking)
{
attacking = false;
}/*
if(!heavyAttackCooldown.Running)
{
DiagnosticsHook.DebugMessage("aaaaa");
heavyAttack();
}
heavyAttackCooldown.Update(delta);*/
heavyAttackCooldown.Update(delta);
timerPath.Update(delta);
attackCooldown.Update(delta);
var time = (float)(delta.ElapsedGameTime.TotalSeconds);
Expand Down
4 changes: 2 additions & 2 deletions Characters/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ public override void Update(GameTime delta)
var mouseState = Mouse.GetState();
Vector2 mousePos = Scene.ToGridLocation(mouseState.Position);
Vector2 deltaPos = new Vector2((mousePos.X - Position.X), -(mousePos.Y - Position.Y));
DiagnosticsHook.DebugMessage(deltaPos.ToString());
//DiagnosticsHook.DebugMessage(deltaPos.ToString());

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);
//DiagnosticsHook.DebugMessage("Radian angle = " + radianAngle);
//sprite.Rotation = radianAngle;

if (health <= 0)
Expand Down
12 changes: 9 additions & 3 deletions Entities/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public bool checkAttack(Vector2 newPos,bool player)
hit = true;
}
}
if (hit) { return true; }
if (hit) {
character.attacking = false;
return true;
}
return false;
}

Expand All @@ -180,7 +183,8 @@ public virtual bool Attack(bool lungeAttack,bool player)
{
if (Math.Abs(enemy.Position.X - character.Position.X) < 40 && Math.Abs(enemy.Position.Y - character.Position.Y) < 40)
{
enemy.onDamage(damage * character.damage, character.attackDirection, (int)(knockback * 1.5));
DiagnosticsHook.DebugMessage("a");
enemy.onDamage(damage * character.damage, character.attackDirection, (int)(knockback * 1.5));
isAttacking = false;
}
}
Expand All @@ -194,8 +198,10 @@ public virtual bool Attack(bool lungeAttack,bool player)
}
}

if(isAttacking)
if (isAttacking)
{
return false;
}

return true;
}
Expand Down

0 comments on commit 268fa9d

Please sign in to comment.