Google Map Race

Long time I didn’t make something… to mush work and too big projects. To make a pause, I give a try to an idea that I had.

One of the annoying thing is to create maps, so I wanted to take map form google so I only have to define start point and end point for a racing game :stuck_out_tongue: (yes race all around the world !!!).

I manage to “stream” map but it was too slow (I only download 1 image at a time to not harm server) and maps from google are far too mush inacurrate. So I go for an editor that download map with a few tools to define road limite. Even so, the size of data is far too mush :frowning: (6mo for a small part of a small town…)

So there is the result (a flew day of works ;)), it is not polished but it is complet : Google Map Race
And the editor : Google Map Race Editor
The source code : User : guest , Password : guest0

For the game :
left : turn left
right : turn right
up : speed up
space : select

For the editor, everything should be put in the “~/.bonbonchan/” folder. To add a race, you have to add a “.txt” file with 3 line :
1/ Name of the race
2/ Start point : ix,dx,iy,dy,angle
3/ End point : ix,dx,iy,dy,angle

ix,iy are integer of the coordinate of the image. dx,dy are double of the coordinate inside the image. angle is a double in radian.

To conclude, this game is not really good (or even legal), but I did’t want to waste the code so ;D.

Nice game ;D I would have loved to be able to get out the car to shoot some people lol.

hey very good idea, It would be nice to be able to see road “locked” also zoom in & out would be awesome.

Got the bread in 2:19:00

Will you release the source code?

Cool. :slight_smile: I think the main thing this could benefit from (and is missing) is the ability to take any side road you want. I felt like I saw all these little roads that I would try to go down to save some time but I would just end up being cut off.

You miss the versionning link :wink:

https://free1.projectlocker.com/bonbonchan/GoogleMapRace/trac/browser
Login : guest
Password : guest0

[quote]Cool. :slight_smile: I think the main thing this could benefit from (and is missing) is the ability to take any side road you want. I felt like I saw all these little roads that I would try to go down to save some time but I would just end up being cut off.
[/quote]
There is several possible paths but it takes a lots of time to edit all the roads.

Thanks. I’m reading the whole source code now. Getting all files one by one is a bit painful. Do you have a GIT or SVN repository?

Maybe it would be easy to allow the car to move back by doing this:

double acceleration = 0;
if(up) { acceleration = A; }
if(down) { acceleration = -A/10; }

instead of

double acceleration = 0;
if(up) { acceleration = A; }

https://free1.projectlocker.com/bonbonchan/GoogleMapRace/svn
Same login/password

Usually in racing game, I don’t even think about slowing down or going backware :stuck_out_tongue:

if u get stuck in a corner?

I usually just smash down the acceleration until some miracle happens and I am out of the corner haha…maybe thats just me though.

hahahahahahaha

This is quite funny, but I wish there was some hint on where is drivable and where is not … on the end of the track I spent hours trying to find where to enter the parking lot .
Good job anyway !

(ps: the link for the editor is not working )

[quote=“teletubo,post:13,topic:35482”]
Corrected :slight_smile:

When I replaced Timer and TimerTask by their JDK equivalent, the window stayed gray. As I did not want to keep these classes, I used something more simple:

public void run() {
        long elapsedTimeInNano = 0, previousTimeInNano, timeInNano = System.nanoTime();
        state = new Title();

        try {
            while ((thread != null) && (thread.isAlive())) {
                time = System.currentTimeMillis();

                previousTimeInNano = timeInNano;
                timeInNano = System.nanoTime();
                elapsedTimeInNano += timeInNano - previousTimeInNano;

                int nb = (int) (elapsedTimeInNano / (1000000000 / FRAMERATE));

                if (nb > 0) {
                    elapsedTimeInNano -= nb * (1000000000 / FRAMERATE);
                }

                for (int i = 0; i < nb; i++) {
                    state.logic();
                }
                
                initDraw();
                state.draw();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

Does my solution consume more CPU time?

Without testing I will say yes, it consumes more CPU time. You have remove all wait so draw() will be invocaded as mush as possible. In my case, draw() is invocaded at most of 60 fps.

For the Timer / TimerTask, I have just copy the jdk code and made modification to have a better accuracy (you should check if I use a time in nanosecond while the original one is in milisecond, I don’t remember how I have done it).

Ok that is what I feared.

I compared the both, I only found an attribute called “offset” in TimerTask and something different in the scheduling. The problem is that I was unable to explain your modifications to some students so I preferred using something more simple. Would it be dangerous to invoke Thread.sleep() in the method JMain.run()?

I’m an example to students ;D funny

In JMain.run(), if nb == 0, it’s mean that you have time to do a Thread.wait( ((1000000000 / FRAMERATE) - elapsedTimeInNano)/1000 ) (or use the nano second method).

For TimeTask, it use System milisecond and there is “rounding” error while using a framerate of 60. So I use an “offset” to correct the error.