JavaScript games are packed with layer-3 code for men.

Source: Internet
Author: User

The preparation of this game is much more difficult than before. This time I usedInheritance of jsAndFactory mode of Design ModeIs also a breakthrough...

The general design concept of the game:
1. Player: A person can move around or up or down.
Basic Methods :{
Move left and right: Move the keyboard left and right,

Downward movement: it is a downward acceleration movement. Each movement will add a value of gravity acceleration,

Move up: it is actually moving up along with the square, moving up at a constant speed,

Bounce: The player first moves at a lower speed, and then, when the speed is less than 1, moves at a lower speed.

}

2. Block Base BlockBase: Base classes of all squares, with common methods and interfaces.

Basic Methods :{

Moving: The square moves up at a constant speed,

Checks whether a player is on the square: checks whether the player is on the square.

}

And some abstract interface functions, only the name, must be implemented in the subclass. For details, see the source code.

 

3. SubclassSuch as normal square NormalBlcok and bounce square FlipBlock

The inheritance method is as follows:

In the constructor: BlockBase. call (this); inherits non-prototype attributes and Methods

Outside the function: subclass box. prototype = new BlockBase (); inherits the attributes and methods of prototype of the base class.

 

4. Factory BlockFactory: Responsible for producing blocks and hitting and processing Blocks

Basic Methods :{

Generate blocks: the key method is to randomly generate a block.

}

In fact, I don't know how to say it. Let's look at the source code. I have made a very specific comment.

Also, bugs will certainly exist. I hope you will understand them...

Finally, we will provide a preview. I hope you can make more bricks to improve. It is best to write the code. 
It's ugly to move around and control the page... Sorry.
DEMO code: http://demo.jb51.net/js/DownFloor/index.html

Complete source code packaging>/201011/yuanma/DownFloor.rar

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.