My Current Project

Hi Everyone,


I have something like 1400+ lines of code for a hardcoded "game" exercise I'm working on using SFML 1.6. I'd like to share the source code with anyone who is interested enough to read through it, I would REALLY like someone\anyone to tear it apart but I can't ask anyone to scan through more then a thousand lines of code for nothing. Where do you guys suggest I upload it?

A few things about the project:

- This is a work in progress, just something for me to do when I can't sleep or I'm too bored to think. Quite a few things are done with a plan to add more to it in the future*. A few things are commented out because they are not done yet. Feel free to ask about any of it.

- There is no sound. Not that I'm having any trouble with it (sound is actually incredibly simple in SFML) it's just a low priority for this project.

- The graphics are stick figures I drew in MS Paint. This is an exercise in CODING for me not drawing. I'll commision a real artist if I ever write a real game, or I kind of like the idea of going old school and brining back "FMV": http://en.wikipedia.org/wiki/Full_motion_video after all a picture is a picture right? Any comments on that are welcome in this thread as well.

*: One such example is something called the "Portrait". This will eventually display the status of the currently selected unit including ammo, health current target etc. To reenable this comment out Line 172 in "Z.cpp" and delete the comment out characters from Lines 119 and 173.

EDIT: I forgot to mention:

- Most of the things the actors do are automatic, the half-assed logic I used is in their respective cpp files. You can suggest directions for them to travel by selecting them with a left click and sending them some where with right click.

-The 'x' in the top right corner doesn't work because I just haven't coded it yet, you close the game by hitting 'esc'.
Last edited on
Is GitHub an upload option or do you want to keep some sort of license? I am very interested to see a game's code from you :)
Last edited on
I'm not to concerned about licencing. The project isn't that far along that I've developed an attachment to it. Github it is, I'm setting up an account now. Thanks LB!
Hint: you upload your sourcecode, it creates the zip for you:
http://github.com/ComputerGeek01/Random/downloads
There's a nice pretty button that says "Download as zip" ;)

I did manage to get it in the end - zip -> folder -> zip -> folder -> code

UVec.erase(UVec.begin(), UVec.end()); //Hopefully Calling The Destructors Of The Objects In The Vector
Yeah, it's calling the destructor of UNIT*, which by no means calls delete ;)

void pause() __attribute__((destructor)); //This Is A GCC\Mingw Specific Function Attribute, I Have No Idea How To Do It Using "cl.exe" SOMEONE PLEASE TELL ME!!!
1
2
3
4
5
6
7
struct PauseAtEnd
{
    ~PauseAtEnd()
    {
        pause();
    }
} pauseatend;
perhaps? Not sure what the attribute does, nor what cl.exe is.
Last edited on
Cl.exe is the compiler for the MS DDK. I assume it's the one for VS as well. I'll fix github in the morning thanks for your patience with downloading that LB. The destructor thing is going to take me some work but thanks for pointing that out.
The destructor thing should not take work ;)
for(std::vector<UNIT*>::iterator it = UVec.begin(); it != UVec.end(); delete *(it++));
Then UVec's own constructor will, of course, clear its elements.
Last edited on
Just curious but did you compile it? I know I'm being pushy but what do you think?
1>------ Rebuild All started: Project: Computergeek01, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'Computergeek01', configuration 'Debug|Win32'
1>Compiling...
1>BASE.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>building.hpp(19) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>building.hpp(20) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>Building.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>building.hpp(19) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>building.hpp(20) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>Enemy.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>enemy.hpp(37) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>enemy.hpp(43) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Fighter.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>fighter.hpp(33) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>fighter.hpp(39) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Portrait.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Units.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.cpp(60) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.cpp(61) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Z.cpp
1>units.hpp(85) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>units.hpp(91) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>fighter.hpp(33) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>fighter.hpp(39) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>enemy.hpp(37) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>enemy.hpp(43) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>building.hpp(19) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>building.hpp(20) : warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data
1>z.cpp(28) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>z.cpp(107) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>z.cpp(108) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>z.cpp(121) : warning C4018: '<' : signed/unsigned mismatch
1>z.cpp(137) : warning C4018: '<' : signed/unsigned mismatch
1>Generating Code...
1>units.cpp(224) : error C4716: 'UNIT::Attack' : must return a value
1>fighter.cpp(195) : warning C4715: 'FIGHTER::draw' : not all control paths return a value
1>Build log was saved at "file://Debug\BuildLog.htm"
1>Computergeek01 - 1 error(s), 36 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I think you have quite the problems here.

The ones that scare me the most:
units.cpp(224) : error C4716: 'UNIT::Attack' : must return a value
fighter.cpp(195) : warning C4715: 'FIGHTER::draw' : not all control paths return a value
After I make UNIT::Attack just return 0, I get about a million unresolved externals errors from the linker.
Last edited on
I needed to change the paths. Backslashes are evil.

Also putted a namespace for pause(). You know, to avoid name collision.
When I realize what it was doing, I just kill it.

Just glanced the code. If you've got virtual methods, you must have a virtual destructor.

For some reasons they all go to the bottom border

Edit:
warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
¿eh? ¿this line? Right = Pos.x + (25 * scale); they are all floats...
I get about a million unresolved externals errors from the linker.
Well, you need to link against the library.
If you are using the makefile, check that the paths are correct
$ g++ *.o -lsfml-{system,window,graphics} -o game.bin
Last edited on
The unresolved externals are from the code Computergeek01 wrote, SFML is linked fine. I don't know where you grabbed that line from, but all the ones I checked do indeed attempt to implicitly convert an int to a float.
Sfml throws a lot of warnings that I had to ignore. I know it seems lazy but seriously try working with that library at more then a novelty level. The loss of data crap is mostly pixel conversion stuff that afaik is fixed in 2.0 . I'll make a note of the virtual destructors. I'm working mostly in XP right now so memory leaks seem unavoidable :p.
Removed the inlines from UNIT and FIGHTER (these cause the linker errors) and commented out the __attribute__ line, runs fine for me VS2010.
Last edited on
@Computergeek: notice that the files giving the warnings are your own and not SFML ;)
And, unless you have really low memory constraints, always use doubles over floats when you can.
Last edited on
@ naraku933: I had notes right next to the "__attributes__" command stating that it was GCC\Mingw only.

@ LB: What lines do I try to convert an integer to a float? Checking one at random from your list Line 85 in "units.hpp" uses 'Pos' which is an sf::Vector2f meaning float, 'scale' and 'Right' which are both floats. The other warnings are from simular lines. You're right though I should use double data types.

This is one of the lines in question:
Pos.x = rand() % 200; //Start Somewhere between 0 and 200
I'm 100% sure that rand() returns an integral type, otherwise you wouldn't be able to use modulo on it with an integral constant.
Well I'll be... That one flew right under my rader. I'll have to fix that.
Topic archived. No new replies allowed.