Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - MrOnlineCoder

Pages: [1] 2
Graphics / [Solved] Combining OpenGL stuff and graphics module
« on: January 03, 2019, 03:46:05 pm »

I am trying to use both OpenGL 3.0+ drawing (for 3D) and SFML for texts and 2d stuff. Currently, I am stuck with it. It is possible to render one of them, but not both at once. I followed recommendations in the tutorial concerning mixing sfml with opengl: https://en.sfml-dev.org/tutorials/2.5/window-opengl.php#using-opengl-together-with-the-graphics-module and added push/pop calls to my code, but it still does not work.

To minimize amount of possible factors, I've created minimal example to test (attached in a zip).

Please, check out this code and tell me where I made the mistake or how can I figure it out. I will appreciate that.

My setup:
Windows 7
SFML 2.5.0 (pre-built binaries from sfml-dev.org)
Visual Studio 2017
glad OpenGL loader

ZIP file contains glad and the source code. In the source code, there are some #defines, which you can
 tweak to test different cases

Check Main.cpp comments for more details. (sorry for messy code and globals, I think it is fine for testing purposes)

Thanks in advance,

SFML projects / ZBreakout - unfinished 2D top-down zombie shooter
« on: August 14, 2018, 06:35:08 pm »
Hello. I want to publish source code and assets that we've used in unpublished game ZBreakout. We do not have enough time and wish to finish it, so I publish it, anyone can fork it and play around.

Basically the game intended to be a clone of Minecraft Hypixel Zombies gamemode.

There is a map (game level). There are 2-4 players, who must defend themselves from waves of zombies. Each next wave is stronger than previous one, includes other types of zombies with different stats and abilities. By killing zombies, players receive gold which they can spent to buy armor, weapons and open doors to new parts of the map. At the start of the game, only 1 part is open, and then players progress forward by opening the doors. The main aspect was hardcore, you should really not win in first attempt.

What's done:
- State machine
- Game/server architecture based on UDP
- Zombies with very basic A* pathfinding
- Weapons
- Doors
- Level loading (tiled .tmx levels)

What is NOT done:
- Zombie waves
- Levels themselves
- most of the game concerning cosmetic things like animations, GUI - ready-to-publish look basically :D

You can download test game build (tested on Windows 7 64bit, 77 MB) from Google Drive: https://drive.google.com/open?id=19KzF3VMIt4ICSnC4Q-vFadhGO0oHXC6M

WASD to move
Left Click to shoot
1,2,3,4,5 to switch inventory slots
F3 to show debug info
K to get all weapons
L to toggle zombies movement
P to spawn a zombie

I would like to thank all of you guys for helping in coding this game, especially:
  • therocode
  • Dbug
  • Rosme
  • Mario
  • eXploit3r
  • fallahn
  • jamesking
  • StephenLynx
  • BlueCobold
  • Johhny

License in all source code files should be considered outdated and inactive, now everything is licensed under MIT license. Do whatever you want :)

Note: most of the assets were taken from opengameart.org and other sites, their copyright rights belong to their respectful authors! (sorry, I am bad at law stuff in English)

GitHub: https://github.com/MrOnlineCoder/ZBreakout

SFML projects / Space Colony - multiplayer strategy project
« on: February 11, 2018, 01:56:42 pm »
Hello. Me and my friend were developing one project - Space Colony, a multiplayer space turn-based strategy game. But, unfortunately, we do not have time to continue working on it. So, I decided to publish it's source code and assets.


Turn based strategy, up to 4-6 multiplayer players.
Each player owns a colony and can own some planets.

Planets contain useful resources - metal, oil and crystals, used to build different structures and objects. Each player has different ships, used to capture other planets.

Colony/player loses the game, if all their planets are captured by other colonies.

One gameplay aspect which we wanted to implement is motherships - special big ships, which are required to control other ships - so you, for e.g, make 10 small attacking ships and 1 mothership. Then you attach theese ships to the mothership, and by moving mothership you move your space fleet.

What we wanted to add:

  • Tech tree
  • Terra incognita (you only see a part of the map, which increases when you explore new areas)
  • Buildings on the planet
  • And, surely, epic space fights ! :)

Code structure

SFML is used for network, graphics, window, audio. Also I use PhysFS for loading resources from 1 zip file Resources.dat.

Game entry point is in Main.cpp, which just creates instance of Engine and then, it loads all resources, game states and starts the game by switching to IntroState.

GUIManager is responsible for GUI.

Game is the main game class, which just implements game logic. It is shared between client and server (I mean, like it is synced over network).

Initially, it was hardly inspired by Heroes of Might and Magic 3 and Starcraft

Code is avaliable at https://github.com/MrOnlineCoder/SpaceColony.

Working win32 release build is avaliable here (which also contains all assets, they are not included in the git repo): https://github.com/MrOnlineCoder/SpaceColony/releases/tag/v1.0

You can fork it, add pull requests, develop your own game based on it, shortly speaking, anything you want, but I'll be very happy if you include my name in credits :)


  • SFML by Laurent Gomila and contributors
  • PhysFS by Ryan C. Gordon
  • Some assets are downloaded from opengameart.org and belong to their respective owners

