Fixed NPC000.

This commit is contained in:
zxin 2019-01-26 15:00:34 +10:00 committed by Clownacy
parent bcd02cb6cc
commit 50ca5e37a2
2 changed files with 83 additions and 79 deletions

View file

@ -43,23 +43,23 @@ bool LoadEvent(char *path_event)
{ {
char path[PATH_LENGTH]; char path[PATH_LENGTH];
sprintf(path, "%s/%s", gDataPath, path_event); sprintf(path, "%s/%s", gDataPath, path_event);
SDL_RWops *fp = SDL_RWFromFile(path, "rb"); SDL_RWops *fp = SDL_RWFromFile(path, "rb");
if (!fp) if (!fp)
return false; return false;
//Read "PXE" check //Read "PXE" check
char code[4]; char code[4];
fp->read(fp, code, 1, 4); fp->read(fp, code, 1, 4);
if (memcmp(code, gPassPixEve, 3)) if (memcmp(code, gPassPixEve, 3))
return false; return false;
//Get amount of npcs //Get amount of NPCs
int count = SDL_ReadLE32(fp); int count = SDL_ReadLE32(fp);
//Load npcs //Load NPCs
memset(gNPC, 0, sizeof(gNPC)); memset(gNPC, 0, sizeof(gNPC));
int n = 170; int n = 170;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
@ -71,7 +71,7 @@ bool LoadEvent(char *path_event)
eve.code_event = SDL_ReadLE16(fp); eve.code_event = SDL_ReadLE16(fp);
eve.code_char = SDL_ReadLE16(fp); eve.code_char = SDL_ReadLE16(fp);
eve.bits = SDL_ReadLE16(fp); eve.bits = SDL_ReadLE16(fp);
//Set NPC parameters //Set NPC parameters
if (eve.bits & npc_altDir) if (eve.bits & npc_altDir)
gNPC[n].direct = 2; gNPC[n].direct = 2;
@ -86,7 +86,7 @@ bool LoadEvent(char *path_event)
gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
//Check flags //Check flags
if (gNPC[n].bits & npc_appearSet) if (gNPC[n].bits & npc_appearSet)
{ {
@ -102,11 +102,11 @@ bool LoadEvent(char *path_event)
{ {
gNPC[n].cond = 0x80; gNPC[n].cond = 0x80;
} }
//Increase index //Increase index
n++; n++;
} }
return true; return true;
} }
@ -144,7 +144,7 @@ void SetDestroyNpChar(int x, int y, int w, int num)
int offset_y = Random(-wa, wa) << 9; int offset_y = Random(-wa, wa) << 9;
SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 0, NULL, 0x100); SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 0, NULL, 0x100);
} }
//Flash effect //Flash effect
//SetCaret(x, y, 12, 0); //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; int offset_y = Random(-wa, wa) << 9;
SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 1, NULL, 0x100); SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 1, NULL, 0x100);
} }
//Flash effect //Flash effect
//SetCaret(x, y, 12, 0); //SetCaret(x, y, 12, 0);
} }
@ -171,7 +171,7 @@ void SetExpObjects(int x, int y, int exp)
if (!gNPC[n].cond) if (!gNPC[n].cond)
{ {
memset(&gNPC[n], 0, sizeof(NPCHAR)); memset(&gNPC[n], 0, sizeof(NPCHAR));
int sub_exp = 0; int sub_exp = 0;
if (exp < 20) if (exp < 20)
{ {
@ -194,7 +194,7 @@ void SetExpObjects(int x, int y, int exp)
exp -= 20; exp -= 20;
sub_exp = 20; sub_exp = 20;
} }
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80u;
gNPC[n].direct = 0; gNPC[n].direct = 0;
gNPC[n].code_char = 1; gNPC[n].code_char = 1;
@ -222,10 +222,10 @@ bool SetBulletObject(int x, int y, int val)
else else
tamakazu_ari[t] = 0; tamakazu_ari[t] = 0;
} }
if (!t) if (!t)
return false; return false;
int n = Random(1, 10 * t); int n = Random(1, 10 * t);
int bullet_no = tamakazu_ari[n % t]; int bullet_no = tamakazu_ari[n % t];
for (n = 0x100; n < NPC_MAX; n++) for (n = 0x100; n < NPC_MAX; n++)
@ -245,7 +245,7 @@ bool SetBulletObject(int x, int y, int val)
return true; return true;
} }
} }
return false; return false;
} }
@ -267,7 +267,7 @@ bool SetLifeObject(int x, int y, int val)
return true; return true;
} }
} }
return false; return false;
} }
@ -294,7 +294,7 @@ void PutNpChar(int fx, int fy)
if (gNPC[n].cond & 0x80) if (gNPC[n].cond & 0x80)
{ {
int8_t a; int8_t a;
if (gNPC[n].shock) if (gNPC[n].shock)
{ {
a = 2 * ((gNPC[n].shock >> 1) & 1) - 1; a = 2 * ((gNPC[n].shock >> 1) & 1) - 1;
@ -308,13 +308,13 @@ void PutNpChar(int fx, int fy)
gNPC[n].damage_view = 0; gNPC[n].damage_view = 0;
} }
} }
int side; int side;
if (gNPC[n].direct) if (gNPC[n].direct)
side = gNPC[n].view.back; side = gNPC[n].view.back;
else else
side = gNPC[n].view.front; side = gNPC[n].view.front;
PutBitmap3( PutBitmap3(
&grcGame, &grcGame,
(gNPC[n].x - side) / 0x200 - fx / 0x200 + a, (gNPC[n].x - side) / 0x200 - fx / 0x200 + a,

View file

@ -10,14 +10,18 @@
//Null //Null
void ActNpc000(NPCHAR *npc) void ActNpc000(NPCHAR *npc)
{ {
RECT rect[1];
rect[0] = {0x00, 0x00, 0x10, 0x10};
if (!npc->act_no) if (!npc->act_no)
{ {
npc->act_no = 1; npc->act_no = 1;
if (npc->direct == 2) if (npc->direct == 2)
npc->y += 0x2000; npc->y += 0x2000;
} }
npc->rect = {0, 0, 16, 16}; npc->rect = rect[0];
} }
//Experience //Experience
@ -31,34 +35,34 @@ void ActNpc001(NPCHAR *npc)
//Set state //Set state
npc->act_no = 1; npc->act_no = 1;
npc->ani_no = Random(0, 4); npc->ani_no = Random(0, 4);
//Random speed //Random speed
npc->xm = Random(-0x200, 0x200); npc->xm = Random(-0x200, 0x200);
npc->ym = Random(-0x400, 0); npc->ym = Random(-0x400, 0);
//Random direction (reverse animation or not) //Random direction (reverse animation or not)
if (Random(0, 1) != 0) if (Random(0, 1) != 0)
npc->direct = 0; npc->direct = 0;
else else
npc->direct = 2; npc->direct = 2;
} }
//Gravity //Gravity
if (npc->flag & 0x100) if (npc->flag & 0x100)
npc->ym += 21; npc->ym += 21;
else else
npc->ym += 42; npc->ym += 42;
//Bounce off walls //Bounce off walls
if (npc->flag & 1 && npc->xm < 0) if (npc->flag & 1 && npc->xm < 0)
npc->xm = -npc->xm; npc->xm = -npc->xm;
if (npc->flag & 4 && npc->xm > 0) if (npc->flag & 4 && npc->xm > 0)
npc->xm = -npc->xm; npc->xm = -npc->xm;
//Bounce off ceiling //Bounce off ceiling
if (npc->flag & 2 && npc->ym < 0) if (npc->flag & 2 && npc->ym < 0)
npc->ym = -npc->ym; npc->ym = -npc->ym;
//Bounce off floor //Bounce off floor
if (npc->flag & 8) if (npc->flag & 8)
{ {
@ -66,7 +70,7 @@ void ActNpc001(NPCHAR *npc)
npc->ym = -0x280; npc->ym = -0x280;
npc->xm = 2 * npc->xm / 3; npc->xm = 2 * npc->xm / 3;
} }
//Play bounce song (and try to clip out of floor if stuck) //Play bounce song (and try to clip out of floor if stuck)
if (npc->flag & 0xD) if (npc->flag & 0xD)
{ {
@ -78,7 +82,7 @@ void ActNpc001(NPCHAR *npc)
{ {
npc->count2 = 0; npc->count2 = 0;
} }
//Limit speed //Limit speed
if (npc->xm < -0x5FF) if (npc->xm < -0x5FF)
npc->xm = -0x5FF; npc->xm = -0x5FF;
@ -96,23 +100,23 @@ void ActNpc001(NPCHAR *npc)
{ {
//Set state //Set state
npc->act_no = 1; npc->act_no = 1;
//Set random speed //Set random speed
npc->ym = Random(-0x80, 0x80); npc->ym = Random(-0x80, 0x80);
npc->xm = Random(0x7F, 0x100); npc->xm = Random(0x7F, 0x100);
} }
//Blow to the left //Blow to the left
npc->xm -= 8; npc->xm -= 8;
//Destroy when off-screen //Destroy when off-screen
if (npc->x <= 0x9FFF) if (npc->x <= 0x9FFF)
npc->cond = 0; npc->cond = 0;
//Limit speed (except pixel applied it to the X position) //Limit speed (except pixel applied it to the X position)
if (npc->x < -0x5FF) if (npc->x < -0x5FF)
npc->x = -0x5FF; npc->x = -0x5FF;
//Bounce off walls //Bounce off walls
if (npc->flag & 1) if (npc->flag & 1)
npc->xm = 0x100; npc->xm = 0x100;
@ -121,11 +125,11 @@ void ActNpc001(NPCHAR *npc)
if (npc->flag & 8) if (npc->flag & 8)
npc->ym = -0x40; npc->ym = -0x40;
} }
//Move //Move
npc->x += npc->xm; npc->x += npc->xm;
npc->y += npc->ym; npc->y += npc->ym;
//Get framerects //Get framerects
RECT rect[6]; RECT rect[6];
rect[0] = {0x00, 0x10, 0x10, 0x20}; rect[0] = {0x00, 0x10, 0x10, 0x20};
@ -134,12 +138,12 @@ void ActNpc001(NPCHAR *npc)
rect[3] = {0x30, 0x10, 0x40, 0x20}; rect[3] = {0x30, 0x10, 0x40, 0x20};
rect[4] = {0x40, 0x10, 0x50, 0x20}; rect[4] = {0x40, 0x10, 0x50, 0x20};
rect[5] = {0x50, 0x10, 0x60, 0x20}; rect[5] = {0x50, 0x10, 0x60, 0x20};
RECT rcNo = {0, 0, 0, 0}; RECT rcNo = {0, 0, 0, 0};
//Animate //Animate
++npc->ani_wait; ++npc->ani_wait;
if (npc->direct) if (npc->direct)
{ {
if (npc->ani_wait > 2) if (npc->ani_wait > 2)
@ -155,9 +159,9 @@ void ActNpc001(NPCHAR *npc)
if (++npc->ani_no > 5) if (++npc->ani_no > 5)
npc->ani_no = 0; npc->ani_no = 0;
} }
npc->rect = rect[npc->ani_no]; npc->rect = rect[npc->ani_no];
//Size //Size
if (npc->act_no) if (npc->act_no)
{ {
@ -171,14 +175,14 @@ void ActNpc001(NPCHAR *npc)
npc->rect.top += 32; npc->rect.top += 32;
npc->rect.bottom += 32; npc->rect.bottom += 32;
} }
npc->act_no = 1; npc->act_no = 1;
} }
//Delete after 500 frames //Delete after 500 frames
if (++npc->count1 > 500 && npc->ani_no == 5 && npc->ani_wait == 2) if (++npc->count1 > 500 && npc->ani_no == 5 && npc->ani_wait == 2)
npc->cond = 0; npc->cond = 0;
//Blink after 400 frames //Blink after 400 frames
if (npc->count1 > 400) if (npc->count1 > 400)
{ {
@ -208,18 +212,18 @@ void ActNpc002(NPCHAR *npc)
rcUp[4] = {96, 24, 128, 48}; rcUp[4] = {96, 24, 128, 48};
rcUp[5] = {128, 24, 160, 48}; rcUp[5] = {128, 24, 160, 48};
rcUp[6] = {160, 24, 192, 48}; rcUp[6] = {160, 24, 192, 48};
//Turn when touching a wall //Turn when touching a wall
if (npc->flag & 1) if (npc->flag & 1)
npc->direct = 2; npc->direct = 2;
else if (npc->flag & 4) else if (npc->flag & 4)
npc->direct = 0; npc->direct = 0;
switch (npc->act_no) switch (npc->act_no)
{ {
case 1: //Shot case 1: //Shot
npc->xm = 7 * npc->xm / 8; npc->xm = 7 * npc->xm / 8;
if (++npc->count1 > 40) if (++npc->count1 > 40)
{ {
if (npc->shock) if (npc->shock)
@ -242,19 +246,19 @@ void ActNpc002(NPCHAR *npc)
npc->xm = 0x400; npc->xm = 0x400;
else else
npc->xm = -0x400; npc->xm = -0x400;
if (++npc->count1 > 200) if (++npc->count1 > 200)
{ {
npc->act_no = 0; npc->act_no = 0;
npc->damage = 1; npc->damage = 1;
} }
if (++npc->ani_wait > 5) if (++npc->ani_wait > 5)
{ {
npc->ani_wait = 0; npc->ani_wait = 0;
++npc->ani_no; ++npc->ani_no;
} }
if (npc->ani_no > 6) if (npc->ani_no > 6)
npc->ani_no = 5; npc->ani_no = 5;
break; break;
@ -263,16 +267,16 @@ void ActNpc002(NPCHAR *npc)
npc->xm = 0x100; npc->xm = 0x100;
else else
npc->xm = -0x100; npc->xm = -0x100;
if (++npc->ani_wait > 8) if (++npc->ani_wait > 8)
{ {
npc->ani_wait = 0; npc->ani_wait = 0;
++npc->ani_no; ++npc->ani_no;
} }
if (npc->ani_no > 3) if (npc->ani_no > 3)
npc->ani_no = 0; npc->ani_no = 0;
if (npc->shock) if (npc->shock)
{ {
npc->count1 = 0; npc->count1 = 0;
@ -281,16 +285,16 @@ void ActNpc002(NPCHAR *npc)
} }
break; break;
} }
//Gravity //Gravity
npc->ym += 0x40; npc->ym += 0x40;
if (npc->ym > 0x5FF) if (npc->ym > 0x5FF)
npc->ym = 0x5FF; npc->ym = 0x5FF;
//Move //Move
npc->x += npc->xm; npc->x += npc->xm;
npc->y += npc->ym; npc->y += npc->ym;
//Set framerect //Set framerect
if (npc->direct) if (npc->direct)
npc->rect = rcUp[npc->ani_no]; npc->rect = rcUp[npc->ani_no];
@ -303,7 +307,7 @@ void ActNpc003(NPCHAR *npc)
{ {
if (++npc->count1 > 100) if (++npc->count1 > 100)
npc->cond = 0; npc->cond = 0;
npc->rect = {0, 0, 0, 0}; npc->rect = {0, 0, 0, 0};
} }
@ -312,7 +316,7 @@ void ActNpc004(NPCHAR *npc)
{ {
RECT rcLeft[8]; RECT rcLeft[8];
RECT rcUp[8]; RECT rcUp[8];
rcLeft[0] = {16, 0, 17, 1}; rcLeft[0] = {16, 0, 17, 1};
rcLeft[1] = {16, 0, 32, 16}; rcLeft[1] = {16, 0, 32, 16};
rcLeft[2] = {32, 0, 48, 16}; rcLeft[2] = {32, 0, 48, 16};
@ -330,13 +334,13 @@ void ActNpc004(NPCHAR *npc)
rcUp[5] = {48, 128, 64, 144}; rcUp[5] = {48, 128, 64, 144};
rcUp[6] = {64, 128, 80, 144}; rcUp[6] = {64, 128, 80, 144};
rcUp[7] = {80, 128, 96, 144}; rcUp[7] = {80, 128, 96, 144};
if (npc->act_no) if (npc->act_no)
{ {
//Slight drag //Slight drag
npc->xm = 20 * npc->xm / 21; npc->xm = 20 * npc->xm / 21;
npc->ym = 20 * npc->ym / 21; npc->ym = 20 * npc->ym / 21;
//Move //Move
npc->x += npc->xm; npc->x += npc->xm;
npc->y += npc->ym; npc->y += npc->ym;
@ -350,20 +354,20 @@ void ActNpc004(NPCHAR *npc)
npc->xm = GetCos(deg) * Random(0x200, 0x5FF) / 0x200; npc->xm = GetCos(deg) * Random(0x200, 0x5FF) / 0x200;
npc->ym = GetSin(deg) * Random(0x200, 0x5FF) / 0x200; npc->ym = GetSin(deg) * Random(0x200, 0x5FF) / 0x200;
} }
//Set state //Set state
npc->ani_no = Random(0, 4); npc->ani_no = Random(0, 4);
npc->ani_wait = Random(0, 3); npc->ani_wait = Random(0, 3);
npc->act_no = 1; npc->act_no = 1;
} }
//Animate //Animate
if (++npc->ani_wait > 4) if (++npc->ani_wait > 4)
{ {
npc->ani_wait = 0; npc->ani_wait = 0;
npc->ani_no++; npc->ani_no++;
} }
//Set framerect //Set framerect
if (npc->ani_no < 8) if (npc->ani_no < 8)
{ {
@ -390,24 +394,24 @@ void ActNpc005(NPCHAR *npc)
rcLeft[0] = {0, 48, 16, 64}; rcLeft[0] = {0, 48, 16, 64};
rcLeft[1] = {16, 48, 32, 64}; rcLeft[1] = {16, 48, 32, 64};
rcLeft[2] = {32, 48, 48, 64}; rcLeft[2] = {32, 48, 48, 64};
rcRight[0] = {0, 64, 16, 80}; rcRight[0] = {0, 64, 16, 80};
rcRight[1] = {16, 64, 32, 80}; rcRight[1] = {16, 64, 32, 80};
rcRight[2] = {32, 64, 48, 80}; rcRight[2] = {32, 64, 48, 80};
switch (npc->act_no) switch (npc->act_no)
{ {
case 0: //Init case 0: //Init
npc->y += 0x600; npc->y += 0x600;
npc->act_no = 1; npc->act_no = 1;
case 1: //Waiting case 1: //Waiting
//Look at player //Look at player
if (npc->x <= gMC.x) if (npc->x <= gMC.x)
npc->direct = 2; npc->direct = 2;
else else
npc->direct = 0; npc->direct = 0;
//Open eyes near player //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->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; npc->ani_no = 1;
} }
//Jump if attacked //Jump if attacked
if (npc->shock) if (npc->shock)
{ {
@ -427,7 +431,7 @@ void ActNpc005(NPCHAR *npc)
npc->ani_no = 0; npc->ani_no = 0;
npc->act_wait = 0; npc->act_wait = 0;
} }
//Jump if player is nearby //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) 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; npc->act_wait = 0;
} }
break; break;
case 2: //Going to jump case 2: //Going to jump
if (++npc->act_wait > 8) if (++npc->act_wait > 8)
{ {
//Set jump state //Set jump state
npc->act_no = 3; npc->act_no = 3;
npc->ani_no = 2; npc->ani_no = 2;
//Jump //Jump
npc->ym = -0x5FF; npc->ym = -0x5FF;
PlaySoundObject(30, 1); PlaySoundObject(30, 1);
//Jump in facing direction //Jump in facing direction
if (npc->direct) if (npc->direct)
npc->xm = 0x100; npc->xm = 0x100;
@ -455,7 +459,7 @@ void ActNpc005(NPCHAR *npc)
npc->xm = -0x100; npc->xm = -0x100;
} }
break; break;
case 3: //Jumping case 3: //Jumping
//Land //Land
if (npc->flag & 8) if (npc->flag & 8)
@ -468,16 +472,16 @@ void ActNpc005(NPCHAR *npc)
} }
break; break;
} }
//Gravity //Gravity
npc->ym += 64; npc->ym += 64;
if (npc->ym > 0x5FF) if (npc->ym > 0x5FF)
npc->ym = 0x5FF; npc->ym = 0x5FF;
//Move //Move
npc->x += npc->xm; npc->x += npc->xm;
npc->y += npc->ym; npc->y += npc->ym;
//Set framerect //Set framerect
if (npc->direct) if (npc->direct)
npc->rect = rcRight[npc->ani_no]; npc->rect = rcRight[npc->ani_no];