Explode at monsters

This commit is contained in:
Miloslav Číž 2019-10-21 23:50:19 +02:00
parent c3b2cc4189
commit f59ca0c43f
2 changed files with 38 additions and 4 deletions

View File

@ -71,4 +71,10 @@
*/ */
#define SFG_ROCKET_SPEED 20 #define SFG_ROCKET_SPEED 20
/**
Distance at which level elements (sprites) collide, in RCL_Unit (1024 per
square).
*/
#define SFG_ELEMENT_COLLISION_DISTANCE 700
#endif // guard #endif // guard

36
main.c
View File

@ -269,10 +269,12 @@ typedef struct
{ {
uint8_t stateType; /**< Holds state (lower 4 bits) and type of monster uint8_t stateType; /**< Holds state (lower 4 bits) and type of monster
(upper 4 bits). */ (upper 4 bits). */
uint8_t coords[2]; uint8_t coords[2]; /**< Monster position, in 1/4s of a square */
uint8_t health; uint8_t health;
} SFG_MonsterRecord; } SFG_MonsterRecord;
#define SFG_MONSTER_COORD_TO_RCL_UNITS(c) (c * 256)
#define SFG_MONSTER_MASK_STATE 0x0f #define SFG_MONSTER_MASK_STATE 0x0f
#define SFG_MONSTER_MASK_TYPE 0xf0 #define SFG_MONSTER_MASK_TYPE 0xf0
@ -1493,10 +1495,36 @@ SFG_createProjectile(p);
} }
} }
if (p->doubleFramesToLive == 0 || (SFG_floorHeightAt( if (p->doubleFramesToLive == 0)
pos[0] / RCL_UNITS_PER_SQUARE,pos[1] / {
RCL_UNITS_PER_SQUARE) >= pos[2]))
eliminate = 1; eliminate = 1;
}
else if (p->type != SFG_PROJECTILE_EXPLOSION)
{
if (SFG_floorHeightAt(pos[0] / RCL_UNITS_PER_SQUARE,pos[1] /
RCL_UNITS_PER_SQUARE) >= pos[2])
eliminate = 1;
for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i)
{
SFG_MonsterRecord *m = &(SFG_currentLevel.monsterRecords[i]);
if ((m->stateType & SFG_MONSTER_MASK_STATE) !=
SFG_MONSTER_STATE_INACTIVE)
{
RCL_Unit distance =
RCL_absVal(
p->position[0] - SFG_MONSTER_COORD_TO_RCL_UNITS(m->coords[0])) +
RCL_absVal(
p->position[1] - SFG_MONSTER_COORD_TO_RCL_UNITS(m->coords[1]));
if (distance <= SFG_ELEMENT_COLLISION_DISTANCE)
{
eliminate = 1;
break;
}
}
}
}
if (eliminate) if (eliminate)
{ {