Skip to content

Commit

Permalink
mob stufff
Browse files Browse the repository at this point in the history
  • Loading branch information
jossse69 committed Aug 13, 2023
1 parent 5e96bdd commit 0d4f082
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
37 changes: 17 additions & 20 deletions Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Player : Entity
public int MaxHP = 100;
public int mana = 100;
public int MaxMana = 100;
public int armor = 0;
public int armor = 1;
public int Gold = 0;
private SchedulingSystem _schedulingSystem;
private List<Mob> mobs = new List<Mob>();
Expand All @@ -26,7 +26,7 @@ public class Player : Entity
public Sound DMGsound = new Sound(DMGsoundBuffer);
public static SoundBuffer attacksoundBuffer = new SoundBuffer("attack.wav");
public Sound attacksound = new Sound(attacksoundBuffer);
public Player(Grid<char> grid, Vector2i position, Color fillColor, Color backgroundColor, Color outlineColor, SchedulingSystem schedulingSystem, float outlineThickness = 0, Map map = null, List<Mob> mobs = null)
public Player(Grid<char> grid, Vector2i position, Color fillColor, Color backgroundColor, Color outlineColor, SchedulingSystem schedulingSystem, float outlineThickness = 0, Map map = null)
: base(grid, '@', position, fillColor, backgroundColor, outlineColor, outlineThickness)
{
movementTimer.Start();
Expand All @@ -39,48 +39,48 @@ public Player(Grid<char> grid, Vector2i position, Color fillColor, Color backgro
}

// Add player-specific logic here, such as handling input and movement
public void HandleInput(Map map)
public void HandleInput(Map map, List<Mob> mobs)
{
// Handle player input and update the player's position
if (movementTimer.ElapsedMilliseconds >= MovementDelayMilliseconds)
{
if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad8)) // Numpad 8 for moving up
{
tryToMove(0, -1, map);
tryToMove(0, -1, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad2)) // Numpad 2 for moving down
{
tryToMove(0, 1, map);
tryToMove(0, 1, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad4)) // Numpad 4 for moving left
{
tryToMove(-1, 0, map);
tryToMove(-1, 0, map, mobs);
}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad6)) // Numpad 6 for moving right
{
tryToMove(1, 0, map);
tryToMove(1, 0, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad7)) // Numpad 7 for moving up-left
{
tryToMove(-1, -1, map);
tryToMove(-1, -1, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad9)) // Numpad 9 for moving up-right
{
tryToMove(1, -1, map);
tryToMove(1, -1, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad1)) // Numpad 1 for moving down-left
{
tryToMove(-1, 1, map);
tryToMove(-1, 1, map, mobs);

}
else if (Keyboard.IsKeyPressed(Keyboard.Key.Numpad3)) // Numpad 3 for moving down-right
{
tryToMove(1, 1, map);
tryToMove(1, 1, map, mobs);

}

Expand All @@ -90,7 +90,7 @@ public void HandleInput(Map map)
}
}

public void tryToMove(int x, int y, Map map)
public void tryToMove(int x, int y, Map map, List<Mob> mobs)
{
int newX = Position.X + x;
int newY = Position.Y + y;
Expand All @@ -106,7 +106,7 @@ public void tryToMove(int x, int y, Map map)
if (mob.HP >= 0)
{

mob.TakeDamage(10);
mob.TakeDamage(15);
// play damage sound using SFML
attacksound.Play();
// Update the scheduling system's time
Expand Down Expand Up @@ -155,17 +155,14 @@ public void UpdateMobs(List<Mob> mobs, Map map)
}
}

public void TakeDamage(int damage)
public void TakeDamage(double damage)
{
var DMGmuti = Math.Clamp(RNG.NextSingle(), 0.7, 1.3);
var finalDMG = (int)(damage * (DMGmuti / (armor + 1)));
var DMGmuti = Math.Clamp(RNG.NextDouble(), 0.8, 1);
var finalDMG = (double) damage * (DMGmuti * (armor + 1 - 0.6));

HP -= Math.Clamp(finalDMG, 0, 999999);
this.HP -= (int) Math.Round(Math.Clamp(finalDMG * 1.25, 0, 999999), 1);

DMGsound.Play();

Console.WriteLine(finalDMG);
Console.WriteLine(HP);
}

}
Expand Down
6 changes: 3 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void Main(string[] args)
var Mobs = new List<Mob>();

