Commit b9593434 authored by 王梦佳's avatar 王梦佳

娃娃机

parent 140f0a58
This diff is collapsed.
This diff is collapsed.
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = "doll-machine";
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "口红机",
"desc": "口红机模块",
"props": {
"frontmargin": {
"alias": "前排娃娃的间距",
"type": "number",
"default": 50
},
"backmargin": {
"alias": "后排娃娃的间距",
"type": "number",
"default": 50
},
"moveSpeed": {
"alias": "娃娃移动的速度",
"type": "number",
"default": 3
},
"bashouMoveDist": {
"alias": "爪子整体左右移动的范围",
"type": "number",
"default": 200
},
"ganMoveEndY": {
"alias": "杆子最后需要移动到的y值位置",
"type": "number",
"default": 700
},
"leftRotation": {
"alias": "左边爪子旋转角度",
"type": "number",
"default": 30
},
"rightRotation": {
"alias": "右边爪子旋转角度",
"type": "number",
"default": -30
},
"playerPositionY": {
"alias": "玩家Y轴位置",
"type": "number",
"default": 900
},
"rainScore": {
"alias": "接中雨滴获得分数",
"type": "number",
"default": 1
},
"stoneScore": {
"alias": "接中石块获得分数",
"type": "number",
"default": -1
},
"speed": {
"alias": "道具掉落初始速度",
"type": "number",
"default": 10
},
"maxSpeed": {
"alias": "道具掉落速度上限",
"type": "number",
"default": 3
},
"gameOverCondition": {
"alias": "游戏结束条件(1:接到炸弹死亡,2:分数负数或接到炸弹死亡)",
"type": "number",
"default": 1
}
},
"assets": [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "游戏背景",
"url": "//yun.duiba.com.cn/aurora/assets/d1f3f60775abfcbd7fdfb3ce525c18977286cd80.png",
"uuid": ": fe77919b-d5d2-464e-8cbe-d671c82d110c",
"ext": ".png"
},
{
"name": "草泥马盒",
"url": "//yun.duiba.com.cn/aurora/assets/cddd0a59964e023ed7c8d77a8f1ad6b90c25d3af.png",
"uuid": "34b596f3-9a17-410f-a6b6-c39b91c7b123",
"ext": ".png"
},
{
"name": "狗盒",
"url": "//yun.duiba.com.cn/aurora/assets/fd47ea43eb4884ebb8f0bcd095083062871e4f90.png",
"uuid": "f78f6bd0-93fd-4965-b18b-32a8e6cd4184",
"ext": ".png"
},
{
"name": "猫盒",
"url": "//yun.duiba.com.cn/aurora/assets/596e89d60f5714e311bdc35171b19097efc54fb5.png",
"uuid": "8bb254c4-cf2a-47cb-824e-a62ba153518b",
"ext": ".png"
},
{
"name": "前传输带",
"url": "//yun.duiba.com.cn/aurora/assets/7bccbc67b3f896176bed7d21c5f4d4307c3919be.png",
"uuid": "06bd03a4-43c3-49bb-94c5-6ef365f70291",
"ext": ".png"
},
{
"name": "后传输带",
"url": "//yun.duiba.com.cn/aurora/assets/df9b718f80747a1e21349d2b9ac35d5e19a61dad.png",
"uuid": "aa0c6ebc-164f-4767-90ca-a79be4316365",
"ext": ".png"
},
{
"name": "把手杆子",
"url": "//yun.duiba.com.cn/aurora/assets/5a9e4ba7ca6701eae85b6d6dcb0612ecb9a3eff9.png",
"uuid": "3ecea516-ca65-4ac2-9b93-08495a52d7d2",
"ext": ".png"
},
{
"name": "把手",
"url": "//yun.duiba.com.cn/aurora/assets/71255a6f3cdf9f66d53589e46d72fcd20fef468d.png",
"uuid": "d918e46f-c7f8-4ad0-8039-08c9c66b4ca6",
"ext": ".png"
},
{
"name": "伸缩杆",
"url": "//yun.duiba.com.cn/aurora/assets/a9cf8b147c52b7d4247e80e90e098f787808bfa9.png",
"uuid": "b0146aee-5741-470c-b0fc-bf00a4aca5f6",
"ext": ".png"
},
{
"name": "左爪",
"url": "//yun.duiba.com.cn/aurora/assets/1e8634fd94bda455d11956c2847d3823e80701d3.png",
"uuid": "d8e399ff-691f-439a-9ce4-4867514e617d",
"ext": ".png"
},
{
"name": "右爪",
"url": "//yun.duiba.com.cn/aurora/assets/4bfc510e0d1fa1db77f5effa187294af38b74ff6.png",
"uuid": "0df49f61-0281-4647-a55f-437b71b352e6",
"ext": ".png"
},
{
"name": "连接点",
"url": "//yun.duiba.com.cn/aurora/assets/39f39234631f739e70e9ab8b713284379f4016fb.png",
"uuid": "00ff944e-d038-4974-97fc-1e481af3a949",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹svga",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
],
"events": {
"in": {
"food-fell-reset": {
"alias": "重置",
"data": {
"goodsProbability": "[0.2,0.5,0.3]道具概率(雨滴、石头、炸弹),所有概率相加为1",
"countDown": "倒计时(s)",
"acceleratedSpeed":"道具掉落加速度(单位:每秒)"
}
},
"food-fell-start": {
"alias": "开始"
},
"food-fell-revive": {
"alias": "复活"
},
"food-fell-pause": {
"alias": "暂停"
},
"food-fell-resume": {
"alias": "恢复"
},
"food-fell-clear": {
"alias": "清空,通过reset事件恢复"
}
},
"out": {
"food-fell-score-update": {
"alias": "分数更新",
"data": {
"score":"分数"
}
},
"food-fell-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"food-fell-game-over": {
"alias": "游戏结束",
"data": {
"score":"分数",
"reason": "结束原因(1:时间到了,2:玩家死亡)"
}
},
"doll-mac-getprize": {
"alias": "中奖",
"data": null
}
}
}
}
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('doll-machine-reset', this.reset, this);
engine.globalEvent.addEventListener('food-fell-start', this.start, this);
engine.globalEvent.addEventListener('food-fell-pause', this.pause, this);
engine.globalEvent.addEventListener('food-fell-resume', this.resume, this);
engine.globalEvent.addEventListener('food-fell-revive', this.revive, this);
engine.globalEvent.addEventListener('food-fell-clear', this.clear, this);
this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
// gameView.reset()
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
injectProps(event.data);
this._status = 1;
this._gameView.start();
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
clear() {
this._gameView.visible = false;
}
private onTap(event) {
// this._gameView.tap(event);
}
}
/**
* Created by rockyl on 2020-02-02.
*
* 掉落物品
*/
import { getTextureByName } from "./utils";
import { props } from "../props";
export class Goods extends engine.Container {
private _body: engine.Rect;
private _toY;
constructor() {
super();
let body;
body = this._body = new engine.Rect();
// let rain = new engine.Sprite(getTextureByName('雨滴'));
// rain["npcType"]="rain"
// let stone = new engine.Sprite(getTextureByName('石块'));
// stone["npcType"]="stone"
// let boom = new engine.Sprite(getTextureByName('炸弹'));
// boom["npcType"]="boom"
let box1 = new engine.Sprite(getTextureByName("草泥马盒"));
box1["npcType"] = "box1";
let box2 = new engine.Sprite(getTextureByName("狗盒"));
box2["npcType"] = "box2";
let box3 = new engine.Sprite(getTextureByName("猫盒"));
box3["npcType"] = "box3";
// rain.visible=false;
// stone.visible=false;
// boom.visible=false;
// body.addChild(rain)
// body.addChild(stone)
// body.addChild(boom)
box1.visible = false;
box2.visible = false;
box3.visible = false;
body.addChild(box1);
body.addChild(box2);
body.addChild(box3);
this.addChild(body);
body.width = 0.0001;
body.height = 0.0001;
body.mouseEnabled = false;
}
getRandomNumberByRange(start, end) {
return Math.floor(Math.random() * (end - start) + start);
}
// reset() {
// this.visible = true;
// this.rotation = 0;
// this.anchorOffsetY = 0;
// this.y = 0;
// this.x = (750-120)*Math.random()+30;
// this.rotation = 0;
// let random=Math.random()
// if(random<props.goodsProbability[0]){
// this.showNpc("box1")
// }else if(random>=props.goodsProbability[0]&&random<=(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box2")
// }else if(random>(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box3")
// }
// }
reset() {
this.visible = true;
this.y = 200;
this.x = 0;
this.rotation = 0;
let random = Math.random();
if (random < 0.3) {
this.showNpc("box1");
} else if (random < 0.6) {
this.showNpc("box2");
} else {
this.showNpc("box3");
}
// this.showNpc("box1");
// this.showNpc("box2");
// this.showNpc("box3");
}
showNpc(type) {
for (let i = 0; i < this._body.children.length; i++) {
this._body.children[i].visible = false;
this._body.children[i].mouseEnabled = false;
}
for (let i = 0; i < this._body.children.length; i++) {
if (this._body.children[i]["npcType"] == type) {
this["npcType"] = type;
console.log(type);
this._body.children[i].visible = true;
this._body.children[i].mouseEnabled = false;
}
}
}
set anchorOffsetY(v) {
this._body.y = v;
}
}
import { getTextureByName } from "./utils";
import { props } from "../props";
import GameView from './GameView';
export class Zhuazi extends engine.Container {
private bashouGan: engine.Sprite;
private bashou: engine.Sprite;
private ganzi: engine.Sprite;
private left_zhuazi: engine.Sprite;
private right_zhuazi: engine.Sprite;
private connect: engine.Sprite;
private ganNode: engine.Container;
private moveNode: engine.Container;
private moveArr = [];
private zhuaziY;
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
private itemShow: engine.Container;
private prizeBoxs = [];
public GameView: GameView;
constructor() {
super();
}
setup() {
this.ganNode = new engine.Container();
this.moveNode = new engine.Container();
this.ganNode.x = 280;
this.ganNode.y = 425;
this.bashouGan = new engine.Sprite(getTextureByName("把手杆子"));
this.bashouGan.x = 60;
this.bashouGan.y = 342;
this.bashou = new engine.Sprite(getTextureByName("把手"));
this.bashou.x = 0;
this.bashou.y = 320;
this.ganzi = new engine.Sprite(getTextureByName("伸缩杆"));
this.ganzi.x = 97;
this.ganzi.y = 382;
this.connect = new engine.Sprite(getTextureByName("连接点"));
this.connect.x = 20;
this.connect.y = 0;
this.left_zhuazi = new engine.Sprite(getTextureByName("左爪"));
this.left_zhuazi.x = 0;
this.left_zhuazi.y = 60;
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
this.left_zhuazi.rotation = 30;
this.right_zhuazi = new engine.Sprite(getTextureByName("右爪"));
this.right_zhuazi.x = 83;
this.right_zhuazi.y = 60;
this.right_zhuazi.rotation = -30;
this.ganNode.addChild(this.left_zhuazi);
this.ganNode.addChild(this.right_zhuazi);
this.ganNode.addChild(this.connect);
this.ganNode.x = 30;
this.zhuaziY = this.ganNode.y;
this.moveNode.addChild(this.ganzi);
this.moveNode.addChild(this.ganNode);
this.moveNode.addChild(this.bashou);
this.moveNode.x = 262;
// this.moveNode.
// this.moveArr = [this.bashou, this.ganzi, this.ganNode];
this.addChild(this.bashouGan);
// this.addChild(this.ganzi);
// this.addChild(this.bashou);
// this.addChild(this.ganNode);
this.addChild(this.moveNode);
this.createPrizeBox();
// setTimeout(() => {
// this.move();
// }, 2000)
}
createPrizeBox() {
this.box1 = new engine.Sprite(getTextureByName("狗盒"));
this.box1["npcType"] = "box1";
this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box2["npcType"] = "box2";
this.box3 = new engine.Sprite(getTextureByName("草泥马盒"));
this.box3["npcType"] = "box3";
this.box4 = new engine.Sprite(getTextureByName("狗盒"));
this.box4["npcType"] = "box4";
this.box5 = new engine.Sprite(getTextureByName("猫盒"));
this.box5["npcType"] = "box5";
this.prizeBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
this.prizeBoxs.forEach(item => {
this.ganNode.addChild(item);
item.visible = false;
item.x = -15;
item.y = 48;
})
}
showPrizeBox() {
this.prizeBoxs.forEach(item => {
console.log(this.GameView.getBox()['npcType']);
if (item['npcType'] === this.GameView.getBox()['npcType']) {
item.visible = true;
this.itemShow = item;
} else {
item.visible = false;
}
})
}
move() {
let rndist = Math.random();
let halfWidth = this.bashou.width / 2;
let randomX = rndist * (rndist > 0.5 ? 1 : -1) * props.bashouMoveDist;
console.log(randomX);
engine.Tween.get(this.moveNode).to({ x: 370 + halfWidth - 71}, 1000).call(() => {
this.zhangkai();
});
// this.moveArr.forEach((item,index) => {
// engine.Tween.get(item).to({ x: item.x +randomX}, 500).to({x: 370}, 500).call(() => {
// if (index == this.moveArr.length-1) {
// this.zhangkai();
// }
// });
// })
}
zhangkai() {
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: props.leftRotation}, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: props.rightRotation }, 1000);
setTimeout(() => {
this.getLong();
}, 500);
}
getLong() {
let droptime = Number((this.GameView.getMoveX() / 60 - 1).toFixed(2)) * 1000;
console.log('dr', droptime);
let times = (props.ganMoveEndY - this.ganzi.y ) / this.ganzi.height;
console.log(Number(times.toFixed(2)) );
engine.Tween.get(this.ganzi).to({ scaleY: Number(times.toFixed(2)) }, droptime).to({ scaleY: 1 }, droptime)
console.log('node', this.zhuaziY);
engine.Tween.get(this.ganNode).to({ y: props.ganMoveEndY }, droptime).call(() => {
this.GameView.stopMove();
this.showPrizeBox();
this.GameView.setVisible(false);
}).to({ y: this.zhuaziY }, droptime).call(() => {
engine.globalEvent.dispatchEvent('doll-mac-getprize');
this.getReset();
})
// .to({ scaleY: 1 }, droptime)
// to({ y: this.zhuaziY }, droptime)
}
getReset() {
this.itemShow.visible = false;
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.moveNode, {loop: false}).to({x: 262}, 1000);
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import { props } from "../props";
export class BackBoxs extends engine.Container {
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
private backBoxs=[];
constructor() {
super();
}
setup() {
let initX , initY = 0;
this.box1 = new engine.Sprite(getTextureByName("狗盒"));
initX = this.box1.x = 188;
initY = this.box1.y = 706;
this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box3 = new engine.Sprite(getTextureByName("草泥马盒"));
this.box4 = new engine.Sprite(getTextureByName("狗盒"));
this.box5 = new engine.Sprite(getTextureByName("猫盒"));
this.backBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
for (let i = 0; i < this.backBoxs.length; i++) {
this.backBoxs[i].scaleX = 0.5;
this.backBoxs[i].scaleY = 0.5;
if(i == 0) {
this.backBoxs[i].x = initX;
} else {
this.backBoxs[i].x = this.backBoxs[i - 1].x + this.backBoxs[i].width + props.backmargin;
}
this.backBoxs[i].y = initY;
this.addChild(this.backBoxs[i]);
}
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.backBoxs.forEach((item) => {
item.x -= props.moveSpeed;
if (item.x <= 0) {
let lastitem = this.backBoxs.shift();
lastitem.x = this.backBoxs[this.backBoxs.length - 1].x + item.width + props.backmargin;
this.backBoxs.push(lastitem);
}
})
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import GameView from './GameView';
import { props } from "../props";
export class FrontBoxs extends engine.Container {
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
// 需隐藏的盒子
private hideBox: engine.Container;
private frontBoxs=[];
public GameView: GameView;
constructor() {
super();
}
setup() {
let initX , initY = 0;
this.box1 = new engine.Sprite(getTextureByName("狗盒"));
this.box1["npcType"] = "box1";
initX = this.box1.x = 435;
initY = this.box1.y = 734;
this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box2["npcType"] = "box2";
this.box3 = new engine.Sprite(getTextureByName("草泥马盒"));
this.box3["npcType"] = "box3";
this.box4 = new engine.Sprite(getTextureByName("狗盒"));
this.box4["npcType"] = "box4";
this.box5 = new engine.Sprite(getTextureByName("猫盒"));
this.box5["npcType"] = "box5";
this.frontBoxs = [this.box1, this.box2, this.box3, this.box4];
for(let i = 0; i < this.frontBoxs.length; i++) {
if(i == 0) {
this.frontBoxs[i].x = initX ;
} else {
this.frontBoxs[i].x = this.frontBoxs[i - 1].x - this.box1.width - props.frontmargin;
}
this.frontBoxs[i].y = initY;
this.addChild(this.frontBoxs[i]);
}
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.frontBoxs.forEach((item, index) => {
item.x += props.moveSpeed;
if(item.x <=0 && !item.visible) {
item.visible = true;
}
if(item.x >= 750) {
let lastitem = this.frontBoxs.shift();
lastitem.x = this.frontBoxs[this.frontBoxs.length - 1].x - this.box1.width - props.frontmargin;
if(!this.GameView.getMoveX() && item.x <= 0) {
this.GameView.setMoveX((370 - item.x - 13) / props.moveSpeed, item);
this.hideBox = item;
}
this.frontBoxs.push(lastitem);
}
})
}
stop() {
// this.removeEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
showHidePrizeBox(isshow) {
this.hideBox.visible = isshow
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
......@@ -12,7 +12,6 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
......@@ -25,7 +24,6 @@
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
//# sourceMappingURL=utils.js.map
var Goods = (function (_super) {
tslib.__extends(Goods, _super);
......@@ -94,7 +92,6 @@
});
return Goods;
}(engine.Container));
//# sourceMappingURL=Goods.js.map
var ObjectPool = engine.ObjectPool;
var PoolName = 'goods';
......@@ -103,7 +100,6 @@
}, function (item, data) {
item.reset();
});
//# sourceMappingURL=object-pool-init.js.map
var ObjectPool$1 = engine.ObjectPool;
var GameView = (function (_super) {
......@@ -345,7 +341,6 @@
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
......@@ -353,7 +348,6 @@
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This diff is collapsed.
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