Start map

This commit is contained in:
Miloslav Číž 2019-10-08 13:46:12 +02:00
parent ed9ac12345
commit 8480dc28fb
4 changed files with 129 additions and 39 deletions

View File

@ -25,9 +25,9 @@ typedef uint16_t SFG_TileDefinition;
aaa: ceiling texture index (from texture available on the map), 111
means completely transparent texture
bbbb: ceiling height (1111 meaning no ceiling) ABOVE the floor
bbbbb: ceiling height (1111 meaning no ceiling) ABOVE the floor
ccc: floor texture index, 111 means completely transparent texture
dddd: floor height
ddddd: floor height
*/
#define SFG_TILE_CEILING_MAX_HEIGHT 31

88
main.c
View File

@ -32,6 +32,7 @@
#define SFG_KEY_JUMP 7
#define SFG_KEY_STRAFE_LEFT 8
#define SFG_KEY_STRAFE_RIGHT 9
#define SFG_KEY_MAP 10
/* ============================= PORTING =================================== */
@ -583,7 +584,8 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y)
RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y)
{
uint8_t properties;
SFG_TileDefinition tile = SFG_getMapTile(SFG_currentLevel.levelPointer,x,y,&properties);
SFG_TileDefinition tile =
SFG_getMapTile(SFG_currentLevel.levelPointer,x,y,&properties);
if (properties == SFG_TILE_PROPERTY_ELEVATOR)
return SFG_CEILING_MAX_HEIGHT;
@ -885,8 +887,91 @@ void SFG_gameStep()
}
}
void SFG_clearScreen(uint8_t color)
{
for (uint16_t j = 0; j < SFG_GAME_RESOLUTION_Y; ++j)
for (uint16_t i = 0; i < SFG_GAME_RESOLUTION_X; ++i)
SFG_setGamePixel(i,j,color);
}
#define SFG_MAP_PIXEL_SIZE (SFG_GAME_RESOLUTION_Y / SFG_MAP_SIZE)
#if SFG_MAP_PIXEL_SIZE == 0
#define SFG_MAP_SIZE 1
#endif
/**
Draws fullscreen map of the current level.
*/
void SFG_drawMap()
{
SFG_clearScreen(0);
uint16_t maxJ =
(SFG_MAP_PIXEL_SIZE * SFG_MAP_SIZE) < SFG_GAME_RESOLUTION_Y ?
(SFG_MAP_SIZE) : (SFG_GAME_RESOLUTION_Y / SFG_MAP_PIXEL_SIZE);
uint16_t maxI =
(SFG_MAP_PIXEL_SIZE * SFG_MAP_SIZE) < SFG_GAME_RESOLUTION_X ?
(SFG_MAP_SIZE) : (SFG_GAME_RESOLUTION_X / SFG_MAP_PIXEL_SIZE);
uint16_t topLeftX =
(SFG_GAME_RESOLUTION_X - (maxI * SFG_MAP_PIXEL_SIZE)) / 2;
uint16_t topLeftY =
(SFG_GAME_RESOLUTION_Y - (maxJ * SFG_MAP_PIXEL_SIZE)) / 2;
uint16_t x;
uint16_t y = topLeftY;
for (int16_t j = maxJ - 1; j >= 0; --j)
{
x = topLeftX;
for (uint16_t i = 0; i < maxI; ++i)
{
uint8_t properties;
SFG_TileDefinition tile =
SFG_getMapTile(SFG_currentLevel.levelPointer,i,j,&properties);
uint8_t color = 94; // init with player color
if (i != SFG_player.squarePosition[0] ||
j != SFG_player.squarePosition[1])
{
if (properties == SFG_TILE_PROPERTY_ELEVATOR)
color = 46;
else if (properties == SFG_TILE_PROPERTY_SQUEEZER)
color = 63;
else
{
color = SFG_TILE_FLOOR_HEIGHT(tile) / 8 + 2;
if (properties == SFG_TILE_PROPERTY_DOOR)
color += 8;
}
}
for (uint16_t k = 0; k < SFG_MAP_PIXEL_SIZE; ++k)
for (uint16_t l = 0; l < SFG_MAP_PIXEL_SIZE; ++l)
SFG_setGamePixel(x + l, y + k,color);
x += SFG_MAP_PIXEL_SIZE;
}
y += SFG_MAP_PIXEL_SIZE;
}
}
void SFG_draw()
{
if (SFG_keyPressed(SFG_KEY_MAP))
{
SFG_drawMap();
}
else
{
for (uint16_t i = 0; i < SFG_GAME_RESOLUTION_X; ++i)
SFG_zBuffer[i] = 255;
@ -925,6 +1010,7 @@ void SFG_draw()
RCL_perspectiveScale(SFG_GAME_RESOLUTION_Y / 2,p.depth),
p.depth / (RCL_UNITS_PER_SQUARE * 2),p.depth);
}
}
}
void SFG_mainLoopBody()

View File

@ -100,6 +100,10 @@ int8_t SFG_keyPressed(uint8_t key)
sdlKeyboardState[SDL_SCANCODE_KP_9];
break;
case SFG_KEY_MAP:
return sdlKeyboardState[SDL_SCANCODE_TAB];
break;
default: return 0; break;
}
}

View File

@ -30,14 +30,14 @@
game to run at smaller resolution (with bigger pixels), do his using
SFG_RESOLUTION_SCALEDOWN;
*/
#define SFG_SCREEN_RESOLUTION_X 1024
#define SFG_SCREEN_RESOLUTION_X 640
/**
Height of the screen in pixels. Set this to ACTUAL resolution. If you want the
game to run at smaller resolution (with bigger pixels), do his using
SFG_RESOLUTION_SCALEDOWN;
*/
#define SFG_SCREEN_RESOLUTION_Y 768
#define SFG_SCREEN_RESOLUTION_Y 480
/**
How many times the screen resolution will be divided (how many times a game