// add mobs
for (int i = 0; i < 5; i++)
for (int i = 0; i < 2; i++)
{
var mob = new Mob(grid, 'M', FindWalkableCell(gameMap), Color.Black, Color.Red, Color.Black, 35 , 1);
Mobs.Add(mob);
Expand All @@ -53,7 +53,7 @@ static void Main(string[] args)
var upStairs = new Entity(grid, '<', new Vector2i(upStairsPosition.X, upStairsPosition.Y), Color.Black, Color.Yellow, Color.White, 1, gameMap);
var downStairs = new Entity(grid, '>', new Vector2i(downStairsPosition.X, downStairsPosition.Y), Color.Black, Color.Yellow, Color.White, 1, gameMap);

var player = new Player(grid, new Vector2i(upStairsPosition.X, upStairsPosition.Y), Color.Black, Color.Green, Color.White, schedulingSystem, 1, gameMap, Mobs);
var player = new Player(grid, new Vector2i(upStairsPosition.X, upStairsPosition.Y), Color.Black, Color.Green, Color.White, schedulingSystem, 1, gameMap);


// Schedule an action to happen after 12 turns
Expand Down Expand Up @@ -110,7 +110,7 @@ static void Main(string[] args)



player.HandleInput(gameMap); // Handle player input and movement
player.HandleInput(gameMap, Mobs); // Handle player input and movement

window.Display();
}
Expand Down
Binary file modified bin/Debug/net7.0/LilRogue.dll
Binary file not shown.
Binary file modified bin/Debug/net7.0/LilRogue.pdb
Binary file not shown.
37 changes: 25 additions & 12 deletions mob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void Update(Map map, Player player, SchedulingSystem schedulingSystem, Li
{
var state = "wander";
var ToGoalPosition = new Vector2i(0,0);
var lastSeenPlayerPosition = new Vector2i(-1, -1);
if (HP <= 0 || HP > MaxHP)
{
// set char to a bloody red "&"
Expand All @@ -68,32 +69,43 @@ public void Update(Map map, Player player, SchedulingSystem schedulingSystem, Li
//update state
if (CanbeSeen(map))
{
lastSeenPlayerPosition = new Vector2i(player.Position.X, player.Position.Y);
state = "chase";
}
else
else if (lastSeenPlayerPosition.X != -1 && lastSeenPlayerPosition.Y != -1)
{
state = "wander";
}

if (state == "chase"){

for (int i = 0; i < schedulingSystem.calculateTimeSteps(schedulingSystem.time, schedulingSystem.time + 4, 1); i++)
for (int i = 0; i < schedulingSystem.calculateTimeSteps(schedulingSystem.time, schedulingSystem.time + 1, 2); i++)
{
ToGoalPosition = GoToLocation(player.Position.X, player.Position.Y, map);

ToGoalPosition = GoToLocation(lastSeenPlayerPosition.X, lastSeenPlayerPosition.Y, map);
//check if the mob has reached the goal position
foreach (var mob in mobs)
if (ToGoalPosition.X == player.Position.X && ToGoalPosition.Y == player.Position.Y)
{
Console.WriteLine("Goal reached! damaging player...");
player.TakeDamage(5);
Console.WriteLine("player reached! damaging player...");
player.TakeDamage(1.25);
break;
}
else if (ToGoalPosition.X == mob.Position.X && ToGoalPosition.Y == mob.Position.Y) //blocked by another mob
{
Console.WriteLine("blocked by another mob...");;
Console.WriteLine("blocked by another mob...");
break;
}
else if (ToGoalPosition.X == mob.Position.X && ToGoalPosition.Y == mob.Position.Y)
{
Console.WriteLine("cant see player...");
lastSeenPlayerPosition = new Vector2i(-1, -1);
break;
}
else
{
Position = new Vector2i(ToGoalPosition.X, ToGoalPosition.Y);
break;
}
}
}
Expand All @@ -111,29 +123,30 @@ public void Update(Map map, Player player, SchedulingSystem schedulingSystem, Li
if (ToGoalPosition.X == player.Position.X && ToGoalPosition.Y == player.Position.Y)
{
Console.WriteLine("blocked by player...");
break;
}
else if (ToGoalPosition.X == mob.Position.X && ToGoalPosition.Y == mob.Position.Y) //blocked by another mob
{
Console.WriteLine("blocked by another mob...");
break;
}
else
{
Position = new Vector2i(ToGoalPosition.X, ToGoalPosition.Y);
break;
}
}
}
}


public void TakeDamage(int damage)
public void TakeDamage(double damage)
{
var DMGmuti = Math.Clamp(RNG.NextSingle(), 0.7, 1.3);
var finalDMG = (int)(damage * (DMGmuti / (armor + 1)));
var DMGmuti = Math.Clamp(RNG.NextDouble(), 0.8, 1);
var finalDMG = (double) damage * (DMGmuti * (armor + 1 - 0.6));

HP -= Math.Clamp(finalDMG, 0, 999999);
this.HP -= (int) Math.Round(Math.Clamp(finalDMG * 1.25, 0, 999999), 1);

Console.WriteLine(finalDMG);
Console.WriteLine(HP);
}

}
Expand Down

0 comments on commit 0d4f082

Please sign in to comment.