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.


Messages - NeroGames

Pages: 1 2 3 [4] 5 6 7
46
SFML projects / Re: Nero Game Engine
« on: December 09, 2018, 07:03:16 pm »
Hi everyone, how do you do, Hope your are doing great.  :)

Twitter account

I opened a Twitter account some days ago, you can follow me and stay update any time on the Engine development.
Twitter - NeroGameEngine.

Scene Screens

Today we are going to talk Screens. This is a new feature in the Engine, I did not plan it for the first version, but I finally thought it would be cool to have it.

What is a Screen ?

First, let's begin by what most people know : Game States. In a Game we generally have several states like : the game levels (each level being a state), the start menu, the pause menu, the options menu and many more. In order to manage all those states people generally develop a Sates and States_Stack system. In this system you can switch between States by pushing or poping them.

Instead of using a State/States_Stack System, the Nero Game Engine will use two differents systems. the Screen System and the World Chunk System. Those two systems combined will offer more power than a simple State System.

  • Screens :
Screens are displayed on top of the Game world. They can be used to build game menu but they can also be used as a UI Panel (window) in a menu.
  • World Chunk :
A World Chunk is a part of the Game World that can be load or destroy dynamically (during the game). Therefore One World chunk can represent a game level, but also, One game level can have any number of World chunks. The ability to load and destroy World Chunks dynamically will allows to build very large level. World Chuncks will be added in the second version of Engine.


Add, Delete and Rename Screens

On the top left of the Engine Interface, just after the Utility_Tab, we now have the Screen_Tab. From this tab, we can see all the available Screens, add new Screens, delete Screens or rename Screens.

Each Scene always has at least one Screen, you can delete any Screens but once it left only one Screen, the delete button will have no effect.




World View and Screen View

By default the Engine start in the World View. In order to access Screens we need to switch to the Screen View. On the right of the Engine Interface there is a button called Screen View. It's a toggle button, when the button is activated we goes in Screen View, when it's desactivated we come back to the World View.



The current View mode is also displayed on the bottom right of the canvas.



Just below the Screen View button there is a list that allows to select a Screen.




Build Screens

When a Screen is selected we can start building it. Each Screen has its own Canvas color, its own Grid, its own Camera, its own layers. Basically everything you do when a Screen is selected will affect only that Screen. Each Screen maintains its own Undos and Redos

Not all types of Objects can be added to a Screen. There is no Physics in a Screen, Therefore it's not possible to add Mesh_Objects, Meshed_Objects (Sprite with Mesh) and Animation_Meshed_Objects (Animation with Mesh) In Screens.

We can only add Sprite_Objects, Animation_Objects, Text_Objects and Button_Objects.

Button_Object is a new type of Object that can be add on Screens but not in the Game World, I will present it in my next post.

Screen and Grid

In my last post, I said that the Grid was important for Screens, it's time to know why. Screens are rendered on top of the Game World and they are not affected by the Camera movement. Therefore in order to be visible a Screen must be contained in a strict area. Since the Canvas is infinite it's become easy to be lost. This is were the Grid comes, if you plan to render your game in a 800 x 600 resolution or a 1024 x 800 resolution, you will have to configure a Grid of the same resolution with an offset of (0, 0). The Grid will represent the Screen area and everything in the Grid will be displayed.

That's all for this post, there is more on Screens but that will be for the next post. The video shows the different Screens I built for the Adventure Scene.


47
SFML projects / Re: Nero Game Engine
« on: November 27, 2018, 02:15:11 pm »
Hi everyone, how are you doing ! Let's continous with the Engine Updates.

Fix Game loop

When playing with my Adventure Scene I notices that the game speed was not stable. Sometime the game accelerate, some time it slow down. The default loop speed is 60 FPS. This is a fixed time, so it surprised me to have that issue. But after inspecting the Engine game loop I saw that the rendering was done in the while loop.

while(timeSinceLastUpdate > TIME_PER_FRAME)
{
    //retrieve 1/60 second in the accumulated time
    timeSinceLastUpdate -= TIME_PER_FRAME;

    //1... handle user inputs
    handleEvent();
    //2... update the game
    update(TIME_PER_FRAME);
    //3... render the game
    render();
}

I put the rendering out of the game loop, now thing work smoothly.

while(timeSinceLastUpdate > TIME_PER_FRAME)
{
    //retrieve 1/60 second in the accumulated time
    timeSinceLastUpdate -= TIME_PER_FRAME;

    //1... handle user inputs
    handleEvent();
    //2... update the game
    update(TIME_PER_FRAME);
}

//3... render the game
render();


The Grid

I now completed the Grid feature. I give up on the idea to build an infinite Grid. Building a grid that update it self when the camera moves is pretty complex and I didn't have time to do it.

The new Grid use a more simple approach. The Grid is made of cells. You can configure the width and the height of cells and choose how many cells you want horizontally and vertically. Finally you can move the entire Grid.

The movement of the Grid is not pixel based. You don't realy move the Grid , it is more accurate to say that you apply an offset to the Grid . Move the Grid is equalent to offset the Grid of one cell. By example if you move the Grid up, the Grid will move of one cell up and the same goes for the other directions.

