C # development Wpf/silverlight animation and games series Tutorials (Game Course): (24)

Source: Internet
Author: User
Tags tostring silverlight

C # development Wpf/silverlight animation and games series Tutorials (Game Course): (24) be careful! Monsters in the front are haunted.

This is the end of the game's daemon framework, so let's experience the magical effects it brings.

A quiet evening, the protagonist leisurely swinging its handsome hair ran alone in Lin Yin Avenue. How can we know that it is late to enter the territory of the moon, Hey, our story begins here: Be careful, the monster in front of haunt!

Really do not have the heart to let the protagonist has a martial arts and nowhere to display, this section in order to no longer let it lonely, I will add to the game lovely goblin sister with the companion:

Like I've seen it somewhere before? Yes, that's her, cutie. (Monster in Qxgameengine, ^_^ | | No wonder it looks familiar.

The Goblin monster belongs to the wizard type, so to make it appear in the game, we only need to create an instance of Qxspirit; Here I add a brush-strange method Initmonster, then loop Add the Monster Wizard instance and parameters:

qxspirit[] Monster

///<summary>

///initialize monster (brush monster)

///</summary>

///<param name= "num" > Monster number ;/param>

private void initmonster (int num) {

Monster = new Qxspirit[num];

Random Random = new Random ()//test, random number coordinate

for (int i = 0; i < num; i++) {

if (Carrier.findna Me ("Magicer" + i.tostring ()) = = null) {

Monster[i] = new Qxspirit ();

Monster[i]. Name = "Magicer" + i.tostring ();

Carrier.registername (Monster[i]. Name, Monster[i]);

Monster[i]. EQUIPMENT[0] = 100;

Monster[i]. EQUIPMENT[1] = 0;

...

Monster[i]. X = 2000-random. Next (1000);

Monster[i]. Y = 1500-random. Next (1000);

...

Carrier.Children.Add (Monster[i]);

}

}

}

The code is too much I will not list, the following I extract some of the important parameters to explain. First I define a random type random function for the generation of random numbers, and then judge whether every named Sprite exists, and if it does not exist, add it to the game. The purpose of registering a name for the elves is to facilitate management later, for example, when the elves die, we need to find an instance of it and remove it, but only through its name or ID, and so on, and at the same time, under the mechanism of the timer, we have to first judge whether an elf still exists, if there is no way to brush one more , just like in the network game whether we have the experience of such as brush boss riot equipment, a radish a pit, the same point brush out two twin boss, this is very strange thing. So after defining the name of the monster, we also need to define its body image code, in this case, its code number 100 (in order to be different from the body picture of the protagonist class Elf, I have 0-99 for the protagonist class body (clothing) code range, 100-n represents the Monster (NPC) category Body code range), Finally, the initial coordinates are defined by the preceding random: a random position in a square range (2000,1500) with a center edge length of 1000.

That's it? Yes, simple, or the old saying, the development of a good structure is to withstand a full range of test drops. Hey, brush it 30 odd (Initmonster (30)) test:

Related Article

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.