diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 7ca49cf7..8256747b 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -43,23 +43,23 @@ bool LoadEvent(char *path_event) { char path[PATH_LENGTH]; sprintf(path, "%s/%s", gDataPath, path_event); - + SDL_RWops *fp = SDL_RWFromFile(path, "rb"); if (!fp) return false; - + //Read "PXE" check char code[4]; fp->read(fp, code, 1, 4); if (memcmp(code, gPassPixEve, 3)) return false; - - //Get amount of npcs + + //Get amount of NPCs int count = SDL_ReadLE32(fp); - - //Load npcs + + //Load NPCs memset(gNPC, 0, sizeof(gNPC)); - + int n = 170; for (int i = 0; i < count; i++) { @@ -71,7 +71,7 @@ bool LoadEvent(char *path_event) eve.code_event = SDL_ReadLE16(fp); eve.code_char = SDL_ReadLE16(fp); eve.bits = SDL_ReadLE16(fp); - + //Set NPC parameters if (eve.bits & npc_altDir) gNPC[n].direct = 2; @@ -86,7 +86,7 @@ bool LoadEvent(char *path_event) gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; SetUniqueParameter(&gNPC[n]); - + //Check flags if (gNPC[n].bits & npc_appearSet) { @@ -102,11 +102,11 @@ bool LoadEvent(char *path_event) { gNPC[n].cond = 0x80; } - + //Increase index n++; } - + return true; } @@ -144,7 +144,7 @@ void SetDestroyNpChar(int x, int y, int w, int num) int offset_y = Random(-wa, wa) << 9; SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 0, NULL, 0x100); } - + //Flash effect //SetCaret(x, y, 12, 0); } @@ -159,7 +159,7 @@ void SetDestroyNpCharUp(int x, int y, int w, int num) int offset_y = Random(-wa, wa) << 9; SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 1, NULL, 0x100); } - + //Flash effect //SetCaret(x, y, 12, 0); } @@ -171,7 +171,7 @@ void SetExpObjects(int x, int y, int exp) if (!gNPC[n].cond) { memset(&gNPC[n], 0, sizeof(NPCHAR)); - + int sub_exp = 0; if (exp < 20) { @@ -194,7 +194,7 @@ void SetExpObjects(int x, int y, int exp) exp -= 20; sub_exp = 20; } - + gNPC[n].cond |= 0x80u; gNPC[n].direct = 0; gNPC[n].code_char = 1; @@ -222,10 +222,10 @@ bool SetBulletObject(int x, int y, int val) else tamakazu_ari[t] = 0; } - + if (!t) return false; - + int n = Random(1, 10 * t); int bullet_no = tamakazu_ari[n % t]; for (n = 0x100; n < NPC_MAX; n++) @@ -245,7 +245,7 @@ bool SetBulletObject(int x, int y, int val) return true; } } - + return false; } @@ -267,7 +267,7 @@ bool SetLifeObject(int x, int y, int val) return true; } } - + return false; } @@ -294,7 +294,7 @@ void PutNpChar(int fx, int fy) if (gNPC[n].cond & 0x80) { int8_t a; - + if (gNPC[n].shock) { a = 2 * ((gNPC[n].shock >> 1) & 1) - 1; @@ -308,13 +308,13 @@ void PutNpChar(int fx, int fy) gNPC[n].damage_view = 0; } } - + int side; if (gNPC[n].direct) side = gNPC[n].view.back; else side = gNPC[n].view.front; - + PutBitmap3( &grcGame, (gNPC[n].x - side) / 0x200 - fx / 0x200 + a, diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 7687b4fe..544d5c77 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -10,14 +10,18 @@ //Null void ActNpc000(NPCHAR *npc) { + RECT rect[1]; + rect[0] = {0x00, 0x00, 0x10, 0x10}; + if (!npc->act_no) { npc->act_no = 1; + if (npc->direct == 2) npc->y += 0x2000; } - - npc->rect = {0, 0, 16, 16}; + + npc->rect = rect[0]; } //Experience @@ -31,34 +35,34 @@ void ActNpc001(NPCHAR *npc) //Set state npc->act_no = 1; npc->ani_no = Random(0, 4); - + //Random speed npc->xm = Random(-0x200, 0x200); npc->ym = Random(-0x400, 0); - + //Random direction (reverse animation or not) if (Random(0, 1) != 0) npc->direct = 0; else npc->direct = 2; } - + //Gravity if (npc->flag & 0x100) npc->ym += 21; else npc->ym += 42; - + //Bounce off walls if (npc->flag & 1 && npc->xm < 0) npc->xm = -npc->xm; if (npc->flag & 4 && npc->xm > 0) npc->xm = -npc->xm; - + //Bounce off ceiling if (npc->flag & 2 && npc->ym < 0) npc->ym = -npc->ym; - + //Bounce off floor if (npc->flag & 8) { @@ -66,7 +70,7 @@ void ActNpc001(NPCHAR *npc) npc->ym = -0x280; npc->xm = 2 * npc->xm / 3; } - + //Play bounce song (and try to clip out of floor if stuck) if (npc->flag & 0xD) { @@ -78,7 +82,7 @@ void ActNpc001(NPCHAR *npc) { npc->count2 = 0; } - + //Limit speed if (npc->xm < -0x5FF) npc->xm = -0x5FF; @@ -96,23 +100,23 @@ void ActNpc001(NPCHAR *npc) { //Set state npc->act_no = 1; - + //Set random speed npc->ym = Random(-0x80, 0x80); npc->xm = Random(0x7F, 0x100); } - + //Blow to the left npc->xm -= 8; - + //Destroy when off-screen if (npc->x <= 0x9FFF) npc->cond = 0; - + //Limit speed (except pixel applied it to the X position) if (npc->x < -0x5FF) npc->x = -0x5FF; - + //Bounce off walls if (npc->flag & 1) npc->xm = 0x100; @@ -121,11 +125,11 @@ void ActNpc001(NPCHAR *npc) if (npc->flag & 8) npc->ym = -0x40; } - + //Move npc->x += npc->xm; npc->y += npc->ym; - + //Get framerects RECT rect[6]; rect[0] = {0x00, 0x10, 0x10, 0x20}; @@ -134,12 +138,12 @@ void ActNpc001(NPCHAR *npc) rect[3] = {0x30, 0x10, 0x40, 0x20}; rect[4] = {0x40, 0x10, 0x50, 0x20}; rect[5] = {0x50, 0x10, 0x60, 0x20}; - + RECT rcNo = {0, 0, 0, 0}; - + //Animate ++npc->ani_wait; - + if (npc->direct) { if (npc->ani_wait > 2) @@ -155,9 +159,9 @@ void ActNpc001(NPCHAR *npc) if (++npc->ani_no > 5) npc->ani_no = 0; } - + npc->rect = rect[npc->ani_no]; - + //Size if (npc->act_no) { @@ -171,14 +175,14 @@ void ActNpc001(NPCHAR *npc) npc->rect.top += 32; npc->rect.bottom += 32; } - + npc->act_no = 1; } - + //Delete after 500 frames if (++npc->count1 > 500 && npc->ani_no == 5 && npc->ani_wait == 2) npc->cond = 0; - + //Blink after 400 frames if (npc->count1 > 400) { @@ -208,18 +212,18 @@ void ActNpc002(NPCHAR *npc) rcUp[4] = {96, 24, 128, 48}; rcUp[5] = {128, 24, 160, 48}; rcUp[6] = {160, 24, 192, 48}; - + //Turn when touching a wall if (npc->flag & 1) npc->direct = 2; else if (npc->flag & 4) npc->direct = 0; - + switch (npc->act_no) { case 1: //Shot npc->xm = 7 * npc->xm / 8; - + if (++npc->count1 > 40) { if (npc->shock) @@ -242,19 +246,19 @@ void ActNpc002(NPCHAR *npc) npc->xm = 0x400; else npc->xm = -0x400; - + if (++npc->count1 > 200) { npc->act_no = 0; npc->damage = 1; } - + if (++npc->ani_wait > 5) { npc->ani_wait = 0; ++npc->ani_no; } - + if (npc->ani_no > 6) npc->ani_no = 5; break; @@ -263,16 +267,16 @@ void ActNpc002(NPCHAR *npc) npc->xm = 0x100; else npc->xm = -0x100; - + if (++npc->ani_wait > 8) { npc->ani_wait = 0; ++npc->ani_no; } - + if (npc->ani_no > 3) npc->ani_no = 0; - + if (npc->shock) { npc->count1 = 0; @@ -281,16 +285,16 @@ void ActNpc002(NPCHAR *npc) } 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) npc->rect = rcUp[npc->ani_no]; @@ -303,7 +307,7 @@ void ActNpc003(NPCHAR *npc) { if (++npc->count1 > 100) npc->cond = 0; - + npc->rect = {0, 0, 0, 0}; } @@ -312,7 +316,7 @@ void ActNpc004(NPCHAR *npc) { RECT rcLeft[8]; RECT rcUp[8]; - + rcLeft[0] = {16, 0, 17, 1}; rcLeft[1] = {16, 0, 32, 16}; rcLeft[2] = {32, 0, 48, 16}; @@ -330,13 +334,13 @@ void ActNpc004(NPCHAR *npc) rcUp[5] = {48, 128, 64, 144}; rcUp[6] = {64, 128, 80, 144}; rcUp[7] = {80, 128, 96, 144}; - + if (npc->act_no) { //Slight drag npc->xm = 20 * npc->xm / 21; npc->ym = 20 * npc->ym / 21; - + //Move npc->x += npc->xm; npc->y += npc->ym; @@ -350,20 +354,20 @@ void ActNpc004(NPCHAR *npc) npc->xm = GetCos(deg) * Random(0x200, 0x5FF) / 0x200; npc->ym = GetSin(deg) * Random(0x200, 0x5FF) / 0x200; } - + //Set state npc->ani_no = Random(0, 4); npc->ani_wait = Random(0, 3); npc->act_no = 1; } - + //Animate if (++npc->ani_wait > 4) { npc->ani_wait = 0; npc->ani_no++; } - + //Set framerect if (npc->ani_no < 8) { @@ -390,24 +394,24 @@ void ActNpc005(NPCHAR *npc) rcLeft[0] = {0, 48, 16, 64}; rcLeft[1] = {16, 48, 32, 64}; rcLeft[2] = {32, 48, 48, 64}; - + rcRight[0] = {0, 64, 16, 80}; rcRight[1] = {16, 64, 32, 80}; rcRight[2] = {32, 64, 48, 80}; - + 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; - + //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) { @@ -419,7 +423,7 @@ void ActNpc005(NPCHAR *npc) { npc->ani_no = 1; } - + //Jump if attacked if (npc->shock) { @@ -427,7 +431,7 @@ void ActNpc005(NPCHAR *npc) npc->ani_no = 0; npc->act_wait = 0; } - + //Jump if player is nearby if (npc->act_wait >= 8 && npc->x - 0x6000 < gMC.x && npc->x + 0x6000 > gMC.x && npc->y - 0xA000 < gMC.y && npc->y + 0x6000 > gMC.y) { @@ -436,18 +440,18 @@ void ActNpc005(NPCHAR *npc) 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; @@ -455,7 +459,7 @@ void ActNpc005(NPCHAR *npc) npc->xm = -0x100; } break; - + case 3: //Jumping //Land if (npc->flag & 8) @@ -468,16 +472,16 @@ void ActNpc005(NPCHAR *npc) } break; } - + //Gravity npc->ym += 64; if (npc->ym > 0x5FF) npc->ym = 0x5FF; - + //Move npc->x += npc->xm; npc->y += npc->ym; - + //Set framerect if (npc->direct) npc->rect = rcRight[npc->ani_no];