I figured combining things would make the emulator run smoother (it slows down in certain rooms due to scripts), but it doesn't seem to have helped.
Here is the issue: there are 96 possible spots in ram that a monster can show up in, and 32 spots for stuff like enemy projectiles. The monsters in one room ALWAYS show up in the same spot in ram (if they are not infinitely respawning types), but I am trying to make scripts to account for all possible places since a map editor is being made by a friend of mine that should let me put more monsters into rooms.
Originally I had separate files for each monster, but in a few rooms if there were too many different TYPES of monsters it slowed things down due to all the scripts that would be running. I started combining them in hopes that it would run smoother, but it seems to have not helped.
Here is the ENTIRE code for one stage. If you have any tips on how I can get it to run these scripts without slowing down the emu as much, let me know.
- Code: Select all
struct SPRITE {
SHORT hmovement;
SHORT hpos;
SHORT vmovement;
SHORT vpos;
LONG hspeed;
LONG vspeed;
SHORT hoffset;
SHORT voffset;
SHORT dirfacing;
SHORT color;
SHORT transp; //amount of transparency for some things
SHORT hwidth; //for dust
SHORT vwidth; //for dust
SHORT anglesmall; //angle of rotating items
SHORT blank62a238;
SHORT blank62a23a;
SHORT blank62a23c;
SHORT sprite1; //what is created, enemy, item, weapon, etc.
SHORT sprite2; //what is created, enemy, item, weapon, etc.
SHORT sprite3;
SHORT action1;
SHORT action2;
SHORT itemnum; //used for when richter is blinking
SHORT blank62a24a;
SHORT blank62a24c;
SHORT showsdmg;
SHORT blank62a250;
SHORT doesdmg1;
SHORT doesdmg2; //does the move hit and do damage? 2 for sub weapons and attacks
SHORT hp;
SHORT dmg;
SHORT dmgtype; //type of element dmg attack does
SHORT blank62a25c;
BYTE hrange;
BYTE vrange;
SHORT delaymult; //delay between hits when touch player.dmg is on
SHORT blank62a262;
SHORT actiondata; //determines player.frame image used for each player.frame number
SHORT blank62a266;
SHORT frame;
SHORT frametimer;
SHORT blank62a26c;
SHORT framepic;
SHORT hitstun;
SHORT blank62a272;
SHORT blank62a274;
SHORT blank62a276;
SHORT blank62a278;
SHORT blank62a27a;
SHORT blank62a27c;
SHORT blank62a27e;
SHORT blank62a280;
SHORT hitscandles; //1=yes, 0 = no
SHORT transp2; //amount of transparency for dust
SHORT blank62a286;
SHORT blank62a288;
SHORT blank62a28a;
SHORT blank62a28c;
SHORT blank62a28e;
SHORT blank62a290;
SHORT blank62a292;
SHORT fadetimer; //used BY daggers to fade out {N/A on player sprite)
SHORT widthtimer; //used by holy book to control how far spinning extends out
SHORT attacktimer; //WARG: timer till next attack
SHORT spinangle; //used BY holy book, determines what angle it spins at
SHORT timer3; //used by prism beam to determine how long till book opens up
SHORT blank62a29e;
SHORT blank62a2a0;
SHORT blank62a2a2;
SHORT dractimer;
SHORT blank62a2a6;
SHORT blinkintensity; //used when richter is blinking to indicate how MUCH to show blinking
SHORT blank62a2aa;
SHORT usertag18;
SHORT usertag17;
SHORT usertag16;
SHORT usertag15;
SHORT usertag14;
SHORT usertag13;
SHORT usertag12;
SHORT atknum;
SHORT usertag10;
SHORT usertag9;
SHORT usertag8;
SHORT usertag7;
SHORT usertag6;
SHORT usertag5;
SHORT usertag4;
SHORT usertag3;
SHORT fivetag;
SHORT novaballs;
SHORT tag1;
SHORT blank62a2d2;
};
struct MONSTER {
LONG text;
SHORT hp;
SHORT dmg;
SHORT element;
SHORT def;
SHORT canblock;
SHORT weakto;
SHORT strongto;
SHORT immuneto;
SHORT absorbs;
SHORT level;
SHORT exp;
SHORT commondrop;
SHORT raredrop;
SHORT commonrate;
SHORT rarerate;
BYTE hsize;
BYTE vsize;
BYTE unknown1;
BYTE special;
};
int count;
/*Monsters: Warg, Zombie, Bat, Fishman, Meman (not needed due to being removed until later), Bone Scimitar*/
**HERE IS WHERE IT RUNS ALL THE SCRIPTS VIA THE LOOP**
void Lock ()
{
extern SHORT stagenum = { "", 0x0064e2e0 };
if (stagenum == 65)
{
{count = 0;}
for (count = 0; count < 96; count++)
{
if (count < 33) {zombie(); fishman();}
{warg(); bonescimitar(); bat();}
}
}
}
[b]**FROM HERE ON IS EACH DIFFERENT CREATURES SCRIPT**[/b]
extern SPRITE player = { "", 0x62a218 };
extern SPRITE enemy[1] = { "", 0x0062d118 };
extern SPRITE respawn[1] = { "", 0x00631798 };
void warg ()
{
extern MONSTER wargperm = { "", 0x00661298 };
if (wargperm.hp != 300) {wargperm.hp = 300; wargperm.dmg = 20; wargperm.weakto = 32896; wargperm.strongto = 8192; wargperm.special = 48; wargperm.level = 3; wargperm.exp = 25;}
if (enemy[count].sprite1 == 74 && enemy[count].sprite2 == -2240 && enemy[count].sprite3 == -32740)
{
//bites and turns faster
if (enemy[count].action1 == 6 && enemy[count].attacktimer > 10) {enemy[count].attacktimer = 10;}
else if (enemy[count].action1 == 5 && enemy[count].frametimer > 3) {enemy[count].frametimer = 3;}
}
}
void zombie ()
{
extern MONSTER zombieperm = { "", 0x00660870 };
//weak to fire/holy, strong to dark, immuneto psn/cur, absorbs none
if (zombieperm.hp < 14) {zombieperm.hp = 14; zombieperm.dmg = 6; zombieperm.weakto = 36864; zombieperm.strongto = 2048; zombieperm.immuneto = 384; zombieperm.level = 1; zombieperm.exp = 3;}
if (respawn[count].sprite1 == 76 && respawn[count].sprite2 == 25776 && respawn[count].sprite3 == -32739)
{
//nothing slows them down
if (respawn[count].showsdmg != -30704) {respawn[count].showsdmg = -30704;}
//fixes hrange
if (respawn[count].hrange == 8) {respawn[count].hrange = 13;}
//rises out of ground faster
if (respawn[count].action1 == 2 && respawn[count].frametimer > 3) {respawn[count].frametimer = 3;}
//certain color zombies move faster than others
if (respawn[count].tag1 == 0)
{
if (respawn[count].color == 723) {respawn[count].tag1 = 1;}
else if (respawn[count].color == 724) {respawn[count].tag1 = 2;}
}
//tags needed so when zombies blink when hit they do NOT slow down
else if (respawn[count].tag1 == 1)
{
if (respawn[count].dirfacing == 0) {respawn[count].hspeed = -100000;}
else {respawn[count].hspeed = 100000;}
}
else if (respawn[count].tag1 == 2)
{
if (respawn[count].dirfacing == 0) {respawn[count].hspeed = -70000;}
else {respawn[count].hspeed = 70000;}
}
}
}
void fishman ()
{
extern MONSTER fishmanperm = { "", 0x0065fb78 };
extern MONSTER fireb = { "", 0x0065fba0 };
//weak to fire/lit, strong to ice
if (fishmanperm.hp != 16) {fishmanperm.hp = 16; fishmanperm.dmg = 6; fishmanperm.weakto = 49152; fishmanperm.strongto = 8192;
fishmanperm.level = 3; fishmanperm.exp = 6; fishmanperm.commondrop = 0; fishmanperm.raredrop = 0;
fireb.hp = 0; fireb.dmg = 8; fireb.canblock = 5; fireb.special = 0;}
//walks slightly faster
if (respawn[count].sprite1 == 65 && respawn[count].sprite2 == 19232 && respawn[count].sprite3 == -32739)
{
if (respawn[count].hspeed > 0 && respawn[count].hspeed < 40000) {respawn[count].hspeed = 40000;}
else if (respawn[count].hspeed < 0 && respawn[count].hspeed > -40000) {respawn[count].hspeed = -40000;}
}
/*FIREBALL: moves faster*/
else if (respawn[count].sprite1 == 66 && respawn[count].sprite2 == 22232 && respawn[count].sprite3 == -32739)
{
if (respawn[count].hspeed > 0 && respawn[count].hspeed < 150000) {respawn[count].hspeed = 150000;}
else if (respawn[count].hspeed < 0 && respawn[count].hspeed > -150000) {respawn[count].hspeed = -150000;}
}
}
void bat ()
{
extern MONSTER batperm = { "", 0x00660140 };
extern SHORT timerticks = { "", 0x0064ea7c };
//weak to psn/stn
if (batperm.dmg < 10) {batperm.dmg = 10; batperm.weakto = 640; batperm.special = 16; batperm.level = 1; batperm.exp = 5;}
if (enemy[count].sprite1 == 72 && enemy[count].sprite2 == 25188 && enemy[count].sprite3 == -32739)
{
//activates enemy sooner
if (enemy[count].action1 == 1 && enemy[count].hpos >= player.hpos-128 && enemy[count].hpos <= player.hpos+128 && enemy[count].vpos >= player.vpos-96 && enemy[count].vpos <= player.vpos+96) {enemy[count].action1 = 2;}
//sets bats to sometimes INSTANTLY attack
if (timerticks %4 == 0 && enemy[count].tag1 == 0) {enemy[count].tag1 = 1;}
else {enemy[count].tag1 = 2;}
if (enemy[count].tag1 == 1 && enemy[count].action1 == 1) {enemy[count].action1 = 2; enemy[count].frame = 9;}
//shakes for less time before it flies at you
if (enemy[count].action1 == 2)
{
if (enemy[count].frame < 6) {enemy[count].frame = 6;}
if (enemy[count].frametimer > 5) {enemy[count].frametimer = 5;}
}
//flies faster now
else if (enemy[count].action1 == 3)
{
if (enemy[count].vspeed > 0) {enemy[count].vspeed = 108544;}
if (enemy[count].hspeed < 0) {enemy[count].hspeed = -81920;}
else if (enemy[count].hspeed > 0) {enemy[count].hspeed = 81920;}
}
//speeds up once on same height plane as you
else if (enemy[count].action1 == 4)
{
if (enemy[count].vspeed > 100000) {enemy[count].vspeed = 57344;}
if (enemy[count].hspeed < 0) {enemy[count].hspeed = -131072;}
else if (enemy[count].hspeed > 0) {enemy[count].hspeed = 131072;}
}
}
}
void bonescimitar ()
{
extern MONSTER bonescimitarperm = { "", 0x006607a8 };
if (bonescimitarperm.dmg < 13) {bonescimitarperm.hp = 25; bonescimitarperm.def = 0; bonescimitarperm.dmg = 10;}
if (enemy[count].sprite1 == 70 && enemy[count].sprite2 == 23212 && enemy[count].sprite3 == -32739)
{
//attacks faster now
if (enemy[count].action1 == 4 && enemy[count].frame == 1) {enemy[count].frame = 4; enemy[count].frametimer = 1;}
//moves faster now ONLY when approaching
if (enemy[count].hspeed > 0 && enemy[count].dirfacing == 1) {enemy[count].hmovement = -32768;}
else if (enemy[count].hspeed < 0 && enemy[count].dirfacing == 0) {enemy[count].hmovement = 0;}
if (enemy[count].frame == 9)
{
//holds sword out for less time
if (enemy[count].frametimer > 13) {enemy[count].frametimer = 13;}
//increases sword range and moves hitbox
{enemy[count].hrange= 25; enemy[count].hoffset= -15;}
}
//moves sooner after atacking
else if (enemy[count].frame > 9 && enemy[count].frametimer > 1) {enemy[count].frametimer = 1;}
}
}