/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public override void ParseTasks(Bullet bullet) { //set the number of times to repeat this action var actionNode = Node as ActionNode; Debug.Assert(null != actionNode); RepeatNumMax = actionNode.RepeatNum(this, bullet); //is this an actionref task? if (ENodeName.actionRef == Node.Name) { //add a sub task under this one for the referenced action ActionRefNode myActionRefNode = Node as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } //call the base class base.ParseTasks(bullet); }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { bullet.MyBulletManager.Trigger(bullet, Flag); TaskFinished = true; return ERunStatus.End; }
/// <summary> /// Init this task and all its sub tasks. /// This method should be called AFTER the nodes are parsed, but BEFORE run is called. /// </summary> /// <param name="bullet">the bullet this dude is controlling</param> public override void InitTask(Bullet bullet) { //Init task is being called on a RepeatTask, which means all the sequence nodes underneath this one need to be reset //Call the HardReset method of the base class HardReset(bullet); }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //remove the bullet via the bullet manager interface IBulletManager manager = bullet.MyBulletManager; Debug.Assert(null != manager); manager.RemoveBullet(bullet); return ERunStatus.End; }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { if (_soundName.Contains("+")) { SoundEngine.PlayRandomClip(_soundName.Split('+')); } else { SoundEngine.PlayClip(_soundName); } return ERunStatus.End; }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { Duration -= 1.0f * bullet.TimeSpeed * TimeFix.Delta; if (Duration >= 0.0f && startDuration > 1f) // 1 frame duration should not be affected by delta time { return ERunStatus.Stop; } else { TaskFinished = true; return ERunStatus.End; } }
/// <summary> /// Get the number of times this action should be repeated. /// </summary> /// <param name="myTask">the task to get the number of repeat times for</param> /// <returns>The number of times to repeat this node, as specified by a parent Repeat node.</returns> public int RepeatNum(ActionTask myTask, Bullet bullet) { if (null != ParentRepeatNode) { //Get the equation value of the repeat node return (int)ParentRepeatNode.GetChildValue(ENodeName.times, myTask, bullet); } else { //no repeat nodes, just repeat it once return 1; } }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { Duration -= 1.0f * bullet.TimeSpeed; if (Duration >= 0.0f) { return ERunStatus.Stop; } else { TaskFinished = true; return ERunStatus.End; } }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { bullet.Speed += SpeedChange; Duration -= 1.0f * bullet.TimeSpeed; if (Duration <= 0.0f || startDuration <= 1) { TaskFinished = true; return ERunStatus.End; } else { return ERunStatus.Continue; } }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { bullet.Speed += GetSpeed(bullet); RunDelta += 1.0f * bullet.TimeSpeed; if (Duration <= RunDelta) { TaskFinished = true; return ERunStatus.End; } else { //since this task isn't finished, run it again next time return ERunStatus.Continue; } }
public override ERunStatus Run(Bullet bullet) { //change the direction of the bullet by the correct amount bullet.Direction += DirectionChange; //decrement the amount if time left to run and return End when this task is finished Duration -= 1.0f * bullet.TimeSpeed; if (Duration <= 0.0f) { TaskFinished = true; return ERunStatus.End; } else { //since this task isn't finished, run it again next time return ERunStatus.Continue; } }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //Add the acceleration to the bullet bullet.Acceleration += Acceleration; //decrement the amount if time left to run and return End when this task is finished Duration -= 1.0f * bullet.TimeSpeed * TimeFix.Delta; if (Duration <= 0.0f || startDuration <= 1) { TaskFinished = true; return ERunStatus.End; } else { //since this task isn't finished, run it again next time return ERunStatus.Continue; } }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //run the action until we hit the limit while (RepeatNum < RepeatNumMax) { ERunStatus runStatus = base.Run(bullet); //What was the return value from running all teh child actions? switch (runStatus) { case ERunStatus.End: { //The actions completed successfully, initialize everything and run it again RepeatNum++; //reset all the child tasks foreach (BulletMLTask task in ChildTasks) { task.InitTask(bullet); } } break; case ERunStatus.Stop: { //Something in the child tasks paused this action return runStatus; } default: { //One of the child tasks needs to keep running next frame return ERunStatus.Continue; } } } //if it gets here, all the child tasks have been run the correct number of times TaskFinished = true; return ERunStatus.End; }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public override void ParseTasks(Bullet bullet) { //is this an actionref task? if (ENodeName.actionRef == Node.Name) { //add a sub task under this one for the referenced action ActionRefNode myActionRefNode = Node as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } //call the base class base.ParseTasks(bullet); }
void Start() { // Read pattern file // We can optimize this later, making it read // every pattern once and storing it somewhere pattern = new BulletPattern(); //pattern.ParseXML(Application.dataPath + "/BulletPatterns/" + PatternFile.name + ".xml"); //pattern.ParseXML(PatternFile.name + ".xml"); pattern.ParseXML (patternFile); // Find the bullet manager // (we need this for the root bullet) BulletManagerScript bManager = FindObjectOfType<BulletManagerScript>(); // Instantiate root bullet rootBullet = new BulletObject(bManager); // Set its initial position rootBullet.X = transform.position.x; rootBullet.Y = transform.position.y; // Assign its pattern rootBullet.InitTopNode(pattern.RootNode); }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { //set the length of time to run this dude startDuration = Node.GetChildValue(ENodeName.term, this); //check for divide by 0 if (0.0f == startDuration) { startDuration = 1.0f; } float ratio = TimeFix.Framerate / 60f; startDuration *= ratio; Duration = startDuration; switch (Node.GetChild(ENodeName.speed).NodeType) { case ENodeType.sequence: { SpeedChange = Node.GetChildValue(ENodeName.speed, this); } break; case ENodeType.relative: { SpeedChange = Node.GetChildValue(ENodeName.speed, this) / Duration; } break; default: { SpeedChange = (Node.GetChildValue(ENodeName.speed, this) - bullet.Speed) / Duration; } break; } }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { RepeatNum = 0; }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { //set the accelerataion we are gonna add to the bullet startDuration = Node.GetChildValue(ENodeName.term, this); //check for divide by 0 if (0.0f == startDuration) { startDuration = 1.0f; } Duration = startDuration; //Get the horizontal node HorizontalNode horiz = Node.GetChild(ENodeName.horizontal) as HorizontalNode; if (null != horiz) { //Set the x component of the acceleration switch (horiz.NodeType) { case ENodeType.sequence: { //Sequence in an acceleration node means "add this amount every frame" _acceleration.x = horiz.GetValue(this); } break; case ENodeType.relative: { //accelerate by a certain amount _acceleration.x = horiz.GetValue(this) / Duration; } break; default: { //accelerate to a specific value _acceleration.x = (horiz.GetValue(this) - bullet.Acceleration.x) / Duration; } break; } } //Get the vertical node VerticalNode vert = Node.GetChild(ENodeName.vertical) as VerticalNode; if (null != vert) { //set teh y component of the acceleration switch (vert.NodeType) { case ENodeType.sequence: { //Sequence in an acceleration node means "add this amount every frame" _acceleration.y = vert.GetValue(this); } break; case ENodeType.relative: { //accelerate by a certain amount _acceleration.y = vert.GetValue(this) / Duration; } break; default: { //accelerate to a specific value _acceleration.y = (vert.GetValue(this) - bullet.Acceleration.y) / Duration; } break; } } }
protected override void SetupTask(Bullet bullet) { _soundName = Node.Text; }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //Create the new bullet IBullet newBullet = bullet.MyBulletManager.CreateBullet(); if (newBullet == null) { //wtf did you do??? TaskFinished = true; return ERunStatus.End; } //set the location of the new bullet newBullet.X = bullet.X; newBullet.Y = bullet.Y; //set the direction of the new bullet newBullet.Direction = FireDirection; //set teh speed of the new bullet newBullet.Speed = FireSpeed; //initialize the bullet with the bullet node stored in the Fire node FireNode myFireNode = Node as FireNode; Debug.Assert(null != myFireNode); newBullet.InitNode(myFireNode.BulletDescriptionNode); //set the owner of all the top level tasks for the new bullet to this dude foreach (BulletMLTask task in newBullet.Tasks) { task.Owner = this; } TaskFinished = true; return ERunStatus.End; }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public virtual ERunStatus Run(Bullet bullet) { //run all the child tasks TaskFinished = true; for (int i = 0; i < ChildTasks.Count; i++) { //is the child task finished running? if (!ChildTasks[i].TaskFinished) { //Run the child task... ERunStatus childStaus = ChildTasks[i].Run(bullet); if (childStaus == ERunStatus.Stop) { //The child task is paused, so it is not finished TaskFinished = false; return childStaus; } else if (childStaus == ERunStatus.Continue) { //child task needs to do some more work TaskFinished = false; } } } return (TaskFinished ? ERunStatus.End : ERunStatus.Continue); }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public virtual void ParseTasks(Bullet bullet) { if (null == bullet) { throw new NullReferenceException("bullet argument cannot be null"); } foreach (BulletMLNode childNode in Node.ChildNodes) { ParseChildNode(childNode, bullet); } }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public virtual void ParseChildNode(BulletMLNode childNode, Bullet bullet) { Debug.Assert(null != childNode); Debug.Assert(null != bullet); //construct the correct type of node switch (childNode.Name) { case ENodeName.repeat: { //convert the node to an repeatnode RepeatNode myRepeatNode = childNode as RepeatNode; //create a placeholder bulletmltask for the repeat node RepeatTask repeatTask = new RepeatTask(myRepeatNode, this); //parse the child nodes into the repeat task repeatTask.ParseTasks(bullet); //store the task ChildTasks.Add(repeatTask); } break; case ENodeName.action: { //convert the node to an ActionNode ActionNode myActionNode = childNode as ActionNode; //create the action task ActionTask actionTask = new ActionTask(myActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } break; case ENodeName.actionRef: { //convert the node to an ActionNode ActionRefNode myActionNode = childNode as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionNode, this); //add the params to the action task for (int i = 0; i < childNode.ChildNodes.Count; i++) { actionTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet)); } //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } break; case ENodeName.changeSpeed: { ChildTasks.Add(new ChangeSpeedTask(childNode as ChangeSpeedNode, this)); } break; case ENodeName.changeDirection: { ChildTasks.Add(new ChangeDirectionTask(childNode as ChangeDirectionNode, this)); } break; case ENodeName.fire: { //convert the node to a fire node FireNode myFireNode = childNode as FireNode; //create the fire task FireTask fireTask = new FireTask(myFireNode, this); //parse the children of the fire node into the task fireTask.ParseTasks(bullet); //store the task ChildTasks.Add(fireTask); } break; case ENodeName.fireRef: { //convert the node to a fireref node FireRefNode myFireNode = childNode as FireRefNode; //create the fire task FireTask fireTask = new FireTask(myFireNode.ReferencedFireNode, this); //add the params to the fire task for (int i = 0; i < childNode.ChildNodes.Count; i++) { fireTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet)); } //parse the children of the action node into the task fireTask.ParseTasks(bullet); //store the task ChildTasks.Add(fireTask); } break; case ENodeName.wait: { ChildTasks.Add(new WaitTask(childNode as WaitNode, this)); } break; case ENodeName.vanish: { ChildTasks.Add(new VanishTask(childNode as VanishNode, this)); } break; case ENodeName.accel: { ChildTasks.Add(new AccelTask(childNode as AccelNode, this)); } break; } }
/// <summary> /// Init this task and all its sub tasks. /// This method should be called AFTER the nodes are parsed, but BEFORE run is called. /// </summary> /// <param name="bullet">the bullet this dude is controlling</param> public virtual void InitTask(Bullet bullet) { TaskFinished = false; foreach (BulletMLTask task in ChildTasks) { task.InitTask(bullet); } SetupTask(bullet); }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { //set the time length to run this dude Duration = Node.GetChildValue(ENodeName.term, this); //check for divide by 0 if (0.0f == Duration) { Duration = 1.0f; } //Get the amount to change direction from the nodes DirectionNode dirNode = Node.GetChild(ENodeName.direction) as DirectionNode; float value = dirNode.GetValue(this) * (float)Mathf.PI / 180.0f; //also make sure to convert to radians //How do we want to change direction? ENodeType changeType = dirNode.NodeType; switch (changeType) { case ENodeType.sequence: { //We are going to add this amount to the direction every frame DirectionChange = value; } break; case ENodeType.absolute: { //We are going to go in the direction we are given, regardless of where we are pointing right now DirectionChange = value - bullet.Direction; } break; case ENodeType.relative: { //The direction change will be relative to our current direction DirectionChange = value; } break; default: { //the direction change is to aim at the enemy DirectionChange = ((value + bullet.GetAimDir()) - bullet.Direction); } break; } //keep the direction between 0 and 360 if (DirectionChange > Mathf.PI) { DirectionChange -= 2 * (float)Mathf.PI; } else if (DirectionChange < -Mathf.PI) { DirectionChange += 2 * (float)Mathf.PI; } //The sequence type of change direction is unaffected by the duration if (changeType != ENodeType.sequence) { //Divide by the duration so we ease into the direction change DirectionChange /= Duration; } }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { //get the direction to shoot the bullet //is this the first time it has ran? If there isn't a sequence node, we don't care! if (InitialRun || (null == SequenceDirectionTask)) { //do we have an initial direction node? if (null != InitialDirectionTask) { //Set the fire direction to the "initial" value float newBulletDirection = InitialDirectionTask.GetNodeValue(bullet) * (float)Math.PI / 180.0f; switch (InitialDirectionTask.Node.NodeType) { case ENodeType.absolute: { //the new bullet points right at a particular direction FireDirection = newBulletDirection; } break; case ENodeType.relative: { //the new bullet direction will be relative to the old bullet FireDirection = newBulletDirection + bullet.Direction; } break; default: { //aim the bullet at the player FireDirection = newBulletDirection + bullet.GetAimDir(); } break; } } else { //There isn't an initial direction task, so just aim at the bad guy. //aim the bullet at the player FireDirection = bullet.GetAimDir(); } } else if (null != SequenceDirectionTask) { //else if there is a sequence node, add the value to the "shoot direction" FireDirection += SequenceDirectionTask.GetNodeValue(bullet) * (float)Math.PI / 180.0f; } //Set the speed to shoot the bullet //is this the first time it has ran? If there isn't a sequence node, we don't care! if (InitialRun || (null == SequenceSpeedTask)) { //do we have an initial speed node? if (null != InitialSpeedTask) { //set the shoot speed to the "initial" value. float newBulletSpeed = InitialSpeedTask.GetNodeValue(bullet); switch (InitialSpeedTask.Node.NodeType) { case ENodeType.relative: { //the new bullet speed will be relative to the old bullet FireSpeed = newBulletSpeed + bullet.Speed; } break; default: { //the new bullet shoots at a predeterminde speed FireSpeed = newBulletSpeed; } break; } } else { //there is no initial speed task, use the old dude's speed FireSpeed = bullet.Speed; } } else if (null != SequenceSpeedTask) { //else if there is a sequence node, add the value to the "shoot direction" FireSpeed += SequenceSpeedTask.GetNodeValue(bullet); } //make sure the direction is between 0 and 359 while (FireDirection > Math.PI) { FireDirection -= (2.0f * (float)Math.PI); } while (-Math.PI > FireDirection) { FireDirection += (2.0f * (float)Math.PI); } //make sure we don't overwrite the initial values if we aren't supposed to NumTimesInitialized++; }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected virtual void SetupTask(Bullet bullet) { //overload in child classes }
/// <summary> /// Gets the node value. /// </summary> /// <returns>The node value.</returns> public float GetNodeValue(Bullet bullet) { return Node.GetValue(this, bullet); }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public override void ParseTasks(Bullet bullet) { if (null == bullet) { throw new NullReferenceException("bullet argument cannot be null"); } foreach (BulletMLNode childNode in Node.ChildNodes) { ParseChildNode(childNode, bullet); } //Setup all the direction nodes GetDirectionTasks(this); GetDirectionTasks(BulletRefTask); //setup all the speed nodes GetSpeedNodes(this); GetSpeedNodes(BulletRefTask); }
/// <summary> /// This gets called when nested repeat nodes get initialized. /// </summary> /// <param name="bullet">Bullet.</param> public virtual void HardReset(Bullet bullet) { TaskFinished = false; foreach (BulletMLTask task in ChildTasks) { task.HardReset(bullet); } SetupTask(bullet); }
/// <summary> /// this sets up the task to be run. /// </summary> /// <param name="bullet">Bullet.</param> protected override void SetupTask(Bullet bullet) { Duration = Node.GetValue(this, bullet.MyBulletManager); }