Commit cf241241 authored by Master Q's avatar Master Q

游戏页面简单搭建

parent 73050b9e
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</script> </script>
<div id="__loading__" style="position:absolute;left:50%;top:50%;margin-left:-45px;color:#ffffff">拼命加载中...</div> <div id="__loading__" style="position:absolute;left:50%;top:50%;margin-left:-45px;color:#ffffff">拼命加载中...</div>
<div id="cusEngine" style="line-height:0;font-size:0;position: absolute;"> <div id="cusEngine" style="line-height:0;font-size:0;position: absolute;">
<canvas id="canvas" style="width: 100%;height: 100%"></canvas> <canvas id="canvas" style="width: 100%;height: 100%;"></canvas>
</div> </div>
<!-- 帧率检测 --> <!-- 帧率检测 -->
<!-- <script src="//yun.duiba.com.cn/db_games/libs0924/stats.js"></script> --> <!-- <script src="//yun.duiba.com.cn/db_games/libs0924/stats.js"></script> -->
......
import { horizontalScreen } from "../../src/Main";
import PanelCtrl from "../ctrls/panelCtrl"; import PanelCtrl from "../ctrls/panelCtrl";
import SceneCtrl from "../ctrls/sceneCtrl"; import SceneCtrl from "../ctrls/sceneCtrl";
...@@ -43,8 +44,8 @@ class Layers extends FYGE.Container { ...@@ -43,8 +44,8 @@ class Layers extends FYGE.Container {
this.addChild(this[arr[i]]); this.addChild(this[arr[i]]);
} }
//都以顶部适配 //都以顶部适配
// this.sceneLayer.y = this.stageOffsetY; // this.sceneLayer.x = Math.abs(this.stageOffsetX);
// this.popupLayer.y = this.stageOffsetY; // this.sceneLayer.y = Math.abs(this.stageOffsetY);
//都以底部适配 //都以底部适配
// this.sceneLayer.y = -this.stageOffsetY; // this.sceneLayer.y = -this.stageOffsetY;
// this.popupLayer.y = -this.stageOffsetY; // this.popupLayer.y = -this.stageOffsetY;
...@@ -91,25 +92,25 @@ class Layers extends FYGE.Container { ...@@ -91,25 +92,25 @@ class Layers extends FYGE.Container {
*/ */
get stageHeight() { get stageHeight() {
if (!this.stage) return 0; if (!this.stage) return 0;
return this.stage.viewRect.height; return horizontalScreen ? this.stage.viewRect.height : this.stage.viewRect.width;
} }
/** /**
* 舞台可见宽度 * 舞台可见宽度
*/ */
get stageWidth() { get stageWidth() {
if (!this.stage) return 0; if (!this.stage) return 0;
return this.stage.viewRect.width; return horizontalScreen ? this.stage.viewRect.width : this.stage.viewRect.height;
} }
/** /**
* 适配方式x两边偏移的量,固定宽度x为0 * 适配方式x两边偏移的量,固定宽度x为0
*/ */
get stageOffsetX() { get stageOffsetX() {
if (!this.stage) return 0; if (!this.stage) return 0;
return this.stage.viewRect.x; return horizontalScreen ? this.stage.viewRect.x : this.stage.viewRect.y;
} }
get stageOffsetY() { get stageOffsetY() {
if (!this.stage) return 0; if (!this.stage) return 0;
return this.stage.viewRect.y; return horizontalScreen ? this.stage.viewRect.y : this.stage.viewRect.x;
} }
/** /**
* 舞台中心点位置x * 舞台中心点位置x
......
...@@ -15,17 +15,20 @@ ...@@ -15,17 +15,20 @@
"mock-webpack-plugin": "^2.0.0", "mock-webpack-plugin": "^2.0.0",
"path": "^0.12.7", "path": "^0.12.7",
"progress": "^2.0.0", "progress": "^2.0.0",
"psd": "^3.2.0",
"readline": "^1.3.0",
"ts-loader": "^4.0.0", "ts-loader": "^4.0.0",
"tslint": "^5.9.1", "tslint": "^5.9.1",
"typescript": "^3.5.1", "typescript": "^3.5.1",
"webpack": "^4.1.0", "webpack": "^4.1.0",
"webpack-cli": "^3.1.1", "webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.0", "webpack-dev-server": "^3.1.0",
"webpack-merge": "^4.1.2", "webpack-merge": "^4.1.2"
"psd": "^3.2.0", },
"readline": "^1.3.0" "dependencies": {
"@types/matter-js": "^0.17.5",
"matter-js": "^0.17.1"
}, },
"dependencies": {},
"scripts": { "scripts": {
"psd": "node scripts/psdH && node scripts/flushRes", "psd": "node scripts/psdH && node scripts/flushRes",
"psdSin": "node scripts/psdHSin", "psdSin": "node scripts/psdHSin",
......
{ {
"groups": [ "groups": [
{ {
"keys": "countdown-back.png", "keys": "boom.png,clock-pointer.png,countdown-back.png",
"name": "CountDownComp" "name": "GameEle"
}, },
{ {
"keys": "back-home.png,jump-icon.png,more-btn.png,new-record-icon.png,product-link__icon.png,share-btn.png", "keys": "GameScene-back.png,extra_scene.png",
"name": "GameOver"
},
{
"keys": "over-back.png,over-tipsicon.png,prize-icon1.png,prize-icon2.png,prize-icon3.png",
"name": "GameOverPanel"
},
{
"keys": "num0.png,num1.png,num2.png,num3.png,num4.png,num5.png,num6.png,num7.png,num8.png,num9.png,numb0.png,numb1.png,numb2.png,numb3.png,numb4.png,numb5.png,numb6.png,numb7.png,numb8.png,numb9.png,numbp.png,nump.png,p1-b.png,p10-b.png,p11-b.png,p12-b.png,p13-b.png,p14-b.png,p15-b.png,p16-b.png,p17-b.png,p18-b.png,p19-b.png,p2-b.png,p20-b.png,p3-b.png,p4-b.png,p5-b.png,p6-b.png,p7-b.png,p8-b.png,p9-b.png",
"name": "GameScene" "name": "GameScene"
}, },
{ {
"keys": "confirm-btn-1.png,newcp-back.png", "keys": "mooncake0-1.png,mooncake0-2.png,mooncake0.png,mooncake1-1.png,mooncake1-2.png,mooncake1.png,mooncake2-1.png,mooncake2-2.png,mooncake2.png,mooncake3-1.png,mooncake3-2.png,mooncake3.png,mooncake4-1.png,mooncake4-2.png,mooncake4.png",
"name": "NewCompletePanel" "name": "MoonCake"
},
{
"keys": "confirm-btn.png,prize-back-title.png,prize-back.png",
"name": "PrizeShowPanel"
}, },
{ {
"keys": "0538f9077d06efad323df05b04e7662e.png,0b5fa6df9b5a26d539e77c2608608d8b.png,0b8805ae-138d-4397-ba2e-78c631199ce0.png,12ec8054b8c348ae7d1e958d1cd2588a.png,1ca73db4-7b05-4b0e-a0fb-8b8554ade130.png,25a820fd42aef3ebf647fa8a8f1b6d97.png,28d56a3f5babaecfd5f73e5813945b5f.png,293052b6-b434-43d0-9ab8-28b6186bd5ca.png,29d49776-b18b-4c9d-a753-82aaaa888624.png,2cf13601-7f36-49cc-8699-2a212858725f.png,359747a74903ade247a702ed9b9229e1.png,39f071fb61eea4b15c28ee87f9a42ab9.png,41178870-b275-495b-8c72-9badb88d9f8c.png,4b8809c43f465d648d826696fa6f402a.png,56b3e456-868a-49a1-bef9-029dc148ed5a.png,6a6640c7-6455-4901-b39c-6b326a1bedbe.png,6e2c9e1567421038ba7a35d5acc53cd5.png,73d6a8ce-2d10-48c1-9d98-6e9b9edf14cb.png,7c52769b370035c2ed3d45c4575899f6.png,8bc5a36a8dbf1a26043a75b265b4b1eb.png,96c45192-0b3e-4bb9-a56b-c8a6f02efef1.png,a0f816ef-8021-4202-a478-1e5c05dde786.png,a92d32f9a8c52dcc79d0c99de311474e.png,ad8b5041-5fdb-4947-8b91-be70e6227ce9.png,adf0dae232a9ffa6a9ce1352a7360980.png,b280118e-fcdf-4d8f-b2fd-357bd153c425.png,b75f6509-258d-4058-8ddc-382c082e5cd7.png,b901f16e009de3b207787382b611a267.png,beaa8224-6905-4ced-96eb-4f89d5896199.png,c2d234e2-dea6-44fd-bdf7-58d932204772.png,c3192272-4150-4f33-8e76-110355f09831.png,ce491a6c44cb6e60d7cc705630d719e1.png,d44c0d0dbb74647e3d1f3114e89a18fa.png,d5a8f96f100df42fd094915c7e70f625.png,d9e2bfe5ede84f7f53e57e6796cb54b2.png,da8a31673c7f5b4c68f4d4dc44ba8faf.png,dc51d376-f884-45fa-a76f-ca96f2f4d028.png,df583b9d-9a9c-4f47-90f1-67bcfa9fb308.png,e2feb63adef7d65f3d56dc84d5b59e65.png,e68dfb4b-2a63-43f2-a476-7445d80a0853.png,f992a7bf1bceafbc97fece72e04bcea9.png,ffc1d98f-d69e-43b1-8554-315276aa1322.png", "keys": "toastBg.png,waitingBg.png,waitingRot.png",
"name": "balance_guidance"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,1daa260b-4ad6-453a-bf2f-3f67fa4ee58d.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3845b99169cdf2ffd89eec33629236b2.png,3965e139993e5072b687ba1e944ae568.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,7454ffe7-f273-42da-a8f3-56dcda5eb90c.png,7acaef1cbaa854fcc731bf08b137faaa.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9da9f6301aab3bb530cc6f45520c8ad5.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,b8bcfabb7cb1690133fbc53df818a86e.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c7d57022-9cec-4af2-bcb3-faf33977b271.png,c9cef93be7451b685edbd1fcd8f61732.png,e0c229e262c34b128c0f50ecac33369b.png,e8e4ae26-a99e-4a79-9261-e5fcac395fb0.png",
"name": "blank_shoe"
},
{
"keys": "comCloseBtn.png,com_light.png,count-start.png,count1.png,count2.png,count3.png,jordan-icon.png,music-off.png,music-on.png,nike-icon.png,percennt0.png,percennt1.png,percennt2.png,percennt3.png,percennt4.png,percennt5.png,percennt6.png,percennt7.png,percennt8.png,percennt9.png,percenntp.png,ruready.png,toastBg.png,waitingBg.png,waitingRot.png,跳过按钮.png",
"name": "common" "name": "common"
},
{
"keys": "c9a24fed01170dc61854098b7f6e50af.png",
"name": "excellent_icon"
},
{
"keys": "009ed41bfa913bd15c5dda62716e608c.png,02f26c4510df27a5acb8ce26b9c5b0ba.png,1d202725fd410588dfa8b3e1ccf810ce.png,2027bc3879e8f06799f1759fa914f426.png,245201acb5b065e60711e402277d4908.png,24cbb272ca0595390a65d16269acc141.png,28c9a63f6e33fbc7b7f9c51db5752ac9.png,32f6ae97f854c575c7130c9c2896a287.png,47d38d653cd78676a3ca3b4e7b6a7044.png,4fd8362250aa1555a1cb6352a10ac312.png,5cf06ed99e90cd0e4464cac6dbb29dc3.png,5d19c027ad8778f99a3f0950acdd2739.png,6c0fa5d1972318368c48f4c09418459d.png,71b5a61c46ec88c372180e56cbc0fb3d.png,722612e4c34ae14ba427382557a0c9cb.png,73ef3d3454a074c9decb1ecb7909105e.png,76d230aac3001933de45c949a9140889.png,77a0ae8dd94043602811479e935beafb.png,84f82a9ec12dd316f44382818fe0553c.png,9ac140216cfe3e2ba0c5f9dcb8de4856.png,a06938c7a7105be8ffd0e68c82527be5.png,a0f9249750bdd4bd9aa3f628c7f47c67.png,a3196dffd24bec4ceeb78c40e789411d.png,a811ad9246c54b177ae8c5a211ecbf02.png,a856a0dae3018ef19512f88849596579.png,addea92ee44e85d3b5c4ad97c67e0bbb.png,b7b9e7b3a43aff9ec5b46f0d253d69cc.png,ba494e2790eab1b74233301f7a6e68e2.png,bf2712c0db9cb0e2d408a529cd2421ec.png,bf3c7702119ae821578eb99c069617a3.png,c08f4c1bceb6c129da183349eaa18702.png,c111333453e0bb104a4c0d89c20c4472.png,c5aab24b86fe3182b1285f85eaec5bfe.png,ca3be215bf1c00d85f491a5ee971554f.png,cbb3cb0886f45f3e42e31b635ac2f13d.png,d024b2620af9a5f440a611167f596457.png,d77eb6d84abf89c0d276de9c598e4c58.png,d82e528b29ad71b09e0be5681959a789.png,db8bdb142b802b126523cfccf4d6a503.png,dfa3f688ec9fdd0a465f9417bd43ebf2.png,dfdbfa372b9183cb08d320aa3cc43a11.png,e0913099d595c5bc06c3d3daa62d2083.png,e1c091647a039b1c089709a81c4cd379.png,e3e8798120c483a49384a4fcc52c099c.png,e8b1bf3e159712ea403845a373fbf92e.png,f52e180cd79bcf8658830bc0c54942b9.png,f782b72f25909b59f23d0cad704f5eb4.png,ff5c46f42d987a67da838ff09c183a93.png",
"name": "guidan_360"
},
{
"keys": "p1.png,p10.png,p11.png,p12.png,p13.png,p14.png,p15.png,p16.png,p17.png,p18.png,p19.png,p2.png,p20.png,p3.png,p4.png,p5.png,p6.png,p7.png,p8.png,p9.png",
"name": "jordan_eles"
},
{
"keys": "p1.png,p10.png,p11.png,p12.png,p13.png,p14.png,p15.png,p16.png,p17.png,p18.png,p19.png,p2.png,p20.png,p3.png,p4.png,p5.png,p6.png,p7.png,p8.png,p9.png",
"name": "nike_eles"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3965e139993e5072b687ba1e944ae568.png,3d5139ce-fcfd-4604-b6da-282230f8afee.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,7acaef1cbaa854fcc731bf08b137faaa.png,7f2a9fd9bb5aa175e606246dd843aed9.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,b9689750-84db-4dc3-9bba-70c6e86ff2ca.png,bbd780a01510cbc706a71d5f96f52dcb.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c7d57022-9cec-4af2-bcb3-faf33977b271.png,c9cef93be7451b685edbd1fcd8f61732.png,ddde1ae50b039bf96ef7737d5708f7dd.png,e0c229e262c34b128c0f50ecac33369b.png,eb51f7d9-1919-48e8-8a5b-5e2ee8cf3075.png",
"name": "red_shoe"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3965e139993e5072b687ba1e944ae568.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,75040919584435153d89b059a3df0bb3.png,77dbe8db0f6b44bf93b5033f3bfcf309.png,7acaef1cbaa854fcc731bf08b137faaa.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c9cef93be7451b685edbd1fcd8f61732.png,e0c229e262c34b128c0f50ecac33369b.png,fd59bf6380de3ea52dcbbbec373bb1b4.png",
"name": "white_shoe"
},
{
"keys": "0513a2914668b008516adc921b90e29e.png",
"name": "yoga_fail"
} }
], ],
"path": "./resource/" "path": "./resource/"
......
...@@ -10,6 +10,7 @@ import { SkinJson } from "./SkinJson"; ...@@ -10,6 +10,7 @@ import { SkinJson } from "./SkinJson";
import { G_EVENT } from "./common/G_EVENT"; import { G_EVENT } from "./common/G_EVENT";
import { Tools } from "./Tools"; import { Tools } from "./Tools";
import IndexScene from './scenes/IndexScene'; import IndexScene from './scenes/IndexScene';
import GameScene from "./scenes/GameScene/GameScene";
/** /**
* 全局事件,为了和小程序交互 * 全局事件,为了和小程序交互
...@@ -17,12 +18,16 @@ import IndexScene from './scenes/IndexScene'; ...@@ -17,12 +18,16 @@ import IndexScene from './scenes/IndexScene';
*/ */
export const GDispatcher = new FYGE.EventDispatcher(); export const GDispatcher = new FYGE.EventDispatcher();
export const horizontalScreen = true
export class Main { export class Main {
//主舞台 //主舞台
stage: FYGE.Stage; stage: FYGE.Stage;
private requestID; private requestID;
private _pause: boolean; private _pause: boolean;
private canvas: HTMLCanvasElement private canvas: HTMLCanvasElement
private stageWidth: number
private stageHeight: number
constructor(canvas: HTMLCanvasElement, PAGE) { constructor(canvas: HTMLCanvasElement, PAGE) {
Tools.PAGE = PAGE; Tools.PAGE = PAGE;
...@@ -33,16 +38,30 @@ export class Main { ...@@ -33,16 +38,30 @@ export class Main {
//@ts-ignore 存在my就初始化 //@ts-ignore 存在my就初始化
sysInfo = my.getSystemInfoSync() sysInfo = my.getSystemInfoSync()
} }
var stageWidth = this.stageWidth = sysInfo && sysInfo.windowWidth || document.body.clientWidth
var stageHeight = this.stageHeight = sysInfo && sysInfo.windowHeight || document.body.clientHeight
//建舞台 //建舞台
var stage = new FYGE.Stage( var stage = horizontalScreen ? new FYGE.Stage(
canvas,
1624,//设计宽度,按设计搞给的就行
750,//设计高度
stageWidth,
stageHeight,
FYGE.RENDERER_TYPE.WEBGL,
true, //视窗居中裁切
true, // 定宽高
) : new FYGE.Stage(
canvas, canvas,
750,//设计宽度,按设计搞给的就行 750,//设计宽度,按设计搞给的就行
1624,//设计高度 1624,//设计高度
sysInfo && sysInfo.windowWidth || document.body.clientWidth, stageWidth,
sysInfo && sysInfo.windowHeight || document.body.clientHeight, stageHeight,
FYGE.RENDERER_TYPE.WEBGL, FYGE.RENDERER_TYPE.WEBGL,
true //视窗居中裁切 true, //视窗居中裁切
// true, // 定宽高
); );
console.log(stage, stageWidth, stageHeight)
this.stage = stage; this.stage = stage;
this.canvas = canvas;//赋值下,为了下面的destroy的cancelAnimationFrame this.canvas = canvas;//赋值下,为了下面的destroy的cancelAnimationFrame
//stage初始化 //stage初始化
...@@ -149,6 +168,21 @@ export class Main { ...@@ -149,6 +168,21 @@ export class Main {
private async onAddToStage() { private async onAddToStage() {
//初始化层级 //初始化层级
layers.init(this.stage); layers.init(this.stage);
// vtodo 开发之后旋转
if (!horizontalScreen) {
layers.sceneLayer.rotation = 90
layers.sceneLayer.x = 750
}
// 让(0, 0) 在视图内
// layers.sceneLayer.x = layers.stageOffsetX
// layers.sceneLayer.y = layers.stageOffsetY
// vtodo 横屏开发
// layers.sceneLayer.x = layers.stageOffsetX
console.log("初始化层级完成") console.log("初始化层级完成")
// 初始化资源配置 // 初始化资源配置
RES.loadConfig(ResJson); RES.loadConfig(ResJson);
...@@ -180,7 +214,7 @@ export class Main { ...@@ -180,7 +214,7 @@ export class Main {
// } // }
// vtodo 是否是新手 // vtodo 是否是新手
changeScene(IndexScene); changeScene(GameScene);
} }
} }
......
export const ResJson = { export const ResJson = {
"groups": [ "groups": [
{ {
"keys": "countdown-back.png", "keys": "boom.png,clock-pointer.png,countdown-back.png",
"name": "CountDownComp" "name": "GameEle"
}, },
{ {
"keys": "back-home.png,jump-icon.png,more-btn.png,new-record-icon.png,product-link__icon.png,share-btn.png", "keys": "GameScene-back.png,extra_scene.png",
"name": "GameOver"
},
{
"keys": "over-back.png,over-tipsicon.png,prize-icon1.png,prize-icon2.png,prize-icon3.png",
"name": "GameOverPanel"
},
{
"keys": "num0.png,num1.png,num2.png,num3.png,num4.png,num5.png,num6.png,num7.png,num8.png,num9.png,numb0.png,numb1.png,numb2.png,numb3.png,numb4.png,numb5.png,numb6.png,numb7.png,numb8.png,numb9.png,numbp.png,nump.png,p1-b.png,p10-b.png,p11-b.png,p12-b.png,p13-b.png,p14-b.png,p15-b.png,p16-b.png,p17-b.png,p18-b.png,p19-b.png,p2-b.png,p20-b.png,p3-b.png,p4-b.png,p5-b.png,p6-b.png,p7-b.png,p8-b.png,p9-b.png",
"name": "GameScene" "name": "GameScene"
}, },
{ {
"keys": "confirm-btn-1.png,newcp-back.png", "keys": "mooncake0-1.png,mooncake0-2.png,mooncake0.png,mooncake1-1.png,mooncake1-2.png,mooncake1.png,mooncake2-1.png,mooncake2-2.png,mooncake2.png,mooncake3-1.png,mooncake3-2.png,mooncake3.png,mooncake4-1.png,mooncake4-2.png,mooncake4.png",
"name": "NewCompletePanel" "name": "MoonCake"
},
{
"keys": "confirm-btn.png,prize-back-title.png,prize-back.png",
"name": "PrizeShowPanel"
}, },
{ {
"keys": "0538f9077d06efad323df05b04e7662e.png,0b5fa6df9b5a26d539e77c2608608d8b.png,0b8805ae-138d-4397-ba2e-78c631199ce0.png,12ec8054b8c348ae7d1e958d1cd2588a.png,1ca73db4-7b05-4b0e-a0fb-8b8554ade130.png,25a820fd42aef3ebf647fa8a8f1b6d97.png,28d56a3f5babaecfd5f73e5813945b5f.png,293052b6-b434-43d0-9ab8-28b6186bd5ca.png,29d49776-b18b-4c9d-a753-82aaaa888624.png,2cf13601-7f36-49cc-8699-2a212858725f.png,359747a74903ade247a702ed9b9229e1.png,39f071fb61eea4b15c28ee87f9a42ab9.png,41178870-b275-495b-8c72-9badb88d9f8c.png,4b8809c43f465d648d826696fa6f402a.png,56b3e456-868a-49a1-bef9-029dc148ed5a.png,6a6640c7-6455-4901-b39c-6b326a1bedbe.png,6e2c9e1567421038ba7a35d5acc53cd5.png,73d6a8ce-2d10-48c1-9d98-6e9b9edf14cb.png,7c52769b370035c2ed3d45c4575899f6.png,8bc5a36a8dbf1a26043a75b265b4b1eb.png,96c45192-0b3e-4bb9-a56b-c8a6f02efef1.png,a0f816ef-8021-4202-a478-1e5c05dde786.png,a92d32f9a8c52dcc79d0c99de311474e.png,ad8b5041-5fdb-4947-8b91-be70e6227ce9.png,adf0dae232a9ffa6a9ce1352a7360980.png,b280118e-fcdf-4d8f-b2fd-357bd153c425.png,b75f6509-258d-4058-8ddc-382c082e5cd7.png,b901f16e009de3b207787382b611a267.png,beaa8224-6905-4ced-96eb-4f89d5896199.png,c2d234e2-dea6-44fd-bdf7-58d932204772.png,c3192272-4150-4f33-8e76-110355f09831.png,ce491a6c44cb6e60d7cc705630d719e1.png,d44c0d0dbb74647e3d1f3114e89a18fa.png,d5a8f96f100df42fd094915c7e70f625.png,d9e2bfe5ede84f7f53e57e6796cb54b2.png,da8a31673c7f5b4c68f4d4dc44ba8faf.png,dc51d376-f884-45fa-a76f-ca96f2f4d028.png,df583b9d-9a9c-4f47-90f1-67bcfa9fb308.png,e2feb63adef7d65f3d56dc84d5b59e65.png,e68dfb4b-2a63-43f2-a476-7445d80a0853.png,f992a7bf1bceafbc97fece72e04bcea9.png,ffc1d98f-d69e-43b1-8554-315276aa1322.png", "keys": "toastBg.png,waitingBg.png,waitingRot.png",
"name": "balance_guidance"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,1daa260b-4ad6-453a-bf2f-3f67fa4ee58d.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3845b99169cdf2ffd89eec33629236b2.png,3965e139993e5072b687ba1e944ae568.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,7454ffe7-f273-42da-a8f3-56dcda5eb90c.png,7acaef1cbaa854fcc731bf08b137faaa.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9da9f6301aab3bb530cc6f45520c8ad5.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,b8bcfabb7cb1690133fbc53df818a86e.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c7d57022-9cec-4af2-bcb3-faf33977b271.png,c9cef93be7451b685edbd1fcd8f61732.png,e0c229e262c34b128c0f50ecac33369b.png,e8e4ae26-a99e-4a79-9261-e5fcac395fb0.png",
"name": "blank_shoe"
},
{
"keys": "comCloseBtn.png,com_light.png,count-start.png,count1.png,count2.png,count3.png,jordan-icon.png,music-off.png,music-on.png,nike-icon.png,percennt0.png,percennt1.png,percennt2.png,percennt3.png,percennt4.png,percennt5.png,percennt6.png,percennt7.png,percennt8.png,percennt9.png,percenntp.png,ruready.png,toastBg.png,waitingBg.png,waitingRot.png,跳过按钮.png",
"name": "common" "name": "common"
},
{
"keys": "c9a24fed01170dc61854098b7f6e50af.png",
"name": "excellent_icon"
},
{
"keys": "009ed41bfa913bd15c5dda62716e608c.png,02f26c4510df27a5acb8ce26b9c5b0ba.png,1d202725fd410588dfa8b3e1ccf810ce.png,2027bc3879e8f06799f1759fa914f426.png,245201acb5b065e60711e402277d4908.png,24cbb272ca0595390a65d16269acc141.png,28c9a63f6e33fbc7b7f9c51db5752ac9.png,32f6ae97f854c575c7130c9c2896a287.png,47d38d653cd78676a3ca3b4e7b6a7044.png,4fd8362250aa1555a1cb6352a10ac312.png,5cf06ed99e90cd0e4464cac6dbb29dc3.png,5d19c027ad8778f99a3f0950acdd2739.png,6c0fa5d1972318368c48f4c09418459d.png,71b5a61c46ec88c372180e56cbc0fb3d.png,722612e4c34ae14ba427382557a0c9cb.png,73ef3d3454a074c9decb1ecb7909105e.png,76d230aac3001933de45c949a9140889.png,77a0ae8dd94043602811479e935beafb.png,84f82a9ec12dd316f44382818fe0553c.png,9ac140216cfe3e2ba0c5f9dcb8de4856.png,a06938c7a7105be8ffd0e68c82527be5.png,a0f9249750bdd4bd9aa3f628c7f47c67.png,a3196dffd24bec4ceeb78c40e789411d.png,a811ad9246c54b177ae8c5a211ecbf02.png,a856a0dae3018ef19512f88849596579.png,addea92ee44e85d3b5c4ad97c67e0bbb.png,b7b9e7b3a43aff9ec5b46f0d253d69cc.png,ba494e2790eab1b74233301f7a6e68e2.png,bf2712c0db9cb0e2d408a529cd2421ec.png,bf3c7702119ae821578eb99c069617a3.png,c08f4c1bceb6c129da183349eaa18702.png,c111333453e0bb104a4c0d89c20c4472.png,c5aab24b86fe3182b1285f85eaec5bfe.png,ca3be215bf1c00d85f491a5ee971554f.png,cbb3cb0886f45f3e42e31b635ac2f13d.png,d024b2620af9a5f440a611167f596457.png,d77eb6d84abf89c0d276de9c598e4c58.png,d82e528b29ad71b09e0be5681959a789.png,db8bdb142b802b126523cfccf4d6a503.png,dfa3f688ec9fdd0a465f9417bd43ebf2.png,dfdbfa372b9183cb08d320aa3cc43a11.png,e0913099d595c5bc06c3d3daa62d2083.png,e1c091647a039b1c089709a81c4cd379.png,e3e8798120c483a49384a4fcc52c099c.png,e8b1bf3e159712ea403845a373fbf92e.png,f52e180cd79bcf8658830bc0c54942b9.png,f782b72f25909b59f23d0cad704f5eb4.png,ff5c46f42d987a67da838ff09c183a93.png",
"name": "guidan_360"
},
{
"keys": "p1.png,p10.png,p11.png,p12.png,p13.png,p14.png,p15.png,p16.png,p17.png,p18.png,p19.png,p2.png,p20.png,p3.png,p4.png,p5.png,p6.png,p7.png,p8.png,p9.png",
"name": "jordan_eles"
},
{
"keys": "p1.png,p10.png,p11.png,p12.png,p13.png,p14.png,p15.png,p16.png,p17.png,p18.png,p19.png,p2.png,p20.png,p3.png,p4.png,p5.png,p6.png,p7.png,p8.png,p9.png",
"name": "nike_eles"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3965e139993e5072b687ba1e944ae568.png,3d5139ce-fcfd-4604-b6da-282230f8afee.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,7acaef1cbaa854fcc731bf08b137faaa.png,7f2a9fd9bb5aa175e606246dd843aed9.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,b9689750-84db-4dc3-9bba-70c6e86ff2ca.png,bbd780a01510cbc706a71d5f96f52dcb.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c7d57022-9cec-4af2-bcb3-faf33977b271.png,c9cef93be7451b685edbd1fcd8f61732.png,ddde1ae50b039bf96ef7737d5708f7dd.png,e0c229e262c34b128c0f50ecac33369b.png,eb51f7d9-1919-48e8-8a5b-5e2ee8cf3075.png",
"name": "red_shoe"
},
{
"keys": "0272a464df7d9c1ca7bcd240ff5b6ff1.png,0339f8cec366210e1895bb822005f5ca.png,0471fa62dfb977981f0bbcbf03d5364c.png,0521db775413790e5754d0a359a26c05.png,056b70b501ad2bb9de96fe5a40ec244c.png,0960016b2a4b0945ae1a504cf05d58b5.png,1366e0dc8765778425bc3612c5a02991.png,16794fd2bb051adab7cf54b7e36d2c87.png,1cb1e4d2fa9e520728a397f33dc41e85.png,23a5d1a88f781623a16727e8defbe5f2.png,243da2df1403d966f345a1bf61310276.png,2592ff4846d8e05ea9280a9206b2b765.png,2b774e8e40d7eeb4f56565090fcf1a1f.png,3965e139993e5072b687ba1e944ae568.png,4947993d9e0c86dd197cab056f32b26e.png,4f7efec7932532041668f88e5eaa6485.png,55223ef0f41017b272998afbf097e11c.png,643f90f77b7858c5a54f1f2d2371a396.png,6a9d7e1fce8bc7e9b014add6ba3a40a6.png,6b5ba368fd1b35b4f7ae7d0941983b5f.png,6eab818514531d8dd0aff35576e834fe.png,70fcb05422163afdc827b4c7aa421932.png,75040919584435153d89b059a3df0bb3.png,77dbe8db0f6b44bf93b5033f3bfcf309.png,7acaef1cbaa854fcc731bf08b137faaa.png,8e2a1bf2cfd857dae69edb9d70820e23.png,9e4c70df3c98f66fc402e0e5e64e1f0b.png,9f874f56586024e4c873b6237d027558.png,a2a8d4e441d527d8fbd8f1d1b6ec237d.png,a4e1f9ed07a40359eaf255394e272272.png,aef93a72f0db18e2c6fbc356d101bac0.png,b18be206e2cfcc766695779607b91e33.png,b7cc11169a1c2980ff1f543adc5e83fb.png,c6d5f14a2986660aec470230367eb3d3.png,c78db3f7c109f9cf731d5045c4886854.png,c9cef93be7451b685edbd1fcd8f61732.png,e0c229e262c34b128c0f50ecac33369b.png,fd59bf6380de3ea52dcbbbec373bb1b4.png",
"name": "white_shoe"
},
{
"keys": "0513a2914668b008516adc921b90e29e.png",
"name": "yoga_fail"
} }
], ],
"path": "./resource/" "path": "./resource/"
......
import Matter = require("matter-js")
import { RES } from "../../module/RES"
export default class BoomEle extends FYGE.Sprite {
public phyBody: Matter.Body
constructor() {
super()
this.texture = RES.getRes('boom.png')
this.anchorY = this.height / 2
this.anchorX = this.width / 2
this.phyBody = Matter.Bodies.circle(this.x, this.y, this.height / 2, {
restitution: .3,// 弹性
mass: .5, // 质量
isStatic: false,
isSensor: true, // 传感器,true检测碰撞但是不会 参与碰撞
render: {fillStyle: '#060a19'},
collisionFilter: {
group: 1
}
})
this.setPhyPos()
var that = this
this.addEventListener(FYGE.Event.ADDED_TO_STAGE, () => {
this.addEventListener(FYGE.Event.ENTER_FRAME, this.syncPos, this)
}, this)
that = new Proxy(this, {
get: function (target, key:string, receiver) {
return Reflect.get(target, key, receiver);
},
set: function (target, key:string, value, receiver) {
var r = Reflect.set(target, key, value, receiver)
if (key == 'x' || key == 'y') {
that.setPhyPos()
}
// console.log(`setting ${key}!`);
return r;
}
})
return that
}
// 同步坐标, 随着刚体进行更新
syncPos() {
this.x = this.phyBody.position.x - this.width / 2;
this.y = this.phyBody.position.y - this.height / 2;
}
setPhyPos() {
Matter.Body.setPosition(this.phyBody, {
x: (this.x + this.width / 2),
y: (this.y + this.height / 2)
});
}
}
\ No newline at end of file
...@@ -12,6 +12,7 @@ export default class CountDownComp extends Module { ...@@ -12,6 +12,7 @@ export default class CountDownComp extends Module {
timeoutFn: Array<Function> timeoutFn: Array<Function>
tobj: TimeObj // 倒计时 tobj: TimeObj // 倒计时
iTime: number // 第一次的时间 iTime: number // 第一次的时间
autoPlay: boolean
get initTime():number { get initTime():number {
return this.iTime return this.iTime
...@@ -27,19 +28,24 @@ export default class CountDownComp extends Module { ...@@ -27,19 +28,24 @@ export default class CountDownComp extends Module {
this.formatTime(t) this.formatTime(t)
} }
constructor(t: number) { constructor(t: number, autoPlay?:boolean) {
super(t) super(t)
this.autoPlay = autoPlay
} }
get groupNames(): string[] { get groupNames(): string[] {
return ['CountDownComp'] return ['GameEle']
} }
cdt: FYGE.TextField cdt: FYGE.TextField
initUi() { initUi() {
UI.Sp(this, 'countdown-back.png') UI.Sp(this, 'countdown-back.png')
var p = UI.Sp(this, 'clock-pointer.png', 28, 29)
p.anchorTexture.set(0.5, 1)
FYGE.Tween.get(p, {loop: true})
.to({rotation: 360}, 5000)
this.cdt = UI.Txt(this, '0', 30, '#ffffff', FYGE.TEXT_ALIGN.CENTER, 40, 55, 14) this.cdt = UI.Txt(this, '00:00', 28, '#ffe8af', FYGE.TEXT_ALIGN.CENTER, 80, 60, 12)
this.initTime = this.data this.initTime = this.data
} }
...@@ -59,9 +65,10 @@ export default class CountDownComp extends Module { ...@@ -59,9 +65,10 @@ export default class CountDownComp extends Module {
} }
formatTime(n:number) { formatTime(n:number) {
var _t = ((n / 1000) >> 0) var _t = ((n / 1000) >> 0);
this.cdt.text = _t + '' var ft = dateLeftFormat('mm:ss', _t)
return _t this.cdt.text = ft + ''
return ft
} }
countDown(time: TimeObj, onChange: Function) { countDown(time: TimeObj, onChange: Function) {
......
import Matter = require("matter-js")
import { RES } from "../../module/RES"
import UI from "../UI"
export default class MoonCake extends FYGE.Sprite {
type: string = 'mooncake'
imgName: string // 游戏元素索引
miss: boolean // 是否错过
constructor(i: number) {
super()
this.imgName = `mooncake${i}`
this.texture = RES.getRes(`mooncake${i}.png`)
// console.log(`mooncake${i}`, this.texture)
// this.anchorTexture.set(0.5, 0.5)
this.anchorY = this.height / 2
this.anchorX = this.width / 2
this.initPhyBody()
this.initEvent()
// 设置物理世界的坐标
this.setPhyPos()
var that = this
that = new Proxy(this, {
get: function (target, key:string, receiver) {
return Reflect.get(target, key, receiver);
},
set: function (target, key:string, value, receiver) {
var r = Reflect.set(target, key, value, receiver)
if (key == 'x' || key == 'y') {
that.setPhyPos()
}
// console.log(`setting ${key}!`);
return r;
}
})
return that
}
phyBody: Matter.Body
initPhyBody() {
this.phyBody = Matter.Bodies.circle(this.x, this.y, this.height / 2, {
isSensor: true, // true 检测碰撞但是不会参与
isStatic: true,
render: {
fillStyle: "#cccccc"
},
collisionFilter: {
group: -1
}
})
}
initEvent() {
this.addEventListener(FYGE.Event.ADDED_TO_STAGE, () => {
this.addEventListener(FYGE.Event.ENTER_FRAME, this.syncPos, this)
}, this)
}
// 同步坐标, 随着刚体进行更新
syncPos() {
this.x = this.phyBody.position.x - this.width / 2;
this.y = this.phyBody.position.y - this.height / 2;
}
setPhyPos() {
Matter.Body.setPosition(this.phyBody, {
x: (this.x + this.width / 2),
y: (this.y + this.height / 2)
});
}
half_left: FYGE.Sprite
half_right: FYGE.Sprite
/**
* 一分为二
*/
doHalf() {
this.texture.valid = false
setTimeout(() => {
this.half_left = UI.Sp(this, `${this.imgName}-2.png`, -5, 0)
this.half_right = UI.Sp(this, `${this.imgName}-1.png`, 5, 0)
}, 1000)
}
}
\ No newline at end of file
import { layers } from "../../../module/views/layers";
import { Scene } from "../../../module/views/Scene";
import UI from "../../UI";
import Matter = require("matter-js");
import BoomEle from "../../components/BoomEle";
import { horizontalScreen } from "../../Main";
import CountDownComp from "../../components/CountDownComp";
import MoonCake from "../../components/MoonCake";
import { randomNum } from "../../utils/utils";
const MouseEvent = FYGE.MouseEvent
const { Engine, Render, Runner, Composite, Bodies, World, Composites } = Matter
export default class GameScene extends Scene {
isOver: boolean = false
mooncakes: Array<MoonCake> = []
maxcakes: number = 5
sceneContainer: FYGE.Container
get groupNames() {
return ['GameScene', 'GameEle', 'MoonCake']
}
_MoonCake: BoomEle
initUi() {
// 初始化物理世界
this.initPhyWorld()
UI.Sp(this, 'GameScene-back.png')
var s = UI.Sp(this, 'extra_scene.png', 0, 0)
s.y = 750 - s.height
var sceneContainer = this.sceneContainer = UI.Ctn(this, layers.stageOffsetX, layers.stageOffsetY)
// var t = UI.Txt(this, '123123', 28)
// t.x = layers.stageOffsetX
// t.y = 0
var boom = sceneContainer.addChild(new BoomEle())
Matter.Body.setStatic(boom.phyBody, true)
// 测试 月饼
this._MoonCake = sceneContainer.addChild(new MoonCake(2))
this._MoonCake.x = 200
Matter.Body.setStatic(this._MoonCake.phyBody, true)
//@ts-ignore
window.test = (x, y) => {
Matter.Body.setStatic(this._MoonCake.phyBody, false)
Matter.Body.setVelocity(this._MoonCake.phyBody, {x, y})
}
var cdp = sceneContainer.addChild(new CountDownComp(61000))
cdp.position.set(layers.stageWidth - 200 , 30)
// vtodo 这里有点问题 一步的
setTimeout(() => {
cdp.start()
}, 0)
// @ts-ignore
this.composites.add(this.world, [boom.phyBody, this._MoonCake.phyBody])
this.initGame()
}
initGame() {
this.gennerateMoonCakes()
}
gennerateMoonCakes() {
if (this.isOver) return
while(this.mooncakes.length < this.maxcakes) {
this.initMoonCake()
}
}
initMoonCake() {
var i = Math.floor(Math.random() * 5)
var mc = new MoonCake(i)
mc.x = randomNum(100, layers.stageWidth - 200)
mc.y = layers.stageHeight-100
// @ts-ignore
this.composites.add(this.world, [mc.phyBody])
this.mooncakes.push(mc)
FYGE.Tween.get(mc, {loop: true})
.to({ rotation: 360 }, 5000)
this.sceneContainer.addChild(mc)
// 每个月饼随机出现
setTimeout(() => {
if (this.isOver) return
Matter.Body.setStatic(mc.phyBody, false)
var k = layers.stageHeight / 750
Matter.Body.setVelocity(mc.phyBody, {x: mc.x < layers.stageWidth / 2 ? randomNum(3,5) : randomNum(-3, -5), y: -17 * k})
}, randomNum(0, 3000))
}
initEvents() {
this.stage.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, this.onMouseDown, this)
this.addEventListener(FYGE.Event.ENTER_FRAME, this.FrameUpdate, this)
Matter.Events.on(this.engine, 'collisionStart', (e) => {
console.log(e)
console.log(e.pairs[0])
// console.log('collision')
})
}
// 帧事件
FrameUpdate() {
this.mooncakes.map((e, i) => {
if (e.y > layers.stageHeight) {
if (!e.miss) {
// console.log('错了一个')
}
this.sceneContainer.removeChild(e)
this.mooncakes.splice(i, 1)
this.gennerateMoonCakes()
}
})
}
onMouseDown(e) {
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove, this)
this.stage.addEventListener(MouseEvent.MOUSE_UP, () => {
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove, this)
})
}
onMouseMove(e) {
this._MoonCake.x = e.localX - this._MoonCake.width / 2
this._MoonCake.y = e.localY - this._MoonCake.height / 2
}
engine: Matter.Engine // 物理引擎
world: Matter.World // 世界
runner: Matter.Runner
composites: Matter.Composites
initPhyWorld() {
this.engine = Engine.create()
this.world = this.engine.world
// 设置物理引擎的y重力
this.engine.gravity.x = 0.0
this.engine.gravity.y = 0.6
this.runner = Runner.create()
// Runner.run(this.runner, this.engine)
this.composites = Composite // 复合体
this.setPhyDebug()
}
private setPhyDebug() {
const canvas = document.createElement("canvas");
canvas.style.width = "100%";
canvas.style.height = "100%";
const div = document.createElement("div");
div.style.position = "absolute"
// div.style.top = "50%";
div.style.pointerEvents = "none";
// div.style.transform = "translateY(-50%)";
div.style.lineHeight = "0";
div.style.fontStyle = "0";
document.body.append(div);
const render = Render.create({
canvas: canvas,
element: div,
engine: this.engine,
options: {
wireframes: true,
width: horizontalScreen ? 1624 : 750,
height: horizontalScreen ? 750 : 1624,
background: 'transparent',
wireframeBackground: 'transparent',
showSleeping: true,
},
});
Render.run(render);
}
update() {
// 让物理引擎 先update 这样就不会看着卡顿 Runner.tick && Runner.run
Runner.tick(this.runner, this.engine, 0)
super.update()
}
}
\ No newline at end of file
import { layers } from "../../module/views/layers";
import { Scene } from "../../module/views/Scene"; import { Scene } from "../../module/views/Scene";
import UI from "../UI"; import UI from "../UI";
export default class IndexScene extends Scene { export default class IndexScene extends Scene {
initUi() { initUi() {
UI.Txt(this, 'index', 28) console.log(layers.stageWidth)
UI.Txt(this, 'index', 28, '#111111', FYGE.TEXT_ALIGN.CENTER, 100, 0)
} }
} }
\ No newline at end of file
var a = 1
a = ''
export function test() {
console.log(233)
}
\ No newline at end of file
...@@ -66,7 +66,7 @@ export function throttle(fn:Function, delay: number=2000) { ...@@ -66,7 +66,7 @@ export function throttle(fn:Function, delay: number=2000) {
} }
/** /**
* 返回时间格式 r 秒单位 * 返回时间格式 入参 r 秒单位
* @param {*} fmt * @param {*} fmt
* @param {*} r * @param {*} r
* @returns * @returns
...@@ -122,3 +122,13 @@ export function onceFnc(fn:Function, count:number = 1) { ...@@ -122,3 +122,13 @@ export function onceFnc(fn:Function, count:number = 1) {
fn.apply(this, arguments) fn.apply(this, arguments)
} }
} }
/**
* 取随机数,这里的随机数不是取整的 [min, max)
* @param min
* @param max
* @returns
*/
export function randomNum(min:number, max:number) {
return Number((Math.random() * (max - min) + min).toFixed(2))
}
\ No newline at end of file
...@@ -57,6 +57,11 @@ ...@@ -57,6 +57,11 @@
"@types/minimatch" "*" "@types/minimatch" "*"
"@types/node" "*" "@types/node" "*"
"@types/matter-js@^0.17.5":
version "0.17.5"
resolved "http://npm.dui88.com:80/@types%2fmatter-js/-/matter-js-0.17.5.tgz#b7ddd422cf5980f01531dfed60fc11682a1adbb9"
integrity sha1-t93UIs9ZgPAVMd/tYPwRaCoa27k=
"@types/minimatch@*": "@types/minimatch@*":
version "3.0.4" version "3.0.4"
resolved "http://npm.dui88.com:80/@types%2fminimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21" resolved "http://npm.dui88.com:80/@types%2fminimatch/-/minimatch-3.0.4.tgz#f0ec25dbf2f0e4b18647313ac031134ca5b24b21"
...@@ -3351,6 +3356,11 @@ map-visit@^1.0.0: ...@@ -3351,6 +3356,11 @@ map-visit@^1.0.0:
dependencies: dependencies:
object-visit "^1.0.0" object-visit "^1.0.0"
matter-js@^0.17.1:
version "0.17.1"
resolved "http://npm.dui88.com:80/matter-js/-/matter-js-0.17.1.tgz#b30ac4c708116258fbcaacd2efd8a94e34a91c7f"
integrity sha1-swrExwgRYlj7yqzS79ipTjSpHH8=
md5.js@^1.3.4: md5.js@^1.3.4:
version "1.3.5" version "1.3.5"
resolved "http://npm.dui88.com:80/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" resolved "http://npm.dui88.com:80/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
...@@ -5674,8 +5684,10 @@ watchpack@^1.7.4: ...@@ -5674,8 +5684,10 @@ watchpack@^1.7.4:
resolved "http://npm.dui88.com:80/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453" resolved "http://npm.dui88.com:80/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453"
integrity sha1-EmfmxV4Lm1vkTCAjrtVDeiwmxFM= integrity sha1-EmfmxV4Lm1vkTCAjrtVDeiwmxFM=
dependencies: dependencies:
chokidar "^3.4.1"
graceful-fs "^4.1.2" graceful-fs "^4.1.2"
neo-async "^2.5.0" neo-async "^2.5.0"
watchpack-chokidar2 "^2.0.1"
optionalDependencies: optionalDependencies:
chokidar "^3.4.1" chokidar "^3.4.1"
watchpack-chokidar2 "^2.0.1" watchpack-chokidar2 "^2.0.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment