CODE
//Screen Dimensions
const int screenWidth = 256;
const int screenHeight = 176;
//Sprite Flips
const int FLIP_H = 1;
const int FLIP_V = 2;
const int FLIP_B = 3;
//Sprite Rotations
const int ROTATE_CW = 4;
const int ROTATE_CCW = 7;
//Sprite Flip+Rotation
const int ROTATE_CW_FLIP = 5;
const int ROTATE_CCW_FLIP = 6;
//NPC Misc Flags
const int NPCMF_DAMAGE = 0x0001;
const int NPCMF_INVISIBLE = 0x0002;
const int NPCMF_NOTRETURN = 0x0004;
const int NPCMF_NOTENEMY = 0x0008;
const int NPCMF_SPAWNFLICKER = 0x0010;
const int NPCMF_LENSONLY = 0x0020;
const int NPCMF_FLASHING = 0x0040;
const int NPCMF_FLICKERING = 0x0080;
const int NPCMF_TRANSLUCENT = 0x0100;
const int NPCMF_SHIELDFRONT = 0x0200;
const int NPCMF_SHIELDLEFT = 0x0400;
const int NPCMF_SHIELDRIGHT = 0x0800;
const int NPCMF_SHIELDBACK = 0x1000;
const int NPCMF_HAMMERBREAK = 0x2000;
//Prevents moving in any direction
void NoMovement()
{
Link->InputUp = false; Link->PressUp = false;
Link->InputDown = false; Link->PressDown = false;
Link->InputLeft = false; Link->PressLeft = false;
Link->InputRight = false; Link->PressRight = false;
}
//Converts velocity into a direction.
int VelocityToDir(float x, float y)
{
if(x == 0 && y == 0) return -1;
else return RadianAngleDir8(RadianAngle(0, x, 0, y));
}
//Converts the x component of a velocity into a direction.
int XSpeedToDir(float x)
{
return VelocityToDir(x, 0);
}
//Converts the y component of a velocity into a direction.
int YSpeedToDir(float y)
{
return VelocityToDir(0, y);
}
//Takes a direction of movement and gets the xspeed.
float DirToXSpeed(int dir)
{
if(dir<4)
return Cond((dir*2)-5 < -1, 0, (dir*2)-5);
else
return Cond(dir<6, -1.5, 1.5);
}
//Takes a direction of movement and gets the yspeed.
float DirToYSpeed(int dir)
{
if(dir>7) dir = toggleBlock(dir);
if(dir < 2) return 0;
float ret = 1;
if(dir>=4) ret += .5;
return Cond(IsEven(dir), -ret, ret);
}
//Returns the angle in radians of a direction; used for weapon angles
float dirToRad(int dir)
{
dir = Clamp(dir, 0, 15);
if(dir<8) dir = toggleBlock(dir);
dir = (dir+2)%8;
return PI * dir / 4;
}
//Returns value from 0 to 360 rather than -180 to 180
float AnglePos(int x1, int y1, int x2, int y2)
{
float angle = ArcTan(x2-x1, y2-y1)*57.2958;
if(angle < 0)
angle += 360;
return angle;
}
//Returns the distance between the given Coordinate and Link's Center.
float DistanceLink(float x, float y)
{
return Distance(CenterLinkX(), CenterLinkY(), x, y);
}
//Returns the distance between the Link's Center and a pointer.
float DistanceLink(ffc f)
{
return Distance(CenterLinkX(), CenterLinkY(), CenterX(f), CenterY(f));
}
float DistanceLink(npc n)
{
return Distance(CenterLinkX(), CenterLinkY(), CenterX(n), CenterY(n));
}
float DistanceLink(lweapon l)
{
return Distance(CenterLinkX(), CenterLinkY(), CenterX(l), CenterY(l));
}
float DistanceLink(eweapon e)
{
return Distance(CenterLinkX(), CenterLinkY(), CenterX(e), CenterY(e));
}
//Converts 8-way direction to 4-way
int dir8ToDir4(int dir)
{
if(dir != Clamp(dir, 0, 15)) return -1;
dir &= 7;
if((dir & 4) == 0)
return dir;
else
return Cond(IsEven(dir), DIR_UP, DIR_DOWN);
}
//Returns the reverse of the given direction.
int reverseDir(int dir)
{
if(dir != Clamp(dir, 0, 15)) return -1;
return Cond(dir<8, OppositeDir(dir), ((dir+4)%8)+8);
}
//Toggles weapon blockability by adjusting its direction
int toggleBlock (int dir)
{
if(dir < 8) dir |= 8;
else dir &= ~8;
return dir;
}