From 0f87d1ee8f5baf42e36fb2b4e26d8780fd79a9ee Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 28 Jan 2019 10:14:32 +0000 Subject: [PATCH] Added bunch of First Cave objects --- Makefile | 2 + src/NpcAct.h | 9 +++ src/NpcAct000.cpp | 2 + src/NpcAct020.cpp | 29 +++++++ src/NpcAct060.cpp | 191 ++++++++++++++++++++++++++++++++++++++++++++++ src/NpcAct200.cpp | 24 ++++++ src/NpcTbl.cpp | 8 +- 7 files changed, 261 insertions(+), 4 deletions(-) create mode 100644 src/NpcAct060.cpp create mode 100644 src/NpcAct200.cpp diff --git a/Makefile b/Makefile index 34111235..1a196823 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,8 @@ SOURCES = \ MycParam \ NpcAct000 \ NpcAct020 \ + NpcAct060 \ + NpcAct200 \ NpChar \ NpcHit \ NpcTbl \ diff --git a/src/NpcAct.h b/src/NpcAct.h index aee50daa..c0c4277f 100644 --- a/src/NpcAct.h +++ b/src/NpcAct.h @@ -1,4 +1,7 @@ +#pragma once + #include "NpChar.h" + void ActNpc000(NPCHAR *npc); void ActNpc001(NPCHAR *npc); void ActNpc002(NPCHAR *npc); @@ -12,6 +15,12 @@ void ActNpc016(NPCHAR *npc); void ActNpc017(NPCHAR *npc); void ActNpc018(NPCHAR *npc); +void ActNpc020(NPCHAR *npc); void ActNpc021(NPCHAR *npc); void ActNpc032(NPCHAR *npc); + +void ActNpc064(NPCHAR *npc); +void ActNpc065(NPCHAR *npc); + +void ActNpc211(NPCHAR *npc); diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 260d541c..9a956ab2 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -1,5 +1,7 @@ #include "WindowsWrapper.h" +#include "NpcAct.h" + #include "MyChar.h" #include "NpChar.h" #include "Game.h" diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp index 4075ba9d..b5439ff2 100644 --- a/src/NpcAct020.cpp +++ b/src/NpcAct020.cpp @@ -1,5 +1,7 @@ #include "WindowsWrapper.h" +#include "NpcAct.h" + #include "MyChar.h" #include "NpChar.h" #include "Game.h" @@ -7,6 +9,33 @@ #include "Back.h" #include "Triangle.h" +//Computer +void ActNpc020(NPCHAR *npc) +{ + RECT rcLeft[1]; + RECT rcRight[3]; + + rcLeft[0] = {288, 16, 320, 40}; + + rcRight[0] = {288, 40, 320, 64}; + rcRight[1] = {288, 40, 320, 64}; + rcRight[2] = {288, 64, 320, 88}; + + if (++npc->ani_wait > 3) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 2) + npc->ani_no = 0; + + if (npc->direct == 0) + npc->rect = rcLeft[0]; + else + npc->rect = rcRight[npc->ani_no]; +} + //Chest (open) void ActNpc021(NPCHAR *npc) { diff --git a/src/NpcAct060.cpp b/src/NpcAct060.cpp new file mode 100644 index 00000000..2f0d9426 --- /dev/null +++ b/src/NpcAct060.cpp @@ -0,0 +1,191 @@ +#include "WindowsWrapper.h" + +#include "NpcAct.h" + +#include "MyChar.h" +#include "NpChar.h" +#include "Game.h" +#include "Sound.h" +#include "Back.h" +#include "Triangle.h" + +//First Cave Critter +void ActNpc064(NPCHAR *npc) +{ + RECT rcLeft[3]; + RECT rcRight[3]; + + rcLeft[0] = {0, 0, 16, 16}; + rcLeft[1] = {16, 0, 32, 16}; + rcLeft[2] = {32, 0, 48, 16}; + + rcRight[0] = {0, 16, 16, 32}; + rcRight[1] = {16, 16, 32, 32}; + rcRight[2] = {32, 16, 48, 32}; + + switch (npc->act_no) + { + case 0: //Init + npc->y += 0x600; + npc->act_no = 1; + + case 1: //Waiting + //Look at player + if (npc->x <= gMC.x) + npc->direct = 2; + else + npc->direct = 0; + + if (npc->tgt_x < 100) + ++npc->tgt_x; + + //Open eyes near player + if (npc->act_wait < 8 || npc->x - 0xE000 >= gMC.x || npc->x + 0xE000 <= gMC.x || npc->y - 0xA000 >= gMC.y || npc->y + 0xA000 <= gMC.y) + { + if (npc->act_wait < 8) + ++npc->act_wait; + npc->ani_no = 0; + } + else + { + npc->ani_no = 1; + } + + //Jump if attacked + if (npc->shock) + { + npc->act_no = 2; + npc->ani_no = 0; + npc->act_wait = 0; + } + + //Jump if player is nearby + if (npc->act_wait >= 8 && npc->tgt_x >= 100 && npc->x - 0x8000 < gMC.x && npc->x + 0x8000 > gMC.x && npc->y - 0xA000 < gMC.y && npc->y + 0x6000 > gMC.y) + { + npc->act_no = 2; + npc->ani_no = 0; + npc->act_wait = 0; + } + break; + + case 2: //Going to jump + if (++npc->act_wait > 8) + { + //Set jump state + npc->act_no = 3; + npc->ani_no = 2; + + //Jump + npc->ym = -0x5FF; + PlaySoundObject(30, 1); + + //Jump in facing direction + if (npc->direct) + npc->xm = 0x100; + else + npc->xm = -0x100; + } + break; + + case 3: //Jumping + //Land + if (npc->flag & 8) + { + npc->xm = 0; + npc->act_wait = 0; + npc->ani_no = 0; + npc->act_no = 1; + PlaySoundObject(23, 1); + } + break; + } + + //Gravity + npc->ym += 0x40; + if (npc->ym > 0x5FF) + npc->ym = 0x5FF; + + //Move + npc->x += npc->xm; + npc->y += npc->ym; + + //Set framerect + if (npc->direct == 0) + npc->rect = rcLeft[npc->ani_no]; + else + npc->rect = rcRight[npc->ani_no]; +} + + +//First Cave Bat +void ActNpc065(NPCHAR *npc) +{ + switch (npc->act_no) + { + case 0: + npc->tgt_x = npc->x; + npc->tgt_y = npc->y; + npc->count1 = 120; + npc->act_no = 1; + npc->act_wait = Random(0, 50); + // Fallthrough + + case 1: + if (++npc->act_wait >= 50) + { + npc->act_wait = 0; + npc->act_no = 2; + npc->ym = 0x300; + } + + break; + + case 2: + if (gMC.x >= npc->x) + npc->direct = 2; + else + npc->direct = 0; + + if (npc->tgt_y < npc->y) + npc->ym -= 0x10; + if (npc->tgt_y > npc->y) + npc->ym += 0x10; + if (npc->ym > 0x300) + npc->ym = 0x300; + if (npc->ym < -0x300) + npc->ym = -0x300; + + break; + } + + npc->x += npc->xm; + npc->y += npc->ym; + + RECT rect_left[4]; + RECT rect_right[4]; + + rect_left[0] = {32, 32, 48, 48}; + rect_left[1] = {48, 32, 64, 48}; + rect_left[2] = {64, 32, 80, 48}; + rect_left[3] = {80, 32, 96, 48}; + + rect_right[0] = {32, 48, 48, 64}; + rect_right[1] = {48, 48, 64, 64}; + rect_right[2] = {64, 48, 80, 64}; + rect_right[3] = {80, 48, 96, 64}; + + if (++npc->ani_wait > 1) + { + npc->ani_wait = 0; + ++npc->ani_no; + } + + if (npc->ani_no > 2) + npc->ani_no = 0; + + if (npc->direct == 0) + npc->rect = rect_left[npc->ani_no]; + else + npc->rect = rect_right[npc->ani_no]; +} + \ No newline at end of file diff --git a/src/NpcAct200.cpp b/src/NpcAct200.cpp new file mode 100644 index 00000000..27606a48 --- /dev/null +++ b/src/NpcAct200.cpp @@ -0,0 +1,24 @@ +#include "WindowsWrapper.h" + +#include "NpcAct.h" + +#include "MyChar.h" +#include "NpChar.h" +#include "Game.h" +#include "Sound.h" +#include "Back.h" +#include "Triangle.h" + +//Spikes (small) +void ActNpc211(NPCHAR *npc) +{ + RECT rects[4]; + + rects[0] = {256, 200, 272, 216}; + rects[1] = {272, 200, 288, 216}; + rects[2] = {288, 200, 304, 216}; + rects[3] = {304, 200, 320, 216}; + + npc->rect = rects[npc->code_event]; +} + \ No newline at end of file diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 227fdb2a..c3dd2779 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -76,7 +76,7 @@ NPCFUNCTION gpNpcFuncTbl[] = ActNpc017, ActNpc018, nullptr, - nullptr, + ActNpc020, ActNpc021, nullptr, nullptr, @@ -120,6 +120,8 @@ NPCFUNCTION gpNpcFuncTbl[] = nullptr, nullptr, nullptr, + ActNpc064, + ActNpc065, nullptr, nullptr, nullptr, @@ -265,9 +267,7 @@ NPCFUNCTION gpNpcFuncTbl[] = nullptr, nullptr, nullptr, - nullptr, - nullptr, - nullptr, + ActNpc211, nullptr, nullptr, nullptr,