The difficulty of writing this game is much higher than before. This time I used the JS inheritance and design mode of the factory model, is also a breakthrough ...
The general idea of the game design:
1, player class player: A person can move around, and move up and down the villain.
The basic method of owning: {
Moving around: Simple keyboard moving around,
Move downward: It is the downward acceleration movement, each move will add a value of acceleration of gravity,
Move up: In fact, follow the box up to move up, the uniform upward movement,
Bounce: Is the player first to the previous deceleration movement, and then, when the speed is less than 1 o'clock, like the acceleration movement
}
2, Square base class Blockbase: base class for all squares, with public methods and interfaces.
The basic method of owning: {
Move: The square of the upward uniform movement,
Check whether the player is on the square: determine if the player stays on the square
}
and some abstract interface functions, only the name, need to be implemented in the subclass, specific look at the source code.
3, each seed class, such as Ordinary block class Normalblcok, Bounce Block class Flipblock and so on
Inheritance is implemented in the following ways:
In constructors: Blockbase.call (this); Inherit non-prototype properties and methods
Outside the function: Subclass square. prototype = new Blockbase (); Properties and methods for inheriting the prototype of base classes
4, factory class Blockfactory: Responsible for the production of squares, as well as hit the processing box
The basic method of owning: {
Building blocks: The key method is to randomly generate a block
}
In fact, I do not know how to say, or look at the source bar. I have a very specific comment inside.
Also, there must be a bug, I hope you understand ...
Finally, give a preview. I hope you can make a lot of bricks, I will improve more. It's best to write your code.
Direction control movement, the interface is done more ugly ... Everyone forgive me.
Demo Code: http://demo.jb51.net/js/DownFloor/index.html
Full Source Packaging >>/201011/yuanma/downfloor.rar