Also the color of the Grid can be changed from the Color Tab.

Next time I will present the most important new feature that as been added to the Engine : Screens and Screens Stack. The Grid plays an important role for Screens so I needed to present it before.



48
SFML projects / Re: Nero Game Engine
« on: November 24, 2018, 11:41:42 am »
Hi everyone !. Hope your are doing great.  ;D
I made a lot of progress on the Engine development, I had not enough time to write a post, so there will be a lot to say.

Text Object

New object types have been added in the Engine. Let's begin by the Text Object.

On the left of the Engine Interface, along with the Sprite Tab, there is a new Tab named Text. From this Tab you can create some Text Objects and edit their properties.

Like other object types, a Text_Object can be moved, rotated, scaled, duplicated etc.

When a Text Object is selected you can change its font, its font size (character size), its outline thickness and its style (bold, italic, underline, linethrough).

From the Color_Tab you can change the text color but also the text outline color.

I'm currently using SFML 2.4.1, in the latest versions of SFML, there are two other text properties : Latter Spacing and Line Spacing. I will add those properties when I update SFML.

Write a New Line.

In order to return to the line when writting the text of your Text Object, you must insert a special character. By default it is  the pipe ( | ) character. You can choose the character you want my modifying the configuration file config/engine_config.json. The property is named carriage_return

It's more easy to explain with a video. So here is one.




Re-order Object

There are now two buttons allowing to move a Object Up or Down in the current Layer.




Default file/directory generation

In a previous post, I said the Engine need some directories and files to be available in order to work properly. For example we have the resource directory and all its sub directories, the log configuration file, the Sansation font, and some new config files I added recently.

From now on the Engine will generate those files and directories automatically on startup if they do not exist.

There are many configuration files in the config directory, If you made some changes on them and want to revert the changes, just delete them, the engine will bring them back.


The Log View

Bellow the Engine Canvas you got the Log View. It is now possible to log in this area from a nero::Scene. Each nero::Scene now provide a function void log(std::string message) that print its message in the Log view. This function internally call the nero_log(message) function, so the message will be also print in the console.

If you create a new class and want to log from this class to the Log View it's pretty easy. The log function is store in a std::function<void(string)>, you can retrieve it with the nero::Scene function getLog() and give it to your class;

myNewClass.setLog( getLog() );


FrameRate and FrameTime

From a nero::Scene it is now possible to retrieve the FrameRate and FrameTime with float getFrameRate() and float getFrameTime().
  • The frame rate is the number frame in one second.
  • The frame time is the duration of one frame in seconds.
The Engine Interface show its own frameRate and frameTime at the Canvas bottom right. The Engine Interface frameRate is not the actual Game frameRate. Since the Engine Interface manage more things, the Game frameRate will be higher.




All nero::Scene Attributes Private

All the attributes in a nero::Scene are now private. Attributes will be accessed by some getters and setters.

It's no longer possible to write :
m_ObjectManager->findObject(name)
Now you will have to write :
getObjectManager()->findObject(name)

The objective is to secure the nero::Scene class. If a variable can be modified there will a setter, if a variable can be accessed there will be getter. This offer a more clean interface.


Last active Scene.

If you are working on several Scenes at the same time, you may switch between Scenes many time. From now on, if you close the Engine and restart it, the Engine will remember the last Scene you were working on, and will select it on Startup.

If the Engine is close properly via the Window close button or the Quit button above the Canvas, the Engine will save all your scenes befor to shutdown.


That's all for this post. There are more changes in the Engine, but those will be for another post. Have a good day !  :)


49
SFML projects / Re: Nero Game Engine
« on: September 27, 2018, 08:57:13 am »
The Nero Adventure Scene

Hi everyone, how do you do.

In order to complet the Engine and reach the first version, I needed to work on a concrete Game Scene. So I took the code of my game prototype and begin to update it. I gave up on the name "Kero", it's now call the "Nero Adventure Scene". The artwork I'am using is from the Open Pixel Project and the Kenney Asset Store.

The Scene will be composed of 5 parts:
   1- A Startup Screen (display when the Render Engine start)
   2- A Game Menu Screen
   3- A Game Scene (the actual game)
   4- A Pause Screen
   5- A Credit Screen (display when you finish the game)

The idea is to cover most of the Engine features. The code develop in this game will be added in the "Nero Game Lib" library.

Here is a first look of the main character


50
SFML projects / Re: Nero Game Engine
« on: September 18, 2018, 03:37:55 pm »
Hi again ! Now the Engine have Animations (see the post above), but that's not all. In this post I will show all the new features I've been working on

Merge Layer

It is now possible to merge two layers. The only condition is that, they have to be of the same type (the same color).
On the Right of the Engine there are two new buttons: "Merge UP" and "Merge Down".
When you merge up by example, the content of the currently selected layer is taken and added to the layer above.



The Axis icon

