Add player start position

This commit is contained in:
Miloslav Číž 2020-01-06 00:00:44 +01:00
parent 6407968e31
commit 0a4957519b
2 changed files with 41 additions and 27 deletions

View File

@ -121,6 +121,8 @@ typedef struct
texture used for door. */ texture used for door. */
uint8_t floorColor; uint8_t floorColor;
uint8_t ceilingColor; uint8_t ceilingColor;
uint8_t playerStart[3]; /**< Player starting location: square X, square Y,
direction (fourths of RCL_Unit). */
uint8_t backgroundImage; /** Index of level background image. */ uint8_t backgroundImage; /** Index of level background image. */
SFG_LevelElement elements[SFG_MAX_LEVEL_ELEMENTS]; SFG_LevelElement elements[SFG_MAX_LEVEL_ELEMENTS];
} SFG_Level; } SFG_Level;
@ -252,6 +254,7 @@ SFG_PROGRAM_MEMORY SFG_Level SFG_level0 =
13, // doorTextureIndex 13, // doorTextureIndex
10, // floorColor 10, // floorColor
32, // ceilingColor 32, // ceilingColor
{10,10,0}, // player start: x, y, direction
0, // backgroundImage 0, // backgroundImage
{ // elements { // elements
{SFG_LEVEL_ELEMENT_BARREL, {9, 1}}, {SFG_LEVEL_ELEMENT_BARREL, {9, 13}}, {SFG_LEVEL_ELEMENT_BARREL, {9, 1}}, {SFG_LEVEL_ELEMENT_BARREL, {9, 13}},
@ -428,6 +431,7 @@ SFG_PROGRAM_MEMORY SFG_Level SFG_level1 =
13, // doorTextureIndex 13, // doorTextureIndex
102, // floorColor 102, // floorColor
32, // ceilingColor 32, // ceilingColor
{10,10,64}, // player start: x, y, direction
1, // backgroundImage 1, // backgroundImage
{ // elements { // elements
{SFG_LEVEL_ELEMENT_NONE, {0, 0}}, {SFG_LEVEL_ELEMENT_NONE, {0, 0}}, {SFG_LEVEL_ELEMENT_NONE, {0, 0}}, {SFG_LEVEL_ELEMENT_NONE, {0, 0}},

64
main.c
View File

@ -487,33 +487,6 @@ SFG_PROGRAM_MEMORY int8_t SFG_backgroundBlurOffsets[9] =
}; };
#endif #endif
void SFG_initPlayer()
{
RCL_initCamera(&SFG_player.camera);
SFG_player.camera.resolution.x =
SFG_GAME_RESOLUTION_X / SFG_RAYCASTING_SUBSAMPLE;
SFG_player.camera.resolution.y = SFG_GAME_RESOLUTION_Y - SFG_HUD_BAR_HEIGHT;
SFG_player.camera.height = RCL_UNITS_PER_SQUARE * 12;
SFG_player.camera.position.x = RCL_UNITS_PER_SQUARE * 15;
SFG_player.camera.position.y = RCL_UNITS_PER_SQUARE * 8;
SFG_recompurePLayerDirection();
SFG_player.previousVerticalSpeed = 0;
SFG_player.headBobFrame = 0;
SFG_player.weapon = 2;
SFG_player.weaponCooldownStartFrame = SFG_gameFrame;
SFG_player.lastHurtFrame = SFG_gameFrame;
SFG_player.health = SFG_PLAYER_MAX_HEALTH;
}
void SFG_pixelFunc(RCL_PixelInfo *pixel) void SFG_pixelFunc(RCL_PixelInfo *pixel)
{ {
uint8_t color; uint8_t color;
@ -889,6 +862,43 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y)
doorHeight * SFG_DOOR_HEIGHT_STEP; doorHeight * SFG_DOOR_HEIGHT_STEP;
} }
void SFG_initPlayer()
{
RCL_initCamera(&SFG_player.camera);
SFG_player.camera.resolution.x =
SFG_GAME_RESOLUTION_X / SFG_RAYCASTING_SUBSAMPLE;
SFG_player.camera.resolution.y = SFG_GAME_RESOLUTION_Y - SFG_HUD_BAR_HEIGHT;
SFG_player.camera.position.x = RCL_UNITS_PER_SQUARE / 2 +
SFG_currentLevel.levelPointer->playerStart[0] * RCL_UNITS_PER_SQUARE;
SFG_player.camera.position.y = RCL_UNITS_PER_SQUARE / 2 +
SFG_currentLevel.levelPointer->playerStart[1] * RCL_UNITS_PER_SQUARE;
SFG_player.camera.height =
SFG_floorHeightAt(
SFG_currentLevel.levelPointer->playerStart[0],
SFG_currentLevel.levelPointer->playerStart[1]);
SFG_player.camera.direction =
SFG_currentLevel.levelPointer->playerStart[2] * 4;
SFG_recompurePLayerDirection();
SFG_player.previousVerticalSpeed = 0;
SFG_player.headBobFrame = 0;
SFG_player.weapon = 2;
SFG_player.weaponCooldownStartFrame = SFG_gameFrame;
SFG_player.lastHurtFrame = SFG_gameFrame;
SFG_player.health = SFG_PLAYER_MAX_HEALTH;
}
RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y) RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y)
{ {
uint8_t properties; uint8_t properties;