Start editing
This commit is contained in:
parent
09a4856a09
commit
2e39b5204b
1 changed files with 62 additions and 12 deletions
72
demo3.cpp
72
demo3.cpp
|
@ -24,6 +24,25 @@ Player player;
|
|||
char floorColor = 0;
|
||||
Vector2D selectedSquare; ///< Coords of tile selected for editing.
|
||||
|
||||
/**
|
||||
Represents one terrain change against the implicit terrain.
|
||||
*/
|
||||
class Change
|
||||
{
|
||||
public:
|
||||
Vector2D mCoords;
|
||||
Unit mHeight;
|
||||
uint8_t mColor;
|
||||
};
|
||||
|
||||
#define MAX_CHANGES 32
|
||||
|
||||
Change changes[MAX_CHANGES];
|
||||
|
||||
bool editReleased = false;
|
||||
bool editing = false;
|
||||
uint16_t changeIndex = 0;
|
||||
|
||||
#define HEIGHT_PROFILE_LENGTH 256
|
||||
const int8_t heightProfile[] = {
|
||||
9,9,9,10,10,10,11,11,12,13,13,14,14,14,15,15,15,16,16,16,16,16,15,15,15,14,14,
|
||||
|
@ -129,6 +148,10 @@ const unsigned char imageBackground[] =
|
|||
|
||||
Unit floorHeightAt(int16_t x, int16_t y)
|
||||
{
|
||||
for (uint16_t i = 0; i < MAX_CHANGES; ++i)
|
||||
if (changes[i].mCoords.x == x && changes[i].mCoords.y == y)
|
||||
return changes[i].mHeight;
|
||||
|
||||
return (heightProfile[absVal(x) % HEIGHT_PROFILE_LENGTH] +
|
||||
heightProfile[absVal(y + 20) % HEIGHT_PROFILE_LENGTH]) *
|
||||
UNITS_PER_SQUARE;
|
||||
|
@ -148,7 +171,7 @@ inline void pixelFunc(PixelInfo pixel)
|
|||
|
||||
if (pixel.isWall)
|
||||
{
|
||||
c = pixel.hit.square.x != selectedSquare.x || pixel.hit.square.y != selectedSquare.y ? 50 : 30;
|
||||
c = pixel.hit.square.x != selectedSquare.x || pixel.hit.square.y != selectedSquare.y || (editing && pokitto.frameCount % 2) == 0 ? 50 : 30;
|
||||
|
||||
intensity = pixel.depth / (UNITS_PER_SQUARE * 3);
|
||||
intensity += pixel.hit.direction % 2 == 0 ? 2 : 0;
|
||||
|
@ -196,7 +219,7 @@ void draw()
|
|||
c.computeTextureCoords = 0;
|
||||
|
||||
render(player.mCamera,floorHeightAt,0,0,pixelFunc,c);
|
||||
|
||||
/*
|
||||
pokitto.display.setColor(rgbToIndex(7,7,3));
|
||||
pokitto.display.setCursor(1,1);
|
||||
pokitto.display.print(player.mCamera.position.x);
|
||||
|
@ -204,11 +227,9 @@ pokitto.display.print(" ");
|
|||
pokitto.display.print(player.mCamera.position.y);
|
||||
pokitto.display.print(" ");
|
||||
pokitto.display.print(player.mCamera.direction);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
bool runReleased = false;
|
||||
|
||||
int main()
|
||||
{
|
||||
initGeneral();
|
||||
|
@ -217,6 +238,13 @@ int main()
|
|||
|
||||
player.setPositionSquare(4,5);
|
||||
|
||||
for (uint16_t i = 0; i < MAX_CHANGES; ++i)
|
||||
{
|
||||
changes[i].mCoords.x = 0;
|
||||
changes[i].mCoords.y = 0;
|
||||
changes[i].mHeight = floorHeightAt(0,0);
|
||||
}
|
||||
|
||||
uint32_t previousTime = 0;
|
||||
uint32_t dt;
|
||||
|
||||
|
@ -276,25 +304,47 @@ int main()
|
|||
|
||||
if (pokitto.cBtn())
|
||||
{
|
||||
if (runReleased)
|
||||
if (editReleased)
|
||||
{
|
||||
player.mRunning = !player.mRunning;
|
||||
runReleased = false;
|
||||
editing = !editing;
|
||||
|
||||
changeIndex = (changeIndex + 1) % MAX_CHANGES;
|
||||
|
||||
for (uint16_t i = 0; i < MAX_CHANGES; ++i)
|
||||
if (changes[i].mCoords.x == selectedSquare.x &&
|
||||
changes[i].mCoords.y == selectedSquare.y)
|
||||
{
|
||||
changeIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
changes[changeIndex].mHeight = floorHeightAt(selectedSquare.x,selectedSquare.y);
|
||||
changes[changeIndex].mCoords.x = selectedSquare.x;
|
||||
changes[changeIndex].mCoords.y = selectedSquare.y;
|
||||
editReleased = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
runReleased = true;
|
||||
editReleased = true;
|
||||
|
||||
if (pokitto.upBtn())
|
||||
{
|
||||
if (aButton)
|
||||
if (editing)
|
||||
{
|
||||
changes[changeIndex].mHeight += 100;
|
||||
}
|
||||
else if (aButton)
|
||||
player.mCamera.shear = min(player.mCamera.shear + 10,60);
|
||||
else
|
||||
moveOffset = d;
|
||||
}
|
||||
else if (pokitto.downBtn())
|
||||
{
|
||||
if (aButton)
|
||||
if (editing)
|
||||
{
|
||||
changes[changeIndex].mHeight -= 100;
|
||||
}
|
||||
else if (aButton)
|
||||
player.mCamera.shear = max(player.mCamera.shear - 10,-60);
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue