Silverlight Game Design: (vi) Scene editor of Open source imagination

Source: Internet
Author: User
Tags bool cos sin silverlight

All game design aids are designed to improve the efficiency of the game development, silverlight-2d game Scene Editor (Qxsceneeditor) is no exception, although it is no more than "Warcraft", "Star", "Empire" and other great map editor has strong to even through "Skin" directly create a new game, but you can through it, with the previous section of the game to set up a way to build almost any 2D game graphics frame. Whether it's RPG (role-playing), SLG (strategy), RTS (Instant Strategy) or Act (action), STG (shooting), CAG (card games) and other types of games, regardless of the wizard is 2 direction (such as: "Underground City and Warriors", "The Three Kingdoms Biography") 4 direction (such as: "Drift") or 8 direction ( such as: "A sword") even 16 direction (such as: "Swordsman World" in the magic), regardless of the scene is horizontal, longitudinal, main angle of view, traction mode, tilt or vertical, regardless of the game space is 2 layers (such as: "Dream of the Fairy"), 3 layers (such as: "Miracle") or n-layer (such as: "Invincible Heroes", " ) and so on, as long as the 2D can be used as a scene layout or erection.

How is the scene editor so highly generic and marvellous? In the second section, I have explained in more detail its core functions: the dynamic coordinate system. By dynamically modifying the scene and its internal map, coordinate system and other objects, we can realize the arbitrary inclination of the scene, cell size, frame of reference, 2D position, 3D rotation and the multiple modes of the protagonist in position display and movement. As for the core code, I have repeatedly stressed that the fact that there are only two of them, consistent with the formula in section tenth of the first one, has proved that they are correct, so please pay special attention to their friends to put 10,000 hearts:

<summary>
Converts the coordinates in the window coordinate system to the coordinates in the game coordinate system
</summary>
Public point getgamecoordinate (double angle, point P, uint gridSize) {
if (angle = = 0) {
Return to New Point ((int) (p.x/gridsize), (int) (p.y/gridsize);
} else {
Double radian = Getradian (angle);
Return to New Point (
(int) ((P.y/(2 * Math.Cos (radian)) + p.x/(2 * Math.sin (Radian)))/gridSize),
(int) ((P.y/(2 * Math.Cos (Radian))-p.x/(2 * Math.sin (Radian)))/gridSize)
);
}
}

<summary>
Convert coordinate in game coordinate system to coordinate in window coordinate system
</summary>
Public point getwindowcoordinate (double angle, point P, uint gridSize) {
if (angle = = 0) {
Return to New Point (p.x * gridSize, P.Y * gridSize);
} else {
Double radian = Getradian (angle);
Return to New Point (
(P.X-P.Y) * Math.sin (radian) * gridSize,
(p.x + p.y) * Math.Cos (radian) * gridSize
);
}
}

Back to the function, only these are not enough; as a scene editor, it is more important that as a follow-up chapter I will show you more about the basic framework of the demo, it also needs to have better and more powerful features.

As the editor of the scene, the change of light energy to achieve the coordinate system can only be half completed, such as the introduction of any map can be regarded as dynamic construction:

Load map
button. Click + = (s, e) => {
OpenFileDialog OpenFileDialog = new OpenFileDialog ();
Openfiledialog.multiselect = false;
Openfiledialog.filter = "image file (*.jpg *.png) |*.jpg;*.png";
try {
BOOL result = (BOOL) openfiledialog.showdialog ();
if (!result) {
Return
} else {
FileInfo FileInfo = openfiledialog.file;
Stream stream = Fileinfo.openread ();
BitmapImage bitmapimage = new BitmapImage ();
Bitmapimage.setsource (stream);
if (Bitmapimage.pixelwidth < this. Width | | Bitmapimage.pixelheight < this. Height) {
MessageBox.Show (String. Format (map load failed! Picture size is less than window size: {0} * {1} ", this.) Width, this. Height));
} else {
Scene. Mapsource = BitmapImage;
Mapdetailsoutput.text = string. Format (width: {0}px height: {1}px), scene. Mapwidth = bitmapimage.pixelwidth, scene. Mapheight = bitmapimage.pixelheight);
}
Stream. Close ();
}
catch {
MessageBox.Show ("Map load failed!)" Check that the picture is in the correct format ");
}
};

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.