/// <summary> /// find and apply a specified image from the pony's cache of them. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> private void LoadImage(PonyAction action, PonyDirection direction) { PonyImage image; // find the requested image from the cache. image = this.Image.Find(delegate(PonyImage img){ if (img.Action == action && img.Direction == direction) { return(true); } else { return(false); } }); if (image == null) { Trace.WriteLine(String.Format( "!! no image for {0} {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } ; // and apply it to the pony window. image.ApplyToPonyWindow(this.Window); }
/// <summary> /// this is called when the teleport (out) animation ends. it handles /// moving the pony across the screen and staging teleporting back in. /// </summary> public void TeleportStage() { int oldpos = (int)this.Window.Left; PonyDirection dir = PonyDirection.None; // yoink. this.Window.Hide(); // make sure she at least went some distance. do { this.Window.PlaceRandomlyX(); }while(Math.Abs(oldpos - this.Window.Left) < this.Window.Width); // if she teleported to the right, face right. left, left. // not technically correct as twilight has demonstrated the ability // to rapid teleport side to side facing inwards each time, but on // our 2d plane here this just looks nicer. if (oldpos - this.Window.Left <= 0) { dir = PonyDirection.Right; } else { dir = PonyDirection.Left; } // start the second half of the teleport sequence. this.TellWhatDo(PonyAction.Teleport2, dir); this.Window.AnimateOnce(); // boink. this.Window.Show(); }
public static Uri SelectImagePath(string name, PonyAction action, PonyDirection direction) { return new Uri( String.Format( "{0}Resources\\{1}\\{2}{3}.gif", AppDomain.CurrentDomain.BaseDirectory, name, action.ToString(), direction.ToString() ), UriKind.Absolute ); }
public static Uri SelectImagePath(string name, PonyAction action, PonyDirection direction) { return(new Uri( String.Format( "{0}Resources\\{1}\\{2}{3}.gif", AppDomain.CurrentDomain.BaseDirectory, name, action.ToString(), direction.ToString() ), UriKind.Absolute )); }
/// <summary> /// this does the work of making the pony traverse across the screen. /// it also detects if she has bumped into a wall (edge of the screen) /// and should change directions. /// /// if the pony has been put into Still mode then she will switch to /// the standing action when hitting the wall. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TrotTick(Object sender, EventArgs e) { PonyDirection direction = Direction; // figure out if she has wallfaced and needs to change directions. if (this.Direction == PonyDirection.Right) { if (((this.Window.Left + this.Window.Width) + 4) >= SystemParameters.PrimaryScreenWidth) { direction = PonyDirection.Left; } } else if (this.Direction == PonyDirection.Left) { if ((this.Window.Left - 4) <= 0) { direction = PonyDirection.Right; } } // update the window position. this.Window.Left += (4 * (int)direction); if (direction != this.Direction) { Trace.WriteLine(String.Format( ">> {0} has hit the {1} wall", this.Name, this.Direction.ToString() )); // if she was trotting even though she had been told to stand // still, now that she has hit the wall she will turn around, // stand there, and look pretty. if (this.Mode == PonyMode.Still) { this.TellWhatDo(PonyAction.Stand, direction, false); } // else about face and keep going like a boss. else { this.TellWhatDo(PonyAction.Trot, direction); } } }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// if she is devoted then she will not allow herself to be distracted /// until this action is done. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> /// <param name="devoted"></param> public void TellWhatDo(PonyAction action, PonyDirection direction, bool devoted) { if (devoted) { // she is devoted to doing this and will stop making decisions // for herself. this.PauseChoiceEngine(); } else { // after she does this she is free to make other choices on // her own. this.ResetChoiceTimer(); } this.TellWhatDo(action, direction); }
/// <summary> /// find and apply a specified image from the pony's cache of them. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> private void LoadImage(PonyAction action, PonyDirection direction) { PonyImage image; // find the requested image from the cache. image = this.Image.Find(delegate(PonyImage img){ if(img.Action == action && img.Direction == direction) return true; else return false; }); if(image == null) { Trace.WriteLine(String.Format( "!! no image for {0} {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; }; // and apply it to the pony window. image.ApplyToPonyWindow(this.Window); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// </summary> /// <param name="action"></param> /// <param name="direction"></param> public void TellWhatDo(PonyAction action, PonyDirection direction) { bool able = true; // if an invalid action was specified, then no. if(direction == PonyDirection.None || action == PonyAction.None) able = false; // if this is an action she is not configured to be able to do then // of course the answer is no. if(!this.CanDo(action)) able = false; if(!able) { Trace.WriteLine(String.Format( "!! {0} cannot {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } Trace.WriteLine(String.Format( ">> {0} will {1} to the {2}", this.Name, action.ToString(), direction.ToString() )); // if this is the first action our pony has done, then we also need to // spool the decision engine up. if(this.ChoiceTimer == null) { this.ChoiceTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Window.Dispatcher); this.ChoiceTimer.Tick += ChooseWhatDo; this.ResetChoiceTimer(); } // no need to muck with the image and window if we are doing more of the // same yeh? also check choicetimer as a means of "is this the first // action ever" to make sure the default gets loaded. if(action != this.Action || direction != this.Direction) { this.Action = action; this.Direction = direction; this.StartAction(); // reset the choice timer to a new interval based on the action // that just happened, but only if it was still enabled. if(this.ChoiceTimer.IsEnabled) this.ResetChoiceTimer(); } // spend the energy associated with this action. if(this.Mode != PonyMode.Clingy) this.EnergySpend(); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// if she is devoted then she will not allow herself to be distracted /// until this action is done. /// </summary> /// <param name="action"></param> /// <param name="direction"></param> /// <param name="devoted"></param> public void TellWhatDo(PonyAction action, PonyDirection direction, bool devoted) { if(devoted) { // she is devoted to doing this and will stop making decisions // for herself. this.PauseChoiceEngine(); } else { // after she does this she is free to make other choices on // her own. this.ResetChoiceTimer(); } this.TellWhatDo(action, direction); }
/////////////////////////////////////////////////////////////////////// // instance work ////////////////////////////////////////////////////// public PonyImage(string name, PonyAction action, PonyDirection direction) { this.Action = action; this.Direction = direction; this.Load(PonyImage.SelectImagePath(name,action,direction)); }
/// <summary> /// tell the pony exactly what to do (even if she is telling herself). /// </summary> /// <param name="action"></param> /// <param name="direction"></param> public void TellWhatDo(PonyAction action, PonyDirection direction) { bool able = true; // if an invalid action was specified, then no. if (direction == PonyDirection.None || action == PonyAction.None) { able = false; } // if this is an action she is not configured to be able to do then // of course the answer is no. if (!this.CanDo(action)) { able = false; } if (!able) { Trace.WriteLine(String.Format( "!! {0} cannot {1} {2}", this.Name, action.ToString(), direction.ToString() )); return; } Trace.WriteLine(String.Format( ">> {0} will {1} to the {2}", this.Name, action.ToString(), direction.ToString() )); // if this is the first action our pony has done, then we also need to // spool the decision engine up. if (this.ChoiceTimer == null) { this.ChoiceTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Window.Dispatcher); this.ChoiceTimer.Tick += ChooseWhatDo; this.ResetChoiceTimer(); } // no need to muck with the image and window if we are doing more of the // same yeh? also check choicetimer as a means of "is this the first // action ever" to make sure the default gets loaded. if (action != this.Action || direction != this.Direction) { this.Action = action; this.Direction = direction; this.StartAction(); // reset the choice timer to a new interval based on the action // that just happened, but only if it was still enabled. if (this.ChoiceTimer.IsEnabled) { this.ResetChoiceTimer(); } } // spend the energy associated with this action. if (this.Mode != PonyMode.Clingy) { this.EnergySpend(); } }
/////////////////////////////////////////////////////////////////////// // instance work ////////////////////////////////////////////////////// public PonyImage(string name, PonyAction action, PonyDirection direction) { this.Action = action; this.Direction = direction; this.Load(PonyImage.SelectImagePath(name, action, direction)); }