SFML community forums

General => SFML projects => Topic started by: dwarfman78 on April 05, 2014, 10:40:07 pm

Title: Tanks !
Post by: dwarfman78 on April 05, 2014, 10:40:07 pm
Intro
Let me introduce you to this game i made for masturbation purpose only as it took me  a ridiculous amount of very long time to do as a hobbyist game developer.
You play a green USofA tank. You must survive endless waves of red chinese communist tanks.

Rules
Each enemy destroyed will add 1 point to your score.
Each bullet you take from an enemy will drop your health by 1 point.
When you run out of health the game is over.

Tech
From a tech aspect, and because i did this for educational purpose, the game features :

- not fully mastered deWitter's game loop
- cheap xml / spritesheet based animation system using pugixml.
- as limited (feature wise) as sexy useless template based resource manager.
- quite decent 2D Opengl drawing , sound and system events handling based on S.F.M.L.
- pitifully bugged entity system. seems stable now.
- super simple particle system designed in a way that it completely wastes lambda expression usefulness.
- lousy memory management. should be ok now.
- some known and probably unknown bugs.
- some other stuff that doesn't deserve to be mentioned.

Website
http://dwarfman78.github.io/tanks/

Medias
(http://s11.postimg.org/tg9dns7c3/Tanks01.png)

(http://s17.postimg.org/cz5ylratr/Tanks02.png)

binaries for windows (4 mb) : https://github.com/dwarfman78/tanks/releases/tag/v1.0.0

Sources available from my github repository : https://github.com/dwarfman78?tab=repositories

You'll need pugixml, Box2D and SFML 2.1 to build the engine and the game.

Controls

Move : Keyboard arrows or joystick, you can assign joystick buttons by editing config.xml
Shoot : Spacebar or designated button in config.xml
M : Mute music
Escape : show/hide menu

Have fun.
Title: Re: Tanks !
Post by: Doodlemeat on April 06, 2014, 01:53:30 am
Quote
this game i made for masturbation purpose only
I hope that is either irony or a spelling mistake.

Seriously though, I think it looks pretty good. But you should consider giving the player smooth movement aswell. From what I can see now, the enemy tanks can attack you from 0-360 angle, while you only can attack them in a 0-45-90.. angle. Whenever you are pressing the W or KEYUP, make the tank go towards the mouse.
Title: Re: Tanks !
Post by: dwarfman78 on April 06, 2014, 09:14:56 am
it is indeed an ironical statement, however the making of this little game was like intellectual s&m porn to me, very stimulating and yet fun to learn c++, trigonometry etc.

I am afraid that introducing the mouse as input controller will compromise the game simplicity and straightforwardness ... unless i move the fire button from spacebar to mouse click button, this is a quite interesting idea thank You.

EDIT : my friends advised me to implement joystick with full 360° rotation and progressive throttle.
Title: Re: Tanks !
Post by: dwarfman78 on April 08, 2014, 09:32:22 pm
To satisfy you bearded geeky paranoid folks, i've posted a new package with bug fixes and embedded src which should compile on both windows and linux provided you declare the needed precompiler instructions.

dependencies are SFML  2.1 (audio, graphics, window, system) and pugixml.

You need to build the engine first then the game itself. I recommend dynamic linking on linux.
Title: Re: Tanks !
Post by: dwarfman78 on April 08, 2014, 10:48:32 pm
By the way you can modify the game's configuration so that red tanks become blue and green tank becomes red (if you're a communist you'd prefer playing a red tank yeah i get that) or run faster.

Make sure you keep aside a backup config before making the game unplayable.

Here's the animation.xml for red vs blue like the old days c&c red alert.

<animations>
        <animation name="joueur_stop" duration="1">
                <frame left="0" top="32" width="32" height="32"/>
        </animation>
        <animation name="joueur_run" duration="1000000">
                <frame left="0" top="32" width="32" height="32"/>
                <frame left="32" top="32" width="32" height="32"/>
                <frame left="64" top="32" width="32" height="32"/>
                <frame left="96" top="32" width="32" height="32"/>
                <frame left="128" top="32" width="32" height="32"/>
                <frame left="160" top="32" width="32" height="32"/>
                <frame left="192" top="32" width="32" height="32"/>
                <frame left="224" top="32" width="32" height="32"/>
        </animation>
        <animation name="ennemi_stop" duration="1">
                <frame left="0" top="96" width="32" height="32"/>
        </animation>
        <animation name="ennemi_run" duration="1000000">
                <frame left="0" top="96" width="32" height="32"/>
                <frame left="32" top="96" width="32" height="32"/>
                <frame left="64" top="96" width="32" height="32"/>
                <frame left="96" top="96" width="32" height="32"/>
                <frame left="128" top="96" width="32" height="32"/>
                <frame left="160" top="96" width="32" height="32"/>
                <frame left="192" top="96" width="32" height="32"/>
                <frame left="224" top="96" width="32" height="32"/>
        </animation>
        <animation name="bullet_fire" duration="1">
                <frame left="180" top="117" width="16" height="17"/>
        </animation>
        <animation name="fire_smoke" duration="1000000">
                <frame left="0" top="560" width="130" height="90"/>
                <frame left="130" top="560" width="130" height="90"/>
                <frame left="260" top="560" width="130" height="90"/>
                <frame left="390" top="560" width="130" height="90"/>
                <frame left="520" top="560" width="130" height="90"/>
                <frame left="650" top="560" width="130" height="90"/>
        </animation>
        <animation name="explosion" duration="750000">
                <frame left="0" top="0" width="64" height="64"/>
                <frame left="64" top="0" width="64" height="64"/>
                <frame left="128" top="0" width="64" height="64"/>
                <frame left="192" top="0" width="64" height="64"/>
                <frame left="0" top="64" width="64" height="64"/>
                <frame left="64" top="64" width="64" height="64"/>
                <frame left="128" top="64" width="64" height="64"/>
                <frame left="192" top="64" width="64" height="64"/>
                <frame left="0" top="128" width="64" height="64"/>
                <frame left="64" top="128" width="64" height="64"/>
                <frame left="128" top="128" width="64" height="64"/>
                <frame left="192" top="128" width="64" height="64"/>
                <frame left="0" top="192" width="64" height="64"/>
                <frame left="64" top="192" width="64" height="64"/>
                <frame left="128" top="192" width="64" height="64"/>
                <frame left="192" top="192" width="64" height="64"/>
        </animation>
</animations>
 
Title: Re: Tanks !
Post by: BaneTrapper on April 10, 2014, 06:47:18 pm
My antivirus has prevented the app from running reported virus i am not known with what it is,
also the site is untrusted, antivirus blocks most of the page from loading i get really weird "page / view".
Is it safe? can anyone confirm?

EDIT::
It was resolved in post as !!!SAFE!!!
Title: Re: Tanks !
Post by: zsbzsb on April 10, 2014, 06:51:26 pm
Your browser complains about the site because it uses HTTPS without a valid certificate, and the executable is fine also.

You can easily check it using any online scanner like this (https://www.virustotal.com/en/url/5891277c2b20ba8a797ace327e83bac0f749eb5b2c113e05720d48a982f97cea/analysis/1397148777/).
Title: Re: Tanks !
Post by: dwarfman78 on April 10, 2014, 07:21:07 pm
There's no danger, you have this message because it is a self signed certificate i could make a valid certificate but i don't want to provide the personal information the authority is asking for.

The binary is safe too, you can build the game yourself if you want as i'am providing the source code within the zip archive.

The game works fine on wine as far as i know.

I've discovered at least a memory leak in the game so, i think i'm going for raii in the next version because i'm starting to be fed up with those memory management problems.
Title: Re: Tanks !
Post by: dwarfman78 on April 13, 2014, 11:09:25 am
New version available

Changelog:

Changed memory management (shared_ptr instead of raw pointers)
Grassy background.
Muzzle flashes, impacts and trails particles added.
Centered window at start.

Have fun.
Title: Re: Tanks !
Post by: dwarfman78 on April 13, 2014, 11:13:02 am
38 points is my best score so far (with default configuration)
Title: Re: Tanks !
Post by: Nexus on April 13, 2014, 11:37:05 am
Funny little game :)

My impressions:
By the way, you should rather use unique_ptr instead of shared_ptr, unless you have a good reason for the latter :P

(My highscore was 32)
Title: Re: Tanks !
Post by: dwarfman78 on April 13, 2014, 07:09:46 pm
Funny little game :)

Thank you ! I'm glad you tried and enjoyed it, thank you for your feedback, here are my answers :

Quote
Sometimes the enemies spawn almost inside or directly behind the player, where you have no chance to evade. Don't you want to let them enter from the border of the screen?

Well i don't know, i see what you mean but i like the effect of surprise and this behavior adds some "luck" parameter to your final score, which is good in any game (skills+a touch of luck = success)

EDIT : spawning enemies outside the window add a little extra immersion i like it !

Quote
There's a bug when you stand still: an enemy tank drives over you and is too close to hit you.

Yes i think i have to stop the enemy before he reaches the player.

Quote
At the moment, you can keep firing all the time. There should be a motivation to limit the fire, for example ammo supply that needs time to reload (so you can fire 5 projectiles, but then have to wait some time), or health that regenerates while you're not firing.

Interesting, i've been thinking about dropping bonuses and ammo crates at a random pace, however it complicates the game's balance.

Quote
I agree that 8 directions limit the gameplay, as you cannot really aim.
I guess i will have to implement mouse+keyboard control and analogic joypad too.

Quote
The smoke could be focused in front of the tank.
I'll make some tests as it shouldn't take long.

Quote
It would be nice to restart directly after game over.
Yeah, i have to add a menu in any case, with a start button and replay button, it should be a nice addition to my little engine as i need to implement a sort of scenes stack (lifo) before i do the gui, there's some work to do in that area and i don't know if i'll be able to do it.

Quote
By the way, you should rather use unique_ptr instead of shared_ptr, unless you have a good reason for the latter :P

You are right, i was not aware of unique_ptr existence. After a short analysis, it needs to be used with temporary entities as i call them in my engine because the main rendering class is the only one to own those entities (from instantiation to destruction).

I must say that i am a bit disappointed about the documentation i found about smart pointers (and c++ in general) on the internet, i do not mean reference websites as i mostly don't care about methods listing and short examples, i'm talking about good, complete, clear and fresh litterature on those cutting edges subjects.

Quote
(My highscore was 32)
Congratulations, most of my friends do an average of 30 points.
Title: Re: Tanks !
Post by: dwarfman78 on April 28, 2014, 08:51:40 pm
New version available:

Added scenes stack, rendering on texture and shaders to the engine.
Added menu to the game using those features.
New musics (using ogg format for better compression).
Foes now spawn out of the screen and stop near the player.
Joystick is enabled but it doesn't work well on windows (though you can tweak buttons assignation numbers from conf file).
Title: Re: Tanks !
Post by: dwarfman78 on April 29, 2014, 09:30:32 pm
New release :

After a little session of profiling, i cleaned the code from the most costly operations.
Title: Re: Tanks !
Post by: dwarfman78 on May 27, 2014, 11:46:08 pm
New release, i can't remember the changelog, the big add is Box2D bodies support to the engine, this is illustrated in the game with gun shells popping out of the tanks.

So how does it look ?
Title: Re: Tanks !
Post by: dwarfman78 on May 27, 2014, 11:52:49 pm
there's a bug with health points z-index.

bodies are described as follow (from physics.xml) :

<physics>
        <world gravity="0.0"/>
        <body name="shell" type="dynamic">
                <fixture density="0.5" friction="0.3" restitution="0.5">
                        <shape type="box">
                                <point x="7.0" y="2.0"/>
                        </shape>
                </fixture>
        </body>
</physics>

for the moment only "boxes" shapes are supported, but i will probably add polygon and circle shaped bodies.

body defs are loaded in memory and reused when needed by their name.


Title: Re: Tanks !
Post by: dwarfman78 on May 29, 2014, 10:18:38 am
New release : https://github.com/dwarfman78/tanks/releases/tag/v1.0.0

I'm going to use github for binaries distribution instead of my personal server.

Added blast from explosion (sprite and physics).
Changed ttf for text to a military styled font.
Bug correction (hp displaying is back to normal)
Title: Re: Tanks !
Post by: dwarfman78 on May 31, 2014, 10:48:28 am
There is a bug with sound effects in general, i did not take into account the fact that there is a limited number of sf::Sound instances that can be in a program at the same time, so i guess i'll have to implement some sort of "sound pool" to manage sf::Sound usage.
Title: Re: Tanks !
Post by: dwarfman78 on June 23, 2014, 10:13:04 pm
I'm currently doing some tests in order to add scripting capabilities to the game (or even maybe the engine) throught chaiscript (http://chaiscript.com/).

for the moment bullet behavior is defined at compile time :

void Bullet::renderLogic()
{
    if(!collision())
    {
        sf::Vector3f pos = myEntity->getPosition();

        myEntity->setPosition(pos.x+(speed.x*(myInterpolation)),
                             pos.y+(speed.y*(myInterpolation)));
    }
    else
    {
        unregister();
    }
}

But now i'm able to write :

void Bullet::renderLogic()
{
    chai.eval_file("bullet.chai");
}

And edit the bullet.chai as follow :

if(!this.collision())
{
        myEntity.setPosition(posX+(speedX*(myInterpolation)),
                             posY+(speedY*(myInterpolation)));
}
else
{
        this.unregister();
}

Providing the binding information :

    chai.add(chaiscript::var(this),"this");
    chai.add(chaiscript::fun(&Bullet::collision),"collision");
    chai.add(chaiscript::var(myEntity),"myEntity");
    chai.add(chaiscript::var(&myInterpolation),"myInterpolation");
    chai.add(chaiscript::fun(&se::Entity::setPosition),"setPosition");
    chai.add(chaiscript::var(&speed.x),"speedX");
    chai.add(chaiscript::var(&speed.y),"speedY");
    chai.add(chaiscript::fun(&se::Entity::getPosition),"getPosition");
    chai.add(chaiscript::var(&myEntity->getPosition().x),"posX");
    chai.add(chaiscript::var(&myEntity->getPosition().y),"posY");
    chai.add(chaiscript::fun<void (Bullet::*) ()>(&Bullet::unregister),"unregister");