PDA

View Full Version : Link Injured Animation (In Progress)



CJC
09-29-2013, 09:14 PM
You know how the classic set comes with 'hurt' tiles? Well I thought I'd find a script that could make the game actually USE them... but when I searched in the usual places I saw nothing.

So I took a shot at writing one myself.

NOTE: This is incomplete! Do not drop it into your ZQuest or angry leprechauns will steal your keyboard!



//Sets up a sprite to take the place of Link when he takes damage
//Used to create an injury animation.
//Injury tiles should be arranged in a column, in this order:
//North, South, West, East

//Sets the north-facing tile when Link is hurt on land (Change as needed)
const int TILE_GOTHURTLAND = 0;
//Sets the north-facing tile when Link is hurt in water (Change as needed)
const int TILE_GOTHURTWATER = 0;


int hurtTile; //Used for a calculation
int currentLTM; //Used to hold Link's cumulative LTM as we calculate it

//NOTE: This loop will not compile on its own, I intend to place it in
//a global script.
while (Link->Action == LA_GOTHURTLAND || Link->Action ==LA_GOTHURTWATER){
//Hides Link while he is hurt
Link->Invisible = true;

//Runs through all of Link's Items (HOPEFULLY) to collect their tile modifiers
for(int i=0, i<512, i++){
item tileModSearch = Link->Item[i];
currentLTM += tileModSearch->Extend;
}
if (Link->Action == LA_GOTHURTLAND){
//Draws the Link Hurt tile for land
hurtTile = TILE_GOTHURTLAND + (Clamp(Link->Dir,0,3) * 20) + currentLTM;
Screen->FastTile(0, Link->X, Link->Y, hurtTile, 6, 128);
else{
//Draws the Link Hurt tile for water
hurtTile = TILE_GOTHURTWATER + (Clamp(Link->Dir,0,4) * 20) + currentLTM;
Screen->FastTile(0, Link->X, Link->Y, hurtTile, 6, 128);
}
Waitframe();
}


This would be dumped somewhere into the global script.

I was wondering if this kind of loop could be made more efficient, or if there's some kind of function that can directly snatch Link's cumulative LTM. My recent studies of computer programming have driven me to want more elegant programming solutions. Should I extract the 'For' loop and establish it as a global method instead of embedding it in the middle like that? Since this segment of code will be within the non-terminating While() loop of the global function, would a regular 'if' loop be better than a 'while' loop? You know, things like that.


EDIT: Should I try to turn this into a generic utility function? Of the form:

LinkAnimation(int AnimationId, int StartingTile, bool RowOrColumn, bool LinkIsVisible)


If we could come up with something like that, we could shove this in a header file and make this sort of thing easier to implement.
...Come to think of it, I should go check some header files. Maybe somebody's done this already.

Chris Miller
09-29-2013, 09:30 PM
Neat. :D
You should do one for bosses too.