Skip to content

Commit

Permalink
added player DEATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jossse69 committed Aug 13, 2023
2 parents 0d4f082 + c899ffe commit 7873e78
Show file tree
Hide file tree
Showing 186 changed files with 49 additions and 2,637 deletions.
29 changes: 29 additions & 0 deletions Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ public class Player : Entity
public Random RNG = new Random();

private Stopwatch movementTimer = new Stopwatch();
private Stopwatch deathwindowTimer = new Stopwatch();
private const int MovementDelayMilliseconds = 100; // Adjust this value to control movement speed
public int HP = 100;
public int MaxHP = 100;
public int mana = 100;
public int MaxMana = 100;
public int armor = 1;
public int Gold = 0;
public bool isDead = false;
public bool showdeathwindow = false;
private SchedulingSystem _schedulingSystem;
private List<Mob> mobs = new List<Mob>();

Expand Down Expand Up @@ -86,12 +89,20 @@ public void HandleInput(Map map, List<Mob> mobs)

// Reset the movement timer
movementTimer.Restart();
//update player
Update();

}
}

public void tryToMove(int x, int y, Map map, List<Mob> mobs)
{
//dont move if the player is dead
if (isDead)
{
return;
}

int newX = Position.X + x;
int newY = Position.Y + y;

Expand Down Expand Up @@ -165,5 +176,23 @@ public void TakeDamage(double damage)
DMGsound.Play();
}

public void Update()
{
//dead
if (HP <= 0)
{
isDead = true;
this.Symbol = '&';
this.BackgroundColor = Color.Black;
this.FillColor = Color.Red;
//wait a bit
deathwindowTimer.Start();
if (deathwindowTimer.ElapsedMilliseconds >= 1000)
{
showdeathwindow = true;
}
}
}

}
}
20 changes: 19 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ static void Main(string[] args)

//UI and ui grid
var UIgrid = new Grid<char> (UIWidth, UIHeight);
var popupwindowgrid = new Grid<char> (mapWidth, mapHeight);
var ui = new UI(UIgrid);

var popupui = new UI(popupwindowgrid);
var upStairsPosition = FindWalkableCell(gameMap);
var downStairsPosition = FindWalkableCell(gameMap);

Expand Down Expand Up @@ -104,9 +105,26 @@ static void Main(string[] args)
// draw gold value
UIgrid.WriteString(15, 1, "Gold: " + player.Gold, Color.Black, Color.Yellow, Color.Black, 1, c => c);

//if player showdeathwindow is true, draw death window
if (player.showdeathwindow == true)
{
popupui.DrawBorderedBox(0, 0, 40, 10, Color.Black, Color.White);
popupwindowgrid.WriteString(18, 0, ":(", Color.Black, Color.Red, Color.Black, 1, c => c);
popupwindowgrid.WriteString(3, 1, "well... looks like you died", Color.Black, Color.White, Color.Black, 1, c => c);
popupwindowgrid.WriteString(14, 9, "[press enter]", Color.Black, Color.White, Color.Black, 1, c => c);

//on enter, close game
if (Keyboard.IsKeyPressed(Keyboard.Key.Enter))
{
window.Close();
break;
}
}

// Render the grid
grid.Draw(window, font, gameMap, 0, 0);
UIgrid.Draw(window, font, null, 0, 30);
popupwindowgrid.Draw(window, font, null, 5, 15);



Expand Down
Loading

0 comments on commit 7873e78

Please sign in to comment.