Make squares selectable
This commit is contained in:
parent
8d370cda93
commit
09a4856a09
1 changed files with 28 additions and 6 deletions
34
demo3.cpp
34
demo3.cpp
|
@ -22,7 +22,7 @@ Player player;
|
||||||
#define JUMP_SPEED 500
|
#define JUMP_SPEED 500
|
||||||
|
|
||||||
char floorColor = 0;
|
char floorColor = 0;
|
||||||
char ceilingColor = 0;
|
Vector2D selectedSquare; ///< Coords of tile selected for editing.
|
||||||
|
|
||||||
#define HEIGHT_PROFILE_LENGTH 256
|
#define HEIGHT_PROFILE_LENGTH 256
|
||||||
const int8_t heightProfile[] = {
|
const int8_t heightProfile[] = {
|
||||||
|
@ -148,7 +148,7 @@ inline void pixelFunc(PixelInfo pixel)
|
||||||
|
|
||||||
if (pixel.isWall)
|
if (pixel.isWall)
|
||||||
{
|
{
|
||||||
c = 50;
|
c = pixel.hit.square.x != selectedSquare.x || pixel.hit.square.y != selectedSquare.y ? 50 : 30;
|
||||||
|
|
||||||
intensity = pixel.depth / (UNITS_PER_SQUARE * 3);
|
intensity = pixel.depth / (UNITS_PER_SQUARE * 3);
|
||||||
intensity += pixel.hit.direction % 2 == 0 ? 2 : 0;
|
intensity += pixel.hit.direction % 2 == 0 ? 2 : 0;
|
||||||
|
@ -196,7 +196,7 @@ void draw()
|
||||||
c.computeTextureCoords = 0;
|
c.computeTextureCoords = 0;
|
||||||
|
|
||||||
render(player.mCamera,floorHeightAt,0,0,pixelFunc,c);
|
render(player.mCamera,floorHeightAt,0,0,pixelFunc,c);
|
||||||
/*
|
|
||||||
pokitto.display.setColor(rgbToIndex(7,7,3));
|
pokitto.display.setColor(rgbToIndex(7,7,3));
|
||||||
pokitto.display.setCursor(1,1);
|
pokitto.display.setCursor(1,1);
|
||||||
pokitto.display.print(player.mCamera.position.x);
|
pokitto.display.print(player.mCamera.position.x);
|
||||||
|
@ -204,7 +204,7 @@ pokitto.display.print(" ");
|
||||||
pokitto.display.print(player.mCamera.position.y);
|
pokitto.display.print(player.mCamera.position.y);
|
||||||
pokitto.display.print(" ");
|
pokitto.display.print(" ");
|
||||||
pokitto.display.print(player.mCamera.direction);
|
pokitto.display.print(player.mCamera.direction);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runReleased = false;
|
bool runReleased = false;
|
||||||
|
@ -214,7 +214,6 @@ int main()
|
||||||
initGeneral();
|
initGeneral();
|
||||||
|
|
||||||
floorColor = rgbToIndex(4,2,0);
|
floorColor = rgbToIndex(4,2,0);
|
||||||
ceilingColor = rgbToIndex(2,2,3);
|
|
||||||
|
|
||||||
player.setPositionSquare(4,5);
|
player.setPositionSquare(4,5);
|
||||||
|
|
||||||
|
@ -236,6 +235,29 @@ int main()
|
||||||
|
|
||||||
Vector2D d = angleToDirection(player.mCamera.direction);
|
Vector2D d = angleToDirection(player.mCamera.direction);
|
||||||
|
|
||||||
|
Vector2D facingOffset;
|
||||||
|
|
||||||
|
if (player.mCamera.direction > (4 * UNITS_PER_SQUARE / 12) &&
|
||||||
|
player.mCamera.direction <= (8 * UNITS_PER_SQUARE / 12))
|
||||||
|
facingOffset.x = -1;
|
||||||
|
else if (player.mCamera.direction < (2 * UNITS_PER_SQUARE / 12) ||
|
||||||
|
player.mCamera.direction >= (10 * UNITS_PER_SQUARE / 12))
|
||||||
|
facingOffset.x = 1;
|
||||||
|
else
|
||||||
|
facingOffset.x = 0;
|
||||||
|
|
||||||
|
if (player.mCamera.direction > (UNITS_PER_SQUARE / 12) &&
|
||||||
|
player.mCamera.direction <= (5 * UNITS_PER_SQUARE / 12))
|
||||||
|
facingOffset.y = -1;
|
||||||
|
else if (player.mCamera.direction > (6 * UNITS_PER_SQUARE / 12) &&
|
||||||
|
player.mCamera.direction <= (11 * UNITS_PER_SQUARE / 12))
|
||||||
|
facingOffset.y = 1;
|
||||||
|
else
|
||||||
|
facingOffset.y = 0;
|
||||||
|
|
||||||
|
selectedSquare.x = divRoundDown(player.mCamera.position.x,UNITS_PER_SQUARE) + facingOffset.x;
|
||||||
|
selectedSquare.y = divRoundDown(player.mCamera.position.y,UNITS_PER_SQUARE) + facingOffset.y;
|
||||||
|
|
||||||
Vector2D moveOffset;
|
Vector2D moveOffset;
|
||||||
|
|
||||||
moveOffset.x = 0;
|
moveOffset.x = 0;
|
||||||
|
@ -302,7 +324,7 @@ int main()
|
||||||
moveOffset = d;
|
moveOffset = d;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
player.mCamera.direction += addition * rotationStep;
|
player.mCamera.direction = wrap(player.mCamera.direction + addition * rotationStep,UNITS_PER_SQUARE);
|
||||||
|
|
||||||
Unit prevHeight = player.mCamera.height;
|
Unit prevHeight = player.mCamera.height;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue