Commit c8ce686b authored by haiyoucuv's avatar haiyoucuv

蛇换皮

parent 66885c92
...@@ -5,12 +5,15 @@ import { EleConfig, EleData, mapSize } from "@/pages/GamePage/config/Config.ts"; ...@@ -5,12 +5,15 @@ import { EleConfig, EleData, mapSize } from "@/pages/GamePage/config/Config.ts";
const foodWeight = new Weight<EleData>(); const foodWeight = new Weight<EleData>();
const negWeight = new Weight<EleData>(); const negWeight = new Weight<EleData>();
for (let eleConfigKey in EleConfig) {
const { neg, weight } = EleConfig[eleConfigKey]; function initWeight() {
if (neg) { for (let eleConfigKey in EleConfig) {
negWeight.add(EleConfig[eleConfigKey], weight); const { neg, weight } = EleConfig[eleConfigKey];
} else { if (neg) {
foodWeight.add(EleConfig[eleConfigKey], weight); negWeight.add(EleConfig[eleConfigKey], weight);
} else {
foodWeight.add(EleConfig[eleConfigKey], weight);
}
} }
} }
...@@ -25,17 +28,19 @@ export class ElementMgr { ...@@ -25,17 +28,19 @@ export class ElementMgr {
this.footCtn = this.root.addChild(new Container()); this.footCtn = this.root.addChild(new Container());
this.negCtn = this.root.addChild(new Container()); this.negCtn = this.root.addChild(new Container());
initWeight();
} }
start() { start() {
Tween.get(this, { loop: true }) Tween.get(this, { loop: true })
.wait(1000) .wait(1500)
.call(() => { .call(() => {
this.flushFood(); this.flushFood();
}); });
Tween.get(this, { loop: true }) Tween.get(this, { loop: true })
.wait(1500) .wait(2000)
.call(() => { .call(() => {
this.flushNeg(); this.flushNeg();
}) })
......
...@@ -4,6 +4,8 @@ import { GameConfig, mapSize } from "@/pages/GamePage/config/Config.ts"; ...@@ -4,6 +4,8 @@ import { GameConfig, mapSize } from "@/pages/GamePage/config/Config.ts";
import { Circle } from "detect-collisions"; import { Circle } from "detect-collisions";
import { collisionSys } from "@/pages/GamePage/GamePage.tsx"; import { collisionSys } from "@/pages/GamePage/GamePage.tsx";
import { Tween } from "@/pages/GamePage/tween"; import { Tween } from "@/pages/GamePage/tween";
import { reaction } from "mobx";
import gameStore from "@/store/gameStore.ts";
export class Snake extends Container { export class Snake extends Container {
head: Sprite = null; head: Sprite = null;
...@@ -26,6 +28,23 @@ export class Snake extends Container { ...@@ -26,6 +28,23 @@ export class Snake extends Container {
init() { init() {
this.initUI(); this.initUI();
this.initPhy(); this.initPhy();
reaction(
() => gameStore.gameInfo.level,
(level) => {
const { levelCfg } = GameConfig;
const { skin } = levelCfg[level];
this.setSkin(skin);
},
{ fireImmediately: true }
);
}
setSkin(skin: string) {
this.bodyScale = 1;
this.head.texture = Assets.get(`蛇/${skin}/head.png`);
this.bodyArr.forEach((body, i) => {
body.texture = Assets.get(`蛇/${skin}/body${i % 2}.png`);
});
} }
initUI() { initUI() {
...@@ -118,7 +137,10 @@ export class Snake extends Container { ...@@ -118,7 +137,10 @@ export class Snake extends Container {
let len = this.bodyArr.length; let len = this.bodyArr.length;
const newBody = new Sprite(Assets.get("蛇/初级/body0.png")); const { levelCfg } = GameConfig;
const { skin } = levelCfg[gameStore.gameInfo.level];
const newBody = new Sprite(Assets.get(`蛇/${skin}/body${len % 2}.png`));
const pre = this.bodyArr[len - 1] || this.head; const pre = this.bodyArr[len - 1] || this.head;
...@@ -132,7 +154,7 @@ export class Snake extends Container { ...@@ -132,7 +154,7 @@ export class Snake extends Container {
} }
positions: PointData[] = []; // 存储历史位置点 positions: PointData[] = []; // 存储历史位置点
private readonly SEGMENT_SPACING = 6.3; // 增加节点间距 private readonly SEGMENT_SPACING = 5; // 增加节点间距
moveTime = 1 / 60; moveTime = 1 / 60;
totalTime = 0; totalTime = 0;
......
...@@ -93,7 +93,7 @@ export class Game extends Container { ...@@ -93,7 +93,7 @@ export class Game extends Container {
} }
addScore(score: number, pos: PointData) { addScore(score: number, pos: PointData) {
gameStore.gameInfo.score += score; gameStore.addScore(score);
const bubble = this.mapCtn.addChild(new ScoreBubble(score)); const bubble = this.mapCtn.addChild(new ScoreBubble(score));
bubble.position.set(pos.x + 20, pos.y - 20); bubble.position.set(pos.x + 20, pos.y - 20);
} }
......
...@@ -28,6 +28,28 @@ export const GameConfig = { ...@@ -28,6 +28,28 @@ export const GameConfig = {
magnetScale: 4, magnetScale: 4,
initEnergy: 10, initEnergy: 10,
growthThreshold: 2, growthThreshold: 2,
levelCfg: [
{
score: 0,
skin: "初级",
level: 0,
},
{
score: 30,
skin: "红色",
level: 1,
},
{
score: 60,
skin: "黄色",
level: 2,
},
{
score: 90,
skin: "蓝色",
level: 3,
},
],
} }
export const EleConfig: { [key in Ele]: EleData } = { export const EleConfig: { [key in Ele]: EleData } = {
...@@ -41,7 +63,7 @@ export const EleConfig: { [key in Ele]: EleData } = { ...@@ -41,7 +63,7 @@ export const EleConfig: { [key in Ele]: EleData } = {
cls: Filiform, cls: Filiform,
texture: "元素/丝状菌.png", texture: "元素/丝状菌.png",
weight: 3, weight: 3,
score: 2, score: 20,
}, },
[Ele.Molecule]: { [Ele.Molecule]: {
cls: Molecule, cls: Molecule,
......
...@@ -5,6 +5,7 @@ import {Toast} from "@grace/ui"; ...@@ -5,6 +5,7 @@ import {Toast} from "@grace/ui";
import {AESEncrypt} from "@/utils/Crypto.ts"; import {AESEncrypt} from "@/utils/Crypto.ts";
import { PageCtrl } from "@/core/ctrls/PageCtrl.tsx"; import { PageCtrl } from "@/core/ctrls/PageCtrl.tsx";
import HomePage from "@/pages/HomePage/HomePage.tsx"; import HomePage from "@/pages/HomePage/HomePage.tsx";
import { GameConfig } from "@/pages/GamePage/config/Config.ts";
class GameStore { class GameStore {
...@@ -39,9 +40,28 @@ class GameStore { ...@@ -39,9 +40,28 @@ class GameStore {
gameInfo: { gameInfo: {
score: number, score: number,
remainTimes: number, remainTimes: number,
level: number,
maxScore: number,
} = { } = {
score: 0, score: 0,
remainTimes: 0, remainTimes: 0,
level: 0,
maxScore: 0,
}
addScore(s: number) {
const score = this.gameInfo.score + s;
this.gameInfo.score = score;
this.gameInfo.maxScore = Math.max(score, this.gameInfo.maxScore);
const { levelCfg } = GameConfig;
for (let i = levelCfg.length - 1; i >= 0; i--) {
if (score >= levelCfg[i].score) {
this.gameInfo.level = i;
break;
}
}
} }
async submit(score: number) { async submit(score: number) {
......
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