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