Board Thread:Questions and Answers/@comment-24454571-20140530055317/@comment-24854750-20140604235022

A couple things:

1: I think the problems with your codes have primarily to do with the graphical limitations of Petit Computer. In your first code you include ACLS within the loop, which means that screen is being completely cleared and then draw upon in about 1/60th of a second. (VSYNC and WAIT times are based on 60ths of a second, which means that WAIT 60 lasts about one second). I can only assume this is similar to what you describe as "the screen was tearing colors from the pixels." From what I've read, the best way to slow the computer down is to use VSYNC. Increasing the value of VSYNC will improve Petit Computer's ability to create graphics. I have not personally tested the differences between WAIT and VSYNC, so I cannot help you there.

2: As for the COLITEST, you might try removing those lines from the code just to see what happens when those lines aren't there. Removing code is not always the best way to test what that particular code is actually doing, but I know what will happen and doing so might help you understand. And here, I will try to explain what those are doing, and what should happen if those aren't there...

The program starts off by setting up a basic map filled with areas you can walk on (which are defined in the program as "0") and areas you cannot walk on (defined as "1"). The information is RESTOREd from the DATA at the end of the code, READ onto the string variable MAPLINE$, and sets up the array MAP to first equal 0 (or an area that can be walked upon), then if the DATA (and consequently MAPLINE$) says a space equals 1 (or a space that cannot be walked upon), the MAP array, at that spot, will equal 1. The next part of the program actually puts the map on the screen, specifically by identifying if the MAP array equals 1 (which cannot be walked on) and placing the BG tile for Randomous' barrier.

The next part of the program contains all of the playable parts of the program, specifically, moving a block around but not moving onto barriers. See the VSYNC 1 just before GOTO @LOOP? Everything that happens between @LOOP and GOTO @LOOP takes approximately 1/60th of a second. Between these, there are 4 variables that the program keeps track of: PLX, PLY, PLXO, and PLXY. For the purpose of understanding how those four lines quoted above work, imagine that PLXO and PLXY are the coordinates for where your box is located, and PLX and PLY are the coordinates for where your box is moving to. If you see it this way, the button presses change the variable PLX and PLY, and when the program loops back to @LOOP, PLXO and PLXY are redefined as the coordinates for where you moved to.

Now for those 4 lines. If you remove them and play the program, your box will move across the screen freely, regardless of whether there is a barrier (1) or not (0). If you keep them in, you should not be able to run over the barriers (1). How does it do this? It takes the coordinates you are trying to move to (PLX and PLY) and compares those coordinates with the DATA saved in the MAP array. Something to note here in case you did not already know, the box that you move around is drawn on the graphic "screen", which is composed of 256x192 pixels, but the BG tiles are displayed on its own "screen" which is only 32x24. Also, those tiles are 8x8 pixels large (and if you want to check the math, 32 x 8 = 256 and 24 x 8 = 192). So in order to compare the coordinates of the location you are trying to move to the MAP array, you must first convert the PLX and PLY coordinates to the size of the BG tiles. Thus, FLOOR(PLX/8) and FLOOR (PLY/8). Why do two of those 4 lines have plus 5? The box that you control is 5 pixels large but the variables only keep track of one coordinate, the top left corner. So when the program checks for collisions, it has to check the right and bottom sides of the box, which are 5 pixels away from the coordinate the variables keep track of. Thus, FLOOR((PLX+5)/8) and FLOOR ((PLY+5)/8). (Remember extra parantheses for order of operations!). So if the space you are trying to move to is defined as a barrier in the MAP array (or equal to 1), then the program cancels your movement by setting the coordinates for where you want to move to (PLX and PLY) to equal the coordinates for where you are actually located (PLXO and PLYO). If the MAP array equals 0, then the program skips over those lines.

In short:

Following the @LOOP, the first three lines say "You are here." The next five say "You want to move there." The four you have trouble with say "You can't move there." And the GFILL draws your square wherever you have or have not moved to.