From 48780a539af7d10377891a3e5a82f5d22728e0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 19 Nov 2020 17:00:40 +0100 Subject: [PATCH] Make monsters aim vertically --- game.h | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/game.h b/game.h index 1d431a8..bea2624 100755 --- a/game.h +++ b/game.h @@ -2227,8 +2227,6 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) - 128 * SFG_MONSTER_AIM_RANDOMNESS + SFG_random() * SFG_MONSTER_AIM_RANDOMNESS; - dir = RCL_normalize(dir); - uint8_t projectile; switch (SFG_GET_MONSTER_ATTACK_TYPE(monsterNumber)) @@ -2270,15 +2268,22 @@ void SFG_monsterPerformAI(SFG_MonsterRecord *monster) currentHeight) ); - uint8_t spriteSize = SFG_GET_MONSTER_SPRITE_SIZE( - SFG_MONSTER_TYPE_TO_INDEX(SFG_MR_TYPE(*monster))); + RCL_Unit middleHeight = currentHeight + + SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(SFG_GET_MONSTER_SPRITE_SIZE( + SFG_MONSTER_TYPE_TO_INDEX(SFG_MR_TYPE(*monster)))); + + RCL_Unit verticalSpeed = (SFG_GET_PROJECTILE_SPEED_UPS(projectile) * + SFG_directionTangent(dir.x,dir.y,SFG_player.camera.height - + middleHeight)) / RCL_UNITS_PER_SQUARE; + + dir = RCL_normalize(dir); SFG_launchProjectile( projectile, pos, - currentHeight + SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(spriteSize), + middleHeight, dir, - 0, + verticalSpeed, SFG_PROJECTILE_SPAWN_OFFSET ); } // if visible @@ -2894,6 +2899,16 @@ static inline uint16_t SFG_getMapRevealBit(uint8_t squareX, uint8_t squareY) return 1 << ((squareY / 16) * 4 + squareX / 16); } +RCL_Unit SFG_directionTangent(RCL_Unit dirX, RCL_Unit dirY, RCL_Unit dirZ) +{ + RCL_Vector2D v; + + v.x = dirX; + v.y = dirY; + + return (dirZ * RCL_UNITS_PER_SQUARE) / RCL_len(v); +} + /** Returns a tangent in RCL_Unit of vertical autoaim, given current game state. */ @@ -2932,12 +2947,8 @@ RCL_Unit SFG_autoaimVertically() SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(spriteSize); if (SFG_spriteIsVisible(worldPosition,worldHeight)) - { - RCL_Unit distance = RCL_len(toMonster); - - return ((worldHeight - SFG_player.camera.height) * RCL_UNITS_PER_SQUARE) - / distance; - } + return SFG_directionTangent(toMonster.x,toMonster.y, + worldHeight - (SFG_player.camera.height)); } }