Javascript object-oriented tank creation (I)

Source: Internet
Author: User

Javascript object-oriented tank creation (I)
PS: This tank war was rewritten by myself after the source code was written online. The purpose of writing this is to consolidate your learning of js during this period of time. It is an arrangement for learning js in the near future. At the same time, we also hope to help our park friends who are learning js. Because I have just learned JavaScript, it is inevitable that errors will occur. If you find that you want to correct it. This tutorial is suitable for beginners who are familiar with basic js syntax and object-oriented syntax. There is nothing that is too difficult. In this case, js object-oriented is better and can be used as an introductory tutorial on js object-oriented. 1. Create a basic object for simple tank movement. 1.1 how do I draw a canvas on a map? Considering browser compatibility, we use dom operations to draw and refresh game objects. How do we store our maps? We should save the map with a two-dimensional array. js does not have a two-dimensional array, but it can be implemented by storing the array in a one-dimensional array. 1.2 code implementation we design the canvas as a two-dimensional array of 13*13. Each element corresponds to a length and width of 40 Px in the map, we can regard the entire map as a table consisting of cells 40 PX * 40 p x, so the size of our entire canvas is 520px * 520px; 1.2.1 create top-level object html code: copy code 1 <! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> 2

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.