From f59ca0c43fc384509b0df2c0ba1bbec567b0acfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 21 Oct 2019 23:50:19 +0200 Subject: [PATCH] Explode at monsters --- constants.h | 6 ++++++ main.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/constants.h b/constants.h index bb49866..28e2f36 100644 --- a/constants.h +++ b/constants.h @@ -71,4 +71,10 @@ */ #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 diff --git a/main.c b/main.c index 753abd4..90b1e36 100755 --- a/main.c +++ b/main.c @@ -269,10 +269,12 @@ typedef struct { uint8_t stateType; /**< Holds state (lower 4 bits) and type of monster (upper 4 bits). */ - uint8_t coords[2]; + uint8_t coords[2]; /**< Monster position, in 1/4s of a square */ uint8_t health; } SFG_MonsterRecord; +#define SFG_MONSTER_COORD_TO_RCL_UNITS(c) (c * 256) + #define SFG_MONSTER_MASK_STATE 0x0f #define SFG_MONSTER_MASK_TYPE 0xf0 @@ -1493,10 +1495,36 @@ SFG_createProjectile(p); } } - if (p->doubleFramesToLive == 0 || (SFG_floorHeightAt( - pos[0] / RCL_UNITS_PER_SQUARE,pos[1] / - RCL_UNITS_PER_SQUARE) >= pos[2])) + if (p->doubleFramesToLive == 0) + { 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) {