On the bottom left of the Canvas there is now a Icon that shows the direction of the X and Y axis. I saw this in Blender so I thought it would be cool to have one in the Engine  8). The Icon rotate when the Camera rotate. You can hide it if you want, just uncheck the "Axis" check box on the Right of the Engine Interface.



Scale preview with Mouse Wheel

When the mouse is over a Sprite_Button or a Animation_Button, you can now scale the preview with the Mouse Wheel. Previously the Divide_Key and Multiply_Key were used, but using the Mouse Wheel is more fun  :).

Mesh Edition, Axe aligned movement

Mesh edition can be tough sometimes. In certain cases you want to move a vertex, only vertically or only horizontally but your mouse just doesn't want to let you do that. Now you don't have to be an expert at moving the mouse to do what you want. I made a little change in the algorithm. When moving a vertex, a line or an entire mesh, if your movement is more vertical than horizontal the Engine will assume that your movement is only vertical.

Example : we have a vertex at (1, 1). we apply a movement of (2, 4). the result should be (1+2, 1+4) = (2, 5).
but now the engine say, abs(4) > abs(2) so lets apply a movement of (0, 4) instead, the movement is nullify on the x Axis.

The Canvas Grid

This feature is still in development. By default the Grid is Hidden, you can make it visible by checking the "Grid" check box on the Right of the Engine.

What I am trying to do here is a "Infinite" Grid. When the Grid is Axe aligned there is no problem to simulate an "Infinite" Grid, you can move the Camera vertically or horizontally as you want, the Grid will adapt itself. But When the Grid is rotated, it becomes difficult to simulate "Infinity".

For now I am just playing with this feature I don't know exactly what it will be.



Lua Script

The integration of Lua in the Engine is beginning slowly. Each nero::Scene now have a instance of a  "Lua State" called "L". All the Lua standard libraries are loaded by default. If you have some experience with Lua and C++ you can already begin to call your scripts in your nero::Scene Class.

Github updated

The Github repository have been updated. we are now at the version 0.8.0 . The code is not stable, I will have to review the code to make sure every is right. When it's done I will publish a new version of the SDK with all the new features. If you like the project don't forget to give a start to the project on Github


That's all for now. thank you for reading my posts and see you later.

51
SFML projects / Re: Nero Game Engine
« on: September 18, 2018, 12:02:08 pm »
Hi everyone !, hope you are doing greet  ;D. Today let's talk about Animation.

Animation Tools

In order to simplify Animations management the Nero Engine relies on other tools. Texture Packer and ShoeBox.

Texture packer

I've already talked about this one. It's a tool that let you pack several images in one Spritesheet.
When you use Texture Packer to pack your animation, you obtain two files. A image file (.png, .jpeg, etc) and a Json file. The Nero Engine relies on this two files to generate animations.

ShoeBox

What is ShoeBox ? ShoeBox also allows to pack image files. But the great thing is that it also allows to Unpack Spritesheets. When you search for animations over the internet, most of the time you will find some animation SpriteSheets. And there come a question : The animation is already packed, how am I going to use it in Texture packer ?. Well,  ShoeBox can unpack SpriteSeets, it can also unpack GIF images. Yep, If you have an animation in GiF format, you can unpack it using an online service or with ShoeBox.

ShoeBox is free, you can find it here.

Load Animation

When you obtain the two files generated by Texture Packer, you simply have to copy and paste them in the "/Resource/Animation" directory. The rest is automatic, the Engine read your files and build the Animations.

In the picture bellow, you can see that each animation is made of one PNG file and one JSON file. Both files must have the same name.


Animation Object

On the left of the Engine Interface, There is now an Animation Tab. All loaded animations can be founded there. Animations work like Sprites. If you put the mouse over an Animation_Button you can see a Preview.
If you click on a Animation_Button you add a Animation_Object onto the Canvas.

Animations are like any other Object, you can move them arround, Rotate them, Scale them, Duplication them etc.

Like Sprite, you can change the Color of your Animation, simply select the Animation Object and process like if it was a Sprite Object.

A Layer of Animations appears with a Yellow color, this is temporary I will review all the Colors for Layer's types

Animations and Physics

Again the process is the same as for Sprite_Object. Hold CRTL and Click on a Animation_Button to add a Animation_Meshed_Object onto the Canvas. When a Animation_Meshed_Object is selected you can go to the Mesh Tab and change the properties of its Mesh Object. When you build your Scene by clicking on the "Return key" or the "Play Button" the Animation_Meshed_Object becomes a Animation_Solid_Object.

A Layer of Animation_Meshed_Object appears with a Light Blue color, this is a temporary color;

Animation Sequences

An Animation is made of Sequences. Each animation has at least one sequence. If the Animation concerns a character we usally have something like ("idle", "walk", "run", "jump"). If the Animation concerns a simple background object like flowers or animals you simply have one sequence.

When you add an Animation Object onto the canvas, the Animation has it's default sequence selected.  In order to do that, the Engine need to know the name of the default sequence.  For a character the default sequence is the "idle" sequence. But for a none character animation is it called "idle" ? I had three choices : "idle", "default", "The name of the animation". I took the last one.

