Commit 3db6819a authored by zjz1994's avatar zjz1994

弹球暂存

parent 596ecfbe
This diff is collapsed.
This diff is collapsed.
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
function injectProps(p) { function injectProps(p) {
engine.injectProp(props, p); engine.injectProp(props, p);
} }
//# sourceMappingURL=props.js.map
function getTexture(uuid) { function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid); return engine.Texture.from(getAssetByUUID(uuid).uuid);
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
inst.source = 'asset://' + engine.getAssetByName(name).uuid; inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst; return inst;
} }
//# sourceMappingURL=utils.js.map
var Goods = (function (_super) { var Goods = (function (_super) {
tslib.__extends(Goods, _super); tslib.__extends(Goods, _super);
...@@ -92,6 +94,7 @@ ...@@ -92,6 +94,7 @@
}); });
return Goods; return Goods;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=Goods.js.map
var ObjectPool = engine.ObjectPool; var ObjectPool = engine.ObjectPool;
var PoolName = 'goods'; var PoolName = 'goods';
...@@ -100,6 +103,7 @@ ...@@ -100,6 +103,7 @@
}, function (item, data) { }, function (item, data) {
item.reset(); item.reset();
}); });
//# sourceMappingURL=object-pool-init.js.map
var ObjectPool$1 = engine.ObjectPool; var ObjectPool$1 = engine.ObjectPool;
var GameView = (function (_super) { var GameView = (function (_super) {
...@@ -299,6 +303,7 @@ ...@@ -299,6 +303,7 @@
}; };
return GameView; return GameView;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) { var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super); tslib.__extends(GameWrapper, _super);
...@@ -341,6 +346,7 @@ ...@@ -341,6 +346,7 @@
}; };
return GameWrapper; return GameWrapper;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) { function index (props) {
prepareProps(); prepareProps();
...@@ -348,6 +354,7 @@ ...@@ -348,6 +354,7 @@
var instance = new GameWrapper(); var instance = new GameWrapper();
return instance; return instance;
} }
//# sourceMappingURL=index.js.map
return index; return index;
......
This diff is collapsed.
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'tanqiu';
(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 source diff could not be displayed because it is too large. You can view the blob instead.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "弹球",
"desc": "弹球模块",
"props": {
"addscore": {
"alias": "消除一个数字加的分数",
"type": "number",
"default": 1
}
},
"assets": [
{
"name": "door",
"url": "//yun.duiba.com.cn/aurora/assets/a6dd9ac99733adbe0f175397dc1f94ee16301847.png",
"uuid": "fc8ca082-90b7-4c22-85cf-9165ffaf47bf",
"ext": ".png"
},
{
"name": "地",
"url": "//yun.duiba.com.cn/aurora/assets/45fca6ffa65282fc61587442c9847b23006c49b0.png",
"uuid": "995b0f29-885a-425d-bb4e-c9f829df4e7d",
"ext": ".png"
},
{
"name": "炮",
"url": "//yun.duiba.com.cn/aurora/assets/c5fd86a2360a34e13bf09600fb1f5742719489db.png",
"uuid": "2a1b3f6e-5bf5-41d1-b6be-39a77728b230",
"ext": ".png"
},
{
"name": "shootline",
"url": "//yun.duiba.com.cn/aurora/assets/ac3bc89a4eccadfa48d3a8abfc834973d6db0aad.png",
"uuid": "0f2c1ee9-c965-4780-82f2-2d8595173952",
"ext": ".png"
},
{
"name": "sq1",
"url": "//yun.duiba.com.cn/aurora/assets/ba9cd3fc1859d4046b6368a45d95f80b35e3fa6e.png",
"uuid": "7b97ea0d-fb86-4842-9fc7-06e6b5ae3882",
"ext": ".png"
},
{
"name": "sq2",
"url": "//yun.duiba.com.cn/aurora/assets/ba6368eb586671cd4045d09126456229dd8dd503.png",
"uuid": "a171bf2c-c6fd-4ba2-aaff-bc8c91a04fe9",
"ext": ".png"
},
{
"name": "sq3",
"url": "//yun.duiba.com.cn/aurora/assets/7960d9aa4b0502c5c791490f575234a66706b63d.png",
"uuid": "d057cc19-66fe-46f6-91c8-cba2686e8d5d",
"ext": ".png"
},
{
"name": "sq4",
"url": "//yun.duiba.com.cn/aurora/assets/e9e31a95fd93bb2941e98156dc08aaa75b7671bf.png",
"uuid": "1865ae57-f5a3-4794-9c43-0b6aa812f971",
"ext": ".png"
},
{
"name": "tri1",
"url": "//yun.duiba.com.cn/aurora/assets/1b4103f506db3ab6739213a30fb3a7d2abc33f3f.png",
"uuid": "b33457fb-4237-4fca-b48c-bc6074bbe29a",
"ext": ".png"
},
{
"name": "tri2",
"url": "//yun.duiba.com.cn/aurora/assets/56b8a873aafed8241f761061204f5f5f890d2a32.png",
"uuid": "738d6649-6e7f-4006-83cc-0b8a904ec071",
"ext": ".png"
},
{
"name": "风扇",
"url": "//yun.duiba.com.cn/aurora/assets/9f5cf7feac84bc6000bea0a038c7df419f3d5dfb.png",
"uuid": "f26b8a49-f8ee-49ac-a24d-4c83858f5c92",
"ext": ".png"
},
{
"name": "风扇1",
"url": "//yun.duiba.com.cn/aurora/assets/48bc2d0380c7a47defad851d5feaf58cd54e7465.png",
"uuid": "e7363682-e025-49ac-a4ef-fc1a61560014",
"ext": ".png"
},
{
"name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/28dcf9632e585903c87cb234b09d60244d253dde.png",
"uuid": "8a580ff7-2ece-413e-b87a-11b47f2a28ea",
"ext": ".png"
},
{
"name": "circle1",
"url": "//yun.duiba.com.cn/aurora/assets/3c0c22f57ff647f83fbb8811e9e4437c8a1ad0b4.png",
"uuid": "9af5e780-9701-4cb0-afab-9f4aec42a9ca",
"ext": ".png"
},
{
"name": "+1",
"url": "//yun.duiba.com.cn/aurora/assets/d4013a0ed9f5a367ec20be286ba26581c680b20f.png",
"uuid": "aae627c9-dd32-4ae7-b580-baaefdb77a88",
"ext": ".png"
}
],
"events": {
"in": {
"game-reset": {
"alias": "重置"
},
"game-start": {
"alias": "开始",
"data":{
"ballNums":"初始球的数量"
}
},
"game-pause": {
"alias": "暂停"
},
"game-resume": {
"alias": "恢复"
}
},
"out": {
"game-score-update": {
"alias": "分数更新",
"data": {
"score":"分数"
}
},
"game-over": {
"alias": "游戏结束",
"data": {
}
}
}
}
}
\ No newline at end of file
import Body from "./physics/Body";
import { sqrt3 } from "./physics/Const";
export default class Effect {
NUMS_MAX = 11;
_parent: engine.Container;
constructor(block: Body, parent: engine.Container) {
const resName = block.view['bg']['__resName__']
for (let i = 0; i < this.NUMS_MAX; i++) {
const data = this.createItem(resName);
parent.addChild(data.shape);
data.shape.x = block.x;
data.shape.y = block.y;
engine.Tween.get(data.shape).to({ x: data.targetX + block.x, y: block.y + data.targetY, scaleY: 0, scaleX: 0 }, 360).call(() => {
data.shape.parent && data.shape.parent.removeChild(data.shape);
});
}
}
createItem(resName: string) {
const moveDisMax = 100;
const squareSize = 100;
const shape = new engine.Shape();
const shapeType = this.getShapeType(resName);
if (shapeType == 'circle') {
shape.beginFill(this.getShapeColor(resName));
shape.drawCircle(0, 0, squareSize / 2);
shape.endFill();
} else if (shapeType == 'tri') {
shape.beginFill(this.getShapeColor(resName));
shape.moveTo(0, -squareSize * sqrt3 / 3);
shape.lineTo(squareSize / 2, squareSize * sqrt3 / 6);
shape.lineTo(-squareSize / 2, squareSize * sqrt3 / 6);
shape.endFill();
} else if (shapeType == 'sq') {
shape.beginFill(this.getShapeColor(resName));
shape.drawRect(-squareSize / 2, -squareSize / 2, squareSize, squareSize);
shape.endFill();
}
const scale = Math.random() * 0.7 + 0.3;
const rotation = Math.random() * 360;
const angle = Math.random() * Math.PI * 2;
const dis = moveDisMax / 2 + moveDisMax / 2 * Math.random();
const targetX = Math.sin(angle) * dis;
const targetY = Math.cos(angle) * dis;
shape.scaleX = shape.scaleY = scale;
shape.rotation = rotation;
return { shape: shape, targetX: targetX, targetY: targetY };
}
getShapeType(resName: string) {
if (resName == 'circle1')
return 'circle';
if (resName.indexOf('tri') > -1)
return 'tri';
if (resName.indexOf('sq') > -1)
return 'sq';
return 'circle'
}
getShapeColor(resName: string) {
if (resName == 'circle1')
return 0xffca55;
if (resName == 'sq1')
return 0xfa7782;
if (resName == 'sq2')
return 0xf677ce;
if (resName == 'sq3')
return 0xffac84;
if (resName == 'sq4')
return 0xffca55;
if (resName == 'tri1')
return 0x2db0ee;
if (resName == 'tri2')
return 0x86e45f;
return 0xffca55
}
}
\ No newline at end of file
This diff is collapsed.
export default class Pool {
pool;
constructor() {
this.pool = {};
}
takeOut(name) {
if (this.pool[name] && this.pool[name].length) {
return this.pool[name].shift();
}
return false;
}
recover(name, obj) {
if (!this.pool[name]) {
this.pool[name] = [];
}
this.pool[name].push(obj);
}
}
\ No newline at end of file
import { LADDER_H_NUMS } from "./gameconsts";
import { shuffle } from "./utils";
let counter;
export const resetCounter = () => {
counter = 1;
}
export const getCounter = () => counter;
const getBlockShape = () => {
const list = shuffle([1, 2, 3]);
return list[0];
}
const random = (start: number, end: number) => {
return start + (end - start) * Math.random();
}
const getNums = (currBallNums: number) => {
return Math.ceil(currBallNums * random(1 * window['numsP'], 3.5 * window['numsP']));
}
const getNums2 = (currBallNums: number) => {
return Math.ceil(currBallNums * random(4 * window['numsP'], 7 * window['numsP']));
}
const getSpecialNumBlocksNums = (currBallNums: number) => {
if (currBallNums < 20) return 1;
if (currBallNums < 50) return 2;
return 3;
}
export const getBlocks = (currBallNums: number) => {
const blockNums = Math.random() > 0.3 ? 3 : 2;
let specialBall = 0;
if (counter % 3 === 0) { // 每隔3行出现一个+球buff
specialBall = 1;
}
let list = [];
for (let i = 0; i < LADDER_H_NUMS; i++) {
list.push(i);
}
list = shuffle(list);
const blockPositions = list.slice(0, blockNums);
const specialBallPosition = list[list.length - 1];
const blocksInfo = [];
for (let j = 0; j < blockPositions.length; j++) {
const p = blockPositions[j];
let nums = getNums(currBallNums);
const specialNumBlocksNums = getSpecialNumBlocksNums(currBallNums);
if (Math.random() < 0.3 && j < specialNumBlocksNums) {
nums = getNums2(currBallNums);
}
if (currBallNums >= 50)
nums = getNums2(currBallNums);
// console.log("添加nums",nums);
blocksInfo.push({
position: p,
type: getBlockShape(),
nums: nums||2
});
}
counter++;
return {
blocksInfo: blocksInfo,
specialBallPosition: specialBall ? specialBallPosition : -1
};
}
\ No newline at end of file
import { BALL_D } from "../gameconsts";
import { Ball } from "../physics/Ball";
import { getTextureByName } from "../utils";
export default () => {
}
export const createBallItem = () => {
const picTex = getTextureByName("ball");
const pic = new engine.Image(picTex);
pic.mouseEnabled = false;
pic.anchorX = pic.width / 2;
pic.anchorY = pic.height / 2;
const ball = new Ball(BALL_D / 2, pic);
return ball;
}
\ No newline at end of file
import { Circle } from "../physics/Circle";
import PlayScene from "../PlayScene";
import { getTextureByName } from "../utils";
export default (that: PlayScene, x, y, num) => {
let block = that.pool.takeOut("circle");
//位置偏移
var anchorx = 0;
var anchory = 0;
if (!block) {
const sprite = new engine.Sprite();
sprite.mouseEnabled = sprite.mouseChildren = false;
//背景
const shape = new engine.Image(getTextureByName('circle1'));
shape['__resName__'] = 'circle1';
const radius = shape.width / 2;
const length = radius * 2;
shape.anchorX = shape.width / 2;
shape.anchorY = shape.height / 2;
anchorx = radius;
anchory = radius;
sprite["bg"] = shape;
sprite.addChild(shape);
shape.x = -anchorx;
shape.y = -anchory;
//数字
const txt = new engine.TextField();
txt.width = length;
txt.height = length;
txt.anchorX = length / 2;
txt.anchorY = length / 2;
txt.size = 30;
txt.fillColor = 0xffffff;
txt.textAlign = engine.TEXT_ALIGN.CENTER;
txt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
sprite["txt"] = txt;
sprite.addChild(txt);
txt.x = -anchorx;
txt.y = -anchory;
block = new Circle(radius, sprite);
}
that.addChild(block.view)
block.x = x;
block.y = y;
// console.log("圆形偏移",anchorx,anchory);
block.num = num;
that.blocks.push(block);
block.ladderNums = 1;
}
\ No newline at end of file
import { RegTriangle } from "../physics/RegTriangle";
import PlayScene from "../PlayScene";
import { getTextureByName } from "../utils";
export default (that: PlayScene, x, y, num) => {
let block = that.pool.takeOut("regTriangle");
const picType = Math.ceil(Math.random() * 2);
const pic = new engine.Sprite(getTextureByName(`tri${picType}`));
pic.anchorX = pic.width / 2;
pic.anchorY = pic.height/2;// * .65;
//位置偏移
var anchorx = 0;
var anchory = 0;
anchorx = pic.width/2;
anchory = pic.height/2;//*0.65;
if (!block) {
const sprite = new engine.Sprite();
sprite.mouseEnabled = sprite.mouseChildren = false;
//背景
const length = pic.width;
const height = pic.height;
// console.log("三角形的文字偏移",pic.width,pic.height);
sprite["bg"] = pic;
sprite.addChild(pic);
pic.x = -anchorx;
pic.y = -anchory;
//数字
const txt = new engine.TextField();
txt.width = length;
txt.height = height;
txt.anchorX = length / 2;
txt.anchorY = height /2;//*0.65;
txt.size = 26;
txt.fillColor = 0xffffff;
txt.textAlign = engine.TEXT_ALIGN.CENTER;
txt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
sprite["txt"] = txt;
sprite.addChild(txt);
txt.x = -anchorx;
txt.y = -anchory+(anchorx-anchory)*2;
block = new RegTriangle(length, sprite);
} else {
if (block.view["bg"]) {
block.view.removeChild(block.view["bg"]);
block.view["bg"] = pic;
block.view.addChild(pic);
block.view.addChild(block.view['txt']);
pic.x = -anchorx;
pic.y = -anchory;
block.view['txt'].x = -anchorx;
block.view['txt'].y = -anchory+(anchorx-anchory)*2;
}
}
block.view["bg"]['__resName__'] = `tri${picType}`;
that.addChild(block.view)
block.x = x;
block.y = y;
// console.log("三角形偏移",anchorx,anchory);
block.rotation = Math.random() * 360;
block.num = num;
that.blocks.push(block);
block.ladderNums = 1;
}
\ No newline at end of file
import { sqrt3 } from "../physics/Const";
import { RegTriangle } from "../physics/RegTriangle";
import PlayScene from "../PlayScene";
export default (that: PlayScene, x, y, length, rotation, key = 'specialRegTriangle') => {
let block: RegTriangle;
const sprite = new engine.Sprite();
sprite.visible = false;//window['debugPhysics'];
sprite.alpha = 0.7;
sprite.mouseEnabled = sprite.mouseChildren = false;
// console.log("显示",window['debugPhysics'])
//背景
const shape = new engine.Shape();
shape.beginFill(0xcccccc);
shape.moveTo(0, -length * sqrt3 / 3);
shape.lineTo(length / 2, length * sqrt3 / 6);
shape.lineTo(-length / 2, length * sqrt3 / 6);
shape.endFill();
sprite["bg"] = shape;
sprite.addChild(shape);
//数字
const txt = new engine.TextField();
txt.width = length;
txt.height = length;
txt.anchorX = length / 2;
txt.anchorY = length / 2;
txt.size = 25;
txt.fillColor = 0xffffff;
txt.textAlign = engine.TEXT_ALIGN.CENTER;
txt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
sprite["txt"] = txt;
sprite.addChild(txt);
console.log("特殊建筑三角形",length);
block = new RegTriangle(length, sprite);
block.type = key;
that.addChild(block.view)
block.x = x;
block.y = y;
block.rotation = rotation;
// block.num = num
that.blocks.push(block);
}
\ No newline at end of file
import { Circle } from "../physics/Circle";
import PlayScene from "../PlayScene";
import { getTextureByName } from "../utils";
export default (that: PlayScene, x, y, num) => {
let block: Circle = that.pool.takeOut("specialCircle");
const radius = (getTextureByName('+1') as engine.Texture).orig.width / 2;
const length = radius * 2;
if (!block) {
const sprite = new engine.Sprite();
sprite.mouseEnabled = sprite.mouseChildren = false;
//背景
const shape = new engine.Sprite(getTextureByName('+1'));
shape.anchorX = shape.width / 2;
shape.anchorY = shape.height / 2;
sprite["bg"] = shape;
sprite.addChild(shape);
shape.x = -shape.width/2;
shape.y = -shape.height/2;
block = new Circle(radius, sprite);
block.type = 'specialCircle';
} else {
if (block.radius != radius) {
block.view.bg.clear();
block.view.bg.beginFill(0xcccccc);
block.view.bg.drawCircle(0, 0, radius);
block.view.bg.endFill();
}
}
that.addChild(block.view)
block.x = x;
block.y = y;
block.num = num;
that.blocks.push(block);
block.ladderNums = 1;
}
\ No newline at end of file
import { Square } from "../physics/Square";
import PlayScene from "../PlayScene";
import { getTextureByName } from "../utils";
export default (that: PlayScene, x, y, num) => {
const picType = Math.ceil(Math.random() * 4);
const pic = new engine.Sprite(getTextureByName(`sq${picType}`));
pic.anchorX = pic.width / 2;
pic.anchorY = pic.height / 2;
let block: Square = that.pool.takeOut("square");
//位置偏移
var anchorx = pic.width/2;
var anchory = pic.height/2;
if (!block) {
const sprite = new engine.Sprite();
sprite.mouseEnabled = sprite.mouseChildren = false;
//背景
const length = pic.width;
sprite["bg"] = pic;
sprite.addChild(pic);
pic.x = -anchorx;
pic.y = -anchory;
//数字
const txt = new engine.TextField();
txt.width = length;
txt.height = pic.height;
txt.anchorX = length / 2;
txt.anchorY = pic.height / 2;
txt.size = 30;
txt.fillColor = 0xffffff;
txt.textAlign = engine.TEXT_ALIGN.CENTER;
txt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
sprite["txt"] = txt;
sprite.addChild(txt);
txt.x = -anchorx;
txt.y = -anchory;
// that.view.addChild(sprite)
block = new Square(length, sprite);
}
//初始化
else {
if (block.view["bg"]) {
block.view.removeChild(block.view["bg"]);
block.view["bg"] = pic;
block.view.addChild(pic);
block.view.addChild(block.view['txt']);
pic.x = -anchorx;
pic.y = -anchory;
block.view['txt'].x = -anchorx;
block.view['txt'].y = -anchory;
}
}
block.view["bg"]['__resName__'] = `sq${picType}`;
that.addChild(block.view)
// console.log("方形偏移",anchorx,anchory);
block.x = x;
block.y = y;
block.num = num;
block.rotation = Math.random() * 360;
// block.rotation = Math.random()>0.5 ? 0 : 45;
that.blocks.push(block);
block.ladderNums = 1;
}
\ No newline at end of file
import { injectProps } from "../props";
import PlayScene from "./PlayScene";
export class gameWrapper extends engine.Container{
private _status;
private _gameView: PlayScene;
constructor() {
super();
engine.globalEvent.addEventListener("game-reset", this.reset, this);
engine.globalEvent.addEventListener("game-start", this.start, this);
engine.globalEvent.addEventListener("game-pause", this.pause, this);
engine.globalEvent.addEventListener("game-resume", this.resume, this);
this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this);
let gameView = this._gameView = new PlayScene();
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.pausegame();
}
resume() {
this._gameView.resumegame();
}
// revive() {
// this._gameView.revive();
// }
clear() {
this._gameView.visible = false;
}
private onTap(event) {
// this._gameView.tap(event);
}
}
\ No newline at end of file
export const BALL_D = 34;//球大小
export const LEFT_GROUND = 80;//左侧墙壁
export const RIGHT_GROUND = 675;//右侧墙壁
export const LADDER_START = 350-100;//
export const LADDER_END = 1150;
export const LADDER_NUMS = 10;
export const LADDER_H_START = 130;
export const LADDER_H_END = 710;
export const LADDER_H_NUMS = 7;
export const bounceStart = 0.9;
export const bounceEnd = 0.99;
export const ACELE_DELAY = 4000;
\ No newline at end of file
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
import { Vector } from "./Vector";
import { Projection } from "./Projection";
export class Ball {
type;
collideNormal;
isCollide;
/**
* 1:射出阶段(应用碰撞检测,不应用重力,可根据加速,碰壁或bloc变为2,碰底后变为3)。
* 2:碰撞阶段(应用重力和检测,可根据加速)。
* 3:回收阶段(不应用重力,不应用检测,以最快速度回到初始位置) */
collideStatus = 1;
recoverDirection; //false为左,true为右
recoverMark = false;
radius;
view;
velocity = new Vector();
constructor(radius, view) {
this.radius = radius;
this.view = view;
}
//新增,矫正偏移
get _viewx(){
return this.view.x;//+this.view.anchorX;
}
get _viewy(){
return this.view.y;//+this.view.anchorY;
}
//圆形在投影轴上的投影对象
project(axis) {
var scalars = []; //用于存放在投影轴上的投影
var dotProduct = new Vector(this.view.x, this.view.y).dotProduct(axis); //得到圆心向量在投影轴上的投影
// scalars.push(dotProduct);
scalars.push(dotProduct + this.radius);
scalars.push(dotProduct - this.radius);
//得到圆投影对象的最大值与最小值
// return new Projection(Math.min.apply(Math, scalars), Math.max.apply(Math, scalars));
return new Projection(dotProduct - this.radius, dotProduct + this.radius)
};
}
\ No newline at end of file
import { Ball } from "./Ball";
export default class Body {
type: string;
userData: any;
view:any;
ladderNums = 1;
collideBall(ball:Ball):any {
}
get num():number {
return
}
set num(value) {
}
set y(value) {}
set x(value) {}
}
\ No newline at end of file
// tslint:disable:only-arrow-functions
// tslint:disable:no-conditional-assignment
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
// tslint:disable:no-inferrable-types
import { Vector } from "./Vector";
import { Tween } from "../tween/Tween";
import Body from "./Body";
export class Circle extends Body {
public type = "circle";
public view;
public radius;
_num;
_x = 0;
_y = 0;
constructor(radius, view) {
super();
this.radius = radius;
this.view = view;
}
get x() {
return this._x;
}
set x(value) {
if (this._x != value) {
this._x = value;
this.view.x = value;
}
}
get y() {
return this._y;
}
set y(value) {
if (this._y != value) {
this._y = value;
this.view.y = value;
}
}
get num() {
return this._num;
}
set num(value) {
if (this._num != value) {
this._num = value;
// console.log("圆形value",value);
this.view.txt&&(this.view.txt.text = value||2+"");
}
}
//新增,矫正偏移
get _viewx(){
return this.view.x;//+this.view.anchorX;
}
get _viewy(){
return this.view.y;//+this.view.anchorY;
}
public shake() {
console.log("circle震动1-------",this.view.bg.x,this.view.bg.y);
var startx = -this.view.bg.anchorX;
var starty = -this.view.bg.anchorY;
this.view.bg.x = startx;
this.view.bg.y = starty;
console.log("circle震动2-------",this.view.bg.x,this.view.bg.y);
Tween.to(this.view.bg, 1, {
x: startx+3,
y: starty+3,
yoyo: 2,
useFrame: true,
onComplete: function () {
console.log("circle震动3-------",this.view.bg.x,this.view.bg.y);
}
})
}
collideBall(ball) {
var ballax = ball._viewx;
var ballay = ball._viewy;
var thisax = this._viewx;
var thisay = this._viewy;
var deltaX = ballax - thisax;
var deltaY = ballay - thisay;
//碰撞
if (deltaX * deltaX + deltaY * deltaY < (this.radius + ball.radius)*(this.radius + ball.radius)) {
var velocity = ball.velocity.clone();
var deta = Math.floor(velocity.length() / ball.radius)+5 //deta就是插值数量,如为0,则直接取上一帧的法向量
var speedX = velocity.x / (deta + 1);
var speedY = velocity.y / (deta + 1);
for (var i = 0; i <= deta; i++) {
var normal = this.nearestCollideNormal({ x: ballax - speedX * (i + 1), y: ballay - speedY * (i + 1) }, ball, deta + 1, i + 1)
if (normal) {
return normal
}
}
} else {
return false
//提前给出要碰撞的法向量
// return new Vector(deltaX,deltaY).cross();
}
}
private nearestCollideNormal(position, ball, deta, i) {
var thisax = this._viewx;
var thisay = this._viewy;
var deltaX = position.x-thisax ;
var deltaY = position.y-thisay;
if (deltaX * deltaX + deltaY * deltaY < (this.radius + ball.radius)*(this.radius + ball.radius)) {
return false;
} else {
//直接更改球的位置为最接近碰撞的位置
ball.view.x -= ball.velocity.x / deta * i;
ball.view.y -= ball.velocity.y / deta * i;
//提前给出要碰撞的法向量
return new Vector(deltaX, deltaY).cross();
}
}
}
\ No newline at end of file
// tslint:disable:only-arrow-functions
// tslint:disable:no-conditional-assignment
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
// tslint:disable:no-inferrable-types
export const degToRad = Math.PI / 180;
export const radToDeg = 180 / Math.PI;
export const sqrt3 = Math.sqrt(3);
export function translateToLocalCor(p, parent) {
var th = parent.rotation * degToRad;
//平移
var xp = p.x - parent.x;
var yp = p.y - parent.y;
//旋转
var x = xp * Math.cos(th) + yp * Math.sin(th);
var y = yp * Math.cos(th) - xp * Math.sin(th);
return { x: x / parent.scaleX, y: y / parent.scaleY }
}
export function translateToGlobalCor(p, parent) {
var th = -parent.rotation * degToRad;
var x = p.x * Math.cos(th) + p.y * Math.sin(th) + parent.x;
var y = p.y * Math.cos(th) - p.x * Math.sin(th) + parent.y;
return { x: x / parent.scaleX, y: y / parent.scaleY }
}
/**
* 以水平向左即x正方向为0,顺时针为正,返回弧度
* @param pointFixed 固定点
* @param point
*/
export function twoPointsAngleDis(pointFixed, point) {
var detaX = point.x - pointFixed.x;
var detaY = point.y - pointFixed.y;
var dis = Math.sqrt(detaX * detaX + detaY * detaY);
var angleH = Math.acos(detaX / dis);
if (detaY < 0) {
angleH = Math.PI * 2 - angleH;
}
return { angle: angleH, dis: dis };
}
\ No newline at end of file
export class Projection {
min: any;
max: any;
constructor(min, max) {
this.min = min;
this.max = max;
}
//检测两个多边形在同一个投影轴上的投影是否有重合,重叠返回true
overlaps(projection) {
return this.max > projection.min && projection.max > this.min;
}
}
\ No newline at end of file
// tslint:disable:only-arrow-functions
// tslint:disable:no-conditional-assignment
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
// tslint:disable:no-inferrable-types
import { Vector } from "./Vector";
import { degToRad, translateToLocalCor, sqrt3, twoPointsAngleDis, radToDeg } from "./Const";
import { Projection } from "./Projection";
import { Tween } from "../tween/Tween";
import Body from "./Body";
//正三角形
export class RegPolygon extends Body {
public type = "regPolygon";
public view;
public length;
public _rotation = 0; //顺时针为正方向,角度制
_x = 0;
_y = 0;
_num;
//各边的直线方程,以a,b记录
linesOri = [];
//原始各点的坐标 考虑是否需要
// pointsOri;
//记录边的方向向量顺时针,从左上边开始 未归一
sideNormals = [];
//记录点的法向量,顺时针,从上开始 未归一
pointNormals = [];
//旋转后的点
points = [];
// //中心点到各点长度
// pointLength;
// //中心点到各边长度
// sideLength;
axes = [];
projects = [];
dirty = true;
constructor(length, view) {
super();
this.length = length;
this.view = view;
this.calculateNormals();
this.calculatePoints();
this.calculateLines()
}
get rotation() {
return this._rotation
}
set rotation(value) {
if (this._rotation != value) {
this._rotation = value;
this.view.rotation = value;
this.view.txt.rotation = -value;
//计算四条边得方向向量,避免每帧计算 暂时不考虑优化90度
var rad = value * degToRad;
this.calculateNormals();
this.calculatePoints();
this.dirty = true;
}
}
get x() {
return this._x;
}
set x(value) {
if (this._x != value) {
this._x = value;
this.view.x = value;
//
this.dirty = true;
}
}
get y() {
return this._y;
}
set y(value) {
if (this._y != value) {
this._y = value;
this.view.y = value;
//
this.dirty = true;
}
}
get num() {
return this._num;
}
set num(value) {
if (this._num != value) {
this._num = value;
// console.log("regPolygon-value",value);
this.view.txt.text = value||3 + "";
}
}
//新增,矫正偏移
get _viewx(){
return this.view.x;
}
get _viewy(){
return this.view.y;
}
//根据继承重写
calculateNormals() {
}
//根据继承重写
calculatePoints() {
}
calculateLines() {
}
getAxes() {
var v1 = new Vector(); //代表多边形的相邻两点
var v2 = new Vector();
var axes = [];
var thisvx = this._viewx
var thisvy = this._viewy;
for (var i = 0; i < this.points.length - 1; i++) { //遍历多边形所有相邻的点得去所有的投影轴
v1.x = this.points[i].x + thisvx;
v1.y = this.points[i].y + thisvy;
v2.x = this.points[i + 1].x +thisvx;
v2.y = this.points[i + 1].y + thisvy;
axes.push(v1.edge(v2).perpendicularNormal());
// console.log(1)
};
//将收尾两点的投影轴也加入
v1.x = this.points[this.points.length - 1].x + thisvx;
v1.y = this.points[this.points.length - 1].y + thisvy;
v2.x = this.points[0].x + thisvx;
v2.y = this.points[0].y + thisvy;
axes.push(v1.edge(v2).perpendicularNormal());
// console.log(axes)
return axes;
};
//得到多边形各个点在某一条投影轴上投影,并得到投影两端点值,传递给投影对象Projection返回投影对象
project(axis) {
var scalars = []; //用于存放所有点向量在投影轴向量上的点积集合,注意点积集合是数量不是向量
var v = new Vector();
var self = this;
var thisvx = this._viewx;
var thisvy = this._viewy;
this.points.forEach(function (point) {
v.x = point.x + thisvx;
v.y = point.y + thisvy;
scalars.push(v.dotProduct(axis));
});
return new Projection(Math.min.apply(Math, scalars), Math.max.apply(Math, scalars));
};
polygonCollidesWithCircle(ball) {
//console.log('多边形与圆形碰撞检测');
var v1;
var v2;
var ballax = ball._viewx;
var ballay = ball._viewy;
// var axes = this.getAxes();
if (this.dirty) {
this.dirty = false;
this.axes = this.getAxes();
for (var i = 0; i < this.axes.length; i++) {
this.projects[i] = this.project(this.axes[i])
}
}
var axes = this.axes.slice();
var closestPoint = this.getPolygonPointClosestToCircle(ball);
v1 = new Vector(ballax, ballay);
v2 = new Vector(closestPoint.x, closestPoint.y);
axes.push(v1.subtract(v2).normalize());
return !this.separationOnAxes(axes, ball);
}
//得到多边形距离圆形最近点
getPolygonPointClosestToCircle(ball) {
var min;
var length;
var testPoint;
var closestPoint;
var ballax = ball._viewx;
var ballay = ball._viewy;
var thisax = this._viewx;
var thisay = this._viewy;
// tslint:disable-next-line:prefer-for-of
for (var i = 0; i < this.points.length; i++) {
testPoint = new Vector(this.points[i].x + thisax, this.points[i].y + thisay);
length = Math.pow(testPoint.x - ballax, 2) + Math.pow(testPoint.y - ballay, 2);
if (!min || length < min) {
min = length;
closestPoint = testPoint;
}
};
// console.log(closestPoint)
return closestPoint;
};
//检测在投影轴上投影是否有分离
separationOnAxes(axes, ball) {
var axis;
var projection1;
var projection2;
for (var i = 0; i < axes.length; ++i) {
axis = axes[i];
projection1 = ball.project(axis); //得到形状在当前投影轴上的投影
if (i == axes.length - 1) {
projection2 = this.project(axis); //得到当前拖拽形状在当前投影轴上的投影
} else {
projection2 = this.projects[i]
}
if (!projection1.overlaps(projection2)) { //检测两个投影在当前投影轴上是否重叠,分离返回false
return true; //在当前投影轴上分离返回true,表示两个形状肯定没有碰撞,不需在检测后面的投影轴了,
}
};
return false; //检测完全部的投影轴上的投影没和一个分离的,返回false;
}
//
collideBall(ball) {
var ballax = ball._viewx;
var ballay = ball._viewy;
var thisax = this._viewx;
var thisay = this._viewy;
if (this.polygonCollidesWithCircle(ball)) {
//如果碰撞。
//先转换坐标,
var returnP = translateToLocalCor({ x: ballax, y: ballay }, this.view);
var velocity = ball.velocity.clone().rotate(-this._rotation * degToRad);
var deta = Math.floor(velocity.length() / ball.radius) + 1 //deta就是插值数量,如为0,则直接取上一帧的法向量
var speedX = velocity.x / (deta + 1);
var speedY = velocity.y / (deta + 1);
// console.log(this.nearestCollideNormal({ x: returnP.x - velocity.x, y: returnP.y - velocity.y }, ball,deta+1,i+1))
for (var i = 0; i <= deta; i++) {
this.ballPosition(ball, deta + 1, i + 1)
if (!this.polygonCollidesWithCircle(ball)) {
//算此时的球的位置所对应碰撞的法向量
var noraml = this.nearestCollideNormal({ x: returnP.x - speedX * (i + 1), y: returnP.y - speedY * (i + 1) });
//如果normal和速度方向一致则判断不碰撞,还原球的位置 暂时没用,去掉
// if(!noraml) console.log(noraml)
// if(noraml.parallel(velocity)){
// console.log(2322)
// ball.view.x += ball.velocity.x / (deta + 1) * (i + 1);
// ball.view.y += ball.velocity.y / (deta + 1) * (i + 1);
// return false
// }else{
return noraml
// }
}
}
} else {
return false
}
}
//同样可以进行碰撞检测,考虑之 继承时重写
nearestCollideNormal(returnP): Vector {
return
}
private ballPosition(ball, deta, i) {
ball.view.x -= ball.velocity.x / deta;
ball.view.y -= ball.velocity.y / deta;
}
public shake() {
console.log("regPolygon震动1----------",this.view.bg.x,this.view.bg.y);
var startx = -this.view.bg.anchorX;
var starty = -this.view.bg.anchorY;
this.view.bg.x = startx;
this.view.bg.y = starty;
console.log("regPolygon震动2----------",this.view.bg.x,this.view.bg.y);
Tween.to(this.view.bg, 1, {
x: startx+3,
y: starty+3,
yoyo: 2,
useFrame: true,
onComplete: function () {
console.log("regPolygon震动3----------",this.view.bg.x,this.view.bg.y);
}
})
}
}
\ No newline at end of file
// tslint:disable:only-arrow-functions
// tslint:disable:no-conditional-assignment
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
// tslint:disable:no-inferrable-types
import { sqrt3, degToRad } from "./Const";
import { RegPolygon } from "./RegPolygon";
import { Vector } from "./Vector";
export class RegTriangle extends RegPolygon {
//中心点到各点长度
pointLength;
//中心点到各边长度
sideLength;
constructor(length, view) {
super(length, view);
this.type="regTriangle";
this.pointLength = this.length * sqrt3 / 3;
this.sideLength = this.length * sqrt3 / 6;
}
calculateNormals() {
if (this._rotation == 0) {
this.sideNormals[0] = new Vector(1, -sqrt3)
this.sideNormals[1] = new Vector(1, sqrt3)
this.sideNormals[2] = new Vector(-1, 0)
this.pointNormals[0] = new Vector(1, 0)
this.pointNormals[1] = new Vector(-1, sqrt3)
this.pointNormals[2] = new Vector(-1, -sqrt3)
} else {
var rad = this._rotation * degToRad;
this.sideNormals[0] = new Vector(1, -sqrt3).rotate(rad);
this.sideNormals[1] = new Vector(1, sqrt3).rotate(rad);
this.sideNormals[2] = new Vector(-1, 0).rotate(rad);
this.pointNormals[0] = new Vector(1, 0).rotate(rad);
this.pointNormals[1] = new Vector(-1, sqrt3).rotate(rad);
this.pointNormals[2] = new Vector(-1, -sqrt3).rotate(rad);
}
}
calculatePoints() {
if (this._rotation == 0) {
this.points[0] = new Vector(0, -this.length * sqrt3 / 3);
this.points[1] = new Vector(this.length / 2, this.length * sqrt3 / 6);
this.points[2] = new Vector(-this.length / 2, this.length * sqrt3 / 6);
} else {
var rad = this._rotation * degToRad;
this.points[0] = new Vector(0, -this.length * sqrt3 / 3).rotate(rad);
this.points[1] = new Vector(this.length / 2, this.length * sqrt3 / 6).rotate(rad);
this.points[2] = new Vector(-this.length / 2, this.length * sqrt3 / 6).rotate(rad);
}
}
calculateLines() {
//三边线的方程 左上开始
this.linesOri = [
{ a: -sqrt3, b: -this.length * sqrt3 / 3 },
{ a: sqrt3, b: -this.length * sqrt3 / 3 },
{ a: 0, b: this.length * sqrt3 / 6 },
]
}
nearestCollideNormal(returnP) {
//算出点在三条线的方向 ,在上为true,在下为false
var zero = this.linesOri[0].a * returnP.x + this.linesOri[0].b - returnP.y > 0;
var one = this.linesOri[1].a * returnP.x + this.linesOri[1].b - returnP.y > 0;
var two = this.linesOri[2].a * returnP.x + this.linesOri[2].b - returnP.y > 0;
// console.log(this.linesOri[0].a * returnP.x + this.linesOri[0].b,returnP.y)
// console.log(zero,one,two)
//左上边
if (zero && !one && two) {
return this.sideNormals[0];
}
//右上边
else if (!zero && one && two) {
return this.sideNormals[1];
}
//下边
else if (!zero && !one && !two) {
return this.sideNormals[2];
}
//上点
else if (zero && one && two) {
return this.pointNormals[0];
}
//右点
else if (!zero && one && !two) {
return this.pointNormals[1];
}
//左点
else if (zero && !one && !two) {
return this.pointNormals[2];
}
}
}
\ No newline at end of file
// tslint:disable:only-arrow-functions
// tslint:disable:no-conditional-assignment
// tslint:disable:prefer-const
// tslint:disable:no-var-keyword
// tslint:disable:no-inferrable-types
import { Vector } from "./Vector";
import { degToRad, translateToLocalCor } from "./Const";
import { Tween } from "../tween/Tween";
import Body from "./Body";
export class Square extends Body {
public type = "square"
public view;
_num;
_x = 0;
_y = 0;
/**
* 边长
*/
public length;
public _rotation = 0; //顺时针为正方向,角度制
//记录四条边的方向向量顺时针,从上边开始
sideNormals = [
new Vector(1, 0),
new Vector(0, 1),
new Vector(-1, 0),
new Vector(0, -1)
];
//记录四点的法向量,顺时针,从左上开始 未归一
pointNormals = [
new Vector(1, -1),
new Vector(1, 1),
new Vector(-1, 1),
new Vector(-1, -1)
]
// points = [
// new Vector(1, -1),
// new Vector(1, 1),
// new Vector(-1, 1),
// new Vector(-1, -1)
// ]
constructor(length, view) {
super();
this.length = length;
this.view = view;
}
get rotation() {
return this._rotation
}
set rotation(value) {
if (this._rotation != value) {
this._rotation = value;
this.view.rotation = value;
this.view.txt.rotation=-value;
//计算四条边得方向向量,避免每帧计算 暂时不考虑优化90度
var rad = value * degToRad;
this.sideNormals[0] = new Vector(1, 0).rotate(rad);
this.sideNormals[1] = new Vector(0, 1).rotate(rad);
this.sideNormals[2] = new Vector(-1, 0).rotate(rad);
this.sideNormals[3] = new Vector(0, -1).rotate(rad);
this.pointNormals[0] = new Vector(1, -1).rotate(rad);
this.pointNormals[1] = new Vector(1, 1).rotate(rad);
this.pointNormals[2] = new Vector(-1, 1).rotate(rad);
this.pointNormals[3] = new Vector(-1, -1).rotate(rad);
}
}
get x() {
return this._x;
}
set x(value) {
if (this._x != value) {
this._x = value;
this.view.x = value;
}
}
get y() {
return this._y;
}
set y(value) {
if (this._y != value) {
this._y = value;
this.view.y = value;
}
}
get num() {
return this._num;
}
set num(value) {
if (this._num != value) {
this._num = value;
// console.log("square-vale",value);
this.view.txt.text = value||4 + "";
}
}
//新增,矫正偏移
get _viewx(){
return this.view.x;//+this.view.anchorX;
}
get _viewy(){
return this.view.y;//+this.view.anchorY;
}
//碰撞,先转换球坐标到局部 在四个点时考虑要不要预先计算四个点的坐标,通过xyr set时确定;
collideBall(ball) {
var returnP = translateToLocalCor({ x: ball._viewx, y: ball._viewy }, this.view);
//正方形左上角点
var ox = - this.length / 2;
var oy = ox;
var nearestX = Math.max(ox, Math.min(returnP.x, ox + this.length));
var nearestY = Math.max(oy, Math.min(returnP.y, oy + this.length));
var deltaX = returnP.x - nearestX;
var deltaY = returnP.y - nearestY;
//碰撞 则根据速度插值给上一帧的碰撞法向量 考虑是否直接按速度大小进行插值,还是用分量
if (deltaX * deltaX + deltaY * deltaY < ball.radius * ball.radius) {
var velocity = ball.velocity.clone().rotate(-this._rotation * degToRad);
var deta = Math.floor(velocity.length() / ball.radius) + 5 //deta就是插值数量,如为0,则直接取上一帧的法向量
var speedX = velocity.x / (deta + 1);
var speedY = velocity.y / (deta + 1);
// console.log(this.nearestCollideNormal({ x: returnP.x - velocity.x, y: returnP.y - velocity.y }, ball,deta+1,i+1))
for (var i = 0; i <= deta; i++) {
var normal = this.nearestCollideNormal({ x: returnP.x - speedX * (i + 1), y: returnP.y - speedY * (i + 1) }, ball, deta + 1, i + 1)
if (normal) {
return normal
}
}
// return false; //意味着碰撞
}
//未碰撞
else {
return false
}
}
private nearestCollideNormal(position, ball, deta, i) {
var ox = - this.length / 2;
var oy = ox;
var nearestX = Math.max(ox, Math.min(position.x, ox + this.length));
var nearestY = Math.max(oy, Math.min(position.y, oy + this.length));
var deltaX = position.x - nearestX;
var deltaY = position.y - nearestY;
if (deltaX * deltaX + deltaY * deltaY < ball.radius * ball.radius) {
return false;
} else {
//直接更改球的位置为最接近碰撞的位置
ball.view.x -= ball.velocity.x / deta * i;
ball.view.y -= ball.velocity.y / deta * i;
//左边
if (nearestX == ox) {
if (nearestY == oy) {
return this.pointNormals[0];
}
else if (nearestY == oy + this.length) {
return this.pointNormals[3];
} else {
return this.sideNormals[3];
}
}
//右边
else if (nearestX == ox + this.length) {
if (nearestY == oy) {
return this.pointNormals[1];
}
else if (nearestY == oy + this.length) {
return this.pointNormals[2];
} else {
return this.sideNormals[1];
}
}
//中间
else {
if (nearestY < 0) {
return this.sideNormals[0];
} else {
return this.sideNormals[2];
}
}
}
}
public shake() {
console.log("square震动1---",this.view.bg.x,this.view.bg.y);
var startx = -this.view.bg.anchorX;
var starty = -this.view.bg.anchorY;
this.view.bg.x = startx;
this.view.bg.y = starty;
console.log("square震动2---",this.view.bg.x,this.view.bg.y);
Tween.to(this.view.bg, 1, {
x: startx+5,
y: starty+5,
yoyo: 3,
useFrame: true,
onComplete: function () {
console.log("square震动3---",this.view.bg.x,this.view.bg.y);
}
})
}
}
\ No newline at end of file
This diff is collapsed.
// import { NetManager } from "../../libs/tw/manager/NetManager";
// import { DataManager } from "../../libs/tw/manager/DataManager";
// import Loading from "../../libs/new_wx/components/Loading";
// export default (cb) => {
// Loading.instace.show();
// NetManager.ins.doJoinPlugDraw((isSuccess) => {
// Loading.instace.hide();
// if (isSuccess) {
// Loading.instace.show();
// NetManager.ins.getPlugOrderStatus((success) => {
// Loading.instace.hide();
// if (success) {
// NetManager.ins.getCredits(() => { });
// cb && cb();
// }
// }, DataManager.ins.doJoinPlugDrawData.orderId,
// () => DataManager.ins.getPlugOrderStatusData.result == 0
// )
// }
// }, window['revivePlugId'], true);
// }
This diff is collapsed.
export enum SoundType {
click = 'click',
bounce = 'bounce',
good = 'good',
recover = 'recover',
shoot = 'shoot',
}
import Body from "./physics/Body";
import { LADDER_START, LADDER_END, LADDER_NUMS, LADDER_H_START, LADDER_H_END, LADDER_H_NUMS } from "./gameconsts";
export const isSpecialBody = (body: Body) => {
return body.type != 'circle' && body.type != 'square' && body.type != 'regTriangle'
}
export const isSpecialCircle = (body: Body)=>{
return body.type ==='specialCircle'
}
const ladderHeight = LADDER_END - LADDER_START;
export const getLadderPosition = (i: number) => {
return ladderHeight / LADDER_NUMS * i + LADDER_START;
}
const ladderWidth = LADDER_H_END - LADDER_H_START;
export const getLadderHPosition = (i: number) => {
return ladderWidth / LADDER_H_NUMS * i + LADDER_H_START;
}
export const getLadderGap = ()=>{
return ladderHeight / LADDER_NUMS
}
export const getBounce = () => {
return 0.9 + Math.random() * 0.09;
}
export const shuffle = (array) => {
const _array = array.concat();
for (let i = _array.length; i--;) {
const j = Math.floor(Math.random() * (i + 1));
const temp = _array[i];
_array[i] = _array[j];
_array[j] = temp;
}
return _array;
}
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) {
return;
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
This diff is collapsed.
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