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