Map design and drawing in the development of J2ME games

Source: Internet
Author: User

In the development of many types of games, the map system needs good design, intuitively, we need the map system is only a 2D array, and then the fastest way to insinuate the array to the screen.

The map in the game is usually not by the programmer with the keyboard input into the program and then modify in the program and then modify the frenzied process, but generally first by the programmer to do a map editor, in this map editor with a mouse point, and then save the process, Or you can download some mature editors from the network such as: Mappy such tools to generate maps, and then use scripting language for Mappy write a program should be saved in what format. Usually the map is divided into 45 degrees, side angle and overlooking angle, and so on, there are also many kinds of angle of 45 degrees, this angle of view relative to the angle and side view is more complex, we mainly discuss overlooking angle, in fact, look at the main difference between the look and look at the picture is not the same style, such as thunder and Lightning is Mario's game is a side view that can be done with the same map editor. In summary, you need to know that the game map is not written by programmers, you like to write can also be modified more cumbersome, and can not be as dynamic management of resources, but a one-time read into memory, more uncomfortable.

In this article, we assume that our 2D array is read by the resource, and the contents are as follows:

public static byte[][] B_maze_2d_array = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0}
, {
0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}
, {
0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, {
0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0}
, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}
, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};

This map has 0, 12 byte numbers, 0 represents a block, 1 represents a block, can also be animated tiles, you draw the time difference is OK. Because we are in the program to draw out the entire graph, there are more than N solutions, I gave two more reasonable plan, of course, the second is more optimized. We assume that your protagonist has been in the center of the screen, when you move the protagonist, the map corresponding changes, that is, the protagonist for reference, map move. We know the size of the map to exceed the screen, we need to set a coordinate system, my method is that the upper left corner of the 0,0 is the same as our common canvas coordinate system is the same, our tile size: element_width, Element_height, So the area of our entire map (absolute area) is the number of blocks of element_width * element_height* ordinate. Therefore, when we put such a large picture on the screen, we need to draw the coordinates of the area (that is, the screen area) from the map out of the other places have been removed, which is more efficient.

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.