Jump to content

Photo

How to make AutoGhost enemies obey solidity


  • Please log in to reply
7 replies to this topic

#1 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 21 April 2012 - 09:20 PM

I'm working on this script. The enemies ignore solidity. It's getting me down. AutoGhost users, PLEASE HELP.

Whoever helps me fix this gets a free cookie and permission to use it as they please.

Test quest

CODE
//import "std.zh"
//import "string.zh"
//import "ghost.zh"

//Attributes
//Type: Walking enemy
//Step speed: How fast to move
//3 = Death Attr 1: How high to jump
//4 = Death Attr 2: How long to stand still
//5 = Death Attr 3: How long to move
//6 = Extra shots: Collision detection (0: intangible; 1: deals damage and can be killed)
//11 = MUST BE equal to GH_INVISIBLE_COMBO in ghost.zh
//12 = Script slot number (check as you're assigning this to an FFC slot)

//DO NOT ALTER THESE CONSTANTS.
const int ANIMAL_ATTRIB_JUMPHEIGHT = 2;
const int ANIMAL_ATTRIB_STANDTIME = 3;
const int ANIMAL_ATTRIB_MOVETIME = 4;
const int ANIMAL_ATTRIB_COLLDETECT = 5;

ffc script animalNPC{
    void run ( int enemyID ){
        //Initialize the autoghost 'enemy'
        npc ghost = Ghost_InitAutoGhost(this, enemyID, GHF_SET_DIRECTION | GHF_4WAY);
        int moveCounter = 0 + Rand(ghost->Attributes[ANIMAL_ATTRIB_STANDTIME]);
        bool moving = false;
        ghost->CollDetection = ghost->Attributes[ANIMAL_ATTRIB_COLLDETECT];
        int ghostStep = ghost->Step; //Save step speed
        int ghostZ = ghost->Z; //Save z position
        while ( true ){
        
            //If it is moving and on the ground
            if ( moving && ghost->Z == 0 ){
                ghost->Jump = ghost->Attributes[ANIMAL_ATTRIB_JUMPHEIGHT]; //Jump
            }
            
            //Move the ghost
            Ghost_Move( ghost->Dir, ghost->Step/100, 0 );
            
            //Increment move counter
            moveCounter++;
            if ( moving && moveCounter > ghost->Attributes[ANIMAL_ATTRIB_MOVETIME] ){
                moving = false;
                moveCounter = 0 + Rand(ghost->Attributes[ANIMAL_ATTRIB_MOVETIME])/10;
                ghost->Step = 0;
            }
            else if ( !moving && moveCounter > ghost->Attributes[ANIMAL_ATTRIB_STANDTIME] ){
                moving = true;
                moveCounter = 0 + Rand(ghost->Attributes[ANIMAL_ATTRIB_STANDTIME])/10;
                ghost->Dir = Rand(8);
                ghost->Step = ghostStep;
            }
            
            //Special waitframe for autoGhost scripts
            Ghost_Waitframe(this, ghost, true, true);
        }
    }
}

Edited by MoscowModder, 21 April 2012 - 10:22 PM.


#2 tox_von

tox_von

    Zelda Addict

  • Members
  • Real Name:Redgor
  • Location:Toxicville , Simcity

Posted 21 April 2012 - 09:46 PM

dont you need this for solids?

CODE
/Courtesy of Saffith/beefster09
   bool isSolid(int x, int y) {
    
     if(x<0 || x>255 || y<0 || y>175) return false;
     int mask=1111b;
      
     if(x % 16 < 8)
       mask &= 0011b;
     else
       mask &= 1100b;
    
     if(y % 16 < 8)
       mask &= 0101b;
     else
       mask &= 1010b;
    
     int ret = Screen->ComboS[ComboAt(x, y)] & mask;
     return (ret!=0);
  
   }


#3 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 21 April 2012 - 10:04 PM

1. Use the global variables from ghost.zh. Not the built in ones for npcs.
2. Use Ghost_Waitframe().
3. Ditch the part of the script that keeps it from leaving the screen. That's not needed.


QUOTE(tox_von @ Apr 21 2012, 08:46 PM) View Post

dont you need this for solids?

CODE
/Courtesy of Saffith/beefster09
   bool isSolid(int x, int y) {
    
     if(x<0 || x>255 || y<0 || y>175) return false;
     int mask=1111b;
      
     if(x % 16 < 8)
       mask &= 0011b;
     else
       mask &= 1100b;
    
     if(y % 16 < 8)
       mask &= 0101b;
     else
       mask &= 1010b;
    
     int ret = Screen->ComboS[ComboAt(x, y)] & mask;
     return (ret!=0);
  
   }



No. icon_deformed.gif

#4 tox_von

tox_von

    Zelda Addict

  • Members
  • Real Name:Redgor
  • Location:Toxicville , Simcity

Posted 21 April 2012 - 10:05 PM

if that doesnt work i also found this.

QUOTE
//This should allow any scripted object to easily mimic Link styled LOZ solidity collision
//checking, be it Link, FFCs, or enemies.
//Note - You should use full_tile=true if you don't want the upper eight pixels to overlap
//solid combos as per LOZ1 behavior.
bool CanWalk(int x, int y, int dir, int step, bool full_tile) {
int c=8;
int xx = x+15;
int yy = y+15;
if(full_tile) c=0;
if(dir==0) return !(y-step<0||Screen->isSolid(x,y+c-step)||Screen->isSolid(x+8,y+c-step)||Screen->isSolid(xx,y+c-step));
else if(dir==1) return !(yy+step>=176||Screen->isSolid(x,yy+step)||Screen->isSolid(x+8,yy+step)||Screen->isSolid(xx,yy+step));
else if(dir==2) return !(x-step<0||Screen->isSolid(x-step,y+c)||Screen->isSolid(x-step,y+c+7)||Screen->isSolid(x-step,yy));
else if(dir==3) return !(xx+step>=256||Screen->isSolid(xx+step,y+c)||Screen->isSolid(xx+step,y+c+7)||Screen->isSolid(xx+step,yy));
return false; //invalid direction
}


#5 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 21 April 2012 - 10:10 PM

It's not needed, solidity detection is built into the ghost.zh functions by default.

#6 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 21 April 2012 - 10:21 PM

Thanks, BB! Previously they did go off the screen, but I guess the normal ghost_waitframe handles that then?

Now another odd problem... all of a sudden, they stopped jumping. Ah, that part about AG-specific variables. Got it.

Edited by MoscowModder, 21 April 2012 - 10:25 PM.


#7 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 21 April 2012 - 10:22 PM

Use Ghost_Jump not ghost->Jump.

#8 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 21 April 2012 - 10:30 PM

I got it right before you mentioned it. Thanks!


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users