All music by Kevin MacLeod (incompetech.com), published under Creative Commons: By Attribution 3.0 License

General / Using multiple views for level and entities
« on: February 01, 2018, 03:24:44 pm »
Hello. I need small tip on using views for my game.

Currently, I load and render Tiled (.tmx) level as a game level using one view called levelView, which represents "camera", so it is moved when the character moves. Also, that view is a little bit scaled, because my level tileset has tiles of size 16x16, so without lowering view size level appears really tiny on the screen.

Then, I have another view - playerView, which is the same as window default view, it is used to draw player UI and the player character sprite in the middle of the screen (the character is not moving, only camera (levelView) is moved).

Now, I need to draw entities: items, enemies. But how can I draw their positions correctly (moving along with the camera)? Which view should I use?

If I draw them with playerView - they appear statically on the screen, like an HUD element. And if I draw them with levelView - they appear really scaled (the quality of texture decreases).

Thanks in advance.

Audio / sf::Music hangs the app with PhysFS
« on: December 22, 2017, 01:34:49 pm »
Hello! I am working on a game and I load all resources from zip file using PhysFS. I am using this class from SFML wiki: https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream

And I have noticed strange behaivour: if I open PhysFsStream once, open music from it, then everything is OK. But if I do this again (to change current music) -  my application hangs (100% of CPU core).

Minimal code (all variables are class members):


//init() - called once when game state is shown up


//input() - called on input.


My PhysFS setup is fully wokrable (I use the same way to load textures, sounds, they are all working and loaded correctly). 

After debugging application for some time, I ended on this code in sf::SoundStream:

void SoundStream::stop()
    // Request the thread to terminate
        Lock lock(m_threadMutex);
        m_isStreaming = false;

I wil really appreciate any help concerning this topic, maybe newer version of PhysFS stream or any possible fixes.

SFML projects / SFML multicolor text class
« on: December 09, 2017, 07:51:27 pm »

In my project I really needed multicolor text, for showing info about game objects and chat text, like this:

Price: 2500 Gold


Damage: 100-120

But I didn't found a solution online, so I wrote one by myself.

Basically, this is just a copy of original sf::Text class with one modification in ensureGeometryUpdate method.

When setting Text string, you can specify new text color using % character (like printf):

FText text;
text.setString("%0Format%2ted %3text");

which will draw:

Formatted text

Escaping % is done by writing two %:

test.setString("%1Damage: %2100 %%");

Damage: 100 %

Character-color pair is translated in sf::Color FText::getColorForChar(char c):
sf::Color FText::getColorForChar(char c) {
        switch (c)
                case '0':
                        return sf::Color::Black;
                case '1':
                        return sf::Color::White;
                case '2':
                        return sf::Color::Red;
                case '3':
                        return sf::Color::Green;
                case '4':
                        return sf::Color::Blue;
                case '5':
                        return sf::Color::Yellow;
                case '6':
                        return sf::Color::Magenta;
                case '7':
                        return sf::Color::Cyan;
                        return sf::Color::Black;

You can expand number of available colors by adding new cases to this method.

Header: https://gist.github.com/MrOnlineCoder/579ddc7c513a8fc6f5b024aa8b43ffbb
Source: https://gist.github.com/MrOnlineCoder/69a3bd3e18e2958526b6bac14dd8d0c9

I am open to any suggestions or comments.

SFML projects / Redstay - simple hobby 2D Platformer
« on: June 14, 2017, 12:31:35 am »
Hello  :) Last week I made a simple platformer on SFML for educational purposes.


- A and D to move
- W to jump
- E to use magnet
- Enter in main menu to start new game

Game objects:
key - required to enter next level
teleport - teleports you to another position
time ray - slows down the time (useless :D )
magnet - pick it up to change gravity

Boss fight tactic:
avoid projectiles using magnet and jump on his head when he is moving

Tools used:
Visual Studio 2012
SFML 2.4.2
Tiled Map Editor

MrOnlineCoder (me) - creator, programmer, level designer
Eric Matyas and Kevin MacLeod - music

Thanks to Laurent Gomila for such useful library, of course!   ;)

Download: https://github.com/MrOnlineCoder/Redstay/releases/download/1.0.0/Redstay.by.MrOnlineCoder.zip

GitHub: https://github.com/MrOnlineCoder/Redstay

(click to show/hide)

Feature requests / addColor method
« on: June 11, 2017, 03:57:12 pm »
Hello. In game, I often use some "flash" effects, or fading animations, where I change sprite/shape color like this:

sf::Color color = sprite.getColor();

It will be very nice and useful if addColor method exists:

General / Creating open-source game engine
« on: May 28, 2017, 03:41:18 pm »
Hello. I have a question: how should I release game engine for public use? Should I release source code, so users will build it and link with their project, or should they just make a file which describes the game and it's resources, so user will run the engine and then it will load the game description file (like GoldSrc, you run hl -game >game folder>), or should I do it in another way?


Hello. I came here to share my extension - sfCoach. I created it for personal needs, but maybe it will be useful for someone. So it helps you to animate objects.

