mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-12-21 23:08:49 -05:00
Start projectiles
This commit is contained in:
parent
40fcef2cb7
commit
e2d157bd09
35
assets.h
35
assets.h
@ -43,8 +43,7 @@ static inline uint8_t SFG_getTexel(const uint8_t *texture, uint8_t x, uint8_t y)
|
||||
(texture[16 + (x * SFG_TEXTURE_SIZE + y) / 2] >> (4 * (y % 2 == 0))) & 0x0f];
|
||||
}
|
||||
|
||||
SFG_PROGRAM_MEMORY uint8_t
|
||||
SFG_texturesWall[][SFG_TEXTURE_STORE_SIZE] =
|
||||
SFG_PROGRAM_MEMORY uint8_t SFG_texturesWall[][SFG_TEXTURE_STORE_SIZE] =
|
||||
{
|
||||
{ // 0: white wooden planks
|
||||
4,21,5,3,20,0,2,26,6,18,57,65,1,16,17,49,0,1,0,3,32,1,33,0,161,64,1,16,64,3,3,
|
||||
@ -348,8 +347,7 @@ SFG_PROGRAM_MEMORY uint8_t SFG_sprites[][SFG_TEXTURE_STORE_SIZE] =
|
||||
}
|
||||
};
|
||||
|
||||
SFG_PROGRAM_MEMORY
|
||||
uint8_t SFG_backgrounds[][SFG_TEXTURE_STORE_SIZE] =
|
||||
SFG_PROGRAM_MEMORY uint8_t SFG_backgrounds[][SFG_TEXTURE_STORE_SIZE] =
|
||||
{
|
||||
{ // 0, city
|
||||
64,73,10,168,19,12,14,13,80,101,0,100,136,57,59,63,34,34,34,68,87,119,119,119,
|
||||
@ -376,8 +374,7 @@ uint8_t SFG_backgrounds[][SFG_TEXTURE_STORE_SIZE] =
|
||||
}
|
||||
};
|
||||
|
||||
SFG_PROGRAM_MEMORY
|
||||
uint8_t SFG_weaponImages[][SFG_TEXTURE_STORE_SIZE] =
|
||||
SFG_PROGRAM_MEMORY uint8_t SFG_weaponImages[][SFG_TEXTURE_STORE_SIZE] =
|
||||
{
|
||||
{ // 0, knife
|
||||
175,0,5,2,6,4,3,83,1,77,85,61,60,62,63,75,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
@ -451,8 +448,7 @@ frame for idle and walking, some enemies can share the same dead sprite etc.).
|
||||
Also: add flip option to sprite drawing function so that some frames can be
|
||||
reused flipped (good for walk anims). */
|
||||
|
||||
SFG_PROGRAM_MEMORY uint8_t
|
||||
SFG_monsterSprites[][SFG_TEXTURE_STORE_SIZE] =
|
||||
SFG_PROGRAM_MEMORY uint8_t SFG_monsterSprites[][SFG_TEXTURE_STORE_SIZE] =
|
||||
{
|
||||
{ // 0, spider idle
|
||||
175,0,4,3,5,6,223,1,7,10,2,20,62,95,120,18,0,1,17,16,0,0,0,0,0,0,0,0,1,17,16,0,
|
||||
@ -500,6 +496,29 @@ SFG_PROGRAM_MEMORY uint8_t
|
||||
}
|
||||
};
|
||||
|
||||
SFG_PROGRAM_MEMORY uint8_t SFG_effects[][SFG_TEXTURE_STORE_SIZE] =
|
||||
{
|
||||
{ // 0, fireball
|
||||
175,103,183,7,191,111,254,31,95,180,173,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,17,17,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,23,17,17,24,0,0,0,0,0,0,0,0,0,0,0,1,23,85,87,81,24,16,16,0,0,
|
||||
0,0,0,0,0,8,17,119,115,55,119,17,129,17,0,0,0,0,0,0,0,129,23,119,51,51,55,113,
|
||||
24,23,16,0,0,0,0,0,8,17,17,113,83,51,85,119,23,113,16,0,0,0,0,0,1,21,113,81,19,
|
||||
53,81,17,119,129,0,0,0,0,0,1,17,19,53,17,19,50,17,17,113,16,0,0,0,0,0,17,33,83,
|
||||
49,17,19,66,34,17,17,18,0,0,0,0,0,1,33,85,53,21,19,18,34,34,24,18,0,0,0,0,0,1,
|
||||
33,85,85,84,68,20,34,35,66,98,0,0,0,0,0,0,33,83,53,20,68,51,51,51,70,34,0,0,0,0,
|
||||
0,0,33,19,49,66,36,67,52,41,40,98,0,0,0,0,0,0,33,19,84,34,36,36,70,38,134,34,0,
|
||||
0,0,0,0,0,8,21,81,18,36,66,98,102,166,32,0,0,0,0,0,0,2,21,81,18,68,68,38,134,
|
||||
105,33,0,0,0,0,0,0,0,18,33,18,68,51,73,102,98,17,0,0,0,0,0,0,0,18,18,34,68,51,
|
||||
74,102,102,17,0,0,0,0,0,0,1,17,17,18,34,36,38,38,129,16,0,0,0,0,0,0,1,16,8,134,
|
||||
38,34,34,104,0,0,0,0,0,0,0,0,0,16,0,2,34,102,96,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0
|
||||
}
|
||||
};
|
||||
|
||||
uint8_t SFG_charToFontIndex(char c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
|
BIN
assets/effect_fireball.png
Normal file
BIN
assets/effect_fireball.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 675 B |
71
main.c
71
main.c
@ -283,6 +283,7 @@ typedef struct
|
||||
#define SFG_MONSTER_STATE_GOING_NW 12
|
||||
|
||||
#define SFG_MAX_MONSTERS 64
|
||||
// TODO: ^ move these MAX constants to constants.h?
|
||||
|
||||
#define SFG_AI_UPDATE_FRAME_INTERVAL \
|
||||
(SFG_FPS / SFG_AI_FPS)
|
||||
@ -294,12 +295,14 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint8_t type;
|
||||
int8_t framesToLive;
|
||||
uint8_t framesToLive;
|
||||
uint16_t position[3]; /**< Current position, stored as u16 to save space, as
|
||||
that is exactly enough to store position on 64x64
|
||||
map. */
|
||||
int16_t direction[3]; /**< Added to position each game step. */
|
||||
} SFG_projectileRecord;
|
||||
} SFG_ProjectileRecord;
|
||||
|
||||
#define SFG_MAX_PROJECTILES 12
|
||||
|
||||
/*
|
||||
GLOBAL VARIABLES
|
||||
@ -366,6 +369,9 @@ struct
|
||||
SFG_MonsterRecord monsterRecords[SFG_MAX_MONSTERS];
|
||||
uint8_t monsterRecordCount;
|
||||
uint8_t checkedMonsterIndex;
|
||||
|
||||
SFG_ProjectileRecord projectileRecords[SFG_MAX_PROJECTILES];
|
||||
uint8_t projectileRecordCount;
|
||||
} SFG_currentLevel;
|
||||
|
||||
#if SFG_DITHERED_SHADOW
|
||||
@ -907,6 +913,8 @@ void SFG_setAndInitLevel(const SFG_Level *level)
|
||||
|
||||
SFG_currentLevel.doorRecordCount = 0;
|
||||
|
||||
SFG_currentLevel.projectileRecordCount = 0;
|
||||
|
||||
for (uint8_t j = 0; j < SFG_MAP_SIZE; ++j)
|
||||
{
|
||||
for (uint8_t i = 0; i < SFG_MAP_SIZE; ++i)
|
||||
@ -1103,6 +1111,23 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster)
|
||||
monster->coords[1] = newPos[1];;
|
||||
}
|
||||
|
||||
/**
|
||||
Adds new projectile to the current level, return 1 if added, 0 if not (max
|
||||
count reached).
|
||||
*/
|
||||
uint8_t SFG_createProjectile(SFG_ProjectileRecord projectile)
|
||||
{
|
||||
if (SFG_currentLevel.projectileRecordCount >= SFG_MAX_PROJECTILES)
|
||||
return 0;
|
||||
|
||||
SFG_currentLevel.projectileRecords[SFG_currentLevel.projectileRecordCount] =
|
||||
projectile;
|
||||
|
||||
SFG_currentLevel.projectileRecordCount++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Performs one game step (logic, physics), happening SFG_MS_PER_FRAME after
|
||||
previous frame.
|
||||
@ -1127,6 +1152,25 @@ void SFG_gameStep()
|
||||
|
||||
int8_t shearing = 0;
|
||||
|
||||
if (SFG_keyJustPressed(SFG_KEY_B))
|
||||
{
|
||||
// fire
|
||||
|
||||
SFG_ProjectileRecord p;
|
||||
|
||||
p.type = 0;
|
||||
p.framesToLive = 255;
|
||||
p.position[0] = SFG_player.camera.position.x;
|
||||
p.position[1] = SFG_player.camera.position.y;
|
||||
p.position[2] = SFG_player.camera.height;
|
||||
|
||||
p.direction[0] = 1;
|
||||
p.direction[1] = 0;
|
||||
p.direction[2] = 0;
|
||||
|
||||
printf("%d\n",SFG_createProjectile(p));
|
||||
}
|
||||
|
||||
if (SFG_keyIsDown(SFG_KEY_A))
|
||||
{
|
||||
if (SFG_keyIsDown(SFG_KEY_UP))
|
||||
@ -1406,6 +1450,7 @@ void SFG_gameStep()
|
||||
SFG_currentLevel.checkedMonsterIndex = 0;
|
||||
}
|
||||
|
||||
// update AI
|
||||
|
||||
if ((SFG_gameFrame - SFG_currentLevel.frameStart) %
|
||||
SFG_AI_UPDATE_FRAME_INTERVAL == 0)
|
||||
@ -1629,6 +1674,28 @@ void SFG_draw()
|
||||
|
||||
// draw sprites:
|
||||
|
||||
|
||||
// projecile sprites:
|
||||
|
||||
for (uint8_t i = 0; i < SFG_currentLevel.projectileRecordCount; ++i)
|
||||
{
|
||||
SFG_ProjectileRecord *proj = &(SFG_currentLevel.projectileRecords[i]);
|
||||
|
||||
RCL_Vector2D worldPosition;
|
||||
|
||||
worldPosition.x = proj->position[0];
|
||||
worldPosition.y = proj->position[1];
|
||||
|
||||
RCL_PixelInfo p =
|
||||
RCL_mapToScreen(worldPosition,proj->position[2],SFG_player.camera);
|
||||
|
||||
if (p.depth > 0)
|
||||
SFG_drawScaledSprite(SFG_effects[0],
|
||||
p.position.x * SFG_RAYCASTING_SUBSAMPLE,p.position.y,
|
||||
RCL_perspectiveScale(SFG_GAME_RESOLUTION_Y,p.depth),
|
||||
p.depth / (RCL_UNITS_PER_SQUARE * 2),p.depth);
|
||||
}
|
||||
|
||||
// monster sprites:
|
||||
for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user