Silverlight Game Design (Game): (11) Dream West Tour (Demo) of "The Unity of Heaven and Man" ②

Source: Internet
Author: User
Tags pow range silverlight

Whether it is a stand-alone game or a network game, the rich plot behind the NPC unknown work, some yell to sell drugs to sell weapons, some pet often mix around, more flexible can also like "Diablo", as a companion to help the enemy. The powerful game is inseparable from the high intelligence AI, while the AI behind the more sophisticated technology is hidden, the script system is its core. For friends who want to learn more about game scripts, I recommend reading script AI and scripting engine this article. To put it simply, the script is characterized by independence from the game's main program code, it allows the game designer, not the game programmer, to write and refine most of the game structure, and the player can easily dissolve into the script and create a whole new game world, all of which show the simplicity of the script magic beauty.

In this section, I'll add some elf NPCs to the fantasy Western world that I created in the previous section and attach some simple script ai to them to make the game seem more vibrant and fun.

In this article, which is an interaction with the embedded scripting language Lua & JavaScript, I have explained in detail how to implement Silverlight programs interacting with JavaScript scripts. So, first of all, we need to add a JavaScript script file in the Dream West Tour demo source, and call the script in the Index.htm page with the game demo embedded:

Next, we also add some of the wizard's own methods in the program to invoke the object as a script; Here I have added two methods: Continuous random speech and random running:

<summary>
Continuous Random Talk
</summary>
<param name= "Content" ></param>
[Scriptablemember]
public void Randomsay (string content) {
Dialog Dialog = new Dialog () {
Duration = 5,
Locatedspritewidth = Bodywidth,
top = Bodytop
};
This. Children.add (Dialog);
Dialog.completed + = (s, e) => {
This. Children.remove (s as Dialog);
HtmlPage.Window.Invoke ("Randomsay", this, new int[] {talkcontentcode});
};
Dialog. Show (content);
}

<summary>
Continuous random Running
</summary>
<param name= "StartX" > Walking range starting point x</param>
<param name= "Starty" > Walking range starting point y</param>
<param name= "EndX" > Walking range Endpoint x</param>
<param name= "EndY" > Walking range Endpoint y</param>
[Scriptablemember]
public void Randommoveto (int startx, int starty, int endx, int endY) {
Random Random = new Random ();
int x = random. Next (StartX, EndX);
int y = random. Next (Starty, EndY);
Point start = this. coordinate;
Point end = new Point (x, y);
This.destination = end;
Double spendtime = math.sqrt (Math.pow (end. X-start. X)/locatedscene.gridsize, 2) + Math.pow (end. Y-start. Y)/locatedscene.gridsize, 2)) * Speed * locatedscene.gridsize; Calculate the total mobile cost
PointAnimation pointanimation = new PointAnimation () {
to = end,
Duration = new Duration (Timespan.frommilliseconds (spendtime))
};
Storyboard.settarget (PointAnimation, this);
Storyboard.settargetproperty (PointAnimation, new PropertyPath ("coordinate"));
Move ();
Stopmovinganimation ();
Moveinganimation = new Storyboard ();
MOVEINGANIMATION.CHILDREN.ADD (PointAnimation);
Moveinganimation.completed + = (s, e) => {
Randommoveto (StartX, Starty, EndX, EndY);
};
Moveinganimation.begin ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.