Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 May 2005
Offline Last Active Today, 09:59 AM

Posts I've Made

In Topic: [java] Hello! First post, a little introduction and few questions! :)

15 May 2014 - 12:36 AM

I do not think they ban anybody because of bad code. It is hard to ask questions that get approval, though. rolleyes.gif


Guess the NPE is taken care of, now. Maybe somebody here knows something about the remaining problem.

  • We initialize objects now before the thread is started.
  • We use a MediaTracker to wait until the images are loaded before we set the Applet to visible and start the main thread.

What does not work is that the logic has already progressed quite a bit when the graphics are rendered for the first time.


Is there a mechanism that would allow us to wait for whatever setVisible does asynchronously to complete?

Waiting (Thread.sleep(...)) after calling setVisible seems to help, so that is why I think that must be the remaining problem.

I tried to react to a COMPONENT_SHOWN ContainerEvent, but I think they are thrown right away when setVisible is called.

Is there any Event that tells us that everything is set up has been rendered successfully once?


Another question: The game is currently an Applet. How different or not is programming graphical apps with the Android SDK?

Is it important to make the transition early or is it pretty similar?

In Topic: Suggestions to a wannabe!

13 May 2014 - 12:10 PM

I am not a fan of starting with text based games ... they deal with weird comparisons and you are likely to end up with weird switch statements or nested ifs.

Especially if you use a language (JavaScript) or even engine (Unity) that is more appropriate for graphical programs, then having to deal with rendering text gets really ugly.


IMO the better idea is doing some of the Google Code Jam challenges. You are forced to learn to think like a programmer and you will be able to apply that way of thinking to making games later.


To decide if ISO is too complex to implement or not you can look at the tutorials that are listed there:



Converting Cartesian coords to ISO coords and figuring out which ISO tile the mouse is hovering over, those are not quite trivial ... but doable.

In Topic: [java] Hello! First post, a little introduction and few questions! :)

13 May 2014 - 12:15 AM

Hello! :-)


So you figured out the NPE is always related to missing images? Did you add debugging (System.out.println() for example) to figure out where in the code the problem occurs?

Do you know how to print and analyze StackTraces?


Missing images ... I would not suspect higher forces like viruses. Most of the time when we (companies I worked at) thought some other program or the system were at fault we had to learn that we were doing something wrong.


What does your build setup look like? The build process might delete and recreate the output / target folder (where the .class files are compiled to).

Putting the resources there does not work.

If that is how your project currently is set up you can try to create another source folder for the resources (... or put them in the source folder with the .java files which is not a nice solution). Then the build process should move those resources to the target folder after it has been cleared.


You could also use Ant or something similar to write logic for the build process but that might be too much of a distraction right now ... it does take a while to learn how to use it unless you know where to "steal" efficiently.



Btw. you might get away with using other languages, if you are not a fan of Java.

There are solutions like Apache Cordova that turn programs into iPhone or Android apps ... even if they were written in other languages (JavaScript in this case).

Probably something similar exists for other languages as well.

