ref: eee18d71a39e4f91b419b6ed4fe4fbeaa783a332
parent: 7a44e6c8e087be7fc1ddf04f12b1eaed4aa662b1
author: cuckydev <cuckydev@users.noreply.github.com>
date: Wed Jan 30 13:44:31 EST 2019
Finally, bullets murder NPCS, also fixed SetExpObjects to not crash... oops!
--- a/src/Caret.cpp
+++ b/src/Caret.cpp
@@ -4,6 +4,7 @@
#include "Caret.h"
#include "Draw.h"
+#include "Triangle.h"
#include "Game.h"
#define CARET_MAX 0x40
@@ -181,6 +182,38 @@
crt->rect = {0, 80, 16, 96};
}
+void ActCaret11(CARET *crt)
+{
+ if (!crt->act_no)
+ {
+ crt->act_no = 1;
+ uint8_t deg = Random(0, 0xFF);
+ crt->xm = 2 * GetCos(deg);
+ crt->ym = 2 * GetSin(deg);
+ }
+
+ crt->x += crt->xm;
+ crt->y += crt->ym;
+
+ RECT rcRight[7];
+ rcRight[0] = {56, 8, 64, 16};
+ rcRight[1] = {64, 8, 72, 16};
+ rcRight[2] = {72, 8, 80, 16};
+ rcRight[3] = {80, 8, 88, 16};
+ rcRight[4] = {88, 8, 96, 16};
+ rcRight[5] = {96, 8, 104, 16};
+ rcRight[6] = {104, 8, 112, 16};
+
+ if (++crt->ani_wait > 2)
+ {
+ crt->ani_wait = 0;
+ if (++crt->ani_no > 6)
+ crt->cond = 0;
+ }
+
+ crt->rect = rcRight[crt->ani_no];
+}
+
void ActCaret13(CARET *crt)
{
RECT rcLeft[2];
@@ -259,7 +292,7 @@
ActCaret08,
ActCaret09,
nullptr, //ActCaret10,
- nullptr, //ActCaret11,
+ ActCaret11,
nullptr, //ActCaret12,
ActCaret13,
nullptr, //ActCaret14,
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -478,7 +478,7 @@
HitNpCharMap();
//HitBossMap();
HitBulletMap();
- //HitNpCharBullet();
+ HitNpCharBullet();
//HitBossBullet();
if (g_GameFlags & 2)
ShootBullet();
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -9,8 +9,10 @@
#include "Caret.h"
#include "MyChar.h"
#include "Game.h"
+#include "ArmsItem.h"
#include "Flags.h"
#include "Sound.h"
+#include "ValueView.h"
#include "NpcTbl.h"
#include "Draw.h"
@@ -172,43 +174,51 @@
void SetExpObjects(int x, int y, int exp)
{
+ int sub_exp;
for (int n = 0x100; exp; SetUniqueParameter(&gNPC[n]))
{
- if (!gNPC[n].cond)
+ while (true)
{
- memset(&gNPC[n], 0, sizeof(NPCHAR));
+ bool v3 = n < NPC_MAX && gNPC[n].cond;
+ if (!v3)
+ break;
+ ++n;
+ }
+
+ if (n == NPC_MAX)
+ break;
+
+ memset(&gNPC[n], 0, sizeof(NPCHAR));
- int sub_exp = 0;
- if (exp < 20)
+ if (exp < 20)
+ {
+ if (exp < 5)
{
- if (exp < 5)
+ if (exp > 0)
{
- if (exp > 0)
- {
- --exp;
- sub_exp = 1;
- }
+ --exp;
+ sub_exp = 1;
}
- else
- {
- exp -= 5;
- sub_exp = 5;
- }
}
else
{
- exp -= 20;
- sub_exp = 20;
+ exp -= 5;
+ sub_exp = 5;
}
-
- gNPC[n].cond |= 0x80u;
- gNPC[n].direct = 0;
- gNPC[n].code_char = 1;
- gNPC[n].x = x;
- gNPC[n].y = y;
- gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
- gNPC[n].exp = sub_exp;
}
+ else
+ {
+ exp -= 20;
+ sub_exp = 20;
+ }
+
+ gNPC[n].cond |= 0x80u;
+ gNPC[n].direct = 0;
+ gNPC[n].code_char = 1;
+ gNPC[n].x = x;
+ gNPC[n].y = y;
+ gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
+ gNPC[n].exp = sub_exp;
}
}
@@ -220,7 +230,7 @@
memset(tamakazu_ari, 0, sizeof(tamakazu_ari));
for (int n = 0; n < 8; n++)
{
- int code = 0; //gArmsData[n].code;
+ int code = gArmsData[n].code;
if (code == 5)
tamakazu_ari[t++] = 0;
else if (code == 10)
@@ -310,7 +320,7 @@
a = 0;
if (gNPC[n].bits & npc_showDamage && gNPC[n].damage_view)
{
- //SetValueView(&gNPC[n].x, &gNPC[n].y, gNPC[n].damage_view);
+ SetValueView(&gNPC[n].x, &gNPC[n].y, gNPC[n].damage_view);
gNPC[n].damage_view = 0;
}
}
--- a/src/NpChar.h
+++ b/src/NpChar.h
@@ -83,6 +83,7 @@
void SetDestroyNpCharUp(int x, int y, int w, int num);
void SetExpObjects(int x, int y, int exp);
bool SetBulletObject(int x, int y, int val);
+bool SetLifeObject(int x, int y, int val);
void VanishNpChar(NPCHAR *npc);
void PutNpChar(int fx, int fy);
void ActNpChar();
--- a/src/NpcHit.cpp
+++ b/src/NpcHit.cpp
@@ -1,4 +1,12 @@
#include "NpChar.h"
+#include "ValueView.h"
+#include "Sound.h"
+#include "Flags.h"
+#include "Caret.h"
+#include "Game.h"
+#include "Bullet.h"
+#include "MyChar.h"
+#include "TextScr.h"
#include "Map.h"
void JadgeHitNpCharBlock(NPCHAR *npc, int x, int y)
@@ -398,4 +406,141 @@
}
}
}
-}
\ No newline at end of file
+}
+
+void LoseNpChar(NPCHAR *npc, bool bVanish)
+{
+ //Play death sound
+ PlaySoundObject(npc->destroy_voice, 1);
+
+ //Create smoke
+ switch (npc->size)
+ {
+ case 1:
+ SetDestroyNpChar(npc->x, npc->y, npc->view.back, 3);
+ break;
+ case 2:
+ SetDestroyNpChar(npc->x, npc->y, npc->view.back, 7);
+ break;
+ case 3:
+ SetDestroyNpChar(npc->x, npc->y, npc->view.back, 12);
+ break;
+ }
+
+ //Create drop
+ if (npc->exp)
+ {
+ int v3 = Random(1, 5);
+ char v4;
+
+ if (v3 == 1)
+ {
+ if (npc->exp <= 6)
+ SetLifeObject(npc->x, npc->y, 2);
+ else
+ SetLifeObject(npc->x, npc->y, 6);
+ }
+ else if (v3 != 2 || (npc->exp <= 6 ? (v4 = SetBulletObject(npc->x, npc->y, 1)) : (v4 = SetBulletObject(npc->x, npc->y, 3)), !v4)) //TODO: what the FUCK
+ {
+ SetExpObjects(npc->x, npc->y, npc->exp);
+ }
+ }
+
+ //Set flag
+ SetNPCFlag(npc->code_flag);
+
+ //Create value view
+ if (!(npc->bits & npc_showDamage))
+ {
+ npc->cond = 0;
+ }
+ else
+ {
+ if ((npc->bits & npc_showDamage) && npc->damage_view)
+ SetValueView(&npc->x, &npc->y, npc->damage_view);
+ if (bVanish)
+ VanishNpChar(npc);
+ }
+}
+
+void HitNpCharBullet()
+{
+ for (int n = 0; n < NPC_MAX; n++)
+ {
+ if ((gNPC[n].cond & 0x80) && (!(gNPC[n].bits & npc_shootable) || !(gNPC[n].bits & npc_interact)))
+ {
+ for (int b = 0; b < BULLET_MAX; b++)
+ {
+ if (gBul[b].cond & 0x80 && gBul[b].damage != -1)
+ {
+ //Check if bullet touches npc
+ bool bHit = false;
+ if (gNPC[n].bits & npc_shootable
+ && gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].enemyXL
+ && gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].enemyXL
+ && gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].enemyYL
+ && gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].enemyYL)
+ bHit = true;
+ else if (gNPC[n].bits & npc_invulnerable
+ && gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].blockXL
+ && gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].blockXL
+ && gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].blockYL
+ && gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].blockYL)
+ bHit = true;
+
+ if (bHit)
+ {
+ //Damage NPC
+ if (gNPC[n].bits & npc_shootable)
+ {
+ gNPC[n].life -= gBul[b].damage;
+
+ if (gNPC[n].life > 0)
+ {
+ if (gNPC[n].shock < 14)
+ {
+ SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 11, 0);
+ SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 11, 0);
+ SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 11, 0);
+ PlaySoundObject(gNPC[n].hit_voice, 1);
+ gNPC[n].shock = 16;
+ }
+ }
+ else
+ {
+ gNPC[n].life = 0;
+
+ if (gNPC[n].bits & npc_showDamage)
+ gNPC[n].damage_view -= gBul[b].damage;
+
+ if ((gMC.cond & 0x80) && gNPC[n].bits & npc_eventDie)
+ StartTextScript(gNPC[n].code_event);
+ else
+ gNPC[n].cond |= 8;
+ }
+ }
+ //Hit invulnerable NPC
+ else if (gBul[b].code_bullet != 13
+ && gBul[b].code_bullet != 14
+ && gBul[b].code_bullet != 15
+ && gBul[b].code_bullet != 28
+ && gBul[b].code_bullet != 29
+ && gBul[b].code_bullet != 30
+ && !(gBul[b].bbits & 0x10))
+ {
+ SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 2, 2);
+ PlaySoundObject(31, 1);
+ gBul[b].life = 0;
+ continue;
+ }
+
+ --gBul[b].life;
+ }
+ }
+ }
+
+ if (gNPC[n].cond & 8)
+ LoseNpChar(&gNPC[n], true);
+ }
+ }
+}
--- a/src/NpcHit.h
+++ b/src/NpcHit.h
@@ -2,3 +2,4 @@
#include "NpChar.h"
void HitNpCharMap();
+void HitNpCharBullet();
--
⑨