Queex's Useful Things

Need help with using DizzyAGE then look here
Post Reply
Queex
Hard Boiled Egg
Posts: 124
Joined: Thu Oct 22, 2009 5:04 pm

Queex's Useful Things

Post by Queex » Thu Nov 05, 2009 1:14 am

Some of the more reusable things I'm using. They may come in handy for someone, or wiser heads may spot problems with them.

Thread on background colour changes.
Thread on floaty text.

Function that gives an item to Dizzy, or drops it at his feet if his inventory is full:

Code: Select all

// Give to player or drop on ground if inventory full
func GiveOrDrop(idx)
{
  if(InventoryAdd(idx)==0){
    ObjSet(idx,O_X,PlayerGet(P_ X) -8);
    ObjSet(idx,O_Y,PlayerGet(P_Y)-4);
    ObjSet(idx,O_DISABLE,0);
  }
}
A line to add to DoPickupObject(idx) for items to avoid embarrassing disappearances behind scenery when they're dropped.

Code: Select all

ObjSet(idx, O_LAYER,5); // move object to player layer
Two simple AI routines- they don't do anything that can't also be achieved with AIUpdateTrain, but I find them handy for very simple movement patterns without having to set up waypoints.

Code: Select all

/////////////////////////////////////////////////////////////////////////////////
// IN: int; idx; object index
// Walker AI
// Moves left and right between two positions.
// O_USER = left x value
// O_USER+1 = right x value
// O_USER+2 = speed
// O_USER+3 = disable_flip, 0 = do flip, 1 = no flip
// O_STATUS = direction 0=right, 1=left (also determines flip)
///////////////////////////////////////////////////////////////////////////////
func AIUpdateWalker(idx)
{
  if(idx==-1) return;
  if(ObjGet(idx,O_DISABLE)) return;
  if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
  x = ObjGet(idx,O_ X) ;
  speed=ObjGet(idx,O_USER+2);
  if(speed==0) speed=4;//default speed
  if(ObjGet(idx,O_STATUS)==0) //right
  {
    tx=ObjGet(idx,O_USER+1);
    if(x<tx)
      x+=speed;
    else {
      ObjSet(idx,O_STATUS,1);
      if(ObjGet(idx,O_USER+3)==0)
        ObjSet(idx,O_FLIP,1);
    }
  } else {
    tx=ObjGet(idx,O_USER);
    if(x>tx)
      x-=speed;
    else {
      ObjSet(idx,O_STATUS,0);
      if(ObjGet(idx,O_USER+3)==0)
        ObjSet(idx,O_FLIP,0);
    }
  }
  ObjSet(idx,O_X,x);
}

/////////////////////////////////////////////////////////////////////////////////
// IN: int; idx; object index
// Walker AI
// Moves left and right between two positions.
// O_USER = top y value
// O_USER+1 = bottom y value
// O_USER+2 = speed
// O_STATUS = direction 0=down, 1=up
///////////////////////////////////////////////////////////////////////////////
func AIUpdateDescender(idx)
{
  if(idx==-1) return;
  if(ObjGet(idx,O_DISABLE)) return;
  if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
  y = ObjGet(idx,O_Y);
  speed=ObjGet(idx,O_USER+2);
  if(speed==0) speed=4;//default speed
  if(ObjGet(idx,O_STATUS)==0) //down
  {
    ty=ObjGet(idx,O_USER+1);
    if(y<ty)
      y+=speed;
    else {
      ObjSet(idx,O_STATUS,1);
      if(ObjGet(idx,O_USER+3)==0)
        ObjSet(idx,O_FLIP,1);
    }
  } else {
    ty=ObjGet(idx,O_USER);
    if(y>ty)
      y-=speed;
    else {
      ObjSet(idx,O_STATUS,0);
      if(ObjGet(idx,O_USER+3)==1)
        ObjSet(idx,O_FLIP,0);
    }
  }
  ObjSet(idx,O_Y,y);
}
- Lost Temple Dizzy -
- Iron Tower Dizzy -

Post Reply