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 - albert_lazaro

Pages: [1]
1
SFML projects / RPG prototype
« on: June 09, 2021, 08:20:49 pm »
Good afternoon, I have been working on the project since the last days of March approx. The project consists of doing a little RPG prototype, so the game is a 2D top-down RPG inspired by the old Final Fantasy games (from I to VI).

What could we do in the prototype?

The basic idea of the prototype is that the player controls a character who moves in a grid-based movement. The world in that the character lives has towns, castles, dungeons... and an overworld. Towns are where the character can buy items, weapons, can learn new spells, can talk to NPCs, can rest in an inn... In the overworld and dungeons, the hero fights with different enemies. The fights start when the character is moving (that's random) and a battle screen is displayed in order to perform it in a turn-based system (Well, the typical Final Fantasy games).

What have I achieved?

For the moment I have been building the basics of a game engine (game loop, resource management, game states management). Also I can display a "map" using a tileset and I can move the character in a smooth grid-based movement with animation.



Why are you doing this project?

I have different reasons that have motivated me to start this project:
  • I always wanted to do my own RPG after I have played the old Final Fantasy games, that I love them and I have replayed them a lot of times.
  • I want to improve my coding skills and be better at structuring software projects.
  • Having a project is always better in a portfolio than nothing.

I will keep this thread updated when I add new features to the prototype  :)

Finally, you can follow me on Twitter: https://twitter.com/alazaro92 to get new updates or in my blog (https://lazaro92.github.io), that I have to write more in it.

2
General / Project Files Organization
« on: May 27, 2021, 07:19:06 pm »
Good afternoon,

I am doing a game with SFML and now I'm doing some refactoring. I have a doubt about how to organize the files. Currently, I have the source files in the Source folder and the headers in the Header folder, but there will be more files in the future so I want to do some tidying.

For example, I have moved the source files for the GUI in Source/UI and the headers in Headers/UI, where I put files like Label, Button, Container...

I have navigated through some projects in Github and I see that people tend to put all files in Header/Source folder without subfolders.

My idea is to have an easy to uderstand project and try to make a clean project.

3
General / Help with tile based movement
« on: May 20, 2021, 07:54:08 pm »
Good afternoon,

First I have to say that I have been trying to implement the SMOOTH tile-based movement for five days (I'm trying to add it using clean code).

For the moment, I have implemented a "teleportation movement" where the sprite moves to the next (up, down, left or right) tile without walking, so it goes 16px automatically. When I say next, if I maintain pressed the button it can be more than one tile. Here goes the GIF:



This is done in the GameState, that represents the state where the game occurs. The most important classes are:
Source/World:  this contains the elements that you see on the screen: the NPCs (for the moment one).
Source/TileMap: this builds and renders the tilemap that you see in the gif.
Source/Npc: this is the guy you see on the image.
Source/Player: this sends the Player output to the Npc via a command Queue.

Github: https://github.com/lazaro92/fantasy-maker/tree/develop

My idea to implement the smooth movement is to move the npc via the Player class, in the Player NpcMover struct. While I move the player, in the World class I would like to check if the movement has been completed (so the npc has moved all the exact16px, not one less or more).

Do you have any ideas or examples of a smooth tile-based movement? It would help me a lot :)

----------------

After I implement the movement, I will start with collision detection, so the idea after movement will be that if I press a key, before the Npc starts to move the system will check if the destination tile is available to move in.

4
Graphics / TileMap: array of sprites vs vertexArray
« on: May 02, 2021, 09:15:21 pm »
Hi,
I'm doing a videogame (or I'm trying to do  :P) that renders a top-down map based on tiles. I had followed the guides and I saw that there is an example that used a vertex array for displaying a map and I had implemented it, but now, before I proceed further, I want to make the correct decisions for the design of the game.

I have been reading some posts related to this topic and I have extracted the next points:

  • So first, Sprites are lightweight objects, so it does not represent a noticeable difference.
  • With VertexArray, the tiles are in a single entity and it does only a draw call, but with the sprite array it makes a draw call per tile. Performance depends on the number of calls to the draw function.
  • With vertexArray, the tiles are static, so they can't change and with sprite array, you can animate them (for example the typical tiles of sea that simulates waves.)
  • With vertexArray, I can draw a map larger than the view, and it does not affect performance. With the tiles, I should only render the tiles that are visible in the view.

