Canvas: covet and covet
I have always been a bit confused. I found this game last week. I was addicted to it after playing it! It should be said that it is a kind of abuse pleasure and a collection of regrets about the accidental death and a new mentality!
I was thinking about how the game would continue after I switched to another application! It is to save my data in time, and then hook me up from this game room, then other players will see that I suddenly disappeared here? So how can I ensure that my recovery does not conflict with other users!
At the same time, I found that every time I came in, the snake next to me was still in the original position, and the same would dodge my attacks, etc, I want to know how the historical data of other players can be used to determine the current switching behavior! At that time, I thought about the algorithm, escaped the time I switched in, and continued the game with other users at the current point! Well, it's complicated!
So when I wrote this article, in order to avoid these problems, I added a small judgment to other snakes to simulate players !! However! However! I only know today that this game itself is a standalone game! Watt ????
Okay, it's not important. After the preparation is complete, let's talk about the implementation problem. I made a video last Saturday evening. It's very urgent. There are a lot of problems that haven't been optimized. It's just a great deal of streaming!
Prepare the web version !! Draw the entire game using CANVAS! Then, call requestAnimationFrame to implement Frame Animation and play the game logic at the same time!
Layout Design
Layout is designed like this, and then, during initialization, the canvas is randomly shifted to PhoneWidth/2 + Random () (the height is the same, as if I had played more Chinese than I was playing a few English letters, coke)
When you operate the joystick, move the canvas in the opposite direction and the snake in the square direction to ensure that the snake is always in the middle!
I'm tired today. I don't want to write it first, Wang!