12-4-17
I wanted to quickly test to see if the character is being detected hitting an edge. This will come in usage a little later in the development. Again, this is a quick test.In Z88dk, you can include various built-in functions like border color.
Just place in an #include at the top
#include "spectrum.h"
and then place this little bit where you want the border to change.
zx_border(6);
Here is the relivant bit of code where I am placing the border change routine.
if( (unsigned int)X1 > scrw < 0 )
{
//screen right
if( mapx < mapw - 2 )//if( mapX1 < mapWidth - 2 )
{
X1 = scrw << 12;//X1 = screenW << 12;
zx_border(6);
}
}
//screen left
if( vX1 < 0 )
{
if( mapx < 16)//if( mapX1 < 8)
{
X1 = 24;
zx_border(6);
}
}
}
Ooooh, look at the colors.
Edit 12-5-2017
Now top and bottom are added to the border detection
if( vY1 < 0 )
{
if( mapy < 8)
{
Y1 = 0;
zx_border(6);
}
}
if( vY1 > 0 )
{
if( mapy < maph - 1 )
{
Y1 = scrh << 12;
vY1= 0;
zx_border(6);
}
}
Now when any sides are touched, flashing border. Of course, any other code can be dropped in now that the edge code is identified, like losing a character life, or transporting to the other side, doing a bounce, etc.
Edit 2 12-5-17
I resized the maps (post coming up soon) and realized the code I placed above was incorrect, not by much but still incorrect.
Bottom and right were not being calculated correctly when you have a map size of 1 screen. Ok if you had a 2,10 screen map, but wrong for a 1×1 map.
In the verticalEdge routine, you need to have
if( vY1 > scrh)
{//screen bottom
Y1 = scrh << 12;;
zx_border(6);
}
which basically says that if you exceed the screen height (remember height is measured from top down.
On to the next issue, screen right
if( vX1 > scrw)
{//screen right
X1 = scrw << 12;;
zx_border(6);
}
The entire vertical routine
void verticalEdge (short vertical[])
{
//mapx is char
//mapy is char
short vY1 = vertical[0];
short aY1 = vertical[1];
short Y1 = vertical[2];
vY1 += aY1;
Y1 += vY1;
if( vY1 + 8 >> 3 )
{
aY1 = -vY1 >> 3;
}
else
{
aY1 = vY1 = 0;
}
if( (unsigned int)Y1 > scrh < 0 )
{
if( mapy < maph - 1 )
{
Y1 = scrh << 12;
vY1= 0;
zx_border(3);
}
}
//top
if( vY1 < 0 )
{
if( mapy scrh)
{
Y1 = scrh << 12;
zx_border(6);
}
}
//returns
vertical[0] = vY1;
vertical[1] = aY1;
vertical[2] = Y1;
}
The entire horizontal routine
void horizontalEdge (short horizonal[])
{
//mapx is char
//mapy is char
short vX1 = horizonal[0];
short aX1 = horizonal[1];
short X1 = horizonal[2];
vX1 += aX1;
X1 += vX1;
if( vX1 + 8 >> 3 )
{
aX1 = -vX1 >> 3;
}
else
{
aX1 = vX1 = 0;
}
if( (unsigned int)X1 > scrw < 0 )
{
if( mapx < mapw - 2 )
{
X1 = scrw << 12;
}
}
//screen left
if( vX1 < 0 )
{
if( mapx scrw)
{
X1 = scrw << 12;;
zx_border(6);
}
}
//returns
horizonal[0] = vX1;
horizonal[1] = aX1;
horizonal[2] = X1;
}
Well, hopefully this will be the last time I have to adjust at least for edge detection.