Compare commits

..

No commits in common. "8507d848b4ed048572b10052a9611358d6b706e2" and "c86df30c9c7c41b254804a9b872ec99c3ffbe2b3" have entirely different histories.

10 changed files with 406 additions and 185 deletions

View File

@ -69,7 +69,6 @@
"jsmpeg": "^1.0.0", "jsmpeg": "^1.0.0",
"matter-js": "^0.18.0", "matter-js": "^0.18.0",
"meshline": "^2.0.3", "meshline": "^2.0.3",
"poly-decomp": "^0.3.0",
"qrcode": "^1.4.4", "qrcode": "^1.4.4",
"snapsvg-cjs": "^0.0.6", "snapsvg-cjs": "^0.0.6",
"stats.js": "^0.17.0", "stats.js": "^0.17.0",
@ -106,4 +105,4 @@
"not dead", "not dead",
"not ie <= 8" "not ie <= 8"
] ]
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -44,7 +44,6 @@ class game {
this.utils = utils; this.utils = utils;
// init Matter // init Matter
this.Matter = Matter;
this.Engine = Matter.Engine, this.Engine = Matter.Engine,
this.Render = Matter.Render, this.Render = Matter.Render,
this.Runner = Matter.Runner, this.Runner = Matter.Runner,
@ -105,7 +104,7 @@ class game {
this.gameView = this.VIEW.loading(this); this.gameView = this.VIEW.loading(this);
this.VIEW.createLoadingParticle(); this.VIEW.createLoadingParticle();
this.scene = 1; this.scene = 1;
this.loadMainRes(); // this.loadMainRes();
}, },
}); });
} }
@ -116,12 +115,10 @@ class game {
imgList: Resource.main.imgList, imgList: Resource.main.imgList,
// audioList: Resource.main.audioList, // audioList: Resource.main.audioList,
loadStart: () => { loadStart: () => {
this.scene = 2;
// console.log(this.VIEW.loading_progress_bar.graphics.command.w) // console.log(this.VIEW.loading_progress_bar.graphics.command.w)
}, },
progressCallBack: (progress) => { progressCallBack: (progress) => {
// progress; // 0.99 // progress; // 0.99
console.log()
gsap.to(this.VIEW.loading_progress_bar.graphics.command, { gsap.to(this.VIEW.loading_progress_bar.graphics.command, {
w: 30 + 432 * progress, w: 30 + 432 * progress,
duration: 0.1, duration: 0.1,
@ -137,11 +134,7 @@ class game {
}, },
completeCallBack: (result) => { completeCallBack: (result) => {
// all loaded triger // all loaded triger
this.VIEW.createGamePage(this); this.VIEW.hideLoading()
setTimeout(() => {
this.VIEW.hideLoading();
this.webGL && this.VIEW.loadingCacheContainer.updateCache();
}, 100)
// this.mainResLoaded(); // this.mainResLoaded();
}, },
}); });
@ -194,45 +187,57 @@ class game {
initMatterEngine() { initMatterEngine() {
// create an engine // create an engine
this.myEngine = this.Engine.create(); this.myEngine = this.Engine.create();
this.myEngine.gravity.y = 0;
this.myWorld = this.myEngine.world; this.myWorld = this.myEngine.world;
// create a renderer // create a renderer
this.myRender = this.Render.create({ // this.myRender = this.Render.create({
// element: this.vue.$refs.container, // element: this.vue.$refs.container,
engine: this.myEngine, // engine: this.myEngine,
canvas: this.vue.$refs.matter, // options: {
options: { // width: window.innerWidth,
width: 375, //window.innerWidth, // height: window.innerHeight,
height: 812, //window.innerHeight, // pixelRatio: 1, // 设置像素比
pixelRatio: 1, // 设置像素比 window.devicePixelRatio // showAngleIndicator: true,
background: 'transparent', // wireframes: true,
wireframeBackground: "transparent", // showDebug: true
showAngleIndicator: false, // }
wireframes: false, // });
showDebug: false,
showVelocity: true,
}
});
// create two boxes and a ground // create two boxes and a ground
// var boxA = this.Bodies.rectangle(100, 200, 80, 80); var boxA = this.Bodies.rectangle(100, 200, 80, 80);
// var boxB = this.Bodies.rectangle(150, 50, 80, 80); var boxB = this.Bodies.rectangle(150, 50, 80, 80);
// var boxC = this.Bodies.rectangle(150, 50, 80, 80); var boxC = this.Bodies.rectangle(150, 50, 80, 80);
// var boxD = this.Bodies.rectangle(150, 50, 80, 80); var boxD = this.Bodies.rectangle(150, 50, 80, 80);
// var ground = this.Bodies.rectangle(0, 800, 750, 10, { isStatic: true }); var ground = this.Bodies.rectangle(0, 800, 750, 10, { isStatic: true });
// this.Composite.add(this.myWorld, [
// this.Bodies.fromVertices(
// 0, 0,
// [
// // 顶点坐标
// { x: 0, y: 0 },
// { x: 0, y: 890 },
// { x: 140, y: 815 },
// { x: 208, y: 614 },
// { x: 548, y: 614 },
// { x: 612, y: 815 },
// { x: 750, y: 890 },
// { x: 750, y: 0 }
// ],
// { isStatic: true }
// )
// ]);
// add all of the bodies to the world // add all of the bodies to the world
// this.Composite.add(this.myWorld, [boxA, boxB, boxC, boxD, ground]); this.Composite.add(this.myWorld, [boxA, boxB, boxC, boxD, ground]);
// create runner // create runner
this.Render.run(this.myRender); // this.Render.run(this.myRender);
// run the engine // run the engine
this.myRunner = this.Runner.create(); // this.myRunner = this.Runner.create();
this.Runner.run(this.myRunner, this.myEngine); // this.Runner.run(this.myRunner, this.myEngine);
this.Engine.run(this.myEngine);
} }
//debug mode destroyed //debug mode destroyed

View File

@ -24,22 +24,13 @@ export default {
main: { main: {
imgList: [ imgList: [
{ {
id: 'coin', id: 'logo',
src: require("@/assets/images/push-coin/coin.png") src: require("@/assets/images/logo.png")
}, },
{ {
id: 'top', id: 'logo',
src: require("@/assets/images/push-coin/top.png") src: require("@/assets/images/logo.png")
}, }
{
id: 'bottom_ban',
src: require("@/assets/images/push-coin/bottom_ban.png")
},
{
id: 'pusher',
src: require("@/assets/images/push-coin/pusher.png")
},
], ],
audioList: [ audioList: [
] ]

View File

@ -3,7 +3,6 @@ import layoutData from './layout';
import createLayout from './createView'; import createLayout from './createView';
// import maskCreater from './maskCreater'; //mask creater // import maskCreater from './maskCreater'; //mask creater
import { gsap } from "gsap"; import { gsap } from "gsap";
import decomp from 'poly-decomp';
// import utils from '@/utils/index.js' // import utils from '@/utils/index.js'
// import { MotionPathPlugin } from "gsap/MotionPathPlugin.js"; // import { MotionPathPlugin } from "gsap/MotionPathPlugin.js";
// import Soul from './plugins/ScrollContainer'; //app scroll plugin module // import Soul from './plugins/ScrollContainer'; //app scroll plugin module
@ -17,6 +16,8 @@ class layout {
} }
init() { init() {
//update btns position by viewport //update btns position by viewport
// this.updatePosByViewport(); // this.updatePosByViewport();
@ -64,9 +65,8 @@ class layout {
} }
} }
createBitmap(name) { createBitmap(spriteSheet, name) {
let img = this.game.mainLoader && this.game.mainLoader.getResult(name); return new createjs.Sprite(spriteSheet, name);
return new createjs.Bitmap(img);
} }
//创建loading页 //创建loading页
@ -95,125 +95,365 @@ class layout {
// 创建粒子动画 // 创建粒子动画
this.createLoadingParticle(); this.createLoadingParticle();
// console.log(this.loading_bg) console.log(this.loading_bg)
return this return this
} }
//隐藏loading页面 //隐藏loading页面
hideLoading() { hideLoading(step = 1) {
//create story index //create story index
gsap.to(this.game.stage.loadingContainer, { alpha: 0, duration: 0.65, }) this.game.scene = 2;
gsap.to([this.game.stage.mainContainer, this.gamePage], { alpha: 1, duration: 0.65 }); gsap.to(this.game.stage.loadingContainer, {
alpha: 0, duration: 0.65, delay: step == 3 ? 1 : 0, onComplete: () => {
// 将loading重置ui显示 为二次加载资源做显示
this.changeLoadingLayout(step);
}
})
gsap.to(this.game.stage.mainContainer, { alpha: 1, duration: 0.65 });
} }
// 创建游戏页 // 准备下一次loading
createGamePage(game) { changeLoadingLayout(step) {
this.game = game; if (step == 1) {
this.gamePage = new createjs.Container().set({ alpha: 0 }); // 进度归零
this.game.stage.mainContainer.addChild(this.gamePage); this.loading_progress_text.text = '0%';
// 隐藏元素
gsap.set([this.loading_start, this.loading_progress_bg, this.loading_progress_bar, this.loading_snow, this.loading_text], { alpha: 0 })
// 显示元素
gsap.set([this.loading_text2, this.loading_box, this.loading_light, this.loading_person], { alpha: 1 })
gsap.set(this.loading_progress_text, { alpha: 1, y: 1260 })
// 准备动画
this.readyLangLoaderAni();
} else if (step == 2) {
// 隐藏元素
gsap.set([this.loading_text2, this.loading_light, this.loading_person], { alpha: 0 })
gsap.set(this.loading_progress_text, { alpha: 0 })
// 显示元素
gsap.set([this.loading_text3, this.loading_light2, this.loading_arrow], { alpha: 1 })
// 如果是英文 显示英文文案
if (this.game.langConfig.id == 3) {
gsap.set([this.loading_text2_en, this.loading_text3], { alpha: 0 })
gsap.set([this.loading_text3_en], { alpha: 1 })
}
// 准备动画
this.readyPosterLoaderAni();
}
}
let bottom = this.createBitmap('bottom_ban').set({ y: 560 }); // 准备语言加载动画
let top = this.createBitmap('top'); readyLangLoaderAni() {
// 添加推板 this.langLoaderAni = [];
let pusher = this.createBitmap('pusher').set({ let ani1 = new gsap.timeline({ repeat: -1, paused: true })
x: 142, .to([this.loading_light, this.loading_person], { alpha: 0.86, duration: 0.2 })
y: 683 .to([this.loading_light, this.loading_person], { alpha: 1, duration: 0.15 })
}); .to([this.loading_light, this.loading_person], { alpha: 0.6, duration: 0.2 })
.to([this.loading_light, this.loading_person], { alpha: 1, duration: 0.1 })
// console.log(pusher) let ani2 = gsap.to([this.loading_person, this.loading_box], { y: '+=15', yoyo: true, repeat: -1, duration: 1.5 })
gsap.to(pusher, { y: '-=202', yoyo: true, repeat: -1, ease: 'none', duration: 5 })
// 添加到
this.gamePage.addChild(bottom, pusher, top);
// Create a concave polygon this.langLoaderAni.push(ani1, ani2)
var _g = [ }
// 顶点坐标
{ x: 0, y: 0 },
{ x: 0, y: 956 },
{ x: 141, y: 881 },
{ x: 206, y: 683 },
{ x: 548, y: 683 },
{ x: 614, y: 881 },
{ x: 750, y: 956 },
{ x: 750, y: 0 },
];
var concavePolygon = [
// 顶点坐标
[0, 0],
[0, 956],
[141, 881],
[206, 683],
[548, 683],
[614, 881],
[750, 956],
[750, 0],
];
// Make sure the polygon has counter-clockwise winding. Skip this step if you know it's already counter-clockwise. // 播放语言加载时动画
decomp.makeCCW(concavePolygon); playLangLoaderAni() {
this.langLoaderAni.forEach((item) => {
item.restart();
})
}
// 暂停语言加载时动画
pauseLangLoaderAni() {
this.langLoaderAni.forEach((item) => {
item.pause();
})
}
// 准备语言加载动画
readyPosterLoaderAni() {
this.posterLoaderAni = [];
let ani1 = new gsap.timeline({ repeat: -1, paused: true })
.to(this.loading_light2, { alpha: 0.86, duration: 0.2 })
.to(this.loading_light2, { alpha: 1, duration: 0.15 })
.to(this.loading_light2, { alpha: 0.6, duration: 0.2 })
.to(this.loading_light2, { alpha: 1, duration: 0.1 })
let ani2 = gsap.to([this.loading_box], { y: '+=15', yoyo: true, repeat: -1, duration: 1.5 })
let ani3 = gsap.to([this.loading_arrow], { y: '+=15', scaleX: 0.95, yoyo: true, repeat: -1, duration: 1.5 })
var convexPolygons = decomp.quickDecomp(concavePolygon); this.posterLoaderAni.push(ani1, ani2, ani3)
// ==> [ [[1,0],[1,1],[0.5,0.5]], [[0.5,0.5],[-1,1],[-1,0],[1,0]] ] }
// // Decompose using the slow (but optimal) algorithm // 播放语言加载时动画
// var convexPolygons = decomp.decomp(concavePolygon); playPosterLoaderAni() {
this.posterLoaderAni.forEach((item) => {
item.restart();
})
}
convexPolygons.forEach((item) => { // 暂停语言加载时动画
item.forEach((t, i) => { pausePosterLoaderAni() {
item.push({ this.posterLoaderAni.forEach((item) => {
x: t[0], item.pause();
y: t[1] })
}) }
if (i == (item.length / 2) - 1) {
item.splice(0, item.length / 2)
} // 帧生成动画
}) framePlayer(config) {
// 图像资源
// 容器
// const container = new createjs.Container();
// loader
const loader = this.game[config.name];
// images
const images = [];
config.imgIds.forEach((item) => {
images.push(loader.getResult(item));
}) })
console.log(convexPolygons) // handle speed
// 添加ground Object.keys(config.sprite.animations).forEach((key) => {
this.game.Composite.add(this.game.myWorld, // console.log('speed=', this.game.globalSpeed * 0.18)
this.game.Bodies.fromVertices( config.sprite.animations[key].speed = this.game.globalSpeed * 0.18;
window.innerWidth / 2, window.innerHeight / 2, config.sprite.animations[key].next = 'wait'
convexPolygons, });
{
isStatic: true,
scale: {
screenX: 0.5,
screenY: 0.5,
},
render: {
fillStyle: 'rgba(39,7,238,0.25)'
}
},
) // animation config
const aniData = {
images,
frames: config.sprite.frames,
animations: config.sprite.animations
}
const spriteSheet = new createjs.SpriteSheet(aniData);
const animation = new createjs.Sprite(spriteSheet);
// default setting
if (config.name === 'guide' || config.name === 'wait') {
animation.set({
name: config.name,
x: 390,
y: 280 + 512,
scaleX: 1.25,
scaleY: 1.25,
regX: 750 * 0.85 / 2,
regY: 1624 * 0.85 / 2,
alpha: 0
})
} else {
animation.set({
name: config.name,
x: 220,
y: 565 + 512,
scaleX: 1,
scaleY: 1,
regX: 750 * 1 / 2,
regY: 1624 * 1 / 2,
alpha: 0
})
}
return animation
}
// 生成海报
createPoster(nickname = '', level = 1) {
this.posterContainer = new createjs.Container().set({ alpha: 1, name: 'posterContainer' });
// this.game.stage.mainContainer.addChild(this.posterContainer);
// 海报图片
let posterImg = this.game.posterLoader.getResult('poster_bg');
// 海报对象
let poster = new createjs.Bitmap(posterImg);
// nickname
let nt;
if (nickname) {
nt = this.game.vue.$Utils.cutString(nickname, 20, true);
}
let nicknameText = new createjs.Text(nt, "38px Helvetica, Arial, sans-serif", "#31425b").set({
x: 375,
y: 1086,
textAlign: 'center'
});
let levelImg = this.game.posterLoader.getResult(`word_${level}`);
let posConfig = [
{
x: 50,
y: 239
},
{
x: 70,
y: 242
},
{
x: 54,
y: 243
},
{
x: 57,
y: 224
},
{
x: 50,
y: 243
}
]
// 等级称号
let levelTitle = new createjs.Bitmap(levelImg).set(
this.game.langConfig.id == 3 ? posConfig[Number(level) - 1] : posConfig[4]
); );
//
// let bounds = pusher.getBounds(); let personImg = this.game.posterLoader.getResult('person');
// pusher.body = this.game.Bodies.trapezoid( // 王冰冰
// pusher.x, let person = new createjs.Bitmap(personImg).set({
// pusher.y, x: this.game.langConfig.id == 3 ? 76 : 86,
// bounds.width, y: this.game.langConfig.id == 3 ? 381 : 256
// bounds.height, });
// 1,
// { isStatic: true } // 根据版本选择不同的二维码 目前全部选用微信版本二维码
// ); let codeName = 'qrcode';
// this.game.Composite.add(this.myWorld, [pusher.body]); // switch (process.env.VUE_APP_CURRENTMODE) {
// case 'ysprod':
// codeName = 'ys_qrcode';
// break;
// case 'wbprod':
// codeName = 'wb_qrcode';
// break;
// default:
// codeName = 'qrcode';
// break;
// }
let qrcodeImg = this.game.posterLoader.getResult(codeName);
// 海报对象
let qrcode = new createjs.Bitmap(qrcodeImg).set({
x: this.game.langConfig.id == 3 ? 305 : 306,
y: this.game.langConfig.id == 3 ? 1256 : 1275,
scaleX: 0.34,
scaleY: 0.34,
width: 136,
height: 136
});
let logoImg = this.game.posterLoader.getResult('logo');
// 海报对象
let logo = new createjs.Bitmap(logoImg).set({
x: this.game.langConfig.id == 3 ? 341 : 341,
y: this.game.langConfig.id == 3 ? 1482 : 1482,
});
// 插入container
this.posterContainer.addChild(poster, nicknameText, qrcode, levelTitle, person, logo);
this.posterContainer.cache(0, 0, 750, 1538);
// easejs > 1.0.0 getCacheDataURL报错 0.8.2版本正常
let baseUrl = this.posterContainer.cacheCanvas.toDataURL('image/png');
// let baseUrl = this.posterContainer.getCacheDataURL();
setTimeout(() => {
this.destroyPosterCreater();
}, 1000);
return baseUrl
} }
// 生成硬币 // 销毁海报生成器
createCoin() { destroyPosterCreater() {
let coinImg = this.game.mainLoader.getResult('coin'); this.posterContainer.uncache();
let coin = new createjs.Bitmap(coinImg); this.posterContainer.removeAllChildren();
this.game.stage.mainContainer.removeChild(this.posterContainer);
this.posterContainer = null;
} }
// index 粒子制造机
createParticle() {
// 容器
// const loadingContainer = this.game.stage.loadingContainer;
// loader
const loader = this.game.vue.$beforeLoader;
// sprite image
const spriteImg = loader.getResult('snowSprite');
const container = new createjs.Container();
const aniData = {
images: [spriteImg],
frames: [
[1, 1, 77, 82, 0, 0, 0],
[1, 85, 57, 55, 0, 0, 0],
[1, 142, 46, 45, 0, 0, 0],
[49, 142, 15, 15, 0, 0, 0],
[60, 85, 8, 12, 0, 0, 0],
[60, 99, 6, 6, 0, 0, 0]
],
animations: {
"snow-1": { "frames": [0] },
"snow-2": { "frames": [1] },
"snow-3": { "frames": [2] },
"snow-4": { "frames": [3] },
"snow-5": { "frames": [4] },
"snow-6": { "frames": [3] },
"snow-7": { "frames": [4] },
"snow-8": { "frames": [2] },
"snow-9": { "frames": [3] },
"snow-10": { "frames": [1] },
}
}
const spriteSheet = new createjs.SpriteSheet(aniData);
const arr = [];
for (let i = 0; i < (window.deviceInfo.system == 'IOS' ? 50 : 50); i++) {
const scale = Math.random() * 0.35 + 0.5;
const name = `snow-${this.game.vue.$Utils.rangeRandom(1, 10)}`;
const sprite = this.createBitmap(spriteSheet, name).set({
x: Math.random() * 750 - 30,
y: Math.random() * 1300,
ox: Math.random() * 750,
oy: -50,
// regX:14,
// regY:14,
scaleX: scale,
scaleY: scale,
speedX: (Math.random() > 0.5 ? 1 : -1) * (Math.random() * 0.5 + 0.25),
speedY: Math.random() * 1 + 1,
speedR: Math.random() * 0.5 + 0.5,
alpha: Math.random() * 0.3 + 0.5,
})
arr.push(sprite)
}
// const mask = new createjs.Shape().setTransform(0, 0, 1, 1);
// mask.graphics.f('#000000').drawRoundRect(0, 0, 750, 1300, 0).es();
// contianer.mask = mask;
// contianer.compositeOperation = 'darker';
// arr.push(mask)
container.children = arr;
this.prarticleContainer = container;
this.game.stage.mainContainer.addChild(container);
return container
}
// loading 粒子制造机 // loading 粒子制造机
createLoadingParticle() { createLoadingParticle() {
const container = new createjs.Container(); const container = new createjs.Container();

View File

@ -7,45 +7,37 @@
* @FilePath: /xfhd-vue-scaffold/src/page/index/Home/Index.vue * @FilePath: /xfhd-vue-scaffold/src/page/index/Home/Index.vue
--> -->
<template> <template>
<div class="pushcoin" id="container" ref="container"> <div class="pushcoin" id="container" ref="container"></div>
<canvas ref="matter" class="matter"></canvas>
</div>
</template> </template>
<script> <script>
// @ is an alias to /src // @ is an alias to /src
import gsap from "gsap"; import gsap from "gsap";
import game from "./game/index"; import game from "./game/index";
export default { export default {
name: "ColorSort", name: "ColorSort",
components: {}, components: {},
data() { data() {
return {}; return {};
}, },
computed: { computed: {
rennderCssHSL() { rennderCssHSL() {
return function (item) { return function (item) {
return `background-color: ${item.csshsl};`; return `background-color: ${item.csshsl};`;
}; };
}, },
}, },
mounted() { mounted() {
this.game = new game(); this.game = new game();
this.game.init(this); this.game.init(this);
}, },
methods: {}, methods: {},
}; };
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only --> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less"> <style scoped lang="less">
.pushcoin { .pushcoin {
.prLayout(100%,100%); .prLayout(100%,100%);
overflow: hidden; overflow: hidden;
background-color: #333; background-color: #333;
.matter {
.paPos(0,0,1);
}
#stageCanvas {
.paLayout(0,0,750px,1624px,0);
}
} }
</style> </style>

View File

@ -40,12 +40,6 @@ module.exports = {
// development模式时打包也带有 hash 值 // development模式时打包也带有 hash 值
config.output.filename('static/js/[name].[hash].js').chunkFilename('static/js/[name].[hash].js').end() config.output.filename('static/js/[name].[hash].js').chunkFilename('static/js/[name].[hash].js').end()
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, { limit: 0 }))
config.resolve.alias config.resolve.alias
.set("@", resolve("src")) .set("@", resolve("src"))
// .set("weui", resolve("src/utils/plugins/weui.js")) // .set("weui", resolve("src/utils/plugins/weui.js"))