Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////
- /// Autohost DeadRock NPC ///
- /// 20-Nov-2016 ///
- /// v0.6.0 ///
- /// By: ZoriaRPG ///
- /////////////////////////////
- const int NPC_DEADROCK_STONETIME = 300; //Time in frames that DeadRock will be petrified.
- const int NPC_DEADROCK_TURNTIME = 48; //The 'halttime' value for Ghost_HaltingWalk4()
- const int NPC_DEADROCK_TILE = 10200; //Tile for DeadRock in stoned state.
- const int NPC_DEADROCK_LAYER = 2; //Layer of drawn 'a[NPC_DEADROCK_ROCK]' tile.
- const int NPC_DEADROCK_CSET = -1; //Set to 0 or higher to use a fixed CSet.
- const int NPC_DEADROCK_DIST = 8; //Radius distant from enemy, when in a stoned state, to block Link's inputs.
- const int NPC_DEADROCK_DIST_HITDIR = 24;
- const int NPC_DEADROCK_WEAPONDIST = 12; //Distance for collisio of the weapon and the npc when in a a[NPC_DEADROCK_ROCK] state.
- const int NPC_DEADROCK_SFX_CLINK = 100;
- //DeadRock ffc internal array a[] indices:
- const int NPC_DEADROCK_WALK = 0;
- const int NPC_DEADROCK_Q = 1;
- const int NPC_DEADROCK_W = 2;
- const int NPC_DEADROCK_ROCK = 3;
- const int NPC_DEADROCK_LASTHP = 4;
- const int NPC_DEADROCK_ORIGHP = 5;
- const int NPC_DEADROCK_RANDOM_HITDIR = 6;
- ffc script DeadRock{
- void run(int enem_id){
- npc ghost = Ghost_InitAutoGhost(this,enem_id);
- Ghost_SetFlag(GHF_FULL_TILE_MOVEMENT); //Will not move onto partially solid combos.
- Ghost_SetFlag(GHF_4WAY); //4-Way walking.
- lweapon l;
- int a[7]={-1};
- a[NPC_DEADROCK_ORIGHP] = ghost->HP;
- a[NPC_DEADROCK_RANDOM_HITDIR] = ghost->Attributes[11];
- //walk = a[NPC_DEADROCK_WALK]; q = a[NPC_DEADROCK_Q]; w = a[NPC_DEADROCK_W]; rock = a[NPC_DEADROCK_ROCK]; lasthp = a[NPC_DEADROCK_LASTHP]
- while(true){
- a[NPC_DEADROCK_LASTHP] = ghost->HP;
- //Handle movement.
- a[NPC_DEADROCK_WALK] = Ghost_HaltingWalk4(
- a[NPC_DEADROCK_WALK],
- ghost->Step,
- ghost->Rate,
- ghost->Homing,
- ghost->Hunger,
- ghost->Haltrate,
- NPC_DEADROCK_TURNTIME);
- //Check for collision with items
- for ( a[NPC_DEADROCK_Q] = Screen->NumLWeapons(); a[NPC_DEADROCK_Q] >= 0; a[NPC_DEADROCK_Q]-- ) {
- l = Screen->LoadLWeapon(a[NPC_DEADROCK_Q]);
- if ( Collision(ghost,l) ) { //&& ghost->HP < a[NPC_DEADROCK_LASTHP]
- //if *anything hits him...
- //Turn to stone:
- //Draw flesh-to-stone transformation anim.
- for ( a[NPC_DEADROCK_Q] = 0; a[NPC_DEADROCK_Q] < 12; a[NPC_DEADROCK_Q]++ ){
- if ( a[NPC_DEADROCK_Q] % 2 == 0 ) {
- for ( a[NPC_DEADROCK_W] = 0; a[NPC_DEADROCK_W] < 5; a[NPC_DEADROCK_W]++ ) {
- ghost->DrawXOffset = ghost->X;
- Ghost_WaitframeLight(this, ghost);
- }
- }
- else {
- for ( a[NPC_DEADROCK_W] = 0; a[NPC_DEADROCK_W] < 5; a[NPC_DEADROCK_W]++ ) {
- ghost->DrawXOffset = -200;
- if ( NPC_DEADROCK_CSET >= 0 ) Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, NPC_DEADROCK_CSET, OP_OPAQUE);
- else Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, ghost->CSet, OP_OPAQUE);
- Ghost_WaitframeLight(this, ghost);
- }
- }
- }
- a[NPC_DEADROCK_ROCK] = NPC_DEADROCK_STONETIME;
- }
- }
- //While he's stoned...
- while (a[NPC_DEADROCK_ROCK]--) {
- //Check for weapon collision and do effects by weapon type
- for ( a[NPC_DEADROCK_Q] = Screen->NumLWeapons(); a[NPC_DEADROCK_Q] >= 0; a[NPC_DEADROCK_Q]-- ) {
- l = Screen->LoadLWeapon(a[NPC_DEADROCK_Q]);
- if ( _____DistXY(ghost,l,NPC_DEADROCK_WEAPONDIST) ) {
- if ( l->ID == LW_HOOKSHOT || l->ID == LW_BRANG ) { l->DeadState = WDS_BOUNCE; Game->PlaySound(NPC_DEADROCK_SFX_CLINK); }
- if ( l->ID == LW_BEAM || l->ID >= LW_SCRIPT1 ) l->DeadState = WDS_DEAD;
- if ( l->ID == LW_ARROW ) { l->DeadState = WDS_DEAD; Game->PlaySound(NPC_DEADROCK_SFX_CLINK); }
- if ( l->ID == LW_SWORD || l->ID == LW_HAMMER || l->ID == LW_WAND ) Game->PlaySound(NPC_DEADROCK_SFX_CLINK);
- }
- }
- //Move the real npc offscreen
- ghost->DrawXOffset = -200; ghost->HitXOffset = -200;
- //Draw the a[NPC_DEADROCK_ROCK] tile
- if ( NPC_DEADROCK_CSET >= 0 ) Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, NPC_DEADROCK_CSET, OP_OPAQUE);
- else Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, ghost->CSet, OP_OPAQUE);
- //Kill inputs if Link tries to pass through DeadRock or damage to Link would push him past DeadRock...
- //Link is on the left side...
- if ( _____LeftOf(ghost) && Link->CollDetection ) {
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
- if ( Link->PressRight || Link->InputRight ) {
- Link->PressRight = false; Link->InputRight = false;
- }
- }
- //Prevent Link from damage boosting past it.
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_RIGHT ) {
- if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
- else {
- do {
- Link->HitDir = Rand(4);
- } while(Link->HitDir == DIR_RIGHT);
- }
- }
- }
- //Link is on the right side...
- if ( _____RightOf(ghost) && Link->CollDetection ) {
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
- if ( Link->PressLeft || Link->InputLeft ) {
- Link->PressLeft = false; Link->InputLeft = false;
- }
- }
- //Prevent Link from damage boosting past it.
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_LEFT ) {
- if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
- else {
- do {
- Link->HitDir = Rand(4);
- } while(Link->HitDir == DIR_LEFT);
- }
- }
- }
- //Link is _____Above...
- if ( _____Above(ghost) && Link->CollDetection ) {
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
- if ( Link->PressDown || Link->InputDown ) {
- Link->PressDown = false; Link->InputDown = false;
- }
- }
- //Prevent Link from damage boosting past it.
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_DOWN ) {
- if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
- else {
- //do {
- // hitdir = Rand(4);
- //} while(hitdir == DIR_DOWN);
- //Link->HitDir = hitdir;
- do {
- Link->HitDir = Rand(4);
- } while(Link->HitDir == DIR_DOWN);
- }
- }
- }
- //Link is _____Below...
- if ( _____Below(ghost) && Link->CollDetection ) {
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
- if ( Link->PressUp || Link->InputUp ) {
- Link->PressUp = false; Link->InputUp = false;
- }
- }
- //Prevent Link from damage boosting past it.
- if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_UP ) {
- if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
- else {
- do {
- Link->HitDir = Rand(4);
- } while(Link->HitDir == DIR_UP);
- }
- }
- }
- Ghost_WaitframeLight(this, ghost);
- }
- //Deadrock is no longer stoned. Restore him...
- ghost->HitXOffset = ghost->X;
- ghost->DrawXOffset = -200;
- ghost->HP = a[NPC_DEADROCK_ORIGHP];
- Ghost_Waitframe(this,ghost,true,true);
- }
- }
- //Embed:
- bool _____DistXY(npc b, int distance) {
- int distx; int disty;
- if ( Link->X > b->X ) distx = Link->X - b->X;
- else distx = b->X - Link->X;
- if ( Link->Y > b->Y ) disty = Link->Y - b->Y;
- else disty = b->Y - Link->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____DistXY(ffc b, int distance) {
- int distx; int disty;
- if ( Link->X > b->X ) distx = Link->X - b->X;
- else distx = b->X - Link->X;
- if ( Link->Y > b->Y ) disty = Link->Y - b->Y;
- else disty = b->Y - Link->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____DistXY(lweapon a, ffc b, int distance) {
- int distx; int disty;
- if ( a->X > b->X ) distx = a->X - b->X;
- else distx = b->X - a->X;
- if ( a->Y > b->Y ) disty = a->Y - b->Y;
- else disty = b->Y - a->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____DistXY(lweapon a, npc b, int distance) {
- int distx; int disty;
- if ( a->X > b->X ) distx = a->X - b->X;
- else distx = b->X - a->X;
- if ( a->Y > b->Y ) disty = a->Y - b->Y;
- else disty = b->Y - a->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____DistXY(npc a, lweapon b, int distance) {
- int distx; int disty;
- if ( a->X > b->X ) distx = a->X - b->X;
- else distx = b->X - a->X;
- if ( a->Y > b->Y ) disty = a->Y - b->Y;
- else disty = b->Y - a->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____DistXY(ffc a, lweapon b, int distance) {
- int distx; int disty;
- if ( a->X > b->X ) distx = a->X - b->X;
- else distx = b->X - a->X;
- if ( a->Y > b->Y ) disty = a->Y - b->Y;
- else disty = b->Y - a->Y;
- return ( distx <= distance && disty <= distance );
- }
- bool _____Above(npc n){ return Link->Y < n->Y; }
- bool _____Below(npc n){ return Link->Y > n->Y; }
- bool _____LeftOf(npc n){ return Link->X < n->X; }
- bool _____RightOf(npc n){ return Link->X > n->X; }
- bool _____Above(ffc n){ return Link->Y < n->Y; }
- bool _____Below(ffc n){ return Link->Y > n->Y; }
- bool _____LeftOf(ffc n){ return Link->X < n->X; }
- bool _____RightOf(ffc n){ return Link->X > n->X; }
- bool _____LinkFacing(ffc f){
- if ( Link->Dir == DIR_UP && Link->Y > f->Y ) return true;
- if ( Link->Dir == DIR_DOWN && Link->Y < f->Y ) return true;
- if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true;
- if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true;
- return false;
- }
- bool _____LinkFacing(npc f){
- if ( Link->Dir == DIR_UP && Link->Y > f->Y ) return true;
- if ( Link->Dir == DIR_DOWN && Link->Y < f->Y ) return true;
- if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true;
- if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement