Monday, 29 December 2014

(SOLVED) Can You Find the Bug?

I'll leave this here for posterity...

The problem was not with the Vector method, but with the caller. I was casting the angle of roundAngle() to int instead of using the math::round function. D'oh!

This is supposed to constrict the vector to 45 degree slots. Only 2D, ignore the z component. The (rounding?) bug occurs when the correct answer is 180 and -90; this algorithm returns 179 and -89 respectively. Why?!

    // ----------------------------------------------------
    //   round the angle to nearest x degrees
    // ----------------------------------------------------
    Vector3 Vector3::roundAngle ( int nearest_angle )
            // vector to return
            Vector3 rounded;

            // convert to radians
            double nearest_radians = RADIANS ( nearest_angle );

            // get the angle of this vector
            double angle =  atan2 ( this->y, this->x );

            // remainder between 2 angles
            double remainder = std::fmod ( angle, nearest_radians );

            // if there is a remainder, do the rounding
            if ( remainder != 0 ) {

                    double new_angle = round ( angle / nearest_radians ) * nearest_radians;

                    rounded.x = cos ( new_angle );
                    rounded.y = sin ( new_angle );
                    rounded.x = this->x;
                    rounded.y = this->y;
                    rounded.z = this->z;

            if ( fabs ( rounded.x ) < TOL ) rounded.x = 0;
            if ( fabs ( rounded.y ) < TOL ) rounded.y = 0;
            if ( fabs ( rounded.z ) < TOL ) rounded.z = 0;

            return rounded.normalised();

Friday, 26 December 2014


The Amiga always had better graphics and sounds, but the first time I loaded a new season on PC, I knew its days were numbered!

Dad's IBM Thinkpad back in 1994. I installed Day of the Tentacle and Championship Manager 93 and I was hooked!

Wednesday, 24 December 2014


Here's a website for the game (if it's ever finished). Amazing what you can do with css these days.

 Senseless Soccer Homepage

Fixed Delta

Fixed as in "constant"... the engine now has a fixed time step (delta) for the physics simulations. Can you tell the difference?

Basically, the game step tries to run at 60 frames per second. The physics and rendering are decoupled and each can concede time back to one another. This means that the physics step may be executed more than once per frame, but always with the same time delta.

Monday, 15 December 2014

Words of Wisdom

"Having one less character to type is NOT a good reason to prefer float over double..."

The extra precision can surprise you by fixing a lot of weird buggy stuff that you hadn't managed to trace back to floating point precision and, unless you're targeting some really specific old hardware or trying to simulate the universe or something, doubles don't cost you anything so might as well use em!

That's the problem with taking examples from badly written books - when your focus is on learning a bit of path-finding or something and the fact that the author riddled his code with floats just doesn't register!

Out of interest, switching to double fixed a few bugs like the rounding of vector angles to their nearest 45 degrees.

Wednesday, 10 December 2014

Under the Hood

The past few late nights have been spent splitting the project into reusable components. It was already structured that way but now we have a shared game library that can be linked to for use in future games.

The lib can be linked statically or dynamically.

An example of the line between the game and the lib is the Player Sprite. The Player Sprite is part of the game and inherits from Sprite which is part of the generic library. Sprite then inherits from a generic Renderable object.

The lib also contains stuff like math tools (vectors), physics, input and Window management. Anything that could be reused for another game really!

P.S. Finally made the jump from bog-standard make to cmake for the shared library. It's just as cryptic but a little easier to use I guess!

Thursday, 4 December 2014

Joystick Input

For future integration in-game, interface tweaked for joystick input (like SWOS).

Moving the joystick highlights different players or the ball (flashing border), pressing fire locks on to the currently selected object(fixed border) to be able to move it around. Pressing fire again unlocks and returns to the "select object" mode.

Monday, 1 December 2014

Quick Tactics Editor in Java

Utilizing the simple grid system from the game, this makes a nice tool for visually setting up tactics and player positions for different situations.

Each player icon represents a player position structure, which is basically just an ordered list of numbers specifying which sector the player should try to get to for each ball sector. See this post for info.

Positions can be created, copied, imported and exported so a full tactic is simply a collection of 10 unique positions in a group.

In future, we'll add more detailed tactics and strategies like passing style, positions for set pieces, marking style etc.