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

Pages: [1]
SFML projects / Another Snake Clone
« on: December 29, 2017, 02:29:51 pm »
Hello everyone,

i wanna show you my actual project, its another Snake Clone.
Its actually in "Demo Mode" xd
Link for the download: Snake.7z
Code is in my Github(but its not every time actual).

- Windows OS(just tested it on Windows 10)
- SSE and rdrand feature of your CPU could be nice
- About 60-80MB Video Ram
- Pixel Shader Support

Some Details:
- Actually 2 "maps"
- Different items to get score/speed/health
- An autokill function, otherwise you could play it infinite
- Pause
- Speed Up Items x2,4,8 are not really x2,4,8, because it would be to fast for you ;-)
- Not directly dead if you hit a wall or the snake themself. Game decides the next movement
- You can control the snake with the Arrow Keys, Escape is for pause

Dev Details:
- Compiled with C11 and gcc on Windows 10. (Codeblocks)
- CSFML used
- Sounds are from freesounds
- Pictures are self created with gimp
- tile based maps, a big picture file + tile data file

Known Bugs:
- Setting & Highscore system got some bugs(setting page has only 15-30fps oO)
- Sometimes Items are spawned in the same position as other items, so maybe you wonder why you picked a food item, and you get faster or get health, iam actually not sure, where the problem is.
- After get died, a weird sound appears in the finish screen.
- The Auto Direction Set for Wallhit/Selfhit is not 100% working. A "Deadlock" Moving(like a spiral) will sometimes not cause a direct dead, sometime the snake moving through themself.

Next Steps:
- searching item spawn problem
- cleaning up my header managment and structure managment(actully its a big dumping ground xd)
- Rework Settings & Highscore subsystem
- Split CSFML subsystem and Menu subsystem(actually in one file)
- Rework completly menu subsystem(need to make more generic)
- implement the enemy subsystem
- implement the event subsystem(needs an enemy subsystem, blank part in level are existent)
- making a little syscheck subsystem(for checking for sse and rdrand)
- maybe rework Movement View(if youre near the wall, you will see black outside the map)
- making it complete in english, actually is mixed with german and english language^^

A picture:

My actually highscore in the map 2 is 14.332. Maybe you could beat me^^

Any criticism, proposals, tips are welcome!

Greetz MOP

Graphics / Problem Calculating Step Movement by Time
« on: November 10, 2017, 08:39:01 pm »
Hi people,

actually i got some problems by timestep calculation (for sfView Movement).
I get for my Snake a block-wise movement, cause block-wise setup for it. Iam using bigger "tilemaps" for an level. So i decided to create some custom view. Actually, the view is moved also block-wise. But imo i could be possible to make the View move smoother. Since the snake setup is block-wise, it couldnt be make a smooth movement.

I build up a central "managment" for time things, in which i set a SecondTick and SnakeTick flag.
SecondTick is just for update my score "+1".
SecondTick release every second, and SnakeTick release "1 Second / Snake Speed".

My Handle Items, Snake Movement is updated every SnakeTick. And Rendering Stuff has no time limit.
(my Movement to the View is actually inserted in the Snake Handle). So the View Move is also block-wise.

(I Call my Update Functions HandleXXXX, dont be confused for the terminology ).

Okay thats was the background.

Now i tried some calculations.

sfView Movement per Tick: 25.0f (x or y depent on direction)
Actually my SnakeTick is: 1 Second / 3 Speed = 333ms
If we have SnakeTick: 1 Second / 4 Speed = 250ms
and so on..

So at 333ms the View must be moved by 25.0f
And at 1 Second the View must be moved by 75.0f

TestValue shall be the Value to be Moved.
The Exactly Frame Move is similar. The Sum into a Full SnakeTick must be exactly.

