Adjust for pokitto

This commit is contained in:
Miloslav Číž 2019-09-27 16:38:55 +02:00
parent 64d806b4de
commit 836d447552
4 changed files with 142 additions and 56 deletions

View File

@ -93,29 +93,7 @@ static inline SFG_TileDefinition SFG_getMapTile
static const SFG_Level SFG_level0 = static const SFG_Level SFG_level0 =
{ {
.map =
{ {
.textureIndices = {0, 1, 2, 3, 4, 5, 6},
.tileDictionary =
{
SFG_TD(0 ,31,0,0),SFG_TD(15,63,5,0),SFG_TD(28,63,1,0),SFG_TD(6 ,63,6,0), // 0
SFG_TD(10,28,2,4),SFG_TD(4 ,26,4,6),SFG_TD(5 ,63,4,0),SFG_TD(1 ,10,1,0), // 4
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 8
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 12
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 16
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 20
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 24
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 28
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 32
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 36
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 40
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 44
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 48
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 52
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 56
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 60
},
.mapArray =
{ {
#define o 0 #define o 0
#define AA (0x04 | SFG_TILE_PROPERTY_ELEVATOR) #define AA (0x04 | SFG_TILE_PROPERTY_ELEVATOR)
@ -187,7 +165,26 @@ static const SFG_Level SFG_level0 =
#undef o #undef o
#undef AA #undef AA
#undef BB #undef BB
} },
{
SFG_TD(0 ,31,0,0),SFG_TD(15,63,5,0),SFG_TD(28,63,1,0),SFG_TD(6 ,63,6,0), // 0
SFG_TD(10,28,2,4),SFG_TD(4 ,26,4,6),SFG_TD(5 ,63,4,0),SFG_TD(1 ,10,1,0), // 4
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 8
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 12
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 16
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 20
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 24
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 28
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 32
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 36
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 40
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 44
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 48
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 52
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 56
SFG_TD(0 ,31,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0),SFG_TD(0 ,63,0,0), // 60
},
{0, 1, 2, 3, 4, 5, 6}
} }
}; };

71
main.c
View File

