Commit 5b67b667 authored by haiyoucuv's avatar haiyoucuv

11

parent 7afc9941
...@@ -18,6 +18,7 @@ import { Level13 } from "@/pages/GamePage/Level/Level13.ts"; ...@@ -18,6 +18,7 @@ import { Level13 } from "@/pages/GamePage/Level/Level13.ts";
import { Level14 } from "@/pages/GamePage/Level/Level14.ts"; import { Level14 } from "@/pages/GamePage/Level/Level14.ts";
import { Level15 } from "@/pages/GamePage/Level/Level15.ts"; import { Level15 } from "@/pages/GamePage/Level/Level15.ts";
import { Level18 } from "@/pages/GamePage/Level/Level18.ts"; import { Level18 } from "@/pages/GamePage/Level/Level18.ts";
import { Level19 } from "@/pages/GamePage/Level/Level19.ts";
import { Level20 } from "@/pages/GamePage/Level/Level20.ts"; import { Level20 } from "@/pages/GamePage/Level/Level20.ts";
import { Level21 } from "@/pages/GamePage/Level/Level21.ts"; import { Level21 } from "@/pages/GamePage/Level/Level21.ts";
import { Level22 } from "@/pages/GamePage/Level/Level22.ts"; import { Level22 } from "@/pages/GamePage/Level/Level22.ts";
...@@ -35,7 +36,7 @@ export class Game extends Base { ...@@ -35,7 +36,7 @@ export class Game extends Base {
const qsBg = this.addChild(new Sprite(Assets.get("问题.png"))); const qsBg = this.addChild(new Sprite(Assets.get("问题.png")));
qsBg.position.set(49, 316); qsBg.position.set(49, 316);
this.level = this.addChild(new Level11()); this.level = this.addChild(new Level19());
globalEvent.on(GameEvent.NextLevel, this.nextLevel, this); globalEvent.on(GameEvent.NextLevel, this.nextLevel, this);
// this.nextLevel(); // this.nextLevel();
......
import { LevelBase } from "@/pages/GamePage/Components/LevelBase.ts";
import { Assets, Sprite } from "pixi.js";
import { Ease, Tween } from "@/core/tween";
import { GameEvent, globalEvent } from "@/pages/GamePage/GameEvent.ts";
export class Level19 extends LevelBase {
level: number = 19;
A: Sprite;
right: Sprite;
error: Sprite;
// 双指缩放相关属性
private initialDistance: number = 0;
private initialScale: number = 1;
private isTouching: boolean = false;
private touchPoints: Map<number, { x: number, y: number }> = new Map();
onLoad() {
super.onLoad();
this.addChild(new Sprite(Assets.get(`level${this.level}/img.png`)))
.position.set(0, 868);
this.A = this.addChild(new Sprite(Assets.get(`level${this.level}/船.png`)));
this.A.anchor.set(0.4, 0.4);
this.A.position.set(430, 1100);
this.A.scale.set(0.5948827292110874);
this.right = this.addChild(new Sprite(Assets.get(`level${this.level}/right.png`)));
this.right.position.set(613, 1104);
this.right.alpha = 0;
this.right.interactive = false;
this.right.eventMode = "none";
this.A.on("pointerdown", this.onPointerDown, this);
this.A.on("globalpointermove", this.onPointerMove, this);
this.A.on("pointerup", this.onPointerUp, this);
this.A.on("pointerupoutside", this.onPointerUp, this);
}
onPointerDown(e) {
console.log("pointerdown", e.pointerId, e.data.global);
// 记录触摸点
this.touchPoints.set(e.pointerId, {
x: e.data.global.x,
y: e.data.global.y
});
// 如果有两个触摸点,开始缩放
if (this.touchPoints.size === 2) {
const points = Array.from(this.touchPoints.values());
this.initialDistance = this.getDistance(points[0], points[1]);
this.initialScale = this.A.scale.x;
this.isTouching = true;
console.log("开始缩放", this.initialDistance, this.initialScale);
}
}
onPointerMove(e) {
if (!this.touchPoints.has(e.pointerId)) return;
// 更新触摸点位置
this.touchPoints.set(e.pointerId, {
x: e.data.global.x,
y: e.data.global.y
});
if (this.isTouching && this.touchPoints.size === 2) {
const points = Array.from(this.touchPoints.values());
const currentDistance = this.getDistance(points[0], points[1]);
// 计算缩放比例
const scaleRatio = currentDistance / this.initialDistance;
const newScale = this.initialScale * scaleRatio;
// 限制最小和最大缩放
const finalScale = Math.max(0.5, Math.min(newScale, 5));
this.A.scale.set(finalScale);
console.log("缩放中", currentDistance, scaleRatio, finalScale);
// 检查是否达到目标大小
this.checkSize();
}
}
onPointerUp(e) {
console.log("pointerup", e.pointerId);
// 移除触摸点
this.touchPoints.delete(e.pointerId);
// 如果少于两个触摸点,停止缩放
if (this.touchPoints.size < 2) {
this.isTouching = false;
console.log("停止缩放");
}
}
getDistance(point1: { x: number, y: number }, point2: { x: number, y: number }): number {
const dx = point1.x - point2.x;
const dy = point1.y - point2.y;
return Math.sqrt(dx * dx + dy * dy);
}
checkSize() {
if (this.A.scale.x >= 1) {
this.triggerSuccess();
}
}
triggerSuccess() {
// 防止重复触发
if (this.right.alpha > 0) return;
this.setTouchEnable(false);
Tween.get(this.right)
.to({ alpha: 1 }, 444, Ease.quadInOut)
.wait(2000)
.call(() => {
globalEvent.emit(GameEvent.NextLevel);
});
}
onDestroy() {
super.onDestroy();
Tween.removeTweens(this.A);
Tween.removeTweens(this.right);
// 移除触摸事件监听
this.A.off("pointerdown", this.onPointerDown, this);
this.A.off("globalpointermove", this.onPointerMove, this);
this.A.off("pointerup", this.onPointerUp, this);
this.A.off("pointerupoutside", this.onPointerUp, this);
}
}
...@@ -13,6 +13,7 @@ import { Level13 } from "@/pages/GamePage/Level/Level13.ts"; ...@@ -13,6 +13,7 @@ import { Level13 } from "@/pages/GamePage/Level/Level13.ts";
import { Level14 } from "@/pages/GamePage/Level/Level14.ts"; import { Level14 } from "@/pages/GamePage/Level/Level14.ts";
import { Level15 } from "@/pages/GamePage/Level/Level15.ts"; import { Level15 } from "@/pages/GamePage/Level/Level15.ts";
import { Level18 } from "@/pages/GamePage/Level/Level18.ts"; import { Level18 } from "@/pages/GamePage/Level/Level18.ts";
import { Level19 } from "@/pages/GamePage/Level/Level19.ts";
import { Level20 } from "@/pages/GamePage/Level/Level20.ts"; import { Level20 } from "@/pages/GamePage/Level/Level20.ts";
import { Level21 } from "@/pages/GamePage/Level/Level21.ts"; import { Level21 } from "@/pages/GamePage/Level/Level21.ts";
import { Level22 } from "@/pages/GamePage/Level/Level22.ts"; import { Level22 } from "@/pages/GamePage/Level/Level22.ts";
...@@ -38,7 +39,7 @@ export const LevelArr = [ ...@@ -38,7 +39,7 @@ export const LevelArr = [
{ cls: Level14, tip: `移动笼子罩住小鸭子` }, // 16 { cls: Level14, tip: `移动笼子罩住小鸭子` }, // 16
{ cls: Level14, tip: `别忘了,人是高等动物哦` }, // 17 { cls: Level14, tip: `别忘了,人是高等动物哦` }, // 17
{ cls: Level18, tip: `移开乌云露出太阳<br/>让冰块融化` }, { cls: Level18, tip: `移开乌云露出太阳<br/>让冰块融化` },
{ cls: Level14, tip: `将冰箱放大至能够装下长颈鹿` }, // 19 { cls: Level19, tip: `将冰箱放大至能够装下长颈鹿` },
{ cls: Level20, tip: `别忘了把题目也装进箱子里` }, { cls: Level20, tip: `别忘了把题目也装进箱子里` },
{ cls: Level21, tip: `移动鸡蛋,碰一碰便知` }, { cls: Level21, tip: `移动鸡蛋,碰一碰便知` },
{ cls: Level22, tip: `移开圣诞老人的衣服看看` }, { cls: Level22, tip: `移开圣诞老人的衣服看看` },
......
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