If you have an Animation called "player" and the following seqences ("idle", "walk", "run", "jump"), the Engine will expect you to name your sequences as followed
("player", "walk", "run", "jump").

If you have a Animation called "flower" whith one sequence, the engine will expect that sequence to be called "flower".

The Sequence Tab

Alongside with the Sprite, Animation and other Tabs, you now have the Sequence Tab. By default this Tab is empty, but when you select an Animation Object, the Sequence Tab shows all the Sequences available for the selected Animation Object.

From this tab you can configure the frame rate of each sequence. the value is in hertz (inverse of second). If you choose of frame rate of "10", it means "1/10 second";




Animation is not Just Animation

You can see a nero::AnimationObject like a nero::SpriteObject that have the power to change is internal Sprite whenever it want. Imagine you have a breakable object in your game. That object will have several state ("healthy", "half break", "break"). This is not a animation, but it can be represented whith a Animation Object.

In order to say to a Animation to stop being a animation, you simply have to tell him to never update itself
animation_object->setUpdateable(false);

After that you have the power to controle the animation manually.
animation_object->setFrame(0) // by default the object is healthy
animation_object->setFrame(1) //the object has been half broken, let go to the second frame
animation_object->setFrame(2) //the object has been complety broken let go to the last frame

that's all for Animation, I will make a post later today in order to present other new features.
Here is a video that shows how Animation looks like




52
SFML projects / Re: Nero Game Engine
« on: August 31, 2018, 11:57:40 pm »
Hi everyone !, I'm back, how do you do ?

During the last two weeks I got a lot of free time, so I worked on the Engine. The Engine has evolved, I added some new features and fixed some bugs. I've made a review of the features that will be availabled in the Engine first version. The first version will be ready by the end on this year. The integration of Lua as a scripting language will take a lot of time, so for the first version there will only be a very minimalist integration of Lua. C++ will be the main language to use the Engine. Finally I plan to open a website early next year, maybe on Junuary. 

that's said, Let's jump on the new features !!!

Startup Screen

The DevEngine now has a Startup Screen or a Loading Screen if you prefer. The Engine just use two threads on startup. While the main thread render the Loading Screen, a second thread load Resources and build the Engine_UI in background.




Custom Startup Screen

While the DevEngine has a fix Startup Screen, the RenderEngine can take a custom Startup Screen. That allows you to create your own game loading screen. In order to create a Startup Screen you simply have to create a class that henerite from nero::StartupScreen

(click to show/hide)

All the methods in the class are virtual pure; you have to override all of them.
the getBackgroundColor() method return a color to clear the sf::RenderWindow;
the getMintime() method return a time in second. It allows you to choose if the LoadingScreen should last in 5 second or 10 second or whatever you want.

the Custom Startup Screen is given to the RenderEngine via it's constructor.

MyStartupScreen myStartupScreen;

nero::RenderEgine engine(myStartupScreen);
engine.setScene<MyScene>("my scene name");
engine.run();

Sound and Music

The Engine can now load and manage Sound and Music. Like other resources the loading is automatic. Just copy some sounds in the folder "/Resource/Sound" and some musics in the folder "/Resource/Music", the Engine will take care the rest. In your Scene class, there is a instance of the class nero::SoundManager. this class let you play a sound or a music at any time in your game.

The DevEngine allows to quickly access all your Musics and Sounds, so you can enjoy them while building a Scene.




Configuration Files

In order to make the Engine more flexible, many hard coded properties are now made evailable as configurations. Configuration files are JSON files, they are all located in the folder "/config"

As a example, for each resource type (Texture, Sound, Music etc), you can now choose the folder where to put them, you can also choose the extensions you want to handle.

For Fonts, you can choose what Font to use as default.

{
        "font" :
                {
                        "folder" : "Resource/Font",
                        "extension" : ["ttf"],
                        "default" : "Sansation"
                },

        "sound" :
                {
                        "folder" : "Resource/Sound",
                        "extension" : ["wav", "ogg", "flac"]
                },

        "music" :
                {
                        "folder" : "Resource/music",
                        "extension" : ["wav", "ogg", "flac"]
                },

        "texture" :
                {
                        "folder" : "Resource/Texture",
                        "extension" : ["png", "jpg", "bmp", "dds", "tga", "psd"],
                        "separator" : "-"
                },

        "shader" :
                {
                        "folder" : "Resource/Shader",
                        "shader-list" : "Resource/Shader/shader.json",
                        "extension" : ["vert", "frag"]
                },

        "animation" :
                {
                        "folder" : "Resource/Animation",
                        "extension" : ["png", "jpg"]
                },

        "script" :
                {
                        "folder" : "Resource/Script",
                        "extension" : ["lua"]
                }

}


Bug fixed : RenderCanvas glitch

In the version of the Engine provided with the SDK (Startup Kit), there is a glitch on the Canvas when you remove a Layer or when the Redo and Undo buttons are used. It tooks me some time to find the reason of this glitch, but it's now fixed.

that's all for this post, There are other new features like Animation and Grid, they are still in development, I will talk about them another day.