@ -2,6 +2,7 @@
#include "constants.h" #include "constants.h"
#include "levels.h" #include "levels.h"
#include "assets.h" #include "assets.h"
#include "palette.h"
#define SFG_KEY_UP 0 #define SFG_KEY_UP 0
#define SFG_KEY_RIGHT 1 #define SFG_KEY_RIGHT 1
@ -49,10 +50,20 @@ void SFG_mainLoopBody();
*/ */
void SFG_init(); void SFG_init();
#include "platform_sdl.h" #ifdef SFG_PLATFORM_POKITTO
#include "platform_pokitto.h"
#else
#include "platform_sdl.h"
#endif
#define SFG_MS_PER_FRAME (1000 / SFG_FPS) // ms per frame with target FPS #define SFG_MS_PER_FRAME (1000 / SFG_FPS) // ms per frame with target FPS
#define SFG_PLAYER_TURN_UNITS_PER_FRAME\
((SFG_PLAYER_TURN_SPEED * RCL_UNITS_PER_SQUARE) / (360 * SFG_FPS))
#define SFG_PLAYER_MOVE_UNITS_PER_FRAME\
((SFG_PLAYER_MOVE_SPEED * RCL_UNITS_PER_SQUARE) / SFG_FPS)
#define RCL_PIXEL_FUNCTION SFG_pixelFunc #define RCL_PIXEL_FUNCTION SFG_pixelFunc
#define RCL_TEXTURE_VERTICAL_STRETCH 0 #define RCL_TEXTURE_VERTICAL_STRETCH 0
@ -218,37 +229,6 @@ RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y)
uint32_t SFG_frame; uint32_t SFG_frame;
uint32_t SFG_lastFrameTimeMs; uint32_t SFG_lastFrameTimeMs;
void SFG_init()
{
SFG_frame = 0;
SFG_lastFrameTimeMs = 0;
RCL_initCamera(&SFG_camera);
RCL_initRayConstraints(&SFG_rayConstraints);
SFG_camera.resolution.x = SFG_RESOLUTION_X;
SFG_camera.resolution.y = SFG_RESOLUTION_Y;
SFG_camera.height = RCL_UNITS_PER_SQUARE;
SFG_camera.position.x = RCL_UNITS_PER_SQUARE * 5;
SFG_camera.position.y = RCL_UNITS_PER_SQUARE * 5;
SFG_rayConstraints.maxHits = 10;
SFG_rayConstraints.maxSteps = 32;
for (uint16_t i = 0; i < SFG_RESOLUTION_Y; ++i)
SFG_backgroundScaleMap[i] = (i * SFG_TEXTURE_SIZE) / SFG_RESOLUTION_Y;
SFG_backgroundScroll = 0;
SFG_setLevel(&SFG_level0);
}
#define SFG_PLAYER_TURN_UNITS_PER_FRAME\
((SFG_PLAYER_TURN_SPEED * RCL_UNITS_PER_SQUARE) / (360 * SFG_FPS))
#define SFG_PLAYER_MOVE_UNITS_PER_FRAME\
((SFG_PLAYER_MOVE_SPEED * RCL_UNITS_PER_SQUARE) / SFG_FPS)
RCL_Vector2D SFG_playerDirection; RCL_Vector2D SFG_playerDirection;
void SFG_recompurePLayerDirection() void SFG_recompurePLayerDirection()
@ -273,11 +253,36 @@ void SFG_setLevel(const SFG_Level *level)
SFG_currentLevel.textures[i] = SFG_currentLevel.textures[i] =
SFG_texturesWall[level->map.textureIndices[i]]; SFG_texturesWall[level->map.textureIndices[i]];
SFG_currentLevel.timeStart = SFG_getTimeMs(); SFG_currentLevel.timeStart = SFG_getTimeMs();
SFG_recompurePLayerDirection(); SFG_recompurePLayerDirection();
} }
void SFG_init()
{
SFG_frame = 0;
SFG_lastFrameTimeMs = 0;
RCL_initCamera(&SFG_camera);
RCL_initRayConstraints(&SFG_rayConstraints);
SFG_camera.resolution.x = SFG_RESOLUTION_X;
SFG_camera.resolution.y = SFG_RESOLUTION_Y;
SFG_camera.height = RCL_UNITS_PER_SQUARE;
SFG_camera.position.x = RCL_UNITS_PER_SQUARE * 5;
SFG_camera.position.y = RCL_UNITS_PER_SQUARE * 5;
SFG_rayConstraints.maxHits = SFG_RAYCASTING_MAX_HITS;
SFG_rayConstraints.maxSteps = SFG_RAYCASTING_MAX_STEPS;
for (uint16_t i = 0; i < SFG_RESOLUTION_Y; ++i)
SFG_backgroundScaleMap[i] = (i * SFG_TEXTURE_SIZE) / SFG_RESOLUTION_Y;
SFG_backgroundScroll = 0;
SFG_setLevel(&SFG_level0);
}
/** /**
Performs one game step (logic, physics), happening SFG_MS_PER_FRAME after Performs one game step (logic, physics), happening SFG_MS_PER_FRAME after
previous frame. previous frame.

0
mbed_config.h Normal file
View File

84
platform_pokitto.h Normal file
View File

@ -0,0 +1,84 @@
#ifndef _SFG_PLATFORM_H
#define _SFG_PLATFORM_H
#include "settings.h"
#undef SFG_FPS
#define SFG_FPS 30
#undef SFG_RESOLUTION_X
#define SFG_RESOLUTION_X 110
#undef SFG_RESOLUTION_Y
#define SFG_RESOLUTION_Y 88
#undef SFG_DITHERED_SHADOW
#define SFG_DITHERED_SHADOW 0
#undef SFG_RAYCASTING_MAX_STEPS
#define SFG_RAYCASTING_MAX_STEPS 20
#undef SFG_RAYCASTING_MAX_HITS
#define SFG_RAYCASTING_MAX_HITS 6
#include "Pokitto.h"
Pokitto::Core pokitto;
uint8_t *pokittoScreen;
void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex)
{
pokittoScreen[y * SFG_RESOLUTION_X + x] = colorIndex;
}
uint32_t SFG_getTimeMs()
{
return pokitto.getTime();
}
void SFG_sleepMs(uint16_t timeMs)
{
}
int8_t SFG_keyPressed(uint8_t key)
{
switch (key)
{
case SFG_KEY_UP: return pokitto.upBtn(); break;
case SFG_KEY_RIGHT: return pokitto.rightBtn(); break;
case SFG_KEY_DOWN: return pokitto.downBtn(); break;
case SFG_KEY_LEFT: return pokitto.leftBtn(); break;
case SFG_KEY_A: return pokitto.aBtn(); break;
case SFG_KEY_B: return pokitto.bBtn(); break;
case SFG_KEY_C: return pokitto.cBtn(); break;
default: return 0; break;
}
}
int main()
{
pokitto.begin();
pokitto.setFrameRate(SFG_FPS);
pokitto.display.setFont(fontTiny);
pokitto.display.persistence = 1;
pokitto.display.setInvisibleColor(-1);
pokitto.display.load565Palette(paletteRGB565);
pokittoScreen = pokitto.display.screenbuffer;
SFG_init();
while (pokitto.isRunning())
{
if (pokitto.update())
{
SFG_mainLoopBody();
}
}
return 0;
}
#endif // guard