środa, 30 maja 2012

Well. I decided to write the blog in English. Since the topic is programming all target audience will be able to understand it. Writing in Polish would only limit the audience and usefulness of the blog.

So. Where to start.

Idea:
As a teenager my favorite game was Battleground: Ardennes. The amazing 3D view was so great. My game will not have 3D view (at least from start, maybe later), but it will be a hex strategic game about World War II.

Preparation:
I need a game engine. I decided to have fun and write it myself. The nowadays programming is awful - lots of XML, already existing classes and libraries, filling only some configuration. If you are lucky - you maybe will write some code. So I want to write some code - if as a hobby - so be it.

Currently I decided to write it in old Borland C++ Builder 6 - Personal. I want to write something in C++, at least for some time, second, I'm sick of Java.

Now I have some basic functionality written - displaying a hex map etc. Small piece of code - finding a hex on which mouse pointer is. I based it on http://gamedev.stackexchange.com/questions/20742/how-can-i-implement-hexagonal-tilemap-picking-in-xna

I have component based on TImage, which displays hex map, and some functions which allows to find which hex is pointed:


Code translating mouse point to column/row of hex map:


bool __fastcall TImageHx::XY2Hex(TPoint* out, int x, int y)
{
        int w = this->MapHexSize;
        int W = 2 * w;
        int h = W;
        

        int i = floor(2.0 * x / (W + w));
        int j = floor(2.0 * y / h);


        double u = (double)x - (i * (W + w) / 2.0);
        double v = (double)y - (j * h /2.0);
        double up = 2.0 * u / (W -w);
        double vp = 2.0 * v / h;
        

        bool upper = ((i % 2 == 0) && (j % 2 == 0)) || ((i % 2 == 1) && (j % 2 == 1));
     
        if( u < ((W - w) / 2))
        {
                if((!upper && vp > up) || (upper && (1 - vp) > up))
                {
                        i -= 1;
                }
        }


        if(i % 2 == 1) j -= 1;
        if(j >= 0) {
                j = j/2;
        }


        if(!isHexOnMap(i, j)){
                return false;
        }


        out->x = i;
        out->y = j;


        return true;
}



I still think about the technology used... maybe it would be better to write it for Android? Maybe if the game will be OK, I will be able to sell it, or at least easily share it?





Brak komentarzy:

Prześlij komentarz