#include_function "lib\Ikareimu\System\Shield.dnh"
/******************************************
* Variables                               *
******************************************/

let OFF = 0;
let ON = 1;

let CollisionObj;
let CollisionState = ON;

/******************************************
* Public Functions                        *
******************************************/

// Starts a microthread to handle the shield
sub CollisionManager_Initialize {
  LoadUserShotData("lib/Ikareimu/Common/ShotDefinition.dnh");
  ObjCollision_create;
}

function ObjCollision_Happened(obj){
  return Collision_Obj_Obj(CollisionObj, obj);
}

function ObjCollision_SetState(state){
  CollisionState = state;
}

function ObjCollision_GetState(){
  return CollisionState;
}

sub CollisionManager_Run {
  ObjCollision_update;
}

sub CollisionManager_Finalize {
  Obj_Delete(CollisionObj);
}

/******************************************
* Private Functions                       *
******************************************/

sub ObjCollision_create {
  CollisionObj = Obj_Create(OBJ_SHOT);
  Obj_SetAngle(CollisionObj, 0);
  Obj_SetSpeed(CollisionObj, 0);
  Obj_SetAlpha(CollisionObj, 0);
  Obj_SetCollisionToPlayer(CollisionObj, false);
  Obj_SetCollisionToObject(CollisionObj, true);
  ObjShot_SetBombResist(CollisionObj, true);
  ObjShot_SetGraphic(CollisionObj, 255);
}

sub ObjCollision_update {
  Obj_SetPosition(CollisionObj, GetPlayerX, GetPlayerY);
  if(Shield_GetState == INACTIVE){
    CollisionState = OFF;
  }
  else {
    CollisionState = ON;
  }
}