Home > Web Front-end > JS Tutorial > body text

JavaScript games are packaged by 100 layers of code for men_javascript skills

WBOY
Release: 2016-05-16 18:16:54
Original
2462 people have browsed it

The writing difficulty of this game is much higher than before. This time I used js inheritance and factory pattern of design pattern, which is also a breakthrough. . .

The general design ideas of the game:
1. Player type Player: a small person who can move left and right and up and down.
Basic methods: {
Move left and right: simply move the keyboard left and right,

Downward movement: It belongs to downward acceleration movement. Each movement will add a value of gravity acceleration,

Move upward: It actually moves upward with the block, moving upward at a constant speed,

Bounce: The player first decelerates upward, and then, when the speed is less than 1, accelerates like below

}

2. Block base class BlockBase: The base class of all blocks, with public methods and interfaces.

Basic methods owned: {

Movement: The block moves upward at a constant speed,

Detect whether the player is on the block: Determine whether the player is staying on the block

}

and some abstract interface functions only have names and need to be implemented in subclasses. Please refer to the source code for details.

3, various subcategories , such as NormalBlcok, FlipBlock, etc.

Inheritance is implemented as follows:

In the constructor: BlockBase.call(this); inherit non-prototype properties and methods

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

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

Basic methods owned: {

Generate blocks: The key method is to randomly generate a block

}

Actually, I don’t know what to say, so let’s look at the source code. I've made very specific comments in it.

Also, there will definitely be bugs, I hope everyone can understand. . .

Finally, let me give you a preview. I hope everyone can help me improve more. It's best to write code.
The left and right directions control movement. The interface is rather ugly. . . Please forgive me.
Demo code: http://demo.jb51.net/js/DownFloor/index.html

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template