thanks for reading my posts and see you later  :).

53
SFML projects / Re: Nero Game Engine
« on: July 21, 2018, 10:32:13 am »
Hi everyone ! it's been a long time since my last post. Hope you are doing well  :).

A new logo design

Here is the new design I made for the logo. Let me know what you think.



TexturePacker

Do you know TexturePacker from CodeAndWeb. It's a tool that easy the creation of Sprite Sheet. If you have a bunch of PNG files by example, you can import them in TexturePacker and it will "pack" them into one single PNG file. The geat thing, it's that it also provide you a JSON file (not only, there are other formats) describing the Sheet, so the  Sprite Sheet can be easily "decoded" by a game engine.

As I mention in my last post I'm currently working on Animation. Before I started implementing anything I searched over the internet if I could find a tool that will simplify the creation of animation. That lead me to TexturePacker.

TexturePacker will be integrated in my Engine workflow. I will talk more about that when the integration with the engine it's done. For now you can learn more about TexturePacker here.

Development Progress

The development of the Engine progress very slowly these days since I don't have munch time to work on it. But with a little chance things can change in the upcoming months.

have a good day ;D

54
SFML projects / Re: Nero Game Engine
« on: April 30, 2018, 12:20:10 am »
How to code with the engine Part 1-8 : Anatomy of the Kero Scene

Hi everyone, how are you doing  ;D. I thought to change this post title, but I finally kept it.

A litte story

There is the story of the Kero scene

once upon a time, there was a little cube with the power to move left and right. After a long long run, the little cube find a blue arrow. The arrow was moving up and down. Intrigued by this arrow the little cube decided to touch it, when it did, some thing amazing happened, the little cube get the power to jump. With its new power the little cube continue its aventure, it later found a moving platform, that was a great opportunity to test its new power, It jumped on the platform which carried it to the beginning of a new aventure.



Build a game with the Nero Game Engine

As you may have seen with the Kero Scene, there are basically  two parts when developing a game with the Engine. I called them the Game Scene part and the Game Code part.
  • The Game Scene