Are the points correct? I'm missing something?

For the moment I'm using VertexArray for displaying a 64x128 tiled map, where tiles are 16x16 pixels and the view is 256*224 pixels (SNES resolution).

5
Good afternoon,

I have found an strange behaviour (sure it's a stupid question) but I was doing a tileMap for my game following the SFML example https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#example-tile-map and the result is:



(This is the good image - the tilemap is smaller than the screen, so it displays the black space)

The int array is created in the buildScene function of class world and passed to the tilemap in the same function.

The problem is that if I create the array in the header file it shows more sprites than normal.



Also, I had changed the c style array to a std::vector that is created in the header and filled in the constructor and it gives the same problem.

Do you know what is happening?

PD printing the array in World::buildScene and TileMap::load gives the same array.

buildScene
1 1 1 1 1 1 1 1 1 1 1 1 1 33 33 291 1 1 1 1 1 1 1 1 1 65 101 99 1 1 32 1 289 1 1 1 1 65 67 1 1 1 1 1 1 1 1 1 0 65 67 1 1 32 32 32 32 1 1 1 1 65 67 1 1 32 1 1 10 11 1 1 1 97 99 1 1 32 32 1 42 43 1 1 1 1 1 1 1 230 231 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 
TileMap::load
1 1 1 1 1 1 1 1 1 1 1 1 1 33 33 291 1 1 1 1 1 1 1 1 1 65 101 99 1 1 32 1 289 1 1 1 1 65 67 1 1 1 1 1 1 1 1 1 0 65 67 1 1 32 32 32 32 1 1 1 1 65 67 1 1 32 1 1 10 11 1 1 1 97 99 1 1 32 32 1 42 43 1 1 1 1 1 1 1 230 231 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


------------------------

header file: https://github.com/lazaro92/fantasy-maker/blob/feature/1/Include/Book/World.hpp
src file: https://github.com/lazaro92/fantasy-maker/blob/feature/1/Source/World.cpp

6
General / SFML, how to learn it
« on: October 06, 2019, 06:51:20 pm »
Hi, I'm beginner with SFML, I have done the Angry bird Udemy tutorial (https://www.udemy.com/course/flappy-bird-sfml/) and now I'm reading the book "SFML Game Development".

MY problem is that I'm learning in my free time, and I doing my don't have a lot of free time. Before buying the book I was doing an RPG project, but after I get the book I'm doing the book project and my progress is slow.

What do you recommend: to read the book and continue with my main project or read the book, make the projects book and after work in my main project?

7
General discussions / Setting Frame Limit of the project
« on: September 18, 2019, 09:15:06 pm »
Hi, I’m learning SFML with “SFML Game Development” (https://www.amazon.com/SFML-Game-Development-Jan-Haller/dp/1849696845) and there is something I don’t understand about fixed time steps technique to give always the same delta time to the update function:

/*
When we are over the required amount for one frame, we substract
desired length of this frame (TimePerFrame) and update the game.
*/

void Game::run()
{
    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;

    while(mWindow.isOpen())
    {
        processEvents();

        timeSinceLastUpdate += clock.restart();
       
        // collects the user input and computes the game logic.
        while (timeSinceLastUpdate > TimePerFrame)
        {
            timeSinceLastUpdate -= TimePerFrame;
            processEvents();
            update(TimePerFrame);    
        }        
        render();
    }
}

So we accumulate the elapsed time in timeSinceLastUpdate and substract the desired length of this frame (TimePerFrame = 1.f /60.f) and do this until we are below the required amount again ant then render the scene (this is called logic frame rate). With this the frame rate is 60 fps.

With this, if rendering is slow, processEvents()  and update() may be called multiple times before one render() call, so the game occasionally slutters becuase not every update is rendered, but the game doesn’t go slow down. On the other hand fast rendering can lead to call render() multiple times without a logic update in between.

Ok, the problem of this method is that CPU usage is high (about 50% or more).

Then I can use sf::RenderWindow::setFrameLimit(60) that calls sleep() internally but lacks precision, and then is sf::RenderWindow::setVerticalSyncEnabled() that adapts the graphical updates to the refresh rate of the monitor (GPU I think).

My question is about what method do you usually use: and accurate method like first, the setFrameLimit function or the setVerticalSyncEnabled()? And if the answer is the first one, how do you solve the problem of the CPU usage?

Thanks to everyone.

Pages: [1]