merge-requests/1/head
Miloslav Číž 2019-09-26 01:34:57 +02:00
parent 3c3f7de1a6
commit 1e38f4d552
3 changed files with 136 additions and 10 deletions

103
assets.h
View File

@ -3,6 +3,16 @@
#define SFG_TEXTURE_SIZE 32
/**
Color index which will in textures and sprites be considered transparent.
*/
#define SFG_TRANSPARENT_COLOR 175
/**
Special index of an implicit texture that consists of only transparent pixels.
*/
#define SFG_TRANSPARENT_TEXTURE 255
static inline uint8_t SFG_getTexel(uint8_t *texture, uint8_t x, uint8_t y)
{
return texture[(y & 0x1f) * SFG_TEXTURE_SIZE + (x & 0x1f)];
@ -10,7 +20,7 @@ static inline uint8_t SFG_getTexel(uint8_t *texture, uint8_t x, uint8_t y)
const uint8_t SFG_texturesWall[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
{
{
{
4,4,4,4,4,4,4,20,4,4,4,4,4,4,4,4,4,4,4,4,4,20,20,3,20,4,5,0,3,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,20,4,20,3,4,4,4,4,4,4,4,21,4,4,5,20,3,4,4,4,4,21,21,21,21,21,4,21,
21,4,4,21,4,21,21,4,4,4,4,4,4,21,4,4,4,4,4,96,3,4,4,4,21,21,21,5,21,21,21,21,21,
@ -41,8 +51,8 @@ const uint8_t SFG_texturesWall[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
5,5,21,5,5,5,5,5,5,4,21,4,4,4,4,4,4,5,5,136,4,4,4,4,4,4,4,21,4,21,4,4,4,4,4,4,4,
4,4,4,4,4,21,4,21,4,4,5,5,4,4,81,4,4,4,20,20,4,3,3,3,3,3,26,3,3,20,3,3,3,3,3,3,
3,3,3,3,3,3,3,4
},
{
},
{
5,4,4,5,59,2,5,5,4,66,45,5,4,4,4,4,4,4,2,5,4,44,4,4,4,4,3,3,2,44,4,4,4,4,4,51,
67,8,5,86,3,2,4,5,4,4,4,4,4,4,2,4,5,4,4,5,4,5,4,50,3,60,44,5,131,131,131,3,2,66,
60,4,2,2,3,3,4,3,4,3,4,3,49,2,2,5,4,3,51,3,131,2,50,66,2,131,4,4,4,4,66,3,3,3,
@ -73,7 +83,92 @@ const uint8_t SFG_texturesWall[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
4,4,4,5,2,4,5,5,44,44,4,5,4,3,5,5,4,66,4,4,3,4,4,4,4,3,4,4,4,4,4,4,4,4,4,86,2,4,
45,4,4,4,4,4,4,83,5,5,4,49,4,4,4,3,4,4,4,3,3,4,4,4,4,3,4,4,3,5,3,5,4,61,4,132,4,
4,4,2,5,85,4,2,4,4,4,4,4,44,4,3,3,5,4,4,4,4,4,4,3,6,66,4,4,4
}
},
{
12,12,12,12,12,83,61,61,61,61,83,61,20,13,84,84,84,13,13,13,13,83,61,61,61,61,
61,61,85,15,85,13,83,11,12,12,84,12,83,83,83,83,83,61,13,12,84,84,13,13,84,13,
13,83,61,83,83,83,83,13,13,85,85,12,83,12,11,83,12,83,12,12,84,13,83,61,12,84,
84,12,84,85,12,85,85,83,61,85,85,12,85,13,85,85,13,85,12,12,83,83,83,83,83,83,
83,83,83,61,83,83,83,83,83,83,83,83,83,83,61,83,83,83,83,83,83,84,85,12,11,11,
12,83,4,20,4,4,4,20,83,61,84,4,20,84,4,84,20,4,20,83,61,4,3,84,20,84,3,85,85,13,
11,11,84,83,4,84,84,20,20,84,83,61,84,20,84,20,84,84,84,20,4,83,61,4,4,4,84,3,
84,85,14,84,12,83,12,83,4,20,20,20,20,20,83,61,84,131,130,131,131,130,130,131,4,
83,61,4,4,4,4,3,20,85,85,13,12,12,83,83,4,84,61,61,61,84,83,61,20,130,20,20,4,4,
84,130,4,83,84,61,61,61,61,20,84,85,13,12,11,12,11,83,20,61,83,83,83,83,61,84,
84,130,20,20,84,4,4,131,4,84,83,83,83,83,61,61,3,85,85,13,11,11,83,83,4,83,83,
20,20,20,84,84,20,131,20,20,20,84,4,130,4,4,4,4,4,4,83,61,84,85,84,13,11,12,11,
83,4,83,61,20,20,20,20,20,20,131,130,131,130,130,130,131,84,4,4,4,4,4,83,61,3,
85,14,13,83,11,83,83,4,83,61,20,20,20,84,84,20,84,84,20,84,84,84,84,84,84,4,4,4,
84,83,61,20,85,84,12,11,11,12,83,20,83,61,20,84,20,84,20,20,4,4,84,4,4,84,4,84,
84,20,84,4,20,83,61,84,85,84,13,12,11,11,83,4,83,61,20,20,3,20,84,20,20,84,20,
84,84,84,4,4,84,84,84,4,3,83,61,3,85,84,13,11,11,83,83,4,83,61,4,84,4,20,4,84,4,
84,20,84,20,20,4,20,84,84,3,20,84,83,61,3,85,85,84,12,11,11,84,85,83,61,85,85,
85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,83,61,85,85,12,12,5,4,5,5,5,
5,6,5,6,5,6,6,5,6,6,6,6,6,7,6,6,6,6,6,6,5,5,5,5,5,5,5,4,4,4,4,3,3,4,3,4,4,4,4,4,
4,4,4,4,4,5,5,5,5,6,5,6,7,6,7,6,7,7,6,4,5,5,5,5,5,5,5,6,5,6,6,6,6,6,6,7,6,6,5,6,
5,5,5,6,5,5,5,5,5,5,5,4,4,4,4,3,3,3,3,3,4,3,4,4,4,4,4,4,4,5,5,5,6,5,6,5,6,6,6,7,
5,7,6,4,5,5,4,5,5,5,5,5,5,5,6,5,6,5,6,6,5,6,5,5,6,5,5,5,5,5,5,5,5,5,5,4,4,4,4,3,
4,3,4,4,4,4,4,4,5,4,5,5,5,5,5,5,5,6,5,6,6,7,5,6,7,6,6,5,5,5,4,5,4,4,4,5,4,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,4,4,4,4,4,5,5,5,4,5,4,5,5,5,5,5,5,6,5,5,6,
6,6,5,6,6,6,7,6,7,6,6,12,12,12,12,12,83,61,12,12,12,12,12,12,12,12,12,12,12,12,
12,12,12,12,12,12,12,83,61,12,12,12,12,12,12,12,12,12,83,61,12,12,12,12,12,12,
13,84,20,13,84,13,13,84,13,85,13,20,20,83,61,85,12,20,12,85,12,12,12,12,83,61,
12,12,12,12,12,12,13,12,12,13,84,13,13,13,13,85,85,85,13,83,61,85,13,85,85,83,
12,12,12,12,83,61,12,12,12,12,61,61,61,61,61,61,61,61,61,61,61,13,85,13,13,83,
61,85,13,13,20,12,12,12,12,83,83,61,12,12,84,83,83,83,83,83,83,83,83,83,83,83,
83,61,13,13,13,83,61,13,13,13,12,12,83,12,12,12,83,61,12,12,12,83,61,12,12,84,
12,20,12,13,13,84,83,61,85,85,13,83,61,85,85,85,13,83,12,12,12,83,83,61,12,12,
12,83,61,12,12,84,84,20,84,13,20,13,83,61,85,85,13,83,61,85,14,85,13,83,12,84,
11,11,83,61,84,11,20,83,61,20,12,84,12,84,13,20,13,20,83,61,85,13,85,83,61,85,
85,12,85
}
};
const uint8_t SFG_backgrounds[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
{
{
10,10,10,10,10,10,10,10,10,10,10,10,59,10,10,10,10,10,10,10,10,10,59,10,10,59,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,59,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,19,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,19,19,10,10,10,10,10,10,10,
10,10,10,10,10,10,19,10,10,10,10,10,10,10,10,10,10,19,19,19,19,10,19,19,19,19,
10,10,10,10,10,19,19,10,10,10,10,10,19,19,10,10,10,10,19,10,10,10,10,10,19,60,
60,19,19,12,12,19,19,19,19,10,19,12,19,10,10,10,19,19,19,19,19,10,10,19,19,19,
19,19,19,19,19,19,19,19,19,12,12,19,12,12,19,19,19,12,10,10,19,19,19,19,19,12,
12,19,19,19,12,12,19,19,19,12,12,12,19,19,19,12,12,12,12,19,19,19,12,12,19,19,
19,12,12,12,12,12,12,12,12,12,61,12,12,19,19,168,168,168,12,19,19,12,13,12,12,
12,19,19,13,19,19,19,12,12,12,12,12,13,13,13,12,12,13,12,12,100,100,168,223,168,
12,12,100,19,13,13,13,14,13,13,13,12,19,19,19,12,13,13,13,13,168,168,168,168,
101,101,101,101,100,168,136,168,100,12,100,100,13,14,14,14,14,14,13,12,12,19,12,
13,13,13,13,13,168,0,0,168,12,101,101,101,101,168,223,168,100,100,101,101,101,
101,101,101,13,14,13,13,13,12,168,168,57,168,13,13,168,223,0,168,12,12,168,168,
168,168,0,168,101,100,100,100,100,100,100,101,13,14,13,13,13,13,168,0,0,168,13,
13,168,0,0,57,12,12,168,168,168,0,0,168,101,101,100,100,100,100,101,14,14,13,13,
13,14,13,168,0,0,168,14,14,168,223,0,168,12,12,168,168,168,0,0,168,187,187,187,
101,100,101,101,14,14,14,13,14,14,14,168,0,0,168,14,14,168,0,0,168,63,101,168,
168,168,0,0,168,101,168,168,168,101,101,209,14,209,14,13,14,14,14,64,0,168,168,
14,14,64,219,168,168,14,14,64,168,64,0,168,168,101,168,64,168,101,71,64,14,64,
63,14,14,168,14,64,168,168,64,14,14,64,168,168,64,14,63,64,64,64,168,168,64,64,
64,64,64,14,14,64,14,64,14,64,14,168,14,64,168,136,64,14,14,64,168,168,168,64,
64,64,64,64,168,168,57,64,64,64,64,14,14,64,64,64,14,80,64,64,14,80,168,64,168,
80,14,80,168,64,168,64,168,80,64,80,168,64,64,80,64,80,64,80,14,80,168,80,14,64,
64,168,14,64,64,168,64,168,80,168,64,168,64,168,64,64,80,168,136,136,80,168,64,
168,80,64,14,64,136,64,63,64,64,64,80,64,64,64,64,64,64,64,64,64,80,80,57,80,
136,64,64,64,80,64,64,64,80,80,14,80,64,64,80,73,80,64,64,136,64,64,64,73,80,73,
64,64,80,64,64,64,64,64,64,64,80,73,64,64,80,73,80,64,64,73,80,64,73,64,64,64,
64,64,64,80,64,80,64,64,73,64,64,64,64,64,64,64,64,80,64,64,64,64,64,64,64,80,
64,64,80,64,64,64,64,64,80,73,64,73,80,73,80,64,64,64,64,64,64,64,64,73,64,136,
64,64,64,64,64,73,64,64,73,73,73,73,64,64,73,64,64,64,64,64,73,64,64,64,64,64,
64,64,136,64,64,64,64,64,64,64,73,73,64,73,64,73,64,73,64,73,73,73,64,73,64,73,
64,73,64,73,64,73,64,73,64,73,64,73,64,73,64,73,64,73,64,136,73,64,136,64,73,64,
73,64,73,64,73,64,73,136,73,64,73,64,73,64,73,136,73,64,73,64,73,64,73,64,73,73,
73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,
73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,
73,73,136,73,73,73,73,73,73,73,73,73,73,73,73,73,73,136,73,73,73,73,73,73,73,73,
73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,
73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73
}
};
#endif // guard

View File

@ -28,6 +28,8 @@ typedef SFG_TileDefinition SFG_TileDictionary[SFG_TILE_DICTIONARY_SIZE];
#define SFG_TILE_FLOOR_HEIGHT(tile) (tile & 0x1f)
#define SFG_TILE_FLOOR_TEXTURE(tile) ((tile & 0xe0) >> 5)
#define SFG_OUTSIDE_TILE SFG_TD(63,10,0,0)
typedef uint8_t SFG_MapArray[SFG_MAP_SIZE * SFG_MAP_SIZE];
/**<
Game map represented as a 2D array. Array item has this format:
@ -56,7 +58,7 @@ typedef struct
static inline SFG_TileDefinition SFG_getMapTile(SFG_Map *map, int16_t x, int16_t y)
{
if (x < 0 || x >= SFG_MAP_SIZE || y < 0 || y >= SFG_MAP_SIZE)
return SFG_TD(63,10,0,0);
return SFG_OUTSIDE_TILE;
return map->tileDictionary[map->mapArray[y * SFG_MAP_SIZE + x] & 0x3f];
}

39
main.c
View File

@ -60,6 +60,9 @@ void SFG_init();
RCL_Camera SFG_camera;
RCL_RayConstraints SFG_rayConstraints;
uint8_t SFG_backgroundScaleMap[SFG_RESOLUTION_Y];
uint16_t SFG_backgroundScroll;
void SFG_pixelFunc(RCL_PixelInfo *pixel)
{
uint8_t color;
@ -67,7 +70,11 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
if (pixel->isWall)
{
color = SFG_getTexel(SFG_texturesWall[pixel->hit.type],pixel->texCoords.x / 32,pixel->texCoords.y / 32);
color =
pixel->hit.type != SFG_TRANSPARENT_TEXTURE ?
(SFG_getTexel(SFG_texturesWall[pixel->hit.type],pixel->texCoords.x / 32,pixel->texCoords.y / 32)) :
SFG_TRANSPARENT_COLOR;
shadow = pixel->hit.direction >> 1;
}
else
@ -75,9 +82,17 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
color = pixel->isFloor ? 20 : 50;
}
shadow += pixel->depth / (RCL_UNITS_PER_SQUARE * 2);
color = palette_minusValue(color,shadow);
if (color != SFG_TRANSPARENT_COLOR)
{
shadow += pixel->depth / (RCL_UNITS_PER_SQUARE * 2);
color = palette_minusValue(color,shadow);
}
else
{
color = SFG_getTexel(SFG_backgrounds[0],
SFG_backgroundScaleMap[(pixel->position.x + SFG_backgroundScroll) % SFG_RESOLUTION_Y],
SFG_backgroundScaleMap[pixel->position.y]);
}
SFG_setPixel(pixel->position.x,pixel->position.y,color);
}
@ -86,6 +101,10 @@ RCL_Unit SFG_textureAt(int16_t x, int16_t y)
{
SFG_TileDefinition tile = SFG_getMapTile(&SFG_level0,x,y);
if (tile == SFG_OUTSIDE_TILE &&
(x < 0 || x >= SFG_MAP_SIZE || y < 0 || y >= SFG_MAP_SIZE))
return SFG_TRANSPARENT_TEXTURE;
return SFG_TILE_FLOOR_TEXTURE(tile);
}
@ -120,6 +139,11 @@ void SFG_init()
SFG_rayConstraints.maxHits = 6;
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;
}
#define SFG_PLAYER_TURN_UNITS_PER_FRAME\
@ -145,16 +169,21 @@ void SFG_gameStep()
}
else if (SFG_keyPressed(SFG_KEY_RIGHT))
{
SFG_camera.direction += SFG_PLAYER_TURN_UNITS_PER_FRAME;
SFG_camera.direction += SFG_PLAYER_TURN_UNITS_PER_FRAME;
recomputeDirection = 1;
}
if (recomputeDirection)
{
SFG_camera.direction = RCL_wrap(SFG_camera.direction,RCL_UNITS_PER_SQUARE);
playerDirection = RCL_angleToDirection(SFG_camera.direction);
playerDirection.x = (playerDirection.x * SFG_PLAYER_MOVE_UNITS_PER_FRAME) / RCL_UNITS_PER_SQUARE;
playerDirection.y = (playerDirection.y * SFG_PLAYER_MOVE_UNITS_PER_FRAME) / RCL_UNITS_PER_SQUARE;
SFG_backgroundScroll =
((SFG_camera.direction * 8) * SFG_RESOLUTION_Y) / RCL_UNITS_PER_SQUARE;
}
if (SFG_keyPressed(SFG_KEY_UP))