The game scene is built with the Dev Engine Interface, the game scene can be modified at any time without the need rewrite the code. That is great if you want to tweak the position or the shape of an object. Modifing the Game Scene also don't required to recompile your game program, and since the scene is represented as a simple json file, it's easy to share. If you think you are not good at Scene disign just ask a friend to build the scene for you and send you the json file (and also the sprites, ya don't forget them ).
  • The Game Code
The game code is where the logic is built. In the game code you can retrieve the objects created in the game scene and manage collisions and events. The modification of the game code require the recompilation of the game program. With this series you get a look at the engine API. The API is pretty generic and does not target a game genre. If you like a specific game genre you can build your own API on top of the engine one like I did with the Nero Game Lib. I'm a fan of plaftormers so the Nero Game Lib will focus only on the platformer genre.

Learn more and continue the development

The part 2 of the series is put in stand by. I won't have time to work on that in the following months. In place of that I will focus my time on learning game engine architecture and continue the development of the Engine (I will be working on Sound and Animation objects).

I'm pretty happy with the current state of the project considering that I taught  my self C++ programming, SFML and game programming. I'm not a game engine expert, I came to that stage of the project using my intuition and determination. But I think it's time to learn some key notions on engine development. I came accross that book Game Engine Architecture of Jason gregory and found it pretty amazing. I will gather many others books and learn a lot in order to produce the best engine I can.

Thanks for reading my posts, and see you later ;D.


55
SFML projects / Re: Nero Game Engine
« on: April 29, 2018, 04:51:27 pm »
How to code with the engine Part 1-7 : Build a simple player

Hi everyone, hope you are doing great. Let's continue with the series.

In this post I will show how to use an ActionObject and some Actions in order the build a simple player

Step 0 : Include the Nero GameLib header

#include <NERO/gamelib.h>

Step 1 : Create the player object

The first step is to create the object that will be your player using the Dev_Engine_Interface. For this example we can take a simple cube or circle to be the player. So let's create a Physic_Object (Polygon Mesh) with the name "my_player" and the category "player"

step 2 : Use an ActionOject to represent the Player

nero::PhysicActionObject my_Player;
my_Player.setObject(m_ObjectManager.findObject("my_player"));

In the Howto on Moving Objects and Platforms, we used a Custom PhysicActionObject called SimpleMovingObject. The SimpleMovingObject inherit from PhysicActionObject in order to build a more complex interface. But as you can see the default interface of the PhysicActionObject is enough for certain cases. There are many ways to use ActionObject and Action, and for this tutorial we are using the most basic one.

step 3 : Give the player defferent capabilities

Let's say we want our player to be able to move right and left. we also want it to be able to jump.

float move_velocity = 100.f
float jump_force   = 150.f

my_Player.registerAction<MoveAction>("move_left", nero::getMoveLeftAction(move_velocity));
my_Player.registerAction<MoveAction>("move_right", nero::getMoveRightAction(move_velocity));
my_PLayer.registerAction<JumpAction>("jump", nero::getJumpAction(jump_force));

In the code above we've registered three Actions, the player can then perform those actions when ever it want.

void handleKeyboardInput(const sf::Keyboard::Key& key, const bool& isPressed)
{
    if(isPressed)  
    {
       switch(key)
       {
       case sf::Keyboard::J:
           {
               my_PLayer.callAction("jump");
           }break;
       }
       
   }  
}

If you want to see how Actions are built, click on the spoiler button.
(click to show/hide)

Step 4 : Make the camera follow your player

The nero::Scene offers a method called setCameratTarget, that you can used to make the camera follow any Physic_Object.

auto player_object    = m_ObjectManager.findObject("my_player"); //retrieve the object to follow
auto target       = nero::PhysicObject::Cast(player_object); // cast the object to a Physic_Object

setCameraTarget(target); // set the target

It's possible to disable and enable this feature at any moment with the following method

setCameraFollowTarget(bool flag);


This post showed how ActionObject and Action could be used to create a simple player, for a complet example you can check the code in the Kero project.

56
SFML projects / Re: Nero Game Engine
« on: April 16, 2018, 09:17:38 pm »
How to code with the Engine Part 1-6 : Handle Collisions

Hi everyone, hope you are doing great. Let's continue this series with Collisons processing

1- Setup the collision rules

Let's consider the following Object Categories (ground, platform, cirlce, cube) and the following rules
  • circles and cubes can collide with ground
  • only circles can collide with platforms
  • circles cannot collide with circles
  • cubes can collide with cubes
  • circles and cubes cannot collide
using a nero::CollisionRule object you can configure this setup with the code bellow

nero::CollisionRule collisionRule;
           
collisionRule.canCollide("circle", "ground");
collisionRule.canCollide("cube", "ground");
collisionRule.canCollide("circle", "platform");
collisionRule.canCollide("cube", "cube");

collisionRule.apply(m_RootObject);

When the apply() method is called, the collisionRule object first remove all previous collision configuration by calling the noCollision() method. When this method is called, no object can collide with any other object, this is why you only have to tell which Category should collide with which one when setting up the rules.

2- Print the collision rule

if you want to see the collision rules in a more readable way, you can called the print() method

collisionRule.print();

3- Process collisions

when a collision occur, the handleCollisionContactBegin() method is called first. The collision is represented as a nero::Collision Object

void handleCollisionContactBegin(nero::Collision collision)
{
    if(collision.isCollising("ground", "cube"))
    {
        nero_log("ground-cube collision detected");

        auto object_1 = collision.getObject("ground");
        auto object_2 = collision.getObject("cube");

        nero_log(_sn(object_1));
        nero_log(_sn(object_2));
    }

    if(collision.isObjectCollising("platform_1", "circle_1"))
    {
        nero_log("platform_1 and circle_1 just collided");

        auto object_1 = collision.getObject("platform_1");
        auto object_2 = collision.getObject("circle_1");

        nero_log(_sn(object_1));
        nero_log(_sn(object_2));
    }
}

4- Test collisions

The collision object offer two methods to test collisions by category or by name

collision.isCollising("object_category_1", "object_category_2");

collision.isObjectCollising("object_name_1", "object_name_2");

The test with a category and a name is not availabled, I will had that for a future release.

5- Retrieve the colliding objects

You can use the getObject() method to retrieve the objects that are colliding, the method takes a category or a name as parameter. The returned object is a nero::PhysicObject

PhysicObject::Ptr collision.getObject(sf::String indicator)

//Example
auto object = collision.getObject("object_category");
//or
auto object = collision.getObject("object_name");


5- Disable collisions

A collision can be easly disabled with the code bellow

collision.setEnabled(false);

6- A full example

You can create the Scene for this example, with this  following json file.

download the scene json

#include <NERO/engine/DevEngine.h>
#include <NERO/scene/CollisionRule.h>

class MyScene : public nero::Scene
{
    public:
        MyScene(nero::Scene::Context context):
            nero::Scene(context)
        {

        }

        void init()
        {
           m_ObjectManager.checkAllObject(
            {
                "platform_1",
                "circle_1",
            });

            nero_log("The collision rules");

            nero::CollisionRule collisionRule;

            collisionRule.canCollide("circle", "ground");
            collisionRule.canCollide("cube", "ground");
            collisionRule.canCollide("circle", "platform");
            collisionRule.canCollide("cube", "cube");

            collisionRule.apply(m_RootObject);

            collisionRule.print();
        }

        void handleCollisionContactBegin(nero::Collision collision)
        {
            //this method is called first when a collision occur;

            if(collision.isCollising("ground", "cube"))
            {
                nero_log("ground-cube collision detected");

                auto object_1 = collision.getObject("ground");
                auto object_2 = collision.getObject("cube");

                //nero_log(_sn(object_1));
                //nero_log(_sn(object_2));
            }

            if(collision.isObjectCollising("platform_1", "circle_1"))
            {
                nero_log("platform_1 and circle_1 just collided");

                auto object_1 = collision.getObject("platform_1");
                auto object_2 = collision.getObject("circle_1");

                //nero_log(_sn(object_1));
                //nero_log(_sn(object_2));
            }


            //If I disabled the collision here, the method (handleCollisionContactEnd) will never be called
            //collision.setEnabled(false);
        }


        void handleCollisionContactEnd(nero::Collision collision)
        {
            //this method is your last change to process a collision
        }
};

int main()
{
    nero::DevEngine engine;
    engine.addScene<MyScene>("My Scene");
    engine.run();
}
 




57
SFML projects / Re: Nero Game Engine
« on: April 14, 2018, 03:40:45 pm »
How to code with the Engine Part 1-5 :  Create Moving Objects and Platforms

Hi everyone! how are you doing :). I've been busy the last weeks so I couldn't pursue the series, but here I am.
In this post I'll present a custom PhysicActionObject called SimpleMovingObject. This ActionObject can be used to create moving platorm or to make move any PhysicObject.