Short documentation
There are 2 main classes: Animation and Coach in sfCoach namespace. The first one is abstract calss and has an update() method. The second one is just a simple container. Let's create a circle:
sf::CircleShape shape(50);
shape.setPosition(150, 150);

Now, you need to create instance of Coach class:
sfCoach::Coach coach;

Also, you should call Coach update() method every frame:
while (window.isOpen) {
  //Handle events....




Now you can animate your objects. You can animate: Sprite, Text, CircleShape, RectangleShape. Currently, there are 3 types of animation: DisplayAnimation, FadeAnimation, MoveAnimation.

DisplayAnimation hides or shows the target after specified amount of time.
FadeAnimation fades the target in or out.
MoveAnimation moves object from point A to point B (interpolation).

Creating animation (for example):
sfCoach::DisplayAnimation hide(sfCoach::createTarget(shape), 3.2f); //3.2f is delay in seconds after which shape will be hidden

sfCoach::createTarget is a factory method. It is overloaded for most drawables to create universal animatable targets.

The last step is simple: play it!

You can find example and source code in GitHub repository:


Thanks to therocode for factory methods idea

Feature requests / sf::Timer class?
« on: March 06, 2017, 07:39:42 pm »
Hello. Very often, in games timers are used. For spell countdown, turn duration, bomb timer, etc... It will be very convinient if SFML would have a timer class. It can be similiar to sf::Clock, but it should go downwards, and it can call a function on end or fire up an event.


Network / TCP server freezes whole program
« on: February 21, 2017, 11:19:38 pm »
Hello. I am making multiplayer game. Currently, I want to implement playing on 1 computer. My idea is to start TCP server on localhost and connect clients in game screen here. But my server freezes whole program, so the render loop of the screen doesn't start. Also, I cannot receive my data (it has 0 size and trash in value)
My Server (please, ignore Logger class, it is just basic file stream logger):
struct ServerPlayer {
    TcpSocket sock;
    std::string name;
    int turns;

class GameServer {
        bool start(unsigned short port);
       //Handle gameplay
        void handleMove(int target, int x, int y);
        void handleAttack(int target, int attacker);
        void handleSpell(int target, int spell);
        void handleSkip();
        void parsePacket();
        void shutdown(string msg);
        bool isRunning;
        TcpListener listener;
        Logger logger;
        vector<ServerPlayer> players;

Implementation of start method:
bool GameServer::start(unsigned short port)
    logger.log("Starting game server on port "+patch::to_string(port));
    if (listener.listen(port) != sf::Socket::Done)
        logger.log("ERROR: Cannot start listening on given port!");
        return false;

    logger.log("Now listening to incoming connections...");

    sf::TcpSocket client;
    isRunning = true;

    while (isRunning) {
        if (listener.accept(client) == sf::Socket::Done) {
            Packet p;
            p << HANDSHAKE;


How I start my server:
void startServer() {
   Thread serverThread(&startServer);
    TcpSocket sock;
    sf::TcpSocket socket;
    sf::Socket::Status status = socket.connect("", GAMEPORT);
    if (status != sf::Socket::Done)
        printf("ERROR: cannot connect to server!");
    Packet p;
    int msg;
    if (p >> msg) {

    } else {
        printf("ERROR: couldn't receive data\n");
    printf("Received packet from Server: %d of %d bytes\n", msg, p.getDataSize());

I hope you will help me and my code isn't too big to read :D.


Network / Network system for 1v1 game
« on: February 18, 2017, 10:53:15 am »
Hello. I am making a game with multiplayer over network support. There are 2 players with: position, rotation and shooting moment. My questions are:
1.What should I choose: TCP or UDP?
2.Should I do client-server or peer-to-peer communication?
3.What server should do (checking shooting intersection, end of game)?

SFML projects / QuadStrike - simple arcade on SFML
« on: February 15, 2017, 11:29:43 pm »
Hello. I was playing a bit with SFML and made this game.
QuadStrike - it is arcade where the goal is simple: eliminate your enemy.


  • WASD to move and Q to shoot for Red player
  • Arrows to move and Right Shift to shoot for Blue Player

  • MrOnlineCoder (me) - author, programmer and artist :)
  • Gasalt Font by Remi Lagast
  • Music by Kevin MacLeod
  • And surely, Laurent Gomila and contributors for SFML :D

  • Y movement
  • Rotation
  • Powerups
  • Network multiplayer

GitHub: https://github.com/MrOnlineCoder/QuadStrike/
Download: https://github.com/MrOnlineCoder/QuadStrike/releases/
I attached Windows binaries (built on Windows 7 64bit MinGW). Linux builds will be available soon.

Version: 1.2.0
Changelog: https://raw.githubusercontent.com/MrOnlineCoder/QuadStrike/master/CHANGELOG.txt

Feature requests / moveTo method for Vector2
« on: October 01, 2016, 08:17:21 pm »
Hello. Very often in games there is need to move object A to object B smoothly. Can this function be implemented in SFML? Something like this:
pointA.moveTo(pointB, 1f);
//=> pointA is now closer to pointB by 1 pixel

Pages: [1] 2