From 8954e9aaca1e08ba86fbd476925cf051f5047e71 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 31 Jan 2019 13:26:59 +0000 Subject: [PATCH 1/3] More NPCs, and added Flash.cpp --- Makefile | 1 + src/Flash.cpp | 153 ++++++++++++ src/Flash.h | 9 + src/Game.cpp | 9 +- src/NpcAct.h | 9 +- src/NpcAct000.cpp | 91 ++++++- src/NpcAct040.cpp | 18 +- src/NpcAct060.cpp | 608 ++++++++++++++++++++++++++++++++++++++++++++++ src/NpcTbl.cpp | 12 +- src/Stage.cpp | 3 +- 10 files changed, 897 insertions(+), 16 deletions(-) create mode 100644 src/Flash.cpp create mode 100644 src/Flash.h diff --git a/Makefile b/Makefile index ddeef95b..ba9fac12 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ SOURCES = \ Escape \ Fade \ Flags \ + Flash \ Font \ Frame \ Game \ diff --git a/src/Flash.cpp b/src/Flash.cpp new file mode 100644 index 00000000..bf930c49 --- /dev/null +++ b/src/Flash.cpp @@ -0,0 +1,153 @@ +#include "Flash.h" + +#include "Draw.h" +#include "WindowsWrapper.h" + +static struct +{ + int mode; + int act_no; + bool flag; + int cnt; + int width; + int x; + int y; + RECT rect1; + RECT rect2; +} flash; + +static unsigned long gFlashColor; + +void InitFlash(void) +{ + gFlashColor = 0xFEFFFF; +} + +void SetFlash(int x, int y, int mode) +{ + flash.act_no = 0; + flash.flag = true; + flash.x = x; + flash.y = y; + flash.mode = mode; + flash.cnt = 0; + flash.width = 0; +} + +void ActFlash_Explosion(int flx, int fly) +{ + if (flash.act_no == 0) + { + flash.cnt += 0x200; + flash.width += flash.cnt; + + int right = (flash.x - flx - flash.width) / 0x200; + int left = (flash.y - fly - flash.width) / 0x200; + int top = (flash.width + flash.x - flx) / 0x200; + int bottom = (flash.width + flash.y - fly) / 0x200; + + if (right < 0) + right = 0; + if (left < 0) + left = 0; + if (top > 320) + top = 320; + if (bottom > 240) + bottom = 240; + + flash.rect1.left = right; + flash.rect1.right = top; + flash.rect1.top = 0; + flash.rect1.bottom = 240; + + flash.rect2.left = 0; + flash.rect2.right = 320; + flash.rect2.top = left; + flash.rect2.bottom = bottom; + + if (flash.width > 0xA0000) + { + flash.act_no = 1; + flash.cnt = 0; + flash.width = 0x1E000; + } + } + else if (flash.act_no == 1) + { + flash.width -= flash.width / 8; + + if ((flash.width / 0x100) == 0) + flash.flag = false; + + int top = (flash.y - fly - flash.width) / 0x200; + if (top < 0) + top = 0; + + int bottom = (flash.width + flash.y - fly) / 0x200; + if (bottom > 240) + bottom = 240; + + flash.rect1.left = 0; + flash.rect1.right = 0; + flash.rect1.top = 0; + flash.rect1.bottom = 0; + + flash.rect2.top = top; + flash.rect2.bottom = bottom; + flash.rect2.left = 0; + flash.rect2.right = 320; + } +} + +void ActFlash_Flash(void) +{ + ++flash.cnt; + + flash.rect1.left = 0; + flash.rect1.right = 0; + flash.rect1.top = 0; + flash.rect1.bottom = 0; + + if (flash.cnt / 2 % 2) + { + flash.rect2.top = 0; + flash.rect2.bottom = 240; + flash.rect2.left = 0; + flash.rect2.right = 320; + } + else + { + flash.rect2.left = 0; + flash.rect2.right = 0; + flash.rect2.top = 0; + flash.rect2.bottom = 0; + } + + if (flash.cnt > 20) + flash.flag = false; +} + +void ActFlash(int flx, int fly) +{ + if (flash.flag) + { + if (flash.mode == 1) + ActFlash_Explosion(flx, fly); + else if (flash.mode == 2) + ActFlash_Flash(); + } +} + +void PutFlash(void) +{ + if (flash.flag) + { + CortBox(&flash.rect1, gFlashColor); + CortBox(&flash.rect2, gFlashColor); + } +} + +void ResetFlash(void) +{ + flash.flag = false; +} diff --git a/src/Flash.h b/src/Flash.h new file mode 100644 index 00000000..bbd99eaf --- /dev/null +++ b/src/Flash.h @@ -0,0 +1,9 @@ +#pragma once + +void InitFlash(void); +void SetFlash(int x, int y, int mode); +void ActFlash_Explosion(int flx, int fly); +void ActFlash_Flash(void); +void ActFlash(int flx, int fly); +void PutFlash(void); +void ResetFlash(void); diff --git a/src/Game.cpp b/src/Game.cpp index d5c22e0b..8421acb3 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -36,6 +36,7 @@ #include "ValueView.h" #include "Draw.h" #include "Ending.h" +#include "Flash.h" int g_GameFlags; int gCounter; @@ -101,7 +102,7 @@ int ModeOpening() InitCaret(); //InitStar(); InitFade(); - //InitFlash(); + InitFlash(); //InitBossLife(); ChangeMusic(0); TransferStage(72, 100, 3, 3); @@ -434,7 +435,7 @@ int ModeAction() InitCaret(); //InitStar(); InitFade(); - //InitFlash(); + InitFlash(); ClearArmsData(); ClearItemData(); //ClearPermitStage(); @@ -485,7 +486,7 @@ int ModeAction() ActBullet(); ActCaret(); MoveFrame3(); - //ActFlash(frame_x, frame_y); + ActFlash(frame_x, frame_y); if (g_GameFlags & 2) AnimationMyChar(true); @@ -513,7 +514,7 @@ int ModeAction() PutMapDataVector(frame_x, frame_y); PutStage_Front(frame_x, frame_y); PutFront(frame_x, frame_y); - //PutFlash(); + PutFlash(); PutCaret(frame_x, frame_y); PutValueView(frame_x, frame_y); //PutBossLife(); diff --git a/src/NpcAct.h b/src/NpcAct.h index ca40f6ea..2be21639 100644 --- a/src/NpcAct.h +++ b/src/NpcAct.h @@ -16,7 +16,7 @@ void ActNpc015(NPCHAR *npc); void ActNpc016(NPCHAR *npc); void ActNpc017(NPCHAR *npc); void ActNpc018(NPCHAR *npc); - +void ActNpc019(NPCHAR *npc); void ActNpc020(NPCHAR *npc); void ActNpc021(NPCHAR *npc); void ActNpc022(NPCHAR *npc); @@ -36,6 +36,7 @@ void ActNpc037(NPCHAR *npc); void ActNpc038(NPCHAR *npc); void ActNpc039(NPCHAR *npc); +void ActNpc041(NPCHAR *npc); void ActNpc042(NPCHAR *npc); void ActNpc043(NPCHAR *npc); @@ -46,10 +47,12 @@ void ActNpc059(NPCHAR *npc); void ActNpc060(NPCHAR *npc); void ActNpc061(NPCHAR *npc); void ActNpc062(NPCHAR *npc); - +void ActNpc063(NPCHAR *npc); void ActNpc064(NPCHAR *npc); void ActNpc065(NPCHAR *npc); - +void ActNpc066(NPCHAR *npc); +void ActNpc067(NPCHAR *npc); +void ActNpc068(NPCHAR *npc); void ActNpc069(NPCHAR *npc); void ActNpc070(NPCHAR *npc); void ActNpc071(NPCHAR *npc); diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 52ec9f45..1cc579e9 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -8,6 +8,7 @@ #include "Sound.h" #include "Back.h" #include "Triangle.h" +#include "Frame.h" //Null void ActNpc000(NPCHAR *npc) @@ -1019,4 +1020,92 @@ void ActNpc018(NPCHAR *npc) npc->rect = rect[0]; break; } -} \ No newline at end of file +} + +// Balrog (burst) +void ActNpc019(NPCHAR *npc) +{ + switch (npc->act_no) + { + case 0: + for (int i = 0; i < 0x10; ++i) + SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100); + + npc->y += 0x1400; + npc->act_no = 1; + npc->ani_no = 3; + npc->ym = -0x100; + PlaySoundObject(12, 1); + PlaySoundObject(26, 1); + SetQuake(30); + // Fallthrough + case 1: + npc->ym += 0x10; + + if (npc->ym > 0 && npc->flag & 8) + { + npc->act_no = 2; + npc->ani_no = 2; + npc->act_wait = 0; + PlaySoundObject(26, 1); + SetQuake(30); + } + + break; + + case 2: + if (++npc->act_wait > 0x10) + { + npc->act_no = 3; + npc->ani_no = 0; + npc->ani_wait = 0; + } + + break; + + case 3: + if (Random(0, 100) == 0) + { + npc->act_no = 4; + npc->act_wait = 0; + npc->ani_no = 1; + } + + break; + + case 4: + if (++npc->act_wait > 0x10) + { + npc->act_no = 3; + npc->ani_no = 0; + } + + break; + } + + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + if (npc->ym < -0x5FF) + npc->ym = -0x5FF; + + npc->x += npc->xm; + npc->y += npc->ym; + + RECT rect_left[4]; + RECT rect_right[4]; + + rect_left[0] = {0, 0, 40, 24}; + rect_left[1] = {160, 0, 200, 24}; + rect_left[2] = {80, 0, 120, 24}; + rect_left[3] = {120, 0, 160, 24}; + + rect_right[0] = {0, 24, 40, 48}; + rect_right[1] = {160, 24, 200, 48}; + rect_right[2] = {80, 24, 120, 48}; + rect_right[3] = {120, 24, 160, 48}; + + if (npc->direct == 0) + npc->rect = rect_left[npc->ani_no]; + else + npc->rect = rect_right[npc->ani_no]; +} diff --git a/src/NpcAct040.cpp b/src/NpcAct040.cpp index 2a29ebd0..1063602b 100644 --- a/src/NpcAct040.cpp +++ b/src/NpcAct040.cpp @@ -9,7 +9,23 @@ #include "Back.h" #include "Triangle.h" -// Sue +//Busted Door +void ActNpc041(NPCHAR *npc) +{ + RECT rect[1]; + + rect[0] = {0, 80, 48, 112}; + + if (npc->act_no == 0) + { + ++npc->act_no; + npc->y -= 0x2000; // Move a tile up + } + + npc->rect = rect[0]; +} + +//Sue void ActNpc042(NPCHAR *npc) { RECT rcLeft[13]; diff --git a/src/NpcAct060.cpp b/src/NpcAct060.cpp index 573e8b60..a8cca143 100644 --- a/src/NpcAct060.cpp +++ b/src/NpcAct060.cpp @@ -10,6 +10,9 @@ #include "Triangle.h" #include "Map.h" #include "CommonDefines.h" +#include "Frame.h" +#include "MycParam.h" +#include "Flash.h" //Toroko void ActNpc060(NPCHAR *npc) @@ -481,6 +484,142 @@ void ActNpc062(NPCHAR *npc) npc->rect = rcLeft[npc->ani_no]; } +//Toroko with stick +void ActNpc063(NPCHAR *npc) +{ + RECT rcLeft[8]; + RECT rcRight[6]; + + rcLeft[0] = {64, 64, 80, 80}; + rcLeft[1] = {80, 64, 96, 80}; + rcLeft[2] = {64, 64, 80, 80}; + rcLeft[3] = {96, 64, 112, 80}; + rcLeft[4] = {112, 64, 128, 80}; + rcLeft[5] = {128, 64, 144, 80}; + + rcRight[0] = {64, 80, 80, 96}; + rcRight[1] = {80, 80, 96, 96}; + rcRight[2] = {64, 80, 80, 96}; + rcRight[3] = {96, 80, 112, 96}; + rcRight[4] = {112, 80, 128, 96}; + rcRight[5] = {128, 80, 144, 96}; + + switch (npc->act_no) + { + case 0: + npc->act_no = 1; + npc->act_wait = 0; + npc->ani_wait = 0; + npc->ym = -0x400; + // Fallthrough + case 1: + if (npc->ym > 0) + npc->bits &= ~8; + + if (++npc->ani_wait > 2) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 3) + npc->ani_no = 0; + + if (npc->direct == 0) + npc->xm = -0x100; + else + npc->xm = 0x100; + + if (npc->act_wait++ && npc->flag & 8) + npc->act_no = 2; + + break; + + case 2: + npc->act_no = 3; + npc->act_wait = 0; + npc->ani_no = 0; + npc->ani_wait = 0; + // Fallthrough + case 3: + if (++npc->ani_wait > 2) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 3) + npc->ani_no = 0; + + if (++npc->act_wait > 50) + { + npc->act_wait = 40; + npc->xm = -npc->xm; + + if (npc->direct == 0) + npc->direct = 2; + else + npc->direct = 0; + } + + if (npc->act_wait > 35) + npc->bits |= 0x20; + + if (npc->direct == 0) + npc->xm -= 0x40; + else + npc->xm += 0x40; + + if (npc->shock) + { + npc->act_no = 4; + npc->ani_no = 4; + npc->ym = -0x400; + npc->bits &= ~0x20; + npc->damage = 0; + } + + break; + + case 4: + if (npc->direct == 0) + npc->xm = -0x100; + else + npc->xm = 0x100; + + if (npc->act_wait++ && npc->flag & 8) + { + npc->act_no = 5; + npc->bits |= 0x2000; + } + + break; + + case 5: + npc->xm = 0; + npc->ani_no = 5; + break; + } + + npc->ym += 0x40; + + if (npc->xm > 0x400) + npc->xm = 0x400; + if (npc->xm < -0x400) + npc->xm = -0x400; + + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + npc->x += npc->xm; + npc->y += npc->ym; + + if (npc->direct == 0) + npc->rect = rcLeft[npc->ani_no]; + else + npc->rect = rcRight[npc->ani_no]; +} + //First Cave Critter void ActNpc064(NPCHAR *npc) { @@ -660,6 +799,475 @@ void ActNpc065(NPCHAR *npc) npc->rect = rect_right[npc->ani_no]; } +//Misery bubble +void ActNpc066(NPCHAR *npc) +{ + RECT rect[4]; + + rect[0] = {32, 192, 56, 216}; + rect[1] = {56, 192, 80, 216}; + rect[2] = {32, 216, 56, 240}; + rect[3] = {56, 216, 80, 240}; + + switch (npc->act_no) + { + case 0: + for (int a = 0; a < 0x200; ++a) + { + if (gNPC[a].code_event == 1000) + { + npc->tgt_x = gNPC[a].x; + npc->tgt_y = gNPC[a].y; + npc->count1 = a; + unsigned char deg = GetArktan(npc->x - npc->tgt_x, npc->y - npc->tgt_y); + npc->xm = 2 * GetCos(deg); + npc->ym = 2 * GetSin(deg); + npc->act_no = 1; + break; + } + } + // Fallthrough + case 1: + if (++npc->ani_wait > 1) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 1) + npc->ani_no = 0; + + if (npc->tgt_x > npc->x - 0x600 && npc->tgt_x < npc->x + 0x600 && npc->tgt_y > npc->y - 0x600 && npc->tgt_y < npc->y + 0x600) + { + npc->act_no = 2; + npc->ani_no = 2; + gNPC[npc->count1].cond = 0; + PlaySoundObject(21, 1); + } + + break; + + case 2: + npc->xm -= 0x20; + npc->ym -= 0x20; + + if (npc->xm < -0x5FF) + npc->xm = -0x5FF; + if (npc->ym < -0x5FF) + npc->ym = -0x5FF; + + if (npc->y < -0x1000) + npc->cond = 0; + + if (++npc->ani_wait > 3) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 3) + npc->ani_no = 2; + + break; + } + + npc->x += npc->xm; + npc->y += npc->ym; + + npc->rect = rect[npc->ani_no]; +} + +//Misery (floating) +void ActNpc067(NPCHAR *npc) +{ + switch (npc->act_no) + { + case 0: + npc->act_no = 1; + npc->tgt_x = npc->x; + npc->tgt_y = npc->y; + npc->ani_no = 0; + PlaySoundObject(29, 1); + // Fallthrough + case 1: + npc->x = npc->tgt_x + (Random(-1, 1) * 0x200); + + if (++npc->act_wait == 0x20) + npc->act_no = 10; + + break; + + case 10: + npc->act_no = 11; + npc->act_wait = 0; + npc->ani_no = 0; + npc->ym = 0x200; + // Fallthrough + + case 11: + if (npc->tgt_y < npc->y) + npc->ym -= 0x10; + if (npc->tgt_y > npc->y) + npc->ym += 0x10; + + if (npc->ym > 0x100) + npc->ym = 0x100; + if (npc->ym < -0x100) + npc->ym = -0x100; + + break; + + case 13: + npc->ani_no = 1; + + npc->ym += 0x40; + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + if (npc->flag & 8) + { + PlaySoundObject(23, 1); + npc->ym = 0; + npc->act_no = 14; + npc->bits |= 8; + npc->ani_no = 2; + } + + break; + + case 15: + npc->act_no = 16; + npc->act_wait = 0; + npc->ani_no = 4; + // Fallthrough + case 16: + if (++npc->act_wait == 30) + { + PlaySoundObject(21, 1); + SetNpChar(66, npc->x, npc->y - 0x2000, 0, 0, 0, npc, 0); + } + + if (npc->act_wait == 50) + npc->act_no = 14; + + break; + + case 20: + npc->act_no = 21; + npc->ani_no = 0; + npc->ym = 0; + npc->bits |= 8; + // Fallthrough + case 21: + npc->ym -= 0x20; + + if (npc->y < -0x1000) + npc->cond = 0; + + break; + + case 25: + npc->act_no = 26; + npc->act_wait = 0; + npc->ani_no = 5; + npc->ani_wait = 0; + // Fallthrough + case 26: + if (++npc->ani_no > 7) + npc->ani_no = 5; + + if (++npc->act_wait == 30) + { + PlaySoundObject(101, 1); + SetFlash(0, 0, 2); + npc->act_no = 27; + npc->ani_no = 7; + } + + break; + + case 27: + if (++npc->act_wait == 50) + npc->act_no = 14; + + break; + } + + npc->x += npc->xm; + npc->y += npc->ym; + + RECT rcLeft[8]; + RECT rcRight[8]; + + rcLeft[0] = {80, 0, 96, 16}; + rcLeft[1] = {96, 0, 112, 16}; + rcLeft[2] = {112, 0, 128, 16}; + rcLeft[3] = {128, 0, 144, 16}; + rcLeft[4] = {144, 0, 160, 16}; + rcLeft[5] = {160, 0, 176, 16}; + rcLeft[6] = {176, 0, 192, 16}; + rcLeft[7] = {144, 0, 160, 16}; + + rcRight[0] = {80, 16, 96, 32}; + rcRight[1] = {96, 16, 112, 32}; + rcRight[2] = {112, 16, 128, 32}; + rcRight[3] = {128, 16, 144, 32}; + rcRight[4] = {144, 16, 160, 32}; + rcRight[5] = {160, 16, 176, 32}; + rcRight[6] = {176, 16, 192, 32}; + rcRight[7] = {144, 16, 160, 32}; + + if (npc->act_no == 11) + { + if (npc->ani_wait) + { + --npc->ani_wait; + npc->ani_no = 1; + } + else + { + if (Random(0, 100) == 1) + npc->ani_wait = 30; + + npc->ani_no = 0; + } + } + + if (npc->act_no == 14) + { + if (npc->ani_wait) + { + --npc->ani_wait; + npc->ani_no = 3; + } + else + { + if (Random(0, 100) == 1) + npc->ani_wait = 30; + + npc->ani_no = 2; + } + } + + if (npc->direct == 0) + npc->rect = rcLeft[npc->ani_no]; + else + npc->rect = rcRight[npc->ani_no]; + + if (npc->act_no == 1 && npc->ani_wait < 32) + npc->rect.bottom = ++npc->ani_wait / 2 + npc->rect.bottom - 16; +} + +//Balrog (running) +void ActNpc068(NPCHAR *npc) +{ + switch (npc->act_no) + { + case 0: + npc->act_no = 1; + npc->ani_no = 0; + npc->act_wait = 30; + + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + // Fallthrough + case 1: + if (--npc->act_wait == 0) + { + npc->act_no = 2; + ++npc->count1; + } + + break; + + case 2: + npc->act_no = 3; + npc->act_wait = 0; + npc->ani_no = 1; + npc->ani_wait = 0; + // Fallthrough + case 3: + if (++npc->ani_wait > 3) + { + npc->ani_wait = 0; + + if (++npc->ani_no == 2 || npc->ani_no == 4) + PlaySoundObject(23, 1); + } + + if (npc->ani_no > 4) + npc->ani_no = 1; + + if (npc->direct == 0) + npc->xm -= 0x10; + else + npc->xm += 0x10; + + if (npc->act_wait >= 8 && gMC.x > npc->x - 0x1800 && gMC.x < npc->x + 0x1800 && gMC.y > npc->y - 0x1800 && gMC.y < npc->y + 0x1000) + { + npc->act_no = 10; + npc->ani_no = 5; + gMC.cond |= 2; + DamageMyChar(2); + } + else + { + ++npc->act_wait; + + if (npc->flag & 5 || npc->act_wait > 75) + { + npc->act_no = 9; + npc->ani_no = 0; + } + else if ((npc->count1 % 3) == 0 && npc->act_wait > 25) + { + npc->act_no = 4; + npc->ani_no = 7; + npc->ym = -0x400; + } + } + + break; + + case 4: + if (npc->flag & 8) + { + npc->act_no = 9; + npc->ani_no = 8; + SetQuake(30); + PlaySoundObject(26, 1); + } + + if (npc->act_wait >= 8 && gMC.x > npc->x - 0x1800 && gMC.x < npc->x + 0x1800 && gMC.y > npc->y - 0x1800 && gMC.y < npc->y + 0x1000) + { + npc->act_no = 10; + npc->ani_no = 5; + gMC.cond |= 2; + DamageMyChar(2); + } + + break; + + case 9: + npc->xm = 4 * npc->xm / 5; + + if (npc->xm == 0) + npc->act_no = 0; + + break; + + case 10: + gMC.x = npc->x; + gMC.y = npc->y; + + npc->xm = 4 * npc->xm / 5; + + if (npc->xm == 0) + { + npc->act_no = 11; + npc->act_wait = 0; + npc->ani_no = 5; + npc->ani_wait = 0; + } + + break; + + case 11: + gMC.x = npc->x; + gMC.y = npc->y; + + if (++npc->ani_wait > 2) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 6) + npc->ani_no = 5; + + if (++npc->act_wait > 100) + npc->act_no = 20; + + break; + + case 20: + PlaySoundObject(25, 1); + gMC.cond &= ~2; + + if (npc->direct == 0) + { + gMC.x += 0x800; + gMC.y -= 0x1000; + gMC.xm = 0x5FF; + gMC.ym = -0x200u; + gMC.direct = 2; + npc->direct = 2; + } + else + { + gMC.x -= 0x800; + gMC.y -= 0x1000; + gMC.xm = -0x5FFu; + gMC.ym = -0x200u; + gMC.direct = 0; + npc->direct = 0; + } + + npc->act_no = 21; + npc->act_wait = 0; + npc->ani_no = 7; + // Fallthrough + case 21: + if (++npc->act_wait >= 50) + npc->act_no = 0; + + break; + } + + npc->ym += 0x20; + + if (npc->xm < -0x400) + npc->xm = -0x400; + if (npc->xm > 0x400) + npc->xm = 0x400; + + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + npc->x += npc->xm; + npc->y += npc->ym; + + RECT rect_left[9]; + RECT rect_right[9]; + + rect_left[0] = {0, 0, 40, 24}; + rect_left[1] = {0, 48, 40, 72}; + rect_left[2] = {0, 0, 40, 24}; + rect_left[3] = {40, 48, 80, 72}; + rect_left[4] = {0, 0, 40, 24}; + rect_left[5] = {80, 48, 120, 72}; + rect_left[6] = {120, 48, 160, 72}; + rect_left[7] = {120, 0, 160, 24}; + rect_left[8] = {80, 0, 120, 24}; + + rect_right[0] = {0, 24, 40, 48}; + rect_right[1] = {0, 72, 40, 96}; + rect_right[2] = {0, 24, 40, 48}; + rect_right[3] = {40, 72, 80, 96}; + rect_right[4] = {0, 24, 40, 48}; + rect_right[5] = {80, 72, 120, 96}; + rect_right[6] = {120, 72, 160, 96}; + rect_right[7] = {120, 24, 160, 48}; + rect_right[8] = {80, 24, 120, 48}; + + if (npc->direct == 0) + npc->rect = rect_left[npc->ani_no]; + else + npc->rect = rect_right[npc->ani_no]; +} + //Sparkle void ActNpc069(NPCHAR *npc) { diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 0b79d230..18807c2e 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -75,7 +75,7 @@ NPCFUNCTION gpNpcFuncTbl[361] = ActNpc016, ActNpc017, ActNpc018, - nullptr, + ActNpc019, ActNpc020, ActNpc021, ActNpc022, @@ -97,7 +97,7 @@ NPCFUNCTION gpNpcFuncTbl[361] = ActNpc038, ActNpc039, nullptr, - nullptr, + ActNpc041, ActNpc042, ActNpc043, nullptr, @@ -119,12 +119,12 @@ NPCFUNCTION gpNpcFuncTbl[361] = ActNpc060, ActNpc061, ActNpc062, - nullptr, + ActNpc063, ActNpc064, ActNpc065, - nullptr, - nullptr, - nullptr, + ActNpc066, + ActNpc067, + ActNpc068, ActNpc069, ActNpc070, ActNpc071, diff --git a/src/Stage.cpp b/src/Stage.cpp index 7a46970c..e595c4c6 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -18,6 +18,7 @@ #include "ValueView.h" #include "Back.h" #include "Stage.h" +#include "Flash.h" #ifdef JAPANESE #define STAGE_ENTRY(parts, map, bkType, back, npc, boss, boss_no, name_en, name_jp) {parts, map, bkType, back, npc, boss, boss_no, name_jp} @@ -195,7 +196,7 @@ bool TransferStage(int no, int w, int x, int y) ClearValueView(); ResetQuake(); //InitBossChar(gTMT[no].boss_no); - //ResetFlash(); + ResetFlash(); gStageNo = no; return true; } From 5c8f80e611662ffe1bb98819a8bac1060af3c13d Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 31 Jan 2019 14:36:54 +0000 Subject: [PATCH 2/3] Added some TSC commands and BossLife.cpp --- Makefile | 1 + src/BossLife.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ src/BossLife.h | 6 ++++ src/Game.cpp | 7 ++-- src/Profile.cpp | 5 +-- src/TextScr.cpp | 43 +++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 src/BossLife.cpp create mode 100644 src/BossLife.h diff --git a/Makefile b/Makefile index ba9fac12..4e6b2edc 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ endif SOURCES = \ ArmsItem \ Back \ + BossLife \ BulHit \ Bullet \ Caret \ diff --git a/src/BossLife.cpp b/src/BossLife.cpp new file mode 100644 index 00000000..bfd51765 --- /dev/null +++ b/src/BossLife.cpp @@ -0,0 +1,84 @@ +#include "BossLife.h" + +#include "Draw.h" +#include "NpChar.h" +#include "WindowsWrapper.h" + +static struct +{ + bool flag; + int *pLife; + int max; + int br; + int count; +} gBL; + +void InitBossLife(void) +{ + gBL.flag = false; +} + +bool StartBossLife(int code_event) +{ + for (int i = 0; i < 0x200; ++i) + { + if (gNPC[i].code_event == code_event) + { + gBL.flag = true; + gBL.max = gNPC[i].life; + gBL.br = gNPC[i].life; + gBL.pLife = &gNPC[i].life; + return true; + } + } + + return false; +} + +bool StartBossLife2(void) +{ + // TODO uncomment me when Boss.cpp is done! +// gBL.flag = true; +// gBL.max = gBoss[0].life; +// gBL.br = gBoss[0].life; +// gBL.pLife = &gBoss[0].life; + return true; +} + +void PutBossLife(void) +{ + RECT rcText = {0, 48, 32, 56}; + RECT rcBox1 = {0, 0, 244, 8}; + RECT rcBox2 = {0, 16, 244, 24}; + RECT rcLife = {0, 24, 0, 32}; + RECT rcBr = {0, 32, 232, 40}; + + if (gBL.flag) + { + if (*gBL.pLife >= 1) + { + rcLife.right = 198 * *gBL.pLife / gBL.max; + + if (gBL.br <= *gBL.pLife) + { + gBL.count = 0; + } + else if (++gBL.count > 30) + { + --gBL.br; + } + + rcBr.right = 198 * gBL.br / gBL.max; + + PutBitmap3(&grcGame, 32, 220, &rcBox1, SURFACE_ID_TEXT_BOX); + PutBitmap3(&grcGame, 32, 228, &rcBox2, SURFACE_ID_TEXT_BOX); + PutBitmap3(&grcGame, 72, 224, &rcBr, SURFACE_ID_TEXT_BOX); + PutBitmap3(&grcGame, 72, 224, &rcLife, SURFACE_ID_TEXT_BOX); + PutBitmap3(&grcGame, 40, 224, &rcText, SURFACE_ID_TEXT_BOX); + } + else + { + gBL.flag = false; + } + } +} diff --git a/src/BossLife.h b/src/BossLife.h new file mode 100644 index 00000000..77d4404f --- /dev/null +++ b/src/BossLife.h @@ -0,0 +1,6 @@ +#pragma once + +void InitBossLife(void); +bool StartBossLife(int code_event); +bool StartBossLife2(void); +void PutBossLife(void); diff --git a/src/Game.cpp b/src/Game.cpp index 8421acb3..1b117843 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -37,6 +37,7 @@ #include "Draw.h" #include "Ending.h" #include "Flash.h" +#include "BossLife.h" int g_GameFlags; int gCounter; @@ -103,7 +104,7 @@ int ModeOpening() //InitStar(); InitFade(); InitFlash(); - //InitBossLife(); + InitBossLife(); ChangeMusic(0); TransferStage(72, 100, 3, 3); SetFrameTargetMyChar(16); @@ -441,7 +442,7 @@ int ModeAction() //ClearPermitStage(); //StartMapping(); InitFlags(); - //InitBossLife(); + InitBossLife(); if ((bContinue && LoadProfile(NULL)) || InitializeGame()) { @@ -517,7 +518,7 @@ int ModeAction() PutFlash(); PutCaret(frame_x, frame_y); PutValueView(frame_x, frame_y); - //PutBossLife(); + PutBossLife(); PutFade(); if (!(g_GameFlags & 4)) diff --git a/src/Profile.cpp b/src/Profile.cpp index d9465a35..e2a7d63e 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -14,6 +14,7 @@ #include "ValueView.h" #include "Stage.h" #include "Game.h" +#include "BossLife.h" const char *gDefaultName = "Profile.dat"; const char *gProfileCode = "Do041220"; @@ -130,7 +131,7 @@ bool LoadProfile(char *name) ClearFade(); SetFrameMyChar(); SetFrameTargetMyChar(16); - //InitBossLife(); + InitBossLife(); CutNoise(); //InitStar(); ClearValueView(); @@ -154,7 +155,7 @@ bool InitializeGame() ClearFade(); SetFrameMyChar(); SetFrameTargetMyChar(16); - //InitBossLife(); + InitBossLife(); CutNoise(); ClearValueView(); //gCurlyShoot_wait = 0; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index c1353781..a4843b0d 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -21,6 +21,8 @@ #include "Sound.h" #include "Organya.h" #include "Game.h" +#include "Map.h" +#include "BossLife.h" #define IS_COMMAND(c1, c2, c3) gTS.data[gTS.p_read + 1] == c1 && gTS.data[gTS.p_read + 2] == c2 && gTS.data[gTS.p_read + 3] == c3 @@ -840,6 +842,16 @@ int TextScriptProc() else gTS.p_read += 13; } + else if (IS_COMMAND('I','T','J')) + { + x = GetTextScriptNo(gTS.p_read + 4); + z = GetTextScriptNo(gTS.p_read + 9); + + if (CheckItem(x)) + JumpTextScript(z); + else + gTS.p_read += 13; + } else if (IS_COMMAND('S','S','S')) { x = GetTextScriptNo(gTS.p_read + 4); @@ -968,6 +980,37 @@ int TextScriptProc() SetNpChar(w, x << 13, y << 13, 0, 0, z, 0, 0x100); gTS.p_read += 23; } + else if (IS_COMMAND('C','M','P')) + { + x = GetTextScriptNo(gTS.p_read + 4); + y = GetTextScriptNo(gTS.p_read + 9); + z = GetTextScriptNo(gTS.p_read + 14); + ChangeMapParts(x, y, z); + gTS.p_read += 18; + } + else if (IS_COMMAND('B','S','L')) + { + z = GetTextScriptNo(gTS.p_read + 4); + + if (z) + StartBossLife(z); + else + StartBossLife2(); + + gTS.p_read += 8; + } + else if (IS_COMMAND('M','Y','D')) + { + z = GetTextScriptNo(gTS.p_read + 4); + SetMyCharDirect(z); + gTS.p_read += 8; + } + else if (IS_COMMAND('M','Y','B')) + { + z = GetTextScriptNo(gTS.p_read + 4); + BackStepMyChar(z); + gTS.p_read += 8; + } else if (IS_COMMAND('M','N','P')) { w = GetTextScriptNo(gTS.p_read + 4); From 28dfac081bfccb856fc836fb21a26373d20b047e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 31 Jan 2019 15:29:19 +0000 Subject: [PATCH 3/3] More NPCs --- src/NpcAct.h | 2 + src/NpcAct000.cpp | 329 ++++++++++++++++++++++++++++++++++++++++++++++ src/NpcAct340.cpp | 47 +++++++ src/NpcTbl.cpp | 2 +- 4 files changed, 379 insertions(+), 1 deletion(-) diff --git a/src/NpcAct.h b/src/NpcAct.h index 2be21639..790ac809 100644 --- a/src/NpcAct.h +++ b/src/NpcAct.h @@ -91,4 +91,6 @@ void ActNpc298(NPCHAR *npc); void ActNpc299(NPCHAR *npc); void ActNpc300(NPCHAR *npc); +void ActNpc355(NPCHAR *npc); + void ActNpc359(NPCHAR *npc); diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 1cc579e9..c1b0873c 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -9,6 +9,7 @@ #include "Back.h" #include "Triangle.h" #include "Frame.h" +#include "Map.h" //Null void ActNpc000(NPCHAR *npc) @@ -803,6 +804,334 @@ void ActNpc008(NPCHAR *npc) npc->rect = rcRight[npc->ani_no]; } +//Balrog (cutscene) +void ActNpc012(NPCHAR *npc) +{ + switch (npc->act_no) + { + case 0: + if (npc->direct == 4) + { + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + } + + npc->act_no = 1; + npc->ani_no = 0; + // Fallthrough + case 1: + if (Random(0, 100) == 0) + { + npc->act_no = 2; + npc->act_wait = 0; + npc->ani_no = 1; + } + + break; + + case 2: + if (++npc->act_wait > 16) + { + npc->act_no = 1; + npc->ani_no = 0; + } + + break; + + case 10: + if (npc->direct == 4) + { + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + } + + npc->act_no = 11; + npc->ani_no = 2; + npc->act_wait = 0; + npc->tgt_x = 0; + // Fallthrough + case 11: + if (++npc->act_wait > 30) + { + npc->act_no = 12; + npc->act_wait = 0; + npc->ani_no = 3; + npc->ym = -0x800; + npc->bits |= 8; + } + + break; + + case 12: + if (npc->flag & 5) + npc->xm = 0; + + if (npc->y < 0) + { + npc->code_char = 0; + PlaySoundObject(26, 1); + SetQuake(30); + } + + break; + + case 20: + if (npc->direct == 4) + { + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + } + + npc->act_no = 21; + npc->ani_no = 5; + npc->act_wait = 0; + npc->count1 = 0; + + for (int i = 0; i < 4; ++i) + SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100); + + PlaySoundObject(72, 1); + // Fallthrough + case 21: + npc->tgt_x = 1; + + if (npc->flag & 8) + ++npc->act_wait; + + if (++npc->count1 / 2 % 2) + npc->x += 0x200; + else + npc->x -= 0x200; + + if (npc->act_wait > 100) + { + npc->act_no = 11; + npc->act_wait = 0; + npc->ani_no = 2; + } + + npc->ym += 0x20; + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + break; + + case 30: + npc->ani_no = 4; + + if (++npc->act_wait > 100) + { + npc->act_no = 0; + npc->ani_no = 0; + } + + break; + + case 40: + if (npc->direct == 4) + { + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + } + + npc->act_no = 41; + npc->act_wait = 0; + npc->ani_no = 5; + // Fallthrough + case 41: + if (++npc->ani_wait / 2 % 2) + npc->ani_no = 5; + else + npc->ani_no = 6; + + break; + + case 42: + if (npc->direct == 4) + { + if (gMC.x < npc->x) + npc->direct = 0; + else + npc->direct = 2; + } + + npc->act_no = 43; + npc->act_wait = 0; + npc->ani_no = 6; + // Fallthrough + case 43: + if (++npc->ani_wait / 2 % 2) + npc->ani_no = 7; + else + npc->ani_no = 6; + + break; + + case 50: + npc->ani_no = 8; + npc->xm = 0; + break; + + case 60: + npc->act_no = 61; + npc->ani_no = 9; + npc->ani_wait = 0; + // Fallthrough + case 61: + if (++npc->ani_wait > 3) + { + npc->ani_wait = 0; + + if (++npc->ani_no == 10 || npc->ani_no == 11) + PlaySoundObject(23, 1); + } + + if (npc->ani_no > 12) + npc->ani_no = 9; + + if (npc->direct == 0) + npc->xm = -0x200; + else + npc->xm = 0x200; + + break; + + case 70: + npc->act_no = 71; + npc->act_wait = 64; + PlaySoundObject(29, 1); + npc->ani_no = 13; + // Fallthrough + case 71: + if (--npc->act_wait == 0) + npc->cond = 0; + + break; + + case 80: + npc->count1 = 0; + npc->act_no = 81; + // Fallthrough + case 81: + if (++npc->count1 / 2 % 2) + npc->x += 0x200; + else + npc->x -= 0x200; + + npc->ani_no = 5; + npc->xm = 0; + npc->ym += 0x20; + + break; + + case 100: + npc->act_no = 101; + npc->act_wait = 0; + npc->ani_no = 2; + // Fallthrough + case 101: + if (++npc->act_wait > 20) + { + npc->act_no = 102; + npc->act_wait = 0; + npc->ani_no = 3; + npc->ym = -0x800; + npc->bits |= 8; + DeleteNpCharCode(150, 0); + DeleteNpCharCode(117, 0); + SetNpChar(355, 0, 0, 0, 0, 0, npc, 0x100); + SetNpChar(355, 0, 0, 0, 0, 1, npc, 0x100); + } + + break; + + case 102: + { + int x = npc->x / 0x200 / 0x10; + int y = npc->y / 0x200 / 0x10; + + if (y >= 0 && y < 35 && ChangeMapParts(x, y, 0)) + { + ChangeMapParts(x - 1, y, 0); + ChangeMapParts(x + 1, y, 0); + PlaySoundObject(44, 1); + SetQuake2(10); + } + + if (npc->y < -0x4000) + { + npc->code_char = 0; + SetQuake(30); + } + + break; + } + } + + if (npc->tgt_x && Random(0, 10) == 0) + SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100); + + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + npc->x += npc->xm; + npc->y += npc->ym; + + RECT rect_left[14]; + RECT rect_right[14]; + + rect_left[0] = {0, 0, 40, 24}; + rect_left[1] = {160, 0, 200, 24}; + rect_left[2] = {80, 0, 120, 24}; + rect_left[3] = {120, 0, 160, 24}; + rect_left[4] = {240, 0, 280, 24}; + rect_left[5] = {200, 0, 240, 24}; + rect_left[6] = {280, 0, 320, 24}; + rect_left[7] = {0, 0, 0, 0}; + rect_left[8] = {80, 48, 120, 72}; + rect_left[9] = {0, 48, 40, 72}; + rect_left[10] = {0, 0, 40, 24}; + rect_left[11] = {40, 48, 80, 72}; + rect_left[12] = {0, 0, 40, 24}; + rect_left[13] = {280, 0, 320, 24}; + + rect_right[0] = {0, 24, 40, 48}; + rect_right[1] = {160, 24, 200, 48}; + rect_right[2] = {80, 24, 120, 48}; + rect_right[3] = {120, 24, 160, 48}; + rect_right[4] = {240, 24, 280, 48}; + rect_right[5] = {200, 24, 240, 48}; + rect_right[6] = {280, 24, 320, 48}; + rect_right[7] = {0, 0, 0, 0}; + rect_right[8] = {80, 72, 120, 96}; + rect_right[9] = {0, 72, 40, 96}; + rect_right[10] = {0, 24, 40, 48}; + rect_right[11] = {40, 72, 80, 96}; + rect_right[12] = {0, 24, 40, 48}; + rect_right[13] = {280, 24, 320, 48}; + + if (npc->direct == 0) + npc->rect = rect_left[npc->ani_no]; + else + npc->rect = rect_right[npc->ani_no]; + + if (npc->act_no == 71) + { + npc->rect.bottom = npc->rect.top + npc->act_wait / 2; + + if (npc->act_wait % 2) + ++npc->rect.left; + } +} + //Chest (closed) void ActNpc015(NPCHAR *npc) { diff --git a/src/NpcAct340.cpp b/src/NpcAct340.cpp index c608752b..f8b56294 100644 --- a/src/NpcAct340.cpp +++ b/src/NpcAct340.cpp @@ -10,6 +10,53 @@ #include "Back.h" #include "Triangle.h" +//Quote and Curly on Balrog's back +void ActNpc355(NPCHAR *npc) +{ + RECT rc[4]; + + rc[0] = {80, 16, 96, 32}; + rc[1] = {80, 96, 96, 112}; + rc[2] = {128, 16, 144, 32}; + rc[3] = {208, 96, 224, 112}; + + if (npc->act_no == 0) + { + switch (npc->direct) + { + case 0: + npc->surf = 16; + npc->ani_no = 0; + npc->x = npc->pNpc->x - 0x1C00; + npc->y = npc->pNpc->y + 0x1400; + break; + + case 1: + npc->surf = 23; + npc->ani_no = 1; + npc->x = npc->pNpc->x + 0x1C00; + npc->y = npc->pNpc->y + 0x1400; + break; + + case 2: + npc->surf = 16; + npc->ani_no = 2; + npc->x = npc->pNpc->x - 0xE00; + npc->y = npc->pNpc->y - 0x2600; + break; + + case 3: + npc->surf = 23; + npc->ani_no = 3; + npc->x = npc->pNpc->x + 0x800; + npc->y = npc->pNpc->y - 0x2600; + break; + } + } + + npc->rect = rc[npc->ani_no]; +} + //Water droplet generator void ActNpc359(NPCHAR *npc) { diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 18807c2e..17f77b4b 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -411,7 +411,7 @@ NPCFUNCTION gpNpcFuncTbl[361] = nullptr, nullptr, nullptr, - nullptr, + ActNpc355, nullptr, nullptr, nullptr,