There is little change in the schedule, the HowTo on the Player will come after the one on Collision. That said, let's begin.

1- Include the NERO\gamelib.h header

#include <NERO/gamelib.h>

The Nero Game Lib library  defined some custom Actions and ActionObjects. This library is not part of The Engine Core, currently it is provided as a header only library. You can find it in the package in : Library\gamelib\NERO\gamelib.h
Further in the tutorial I will show How to create custom Actions and ActionObjects. For now let's use the ones provided in the gamelib library.

2- SimpleMovingObject, the constructor

nero::SimpleMovingObject(direction, velocity, maxOne, maxTwo);

direction    : [right_left , up_down]    // the direction of the movement
velocity     : [float]                   // the speed of the movement
maxOne       : [float]            // the distance to cover in the first direction (right or up)
maxTwo       : [float]            // the distance to cover in the second direction (left or down)

3- Example

nero::SimpleMovingObject(nero::SimpleMovingObject::Right_Left, 20.f, 100.f, 150.f)

//In the following example, the targeted object will move right and left at a speed of 20 float;
//The object will first move 100 float to the right, then it will come back to its initial position before
//to move 150 float to the left. the total distance of the movement it's therefore 350 float

4- A little trick

If you want the object to move Left_Right, instead of Right_Left, just set maxOne to Zero (0.f)

nero::SimpleMovingObject(nero::SimpleMovingObject::Right_Left, 20.f, 0.f, 250.f)

//Since the object should move 0 float to the right before to go left,
//the object will go left first, what's give you a left_right movement. this work also for the up_down movement.

5- Add the SimpleMovingObject to the Object Tree

The role of an ActionObject is to provide a behavior to another Object (the Target). As we want our ActionObject to have full control of the target, we will first remove the target from the Object Tree, and then give it to the ActionObject. Only after that we can add the ActionObject to the Object Tree

We create the ActionObject as a Pointer since it will be added to the Object_Tree

nero::SimpleMovingObject::Ptr my_Platform;
my_Platform(new nero::SimpleMovingObject(nero::SimpleMovingObject::Right_Left, 20.f, 0.f, 250.f));

We remove the Target from the Object Tree and give it to the ActionObject.
the Object_Manager MoveObject method, cut the target from the Tree and return it

auto target = m_ObjectManager.moveObject("my_platform");
my_Platform->setObject(target);

The Object_Manager will add the ActionObject to the Object Tree

m_ObjectManager.addObject(my_Platform);

6- Some reminders

The SimpleMovingObject is a PhysicActionObject, currently it's the only ActionObject in the gamelib library. As a PhysicActionObject, it handles only PhysicObjects (SolidObjects are also PhysicObjects).

This ActionObject should be used on Kinematic PhysicObject.

Static Objects are not meant to move and Dynamic Objects are meant to be affected by a lot of things (gravity, collisions) what is not ideal for this ActionObject.

7- A full example

First create a Kinematic PhysicObject (Kinematic Mesh) named "my_platform" before to run this code

#include <NERO/engine/DevEngine.h>
#include <NERO/gamelib.h>

class MyScene : public nero::Scene
{
    public:
        MyScene(nero::Scene::Context context):
         nero::Scene(context)
         ,my_Platform(new nero::SimpleMovingObject(nero::SimpleMovingObject::Right_Left, 50.f, 100.f, 100.f))

        {

        }

        void init()
        {
            //First create a Kinematic PhysicObject (Kinematic Mesh) before to run this code

            m_ObjectManager.checkAllObject(
            {
                "my_platform",
            });

            auto target = m_ObjectManager.moveObject("my_platform");
            my_Platform->setObject(target);

            m_ObjectManager.addObject(my_Platform);

        }

        nero::SimpleMovingObject::Ptr my_Platform;
};

int main()
{
    nero::DevEngine engine;
    engine.addScene<MyScene>("My Scene");
    engine.run();
}


58
SFML projects / Re: Nero Game Engine
« on: March 26, 2018, 11:54:10 pm »
How to code with the Engine Part 1-4 :  Retrieve objects

1- Find Objects

The findObject() method, run other the whole Object_Tree_Node to find an Object. This may be resource and time consuming if your Scene contains too many Objects. You can optimize the research if you know the nature of the Object you are looking up for.

