MoveCircle.java

Usually turn-based tactics and strategy game’s game objects are inside squares or hexes. I’ve decided that in my game it would be fun to make turn-based game without those board game like cells. Biggest differences compared to hex and square thingies, I could think of when I planned this, were: objects positions are not hex No. X but x and y float coordinates in game space, distances are not X amount of hexes but  float numbers and the area where game characters can move are now circles. So I’ve came up with MoveCircle which shows where player character can move, how many action points moving will take and path which character will use. I can’t remember, have I seen this kind of way to control character in any other game but it’s so simple I think I am just reinventing the CIRCLE here (but that joke was really original).

Moving path (the blue line in the picture) now shows how far within the green circle the character will go but I’m also going to make it show a path around objects which are blocking the way.

Since OpenGL doesn’t have circle shapes by default  I had to make my circles by myself from triangles. Easiest way for this is to make for-loop which counts vertices from distance from the center of the circle and angle with the help of my arch-nemeses from senior high school: sine and cosine.

//Green circle's vertices
circleArray[0] = 0;
circleArray[1] = 0;
// Angle
float theta = 0;

for (int i = 2; i < circleArray.length; i+=2) {
    // x-coordinate
    circleArray[i] = FloatMath.cos(theta);
    // y-coordinate
    circleArray[i+1] = FloatMath.sin(theta);
    //Black line circle's vertices
    lineCircleArray[i-2] = circleArray[i];
    lineCircleArray[i-1] = circleArray[i+1];
    // The angle is in radians
    theta += 2*(Math.PI) /((circleArray.length/2)-1) ;
}

The circleArray is an array which consists the green transparent circle’s vertices. It also has the center vertices because it will be drawn from triangles. This loop also includes the black hollow circle’s vertices. It doesn’t have center vertex  because it’s made from lines. When for-loop fills the arrays the line circles and green circle are same size but when OpenGL draws them I just scale them smaller.

The more circle has vertices  the more smoother it is. This also means bigger arrays for vertices and possibly less frames per second. My circleArray’s length is 38 so it has 19 vertices (18 on the edges and 1 in the center). Of course one can distinguish the edge lines in my circles but it’s perfectly adequate for testing.

More about OpenGL ES circles:

http://stackoverflow.com/questions/4811981/drawing-a-circle-in-android-with-opengl-es-results-in-a-square

http://gamedev.stackexchange.com/questions/26232/drawing-a-circle-in-opengl-es-android-squiggly-boundaries

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s