My Idea which i test:
(its C)
Code: [Select]
TestValue += (GameClock.GC_DeltaTime * 25.0f * GameSnake.S_Speed);

        printf("TestValue must be 25.0f: %f\n", TestValue);
        TestValue_Extended += TestValue;
        TestValue = 0.0f;

        printf("TestValue_Extended must be 75.0f: %f\n", TestValue_Extended);
        TestValue_Extended = 0.0f;

But i get the following Output:
Code: [Select]
TestValue must be 25.0f: 25.320147
TestValue must be 25.0f: 25.297354
TestValue must be 25.0f: 25.276875
TestValue_Extended must be 75.0f: 75.894379
TestValue must be 25.0f: 25.344891
TestValue must be 25.0f: 25.220773
TestValue must be 25.0f: 25.210583
TestValue_Extended must be 75.0f: 75.776245

As you see, i cant actually the "right value".

The Movement by a frame is similar. But the Sum to a full SnakeTick have to be exactly 25.0f, otherwise it will definitly lead to crazy bugs.

Do you have an idea, what can i do?

Thanks in advance

Greetz MOP.

General / General question about Rotation Function
« on: November 07, 2017, 11:29:59 pm »
Hello people,

just a general question / ask for feature.

In my actual project i need some rotation, and i was really confused and suprised, that the object rotate in the wrong direction x) Firstly i thought i got some brainbugs, then i realized that the rotation is every time clockwise. So i looked up for an option to inverse that. Actually i realized with it in my shader for the object.

I read the article on the tutorial, and i understand why it is clockwise, becuase of the down mirrored coordinate system.

So why is this a bit nervy for me, i created my object texture aligned to the first quadrant. If i would use the current clockwise rotation, the code could be a bit non-comprehensible imo.

Whats about a feature like:
sfSprite_setRotation(90.0f, true) [C] true = anticlockwise, false = clockwise
Sprite.setRotation(90.0f, true) [C++]

I looked up the source, maybe it is just an extra rotation matrix which is inversed.

I know this seems like a bit fussy, but i get really brainbugs, with the clockwise rotation. I learned that rotation is every time anti clockwise according to euclidean room ;)