Engines like Unity can turn relatively neutral code into Apps for different platforms as well (I think you can do "scripting" in C# or something like that).

In Topic: How do I simplify the symmetry math

12 May 2014 - 02:32 PM

Dealt with the cartesian to img index brainf... by writing conversion methods (indexYToCartesian) and working with cartesian coords.
After a little break from the code I was also able to write the logic that determines the offset for points that are not on the y axis.

MirrorModeHelperPoint.prototype.calculateOffset = function(indexX, indexY, slope) {

	var offset = Math.floor(-1 * ((indexX * slope) - indexY));
	return offset;

 To simplify that I made sure that the first point of the line object (now created by getCartesianLine()) is the one on the left (lower x index).
I also separated the mirror mode helper logic for axis and point symmetry.
Now the isPointMirrored check basically works. The seams are where I would expect them.
The remaining problems (still undefined or unsupported tile height values) might just be a result of rounding issues.
I made the problem visible at http://procgames.com/raidaces2/
There are colorful dots on the map (neon green for unsupported value, magenta for undefined value) and log messages show the coords of evil dots.

I guess some problems are not covered by that visualisation because when points are handled twice there is a chance that the resulting value is not outside the supported range.

In Topic: How do I simplify the symmetry math

11 May 2014 - 03:52 PM

Well, the resulting map can be seen here (the small overview map):

When I started the thread I was hoping that the only problem with the code was that there was unneccessary complexity ... now I get that data structures are not optimal and the algorithm confusing. I should probably try to work on clarity ... because I am confused enough that I can not explain the problem.

There is a blur of causes and symptoms now that I do not really want anybody else to struggle with.

I still think the only problems lie in the forEachPixelToUpdate method and the methods of the MirrorModeHelper. Some points are handled twice, some not at all.

I think that indicates that MirrorModeHelper.prototype.isPointMirrored might cause all my troubles but not sure.


I don't think anybody should still look at the code and figure out what is wrong with it. Pointers to how this could be accomplished in a different way would be great, though (and if anybody can think of ways to improve the clarity ... please shoot :-)).


Don't really know where to start explaining, but the map is built as follows:

  • The kind of symmetry is chosen (axis or point, plus a line that divides the map in two parts - one that gets rendered explicitly, one that gets rendered because the values are copied there).
  • The map creators can use forEachPixelToUpdate to modify the map array. The function iterates over the points of one of those parts and passes the y and x indices and the mirror indices to the action that was passed to the forEachPixelToUpdate process.
  • First, all the points are set to 2 (the central layer) by using forEachPixelToUpdate and passing the action:
    ForeachTileHelper.prototype.setMiddleValue = function(streamSource,
            map, indexX, indexY, mirrorIndexX, mirrorIndexY, maxValue, minValue,
            neighborTopLeft, neighborTopCenter, neighborTopRight, neighborLeft,
            neighborRight, neighborBottomLeft, neighborBottomCenter,
            neighborBottomRight) {
        map.mapArray[indexY][indexX] = 2;
        map.mapArray[mirrorIndexY][mirrorIndexX] = 2;
  • Then it is used again to raise and lower some of the values ... by calling it several times with the function created by this method:
    CreatorMapMoba.prototype.createCheckedRaiseAndLowerAction = function(doRaise,
            raiseLowerMap) {
        return function(streamSource, map, indexX, indexY, mirrorIndexX,
                mirrorIndexY, maxValue, minValue, neighborTopLeft,
                neighborTopCenter, neighborTopRight, neighborLeft, neighborRight,
                neighborBottomLeft, neighborBottomCenter, neighborBottomRight) {
            var currentValue = map.mapArray[indexY][indexX];
            if (1 == raiseLowerMap.mapArray[indexY][indexX]) {
                if (doRaise) {
                    map.mapArray[indexY][indexX] = currentValue + 1;
                    map.mapArray[mirrorIndexY][mirrorIndexX] = currentValue + 1;
                } else {
                    map.mapArray[indexY][indexX] = currentValue - 1;
                    map.mapArray[mirrorIndexY][mirrorIndexX] = currentValue - 1;

The raiseLowerMap has also been created in a similar way. First random pixels (0 or 1) were set:

ForeachTileHelper.prototype.chooseRandomBooleanValue = function(streamSource,
        map, indexX, indexY, mirrorIndexX, mirrorIndexY, maxValue, minValue,
        neighborTopLeft, neighborTopCenter, neighborTopRight, neighborLeft,
        neighborRight, neighborBottomLeft, neighborBottomCenter,
        neighborBottomRight) {

    var initialValue = (streamSource.consumeShort() % 2);
    map.mapArray[indexY][indexX] = initialValue;
    map.mapArray[mirrorIndexY][mirrorIndexX] = initialValue;

And then a cellular automation algorithm created areas out of the chaos.

ForeachTileHelper.prototype.basicCellularAutomationAction = function(
        streamSource, map, indexX, indexY, mirrorIndexX, mirrorIndexY,
        maxValue, minValue, neighborTopLeft, neighborTopCenter,
        neighborTopRight, neighborLeft, neighborRight, neighborBottomLeft,
        neighborBottomCenter, neighborBottomRight) {

    var mapArray = map.mapArray;
    var countNeighborsTrue = 0;

    if (1 == neighborTopLeft) {
    if (1 == neighborTopCenter) {
    if (1 == neighborTopRight) {
    if (1 == neighborLeft) {
    if (1 == neighborRight) {
    if (1 == neighborBottomLeft) {
    if (1 == neighborBottomCenter) {
    if (1 == neighborBottomRight) {

    // Guess I should update a buffer array first and keep using the original
    // for the algorithm.
    if (4 < countNeighborsTrue) {
        mapArray[indexY][indexX] = 1;
        mapArray[mirrorIndexY][mirrorIndexX] = 1;
    } else if ((3 < countNeighborsTrue) && (1 == mapArray[indexY][indexX])) {
        mapArray[indexY][indexX] = 1;
        mapArray[mirrorIndexY][mirrorIndexX] = 1;
    } else {
        mapArray[indexY][indexX] = 0;
        mapArray[mirrorIndexY][mirrorIndexX] = 0;