If the Object is a Physic_Object by example, use the findPhysicObject() method, This method will skip all layer that does not contain Physic Objects during its look up process.

There are a list of methods you can use to retrieve Object more efficiently
Object::Ptr     findObject(sf::String name);
Object::Ptr     findLayerObject(sf::String layer_name);
Object::Ptr     findObjectInLayer(sf::String name, sf::String layer_name);
Object::Ptr     findSpriteObject(sf::String name);
Object::Ptr     findPhysicObject(sf::String name);
Object::Ptr     findSolidObject(sf::String name);
 

2- Move Objects

The Move methods, cut the Objects you are looking up for from the Object_Tree_Node. So you can re-attach them somewhere else in the Tree.

Object::Ptr     moveObject(sf::String name);
Object::Ptr     movePhysicObject(sf::String name);
Object::Ptr     moveSpriteObject(sf::String name);
Object::Ptr     moveSolidObject(sf::String name);
 

3- Remove Objects

The Remove methods, will destroy complety an object. If the Remove methods do not find the object you want to remove they return false

bool            removeObject(Object::Ptr object);
bool            removeObject(sf::String name);
 

4- Objects Casting

The Find and Move methods always return a generic nero::Object, if you want to perform object specific tasks, you will have to cast the returned Object first. All Object Type have a static Cast() method for that.

nero::Object::Cast()
nero::LayerObject::Cast()
nero::SpriteObject::Cast()
nero::PhysicObject::Cast()
 

Example
auto my_cloud_sprite    = m_ObjectManager.findObject("cloud_sprite");
auto my_ground          = m_ObjectManager.findObject("ground_01");

nero::SpriteObject::Ptr sprite_object = nero::SptriteObject::Cast(my_cloud_sprite);
nero::PhysicObject::Ptr physic_object = nero::PhysicObject::Cast(my_ground);
 

A Solid_Object is a Physic_Object with a Sprite_Object as a child. So a Solid_Object is casted to a Physic_Object

auto object = m_ObjectManager.findSolidObject("object_name");

nero::PhysicObject::Ptr physic_object = nero::PhysicObject::Cast(object);
nero::SpriteObject::Ptr sprite_object = nero::SptriteObject::Cast(object->getFirstChild());
 

59
SFML projects / Re: Nero Game Engine
« on: March 26, 2018, 11:21:18 pm »
How to code with the Engine Part 1-3 :  Check Objects

Any Object can be retrieved at any moment with a  [ m_ObjectManager.findObject("object_name") ] . The thing to know is that the Object_Manager return a Null_Ptr when it does not found a Object. The reasons the Object_Manager does not found a object may be because the Object simply does not exist, may be you misspelled the Object_Name, or you simply forget to assign the name with the Dev_Engine Interface. So in principle you should test any returned object before to use it like that.

auto object = m_ObjectManager.findObject("oject_name")
if(object)
{
        //do something
}

This is pretty combersome. In order to reduce the risk of using unexisting Objects, you can check them all at the beginning of the init() method.
the method [ m_ObjectManger.checkAllObject(std::vector<sf::String>) ] is there for that. you can give it all the Object_Names you will be using. If it found that a object does not exist, it throws a exception and give you the culprit, I means the Object_Name, that refer to nothing.

void init()
{
    //Test that all objects exist before to continue
    m_ObjectManager.checkAllObject(
    {
        NamePool.start_ground,
        NamePool.jump_power,
        NamePool.player,
        NamePool.start_platform,
        NamePool.start_end,
    });


    // Everything fine here, we can continue safely

}

60
SFML projects / Re: Nero Game Engine
« on: March 26, 2018, 11:06:59 pm »
How to code with the Engine Part 1-2 :  Use constants

The Engine use a lot of Strings to do its stuffs. Objects in a Scene are identified by they Name and they Category. The Names and Categories are used everywhere and many time in the code, writting them every time is error prone, so as a good practice, this Strings should be declared as constants and maintained in one place. Also notice that Names and Categories should be unique.

As an example the kero project defined several constants in the Kero_utility.h file like this.

struct _NamePool
{
    const sf::String start_ground       = "start_ground";
    const sf::String player             = "kero";
    const sf::String jump_power         = "jump_power";
    const sf::String start_platform     = "start_platform";
    const sf::String start_end          = "start_end";

};

struct _CategoryPool
{
    const sf::String ground             = "ground";
    const sf::String wall               = "wall";
    const sf::String player             = "player";
    const sf::String power              = "power";
    const sf::String platform           = "platform";
};

struct _PlayerActionPool
{
    const sf::String move_left         = "move_left";
    const sf::String move_right        = "move_right";
    const sf::String move_none         = "move_none";
    const sf::String jump              = "jump";
    const sf::String dash_left         = "dash_left";
    const sf::String dash_right        = "dash_right";
};

const _NamePool             NamePool;
const _CategoryPool         CategoryPool;
const _PlayerActionPool     PlayerActionPool;
 

Pages: 1 2 3 [4] 5 6 7
anything