Draw weapon

This commit is contained in:
Miloslav Číž 2019-10-14 01:47:41 +02:00
parent db4d41f5df
commit 99f0205645
4 changed files with 155 additions and 2 deletions

View File

@ -588,6 +588,53 @@ uint8_t SFG_backgrounds[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
}
};
SFG_PROGRAM_MEMORY
uint8_t SFG_weaponImages[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
{
{ // 0, shotgun
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,1,1,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,1,1,1,1,17,
100,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,1,1,1,5,6,4,17,100,101,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,1,1,1,1,5,6,4,6,5,17,100,101,101,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,1,1,1,4,4,6,7,7,6,1,3,5,
17,99,101,101,175,175,175,175,175,175,175,175,175,175,175,175,1,1,1,1,5,5,5,7,7,
6,6,6,5,1,3,5,17,99,100,101,175,175,175,175,175,175,175,175,175,175,1,1,6,5,6,6,
7,7,6,6,4,6,7,7,4,6,6,5,17,99,100,101,175,175,175,175,175,175,175,175,175,1,6,6,
3,6,7,6,6,7,7,4,5,6,6,4,4,5,5,4,17,99,99,100,175,175,175,175,175,175,175,175,1,
6,6,6,3,6,7,7,7,7,6,4,4,5,3,3,5,1,3,4,17,98,99,100,175,175,175,175,175,175,175,
175,1,7,7,2,6,7,7,6,5,5,5,5,3,3,74,4,4,1,3,4,17,98,98,99,175,175,175,175,175,
175,175,1,6,6,6,2,6,6,6,5,5,5,5,5,4,4,4,4,4,4,4,4,3,17,18,18,175,175,175,175,
175,175,175,1,6,6,6,4,6,4,4,4,4,4,4,4,4,3,3,3,3,3,3,1,3,74,17,98,175,175,175,
175,175,175,17,1,1,4,4,4,2,4,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,74,17,17,175,175,175,
175,175,101,99,25,25,1,3,42,2,3,42,3,42,42,42,42,42,42,42,74,42,74,74,42,74,17,
17,1,175,175,175,175,175,17,17,17,25,25,25,25,9,17,17,17,17,17,1,17,1,17,1,1,1,
1,1,1,73,1,1,1,175,175,175,175,175,175,175,1,25,25,25,26,26,26,19,19,19,19,19,
19,19,19,19,19,19,19,26,26,18,73,17,1,175,175,175,175,175,17,17,17,25,25,25,19,
100,100,100,101,101,101,101,101,101,101,101,101,101,101,100,100,19,19,17,1,175,
175,175,175,175,101,99,25,25,1,4,4,26,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,3,17,17,
175,175,175,175,175,175,17,1,1,6,6,4,4,6,6,6,7,7,6,6,6,5,5,5,4,4,4,1,3,3,17,99,
175,175,175,175,175,175,175,1,7,7,7,2,6,7,7,7,7,7,7,7,7,6,6,6,7,7,7,7,5,3,17,
100,175,175,175,175,175,175,175,1,6,6,6,2,5,6,6,6,6,6,7,6,6,7,7,7,6,1,3,7,5,17,
99,100,175,175,175,175,175,175,175,175,1,4,4,2,4,6,5,5,5,5,6,6,4,4,4,6,6,1,3,5,
4,17,100,101,175,175,175,175,175,175,175,175,1,5,5,5,2,5,4,4,4,4,4,74,3,4,3,3,5,
6,6,5,17,99,101,101,175,175,175,175,175,175,175,175,175,1,5,5,4,4,4,4,3,4,4,2,2,
3,3,74,2,4,4,4,17,99,101,101,175,175,175,175,175,175,175,175,175,175,1,1,3,3,53,
5,4,3,3,3,2,42,3,3,2,1,3,3,17,99,100,101,175,175,175,175,175,175,175,175,175,
175,175,175,1,1,1,1,3,5,5,5,5,4,4,3,2,1,3,2,17,99,100,101,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,1,1,1,84,84,3,5,5,5,2,3,2,17,99,99,
100,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
1,1,1,1,83,84,74,84,2,17,98,99,100,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,1,1,1,4,4,2,17,98,99,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,1,1,1,1,17,18,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,1,1,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175
}
};
uint8_t SFG_charToFontIndex(char c)
{
if (c >= 'a' && c <= 'z')

BIN
assets/weapon_shotgun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

106
main.c
View File

@ -111,6 +111,19 @@ void SFG_init();
#define SFG_MS_PER_FRAME 1
#endif
#define SFG_WEAPON_IMAGE_SCALE \
(SFG_GAME_RESOLUTION_X / (SFG_TEXTURE_SIZE * 5))
#if SFG_WEAPON_IMAGE_SCALE == 0
#define SFG_WEAPON_IMAGE_SCALE 1
#endif
#define SFG_WEAPON_IMAGE_POSITION_X \
(SFG_GAME_RESOLUTION_X / 2 - (SFG_WEAPON_IMAGE_SCALE * SFG_TEXTURE_SIZE) / 2)
#define SFG_WEAPON_IMAGE_POSITION_Y \
(SFG_GAME_RESOLUTION_Y - (SFG_WEAPON_IMAGE_SCALE * SFG_TEXTURE_SIZE))
#define SFG_PLAYER_TURN_UNITS_PER_FRAME \
((SFG_PLAYER_TURN_SPEED * RCL_UNITS_PER_SQUARE) / (360 * SFG_FPS))
@ -450,6 +463,96 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
}
}
/**
Draws image on screen, with transparency. This is faster than sprite drawing.
For performance sake drawing near screen edges is not pixel perfect.
*/
void SFG_blitImage(
const uint8_t *image,
int16_t posX,
int16_t posY,
uint8_t scale)
{
if (scale == 0)
return;
uint16_t x0 = posX,
x1,
y0 = posY,
y1;
uint8_t u0 = 0, v0 = 0;
if (posX < 0)
{
x0 = 0;
u0 = (-1 * posX) / scale;
}
posX += scale * SFG_TEXTURE_SIZE;
uint16_t limitX = SFG_GAME_RESOLUTION_X - scale;
uint16_t limitY = SFG_GAME_RESOLUTION_Y - scale;
x1 = posX >= 0 ?
(posX <= limitX ? posX : limitX)
: 0;
if (x1 >= SFG_GAME_RESOLUTION_X)
x1 = SFG_GAME_RESOLUTION_X - 1;
if (posY < 0)
{
y0 = 0;
v0 = (-1 * posY) / scale;
}
posY += scale * SFG_TEXTURE_SIZE;
y1 = posY >= 0 ?
(posY <= limitY ? posY : limitY)
: 0;
if (y1 >= SFG_GAME_RESOLUTION_Y)
y1 = SFG_GAME_RESOLUTION_Y - 1;
uint8_t u,v;
v = v0;
for (uint16_t y = y0; y < y1; y += scale)
{
u = u0;
for (uint16_t x = x0; x < x1; x += scale)
{
uint8_t color = SFG_getTexel(image,u,v);
if (color != SFG_TRANSPARENT_COLOR)
{
uint16_t sY = y;
for (uint8_t j = 0; j < scale; ++j)
{
uint16_t sX = x;
for (uint8_t i = 0; i < scale; ++i)
{
SFG_setGamePixel(sX,sY,color);
sX++;
}
sY++;
}
}
u++;
}
v++;
}
}
#define SFG_MAX_SPRITE_SIZE SFG_GAME_RESOLUTION_X
uint8_t SFG_spriteSamplingPoints[SFG_MAX_SPRITE_SIZE];
@ -1257,6 +1360,9 @@ SFG_drawText("ammo",
SFG_GAME_RESOLUTION_X - 10 - 4 * (SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM + 1)
,SFG_GAME_RESOLUTION_Y - 10 - SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM,SFG_FONT_SIZE_MEDIUM,7);
SFG_blitImage(SFG_weaponImages[0],
SFG_WEAPON_IMAGE_POSITION_X,SFG_WEAPON_IMAGE_POSITION_Y ,SFG_WEAPON_IMAGE_SCALE);
}
}

View File

@ -154,8 +154,8 @@
#define RCL_min(a,b) ((a) < (b) ? (a) : (b))
#define RCL_max(a,b) ((a) > (b) ? (a) : (b))
#define RCL_nonZero(v) (v + (v == 0)) ///< To prevent zero divisions.
#define RCL_zeroClamp(x) (x * (x >= 0))
#define RCL_nonZero(v) ((v) + ((v) == 0)) ///< To prevent zero divisions.
#define RCL_zeroClamp(x) ((x) * ((x) >= 0))
#define RCL_likely(cond) __builtin_expect(!!(cond),1)
#define RCL_unlikely(cond) __builtin_expect(!!(cond),0)