The realization and thinking of the Battle of canvas snake

Source: Internet
Author: User


has always been compared to later, last week only discovered the greedy snake fight this game, play a bit, incredibly addictive! It should be said to be a collection of abusive pleasures and careless dead regrets and another set of mentality!

Just then there was a thought, is how the game after I switch to other applications still back can continue to battle! is to save my data in time and then hang me up from this game room, and then the other players will see me disappear here suddenly? How to protect me from other users when I recover

At the same time I found that every time I come in, the snake is still in the original position, and the same will dodge my attack, etc., I think the other players of the historical data is how to judge my current switch in the behavior! I also thought about the algorithm, avoiding the time I switched in, and then sync with the other user's current point to continue the game! Yes, it's complicated!

So, when I write, in order to avoid these problems, to other snakes added a small judgment to simulate the player!! However! However! I only know today, the game itself is a stand-alone! Watt????

OK, not important, the cushion is finished, the following is the implementation of the problem, I was on the evening of Saturday, more urgent, many no optimization, is the flow of a pass!

Ready to make Web version!! The whole game is drawn with canvas! Then call Requestanimationframe to implement the frame animation while playing the game logic!

Layout design speak a little

Layout so design, and then initialize the time, randomly let the canvas offset phonewidth/2+random () (height of the same operation, as if playing Chinese more than I play a few English, Koko)


When operating the joystick, move the canvas in the opposite direction, moving the snake in the right direction, so that the snake will always be in the middle!


Today tired, don't write first, bark!

The realization and thinking of the Battle of canvas snake

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.