Dont hate me  :(

Greetz MOP

C / Shader set a Float Uniforms causes to Crash
« on: November 01, 2017, 10:23:10 pm »
Hello folks,

iam currently working on my Snake Project, actually trying to implement some Item Stuff. I applied for every Item(Food, Speedups, Healthups) a file, which contains simplify a Struct. In this Struct are some propertys saved and Path Names to Shader and Textures. For every Item i load Stuff.

Actually i have the Problem, if i "out-comment" this line here:
(in CSFMLGameClock.c)
Code: [Select]
// Set GameTime to Item Shaders
        size_t it;
        for(it = 0; it<GameItem.GI_Items_Count; it++)
            if(GameItem.GI_Coordinates_Setted[it] && GameItem.GI_Placed[it])
                //sfShader_setFloatUniform(GameItem.GI_Shaders[it], "Time", GameClock.GC_Time); // <- This

On Start, it works fine, if i move my Snake then with a key, it directly lead to a crash. Iam not sure, where's the problem. Maybe you can give me some tip.
If it outcommentated, it works fine.

I applied fast a github repo, if you want to see the full code.
You can see it here: https://github.com/MasterOfPenetrator/SnakeGame


C / Send a Struct Array to a Shader
« on: October 23, 2017, 12:46:18 pm »
Hi folks,

actually iam faced with a little problem. Iam actually using a pixel shader for diffuse/normal/specular mapping with different lights(point and cone lighting). I wanna reorganize my shader Input to a single Struct.
But iam not to find a function to set a uniform struct directly to a shader.

Iam actually making a snake game, with different "levels"(levels splitted to a texture, a textform tilemap, a eventmap(e.g. for boss "fights")). The Map-Texture included all Tiles, excluded dynamiclly tiles(like bosses, foods, powerups etc.), to reduce Texture handles and resources. Okay thats was a bit OT.

Also i wanna place and remove dynamiclly lights to the maps.
Actually my solution is very creepy :x

I got a struct-like organisation(C):
Code: [Select]
// Game Lichter
sfGlslVec3 *GameLight_Lightpos;
sfGlslVec3 *GameLight_Conepos;
float *GameLight_Coneactive;
float *GameLight_FBMactive;
float *GameLight_Ambientactive;
float *GameLight_Coneangle;
bool *GameLight_type;
size_t light_count;

And when i add or remove lights, i use the mm functions from std, like malloc/realloc etc.
My Shader contains this(did in german language):
Code: [Select]
uniform vec3 Licht_Position[MAX_LIGHTS];
uniform vec3 Kegel_Position[MAX_LIGHTS];
uniform float Licht_Kegel_Aktiv[MAX_LIGHTS];
uniform float FBM_Kegel_Aktiv[MAX_LIGHTS];
uniform float Ambient_Aktiv[MAX_LIGHTS];
uniform float Licht_Kegel_Winkel[MAX_LIGHTS];
uniform int Anzahl_Lichter;

As you see, i setted up the bool-like variables to a float, cause, i dont find a function like:

Now i wanna reorganize my Shader Input to a single Structure, also in my C Code.

Is there any possibility with the SFML Framework to do this?

Thanks in advance!

Greetz MOP

Hello folks,

this is my first topic in this forum. First of all my english is not very good.  ;D

Iam actually playing with the C-SFML Libary. Iam coding in C. Iam dont rly know C++, so thats why.

Former i used the SDL Libary, which was easy. C-SFML seems also to be very easy.

Actually i try to put some Example Shader(Edge Detection from the Examples), to a picture. Just for testing in my own gui. But i just failing first for the blend mode...

I use the latest codeblocks and csfml version, with mingw32.

Code: [Select]
bool MenuPlaceIMG(int x, int y, bool type, int id)
    // Initialisieren
    if(!CSFMLIsInit || !mstate.isInit)
        return false;

    sfSprite *sprite = sfSprite_create();
    sfShader *shader = sfShader_createFromFile(NULL, NULL, "edge.frag");
    sfRenderStates state;

    if(shader == NULL || sprite == NULL)
        printf("Shader oder Sprite kann nicht geladen werden!");
        return false;

    sfVector2f position = {x, y};
    sfSprite_setPosition(sprite, position);

    sfShader_setFloatUniform(shader, "edge_threshold", 1.0f);

    // Bild zeichnen
    if(type == false)
        sfSprite_setTexture(sprite, media.header, sfTrue);
        sfTexture_setSmooth(media.header, sfTrue);
        sfShader_setTextureUniform(shader, "texture", media.header);

        state.blendMode = sfBlendAdd;
        state.shader = shader;
        state.texture = media.header;
        state.transform = sfTransform_Identity;
        sfSprite_setTexture(sprite, media.bg[id].background, sfTrue);
        sfTexture_setSmooth(media.bg[id].background, sfTrue);
        sfShader_setTextureUniform(shader, "texture", media.bg[id].background);

        state.blendMode = sfBlendAdd;
        state.shader = shader;
        state.texture = media.bg[id].background;
        state.transform = sfTransform_Identity;

    sfRenderWindow_drawSprite(screen, sprite, &state);

    // Speicher freigeben
    shader = NULL;
    sprite = NULL;

    return true;

If i tryn compile this, i got some linker errors, and iam actually sure, that i linked all libarys...

My errors:
Code: [Select]
|249|undefined reference to `_imp__sfBlendAdd'|
|252|undefined reference to `_imp__sfTransform_Identity'|
|260|undefined reference to `_imp__sfBlendAdd'|
|263|undefined reference to `_imp__sfTransform_Identity'|
||error: ld returned 1 exit status|

By The way, when i want to use the default Colors like sfBlack or something, i get the same errors.

My Link-Libarys sequence are the following

Anyone an idea to fix this?

Thank you all in advance for help or tips.

Greetings MOP

Pages: [1]