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

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and games series (Game Course): (27) The construction of dynamic obstacle system on the eve of battle

In standard MMORPG, each Elf object occupies an area (a small area of the base of the foot), which is also part of the obstacle system, and is dynamic, changing as the sprite moves. The realization of the dynamic obstacle construction in the game to make the obstacle system perfect is a necessary prelude to entering the combat system, we do not want to see the protagonist and the monster stacked together to fight it?

In the previous chapters, there was only one obstacle array, it contains only the map obstacle information (fixed in the map of the obstacles), so to achieve the dynamic construction of obstacles, we have to add an array of obstacles as the current game game relative to the protagonist of the dynamic obstacle array, the following is the definition of these two obstacles array:

byte[,] fixedobstruction = new byte[1024, 1024], varyobstruction;

Where Fixedobstruction is the matrix in the previous chapter, and here for the sake of understanding, I have called it a new life.

So how do you define the obstacle area of the elf's angular base? We also have to add the following two properties for the wizard control:

// 获取或设置脚底示为障碍物区域扩展宽度

public int HoldWidth { get; set; }

// 获取或设置脚底示为障碍物区域扩展高度

public int HoldHeight { get; set; }

These two properties represent the width and height of the elf's foot-base coordinates (that is, its x,y) (see figure below).

In this section, I set the holdwidth of all sprites to 1,holdheight set to 0, so that all sprites have an area of the foot barrier that is shown in the second wizard in the left number above.

After defining the obstacle area of the elf foot, we also need to adjust the current method of obstacle prediction accordingly. At this time, when predicting obstacles, we must first exclude the obstacle area that the elf occupies, and then replace the original obstacle prediction point with the edge point of the region (the 20th section can be referred to for the obstacle prediction point). Let me move the wizard to the left, for example, the obstacle prediction in this direction needs to be improved as follows:

private bool WillCollide() {

 switch ((int)Leader.Direction) {

  case 6:

   return VaryObstruction[

(int)(Leader.X / GridSizeX) - Leader.HoldWidth - 1,

(int)(Leader.Y / GridSizeY)

]

== 0 ? true : false;

 }

}

The yellow portion of the code expands the area of the obstacle prediction by adding a new part to the original base. The following illustration shows the example illustration:

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.