├── game.json ├── res ├── launch.mp3 ├── background.png ├── startbutton.png └── xuemaojiao.mp3 ├── dist ├── res │ ├── launch.mp3 │ ├── background.png │ ├── startbutton.png │ └── xuemaojiao.mp3 ├── index.html └── game.5d4643f2.js ├── src ├── base │ ├── Body.js │ ├── Resource.js │ ├── DataStore.js │ ├── Sprite.js │ └── ResourceLoader.js ├── sprite │ ├── BackGround.js │ ├── StartButton.js │ └── Score.js ├── body │ ├── Border.js │ ├── Bridge.js │ ├── Block.js │ └── Aim.js └── Director.js ├── .babelrc ├── .gitignore ├── package.json ├── project.config.json ├── index.html ├── README.md ├── App.js └── game.js /game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait" 3 | } 4 | -------------------------------------------------------------------------------- /res/launch.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/res/launch.mp3 -------------------------------------------------------------------------------- /dist/res/launch.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/dist/res/launch.mp3 -------------------------------------------------------------------------------- /res/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/res/background.png -------------------------------------------------------------------------------- /res/startbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/res/startbutton.png -------------------------------------------------------------------------------- /res/xuemaojiao.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/res/xuemaojiao.mp3 -------------------------------------------------------------------------------- /dist/res/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/dist/res/background.png -------------------------------------------------------------------------------- /dist/res/startbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/dist/res/startbutton.png -------------------------------------------------------------------------------- /dist/res/xuemaojiao.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheneyweb/wxgame-elastic/HEAD/dist/res/xuemaojiao.mp3 -------------------------------------------------------------------------------- /src/base/Body.js: -------------------------------------------------------------------------------- 1 | // 物体基类 2 | export class Body { 3 | constructor(physics) { 4 | this.physics = physics 5 | } 6 | } -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env" 4 | ], 5 | "plugins": [ 6 | "transform-class-properties", 7 | "transform-object-rest-spread" 8 | ] 9 | } -------------------------------------------------------------------------------- /src/base/Resource.js: -------------------------------------------------------------------------------- 1 | export const Resources = [ 2 | ['background', 'res/background.png'], 3 | ['startButton', 'res/startbutton.png'], 4 | ['bgm', 'res/xuemaojiao.mp3'], 5 | ['launch', 'res/launch.mp3'] 6 | ] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | #/dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | package-lock.json 8 | vendor-manifest.json 9 | vendor.dll.js 10 | .cache 11 | 12 | # Editor directories and files 13 | .idea 14 | .vscode 15 | *.suo 16 | *.ntvs* 17 | *.njsproj 18 | *.sln 19 | -------------------------------------------------------------------------------- /src/sprite/BackGround.js: -------------------------------------------------------------------------------- 1 | import { Sprite } from '../base/Sprite.js' 2 | /** 3 | * 背景类 4 | */ 5 | export class BackGround extends Sprite { 6 | constructor(physics) { 7 | const image = Sprite.getImage('background') 8 | super( 9 | physics.ctx, image, 10 | (physics.canvas.width - image.width) / 2, 11 | (physics.canvas.height - image.height) / 2.5, 12 | image.width, image.height, 13 | 0, 14 | 0, 15 | image.width, image.height 16 | ) 17 | } 18 | } -------------------------------------------------------------------------------- /src/sprite/StartButton.js: -------------------------------------------------------------------------------- 1 | import { Sprite } from '../base/Sprite.js' 2 | /** 3 | * 开始按钮类 4 | */ 5 | export class StartButton extends Sprite { 6 | constructor(physics) { 7 | const image = Sprite.getImage('startButton') 8 | super( 9 | physics.ctx, image, 10 | (physics.canvas.width - image.width) / 2, 11 | (physics.canvas.height - image.height) / 2.5, 12 | image.width, image.height, 13 | 0, 14 | 0, 15 | image.width, image.height 16 | ) 17 | } 18 | } -------------------------------------------------------------------------------- /src/sprite/Score.js: -------------------------------------------------------------------------------- 1 | import { DataStore } from '../base/DataStore.js' 2 | /** 3 | * 计分器类 4 | */ 5 | export class Score { 6 | constructor(physics) { 7 | this.ctx = physics.ctx 8 | // 数据管理 9 | this.dataStore = DataStore.getInstance() 10 | this.dataStore.scoreCount = 0 11 | } 12 | 13 | // 绘制 14 | draw() { 15 | this.ctx.font = '25px Arial' 16 | this.ctx.fillStyle = '#464444' 17 | this.ctx.fillText(`分数 ${this.dataStore.scoreCount}`, 50, 20) 18 | } 19 | // 加分 20 | static increase() { 21 | DataStore.getInstance().scoreCount += 1 22 | } 23 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wxgame-elastic", 3 | "version": "1.0.0", 4 | "description": "微信小游戏-弹一弾", 5 | "main": "index.html", 6 | "scripts": { 7 | "dev": "parcel index.html", 8 | "build": "parcel build index.html --public-url / --no-source-maps", 9 | "build-github": "parcel build index.html --public-url /wxgame-elastic/dist/ --no-source-maps" 10 | }, 11 | "author": "cheneyxu", 12 | "license": "ISC", 13 | "dependencies": {}, 14 | "devDependencies": { 15 | "babel-plugin-transform-class-properties": "^6.24.1", 16 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 17 | "babel-preset-env": "^1.7.0", 18 | "parcel-bundler": "^1.9.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件", 3 | "packOptions": { 4 | "ignore": [] 5 | }, 6 | "setting": { 7 | "urlCheck": false, 8 | "es6": true, 9 | "postcss": true, 10 | "minified": true, 11 | "newFeature": true 12 | }, 13 | "compileType": "game", 14 | "libVersion": "2.1.1", 15 | "appid": "touristappid", 16 | "projectname": "elastic", 17 | "isGameTourist": true, 18 | "condition": { 19 | "search": { 20 | "current": -1, 21 | "list": [] 22 | }, 23 | "conversation": { 24 | "current": -1, 25 | "list": [] 26 | }, 27 | "plugin": { 28 | "current": -1, 29 | "list": [] 30 | }, 31 | "game": { 32 | "list": [], 33 | "current": -1 34 | }, 35 | "miniprogram": { 36 | "current": -1, 37 | "list": [] 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/base/DataStore.js: -------------------------------------------------------------------------------- 1 | // 数据管理 2 | export class DataStore { 3 | // 单例 4 | static getInstance() { 5 | if (!DataStore.instance) { 6 | DataStore.instance = new DataStore() 7 | } 8 | return DataStore.instance 9 | } 10 | // 构造存储容器 11 | constructor() { 12 | this.map = new Map() 13 | this.res = null // 游戏资源 14 | this.isGameOver = false // 游戏进度标识 15 | this.scoreCount = 0 // 游戏分数 16 | } 17 | // 存入 18 | put(key, value) { 19 | // 如果传入的参数是函数,则new function 20 | if (typeof value === 'function') { 21 | value = new value() 22 | } 23 | this.map.set(key, value) 24 | // 可链式使用 25 | return this 26 | } 27 | // 取出 28 | get(key) { 29 | return this.map.get(key) 30 | } 31 | //销毁 32 | destroy() { 33 | for (let value of this.map.values()) { 34 | value = null 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/base/Sprite.js: -------------------------------------------------------------------------------- 1 | import { DataStore } from './DataStore.js' 2 | export class Sprite { 3 | constructor(ctx, img, x = 0, y = 0, w = 0, h = 0, srcX = 0, srcY = 0, srcW = 0, srcH = 0, ) { 4 | this.ctx = ctx 5 | this.img = img 6 | this.srcX = srcX 7 | this.srcY = srcY 8 | this.srcW = srcW 9 | this.srcH = srcH 10 | this.x = x 11 | this.y = y 12 | this.w = w 13 | this.h = h 14 | } 15 | 16 | /** 17 | * 绘制图片 18 | * img 传入Image对象 19 | * srcX 要剪裁的起始X坐标 20 | * srcY 要剪裁的起始Y坐标 21 | * srcW 剪裁的宽度 22 | * srcH 剪裁的高度 23 | * x 放置的x坐标 24 | * y 放置的y坐标 25 | * w 要使用的宽度 26 | * h 要使用的高度 27 | */ 28 | draw(img = this.img, 29 | x = this.x, y = this.y, w = this.w, h = this.h, 30 | srcX = this.srcX, srcY = this.srcY, srcW = this.srcW, srcH = this.srcH) { 31 | this.ctx.drawImage(img, srcX, srcY, srcW, srcH, x, y, w, h) 32 | } 33 | 34 | static getImage(key) { 35 | return DataStore.getInstance().res.get(key) 36 | } 37 | } -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 |
1?(m=a.create(s.extend({parts:f.slice(0)},o)),a.setPosition(m,{x:e,y:t}),m):f[0]}},{"../body/Body":1,"../core/Common":14,"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29}],24:[function(e,t,n){var o={};t.exports=o;var i=e("../body/Composite"),r=e("../constraint/Constraint"),s=e("../core/Common"),a=e("../body/Body"),l=e("./Bodies");o.stack=function(e,t,n,o,r,s,l){for(var c,d=i.create({label:"Stack"}),u=e,p=t,m=0,f=0;f