Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rommmmaha committed Jun 8, 2024
1 parent 0b41997 commit f4a5efd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
48 changes: 29 additions & 19 deletions client/game.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "game.hpp"
#include "iostream"
#include "myfunc.hpp"
game::game()
{
Expand All @@ -18,8 +17,6 @@ game::game()
damaged.setBuffer(sb_damaged);
captured.setBuffer(sb_captured);

intro.setVolume(10.f);

font.loadFromFile("resources/04B_30__.TTF");

_RenderWindow = new sf::RenderWindow(sf::VideoMode(800, 600), "xonix-x", sf::Style::Titlebar | sf::Style::Close);
Expand All @@ -28,12 +25,41 @@ game::game()
firstStart = true;
}

bool game::isRunning() const
{
return running;
}

void game::close()
{
clear();
_RenderWindow->close();
}

int game::count_walls() const
{
int count = 0;
for (int i = 0; i < map_size.x; ++i)
for (int j = 0; j < map_size.y; ++j)
if (map[pos2index(i, j, map_size.x)] == 1)
++count;
return count;
}

void game::update_tmp_map()
{
for (size_t i = 0; i < map_size.z; ++i)
tmp_map[i] = map[i];
}

void game::clear()
{
if (map != nullptr)
delete map;
if (tmp_map != nullptr)
delete tmp_map;
map = nullptr;
tmp_map = nullptr;
leftNeighbours.clear();
rightNeighbours.clear();
}
Expand Down Expand Up @@ -462,19 +488,3 @@ void game::draw()
// - Display
_RenderWindow->display();
}

int game::count_walls() const
{
int count = 0;
for (int i = 0; i < map_size.x; ++i)
for (int j = 0; j < map_size.y; ++j)
if (map[pos2index(i, j, map_size.x)] == 1)
++count;
return count;
}

void game::update_tmp_map()
{
for (size_t i = 0; i < map_size.z; ++i)
tmp_map[i] = map[i];
}
9 changes: 5 additions & 4 deletions client/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ class game
{
public:
game();
void clear();
void draw_intro();

void init();
void update();
void draw();
void close();

bool running;
bool isRunning() const;
bool needInitialization;

private:
bool running;
bool firstStart;
int fps;
int number_of_enemies;
Expand Down Expand Up @@ -47,13 +47,14 @@ class game
sf::SoundBuffer sb_intro;
sf::SoundBuffer sb_damaged;
sf::SoundBuffer sb_captured;
sf::SoundBuffer sb_dead;

sf::Sound intro;
sf::Sound damaged;
sf::Sound captured;

sf::Font font;

int count_walls() const;
void update_tmp_map();
void clear();
};
4 changes: 2 additions & 2 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
int main()
{
game _game;
while (_game.running)
while (_game.isRunning())
{
if (_game.needInitialization)
_game.init();
_game.update();
_game.draw();
}
_game.clear();
_game.close();
return 0;
}
int WinMain()
Expand Down
15 changes: 0 additions & 15 deletions client/myfunc.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
#pragma once
#include "SFML/System.hpp"
#include <vector>
// min max
template <typename T> T min(T a, T b)
{
return a < b ? a : b;
}
template <typename T> T max(T a, T b)
{
return a > b ? a : b;
}

// Vector2 functions
template <typename T, typename U> sf::Vector2<T> V2_convert(sf::Vector2<U> a)
{
return sf::Vector2<T>(T(a.x), T(a.y));
}

template <typename T> sf::Vector2<T> V2_invert(sf::Vector2<T> a)
{
return sf::Vector2<T>(-a.x, -a.y);
}

//
size_t pos2index(size_t x, size_t y, size_t max_x)
{
Expand Down

0 comments on commit f4a5efd

Please sign in to comment.