Skip to content

Commit

Permalink
feat: Implemented Pausing and Playing, Cleaned up UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris66 committed Jul 29, 2023
1 parent 18483e3 commit 1290e85
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Binary file added font.ttf
Binary file not shown.
47 changes: 39 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,43 @@

int main()
{
int windowWidth = 1200;
int windowHeight = 800;
// Global Variables
int windowWidth = 700;
int windowHeight = 700;

int sideBarWidth = 400;
int titleHeight = 100;
int sideBarGap = 50;
int titleHeight = 75;

int width = 600;
int height = 600;

int size = 40;

int x = width / size;
int y = height / size;
// Game Variables
bool paused = false;

// Create the main window
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Game of Life");
window.setKeyRepeatEnabled(false);

// Create Grid
int x = width / size;
int y = height / size;

Grid grid(size, sideBarGap, titleHeight, x, y);

Grid grid(size, sideBarWidth, titleHeight, x, y);
// Create Font
sf::Font font;
font.loadFromFile("font.ttf");

// Title Text
sf::Text title;
title.setFont(font);
title.setString("Game Of Life");
title.setCharacterSize(32);
title.setPosition(windowWidth / 2 - 100, 15);

// Create Clock
sf::Clock clock;
// Main Loop
while (1 == window.isOpen())
Expand All @@ -34,11 +54,22 @@ int main()
{
window.close();
}

if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::P)
{
paused = !paused;
}
}
}

window.clear(sf::Color::Black);

if (clock.getElapsedTime().asSeconds() > 1.0f)
// Draw Text
window.draw(title);

if (clock.getElapsedTime().asSeconds() > 1.0f && !paused)
{
grid.update();
clock.restart();
Expand Down
Binary file modified main.o
Binary file not shown.
Binary file modified run
Binary file not shown.

0 comments on commit 1290e85

Please sign in to comment.