The second is the clock: This is actually the speed of the game. For general retarded game machines, it also represents the difficulty. Objects move once when each clock arrives. For example, Tetris moves down one level at a time. Racing games move forward one step at a time. Generally, the time of this type of clock is between 0.X seconds and 1 second. Objects move at a regular and uniform speed, which makes people feel that they are moving continuously.
Third movement: Here, I will first introduce two common rules for the movement of objects in retarded game machines: soft body transmission and rigid body transmission. The representative work of rigid body transmission is Tetris. The so-called rigid body is a hard thing that does not rotate much when moving (note that Tetris can rotate, but in fact it does not rotate through an algorithm, it is purely extracted in the form of an array, that is, a block is made into a lattice structure with 4 modes, which is actually 4 directions, haha). For the transmission of a rigid body, a fixed lattice moves in one direction (most likely input by the user) at the arrival of each clock. If expressed in coordinates, all the basic lattices of the object move one unit in one direction (X or Y) at the same time. The representative work of soft body transmission
is the greedy snake. When the greedy snake runs, it is not the whole snake that moves in one direction (haha, the snake's body is stiff), but at the arrival of each clock, the object is driven by the energy head (such as the snake head), and the direction of each point propagates to the next point, and then it moves one step in the new direction. After moving, the next point gets the direction of the previous point and
moves one step in the same way, so it will immediately fill the place of the previous point, and so on. It seems that it is not said. It doesn't matter if you don't understand it, because the actual algorithm can be simplified (only fools will move one point at a time). In fact, when designing the greedy snake, you only need to remove the dot matrix of the snake's tail and then put a dot matrix in the new direction of the snake's head. During this period, you need to record the position of the fixed dot matrix of each snake body, and refresh the position of each point after each movement moment.
The fourth display interface: What we usually use is a dot-matrix LCD, which is a large area of dots, 128*64, 132*64, 240*128, etc. These are also called strip screens, which means writing one line at a time - 8 dots (some also provide the function of writing one dot, but it is expensive, at least I don't have it). So what if you only want to write one dot? Then you have to read out the strip where the dot is located first, and then put it back on the LCD after AND, OR operations. At this time, it involves a problem of reading LCD. Some LCDs provide the reading function, and they remember what you have written on it very clearly, but some cheap ones don't work. So what should we do? It doesn't matter. You extract a space in the memory and virtualize an LCD. Every time you write on the real LCD, you also write to which virtual LCD in the memory. Then when you want to read the value of the LCD, you actually read the data on the virtual LD, and then write it to the LCD again after AND or OR. Remember to write it to the virtual LCD. You can call this buffer video memory,
Fifth. Game flow: The snake moves in a fixed direction. When each movement clock arrives, it needs to do the following: 1. Determine the food sign. If there is no food, place one. When placing it, it must not overlap with the snake body. 2. Get the user's key value. The snake takes a step and determines whether it is killed. If not, it determines whether it has eaten. If not, it waits for the next movement clock. If it has eaten, it will increase a little. Set a sign that there is no food. Then wait for the next moment to come. Haha, in fact, the program is so simple. Only the LCD part and the key part of the basic design are related to the single-chip microcomputer. The rest are program thinking and algorithms. For rookies, the difficulty lies in thinking, not the single-chip microcomputer. The source code of this program can be downloaded from http://www.51hei.com/bbs/dpj-18901-1.html .
Previous article:STC89C52 MCU receiving (RX) C language program based on NRF24L01 wireless module
Next article:Keep Running: Light Cube on a Breadboard
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- esp32 makes an open source handheld game console
- Some questions about DC-DC2596
- To show your companionship, you will get twice the result. Tektronix’s universal lucky bags are being delivered. There are seven lucky bags for you to choose from!
- High frequency power resonant amplifier, how to adjust the optimal impedance
- Wireless technology comparison (ZigBee, UWB, Wi-Fi, Bluetooth, NFC)
- TouchGFX design" + online battery status monitoring
- MicroPyhton-NodeMcuEsp8266, driving ultrasonic detector-buzzer-OLED screen
- CH543: 12V PD power management MCU
- T6963C does not display the problem
- [Telink's new generation of low-power, high-performance multi-protocol wireless kit B91 review] Home Assistant installation