JavaScript game is a man on the next 100 layers of code packaging _javascript tips

Source: Internet
Author: User
Tags inheritance

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

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.