Skip to content

Commit

Permalink
增加自定义关卡(不稳定!!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanbe-Kotori committed Dec 9, 2020
1 parent b8432ec commit 33e1e53
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 51 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/TextHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class TextHelper {
StageData.stageEX_4.title = "ex-4 九宫八卦";
StageData.stageEX_5.title = "ex-5 阴阳交错";

StageData.test.title = "测试关卡";

StageData.tutorial1.tutorial_text = "在本游戏中,玩家可以通过拖动游戏画面的任何部分,来1:1地移动自机位置。点击屏幕右下角的i按钮可以查看当前关卡的小贴士。";
StageData.tutorial2.tutorial_text = "本关学习自机的判定点。在本游戏中,玩家只有金鱼中间的黑点中弹才算游戏失败,因此本关站着不动即可过关。";
StageData.tutorial3.tutorial_text = "本关认识弹幕中最常见的一类——固定弹,即无论如何都不发生变化的弹幕。请点击右下角的i按钮查看帮助。";
Expand Down Expand Up @@ -289,8 +287,6 @@ class TextHelper {
+ "\n\n本关制作者:chitose"
+ "\n\n本关设计者:花花";

StageData.test.help_text = "本关是开发者用来测试临时关卡用的,不要过于好奇哦";

/*
"本关在设计时就觉得有点迷。。虽然最后发现可以躲在版底强扭,但我一开始想的是绕屏幕转圈引自机狙,结果由于需要多次穿越紫色弹幕所以反而更难了。\n\n" +
"如果你是车万狗的话,本关应该难不倒你。但假如实在过不去的话,建议跳过本关。";
Expand Down
18 changes: 16 additions & 2 deletions src/scene/page/PageChapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class PageChapter extends PageBase {
this.addChild(this.titleText);

for (let i in this._stage_map) {
if (i == "custom") {
let button = this._stage_map[i];
let func:Function = () => {
this.removeChildren();
Main.getMain().removeChildren();
Main.getMain().addChild(PageCustomStage.INSTANCE);
};
button.setAction(func);
this.addChild(button);
continue;
}
let stage = StageData.getStage(i);
let front = stage.front_stage;
if (front == null || LocalData.getStageData(front) == STAGE_DATA.FINISHED || LocalData.getStageData(front) == STAGE_DATA.SKIPPED) {
Expand All @@ -56,11 +67,14 @@ class PageChapter extends PageBase {
}

public addStage(stage_id:string, button_text:string, point:egret.Point) {
if (stage_id == "custom") {
let button = new ButtonWithText(550, 150, point, "自定义关卡!");
this._stage_map[stage_id] = button;
return;
}
let button = new ButtonWithText(160, 160, point, button_text).setTexture(TextureNames.STAGE_UNFINISHED);
button.setColor(0x000000);
this._stage_map[stage_id] = button;
//button.setAction(PageChapter.createFunc(stage, this));
//this.arrayButton.push(button);
}

public static createFunc(stage:StageBase, chapter:PageChapter) {
Expand Down
94 changes: 94 additions & 0 deletions src/scene/page/PageCustomStage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
class PageCustomStage extends PageBase {

public static readonly INSTANCE:PageCustomStage = new PageCustomStage();

protected titleText:egret.TextField;
protected contentText:egret.TextField;

protected onAddToStage(event:egret.Event) {
super.onAddToStage(event);
}

protected doRender() {
let sky = MyUtils.createBitmapByName(TextureNames.MAIN_PAGE);
sky.width = Main.X;
sky.height = Main.Y;
sky.alpha = 1;
this.addChild(sky);

this.titleText = new egret.TextField();
this.titleText.width = 1080;
this.titleText.height = 120;
this.titleText.x = 0;
this.titleText.y = 60;
this.titleText.size = 72;
this.titleText.text = "自定义关卡";
this.titleText.textColor = 0x000000;
this.titleText.fontFamily = "KaiTi";
this.titleText.textAlign = egret.HorizontalAlign.CENTER;
this.titleText.verticalAlign = egret.VerticalAlign.MIDDLE;
this.addChild(this.titleText);

this.contentText = new egret.TextField();
this.contentText.type = egret.TextFieldType.INPUT;
this.contentText.multiline = true;
this.contentText.width = 1000;
this.contentText.height = 1320;
this.contentText.x = 40;
this.contentText.y = 360;
this.contentText.size = 32;
this.contentText.textFlow = <Array<egret.ITextElement>>[
{text: "//在这里通过代码自定义关卡!\n", style: {"bold": true, "textColor": 0xff0000}},
{text: "//代码示例:github.com/NullaDev/SBSTG/tree/master/src/scene/stage。"},
{text: "请注意,由于eval()函数不能运行ts代码,所以请把示例代码里的“变量名:类型”中的“:类型”去掉,以转换为js代码。\n", style: {"bold": true, "textColor": 0xff0000}},
{text: "//本页面的代码目前还没有实现保存功能(其实是懒)!因此,请在别处保存好代码再进行测试,以免一直以来的所有努力全部木大!\n", style: {"bold": true, "textColor": 0xff0000}},
{text: "let point1 = new egret.Point(540, 900);\n"},
{text: "let launcher1= LauncherFactory.texturedLauncher(TextureNames.FLOWER0, 160, 120).setInitialPos(point1);\n"},
{text: "launcher1.addLogic(\n"},
{text: " new ScatterRotate(launcher1,new EllipticalMissile().setSize(15, 120).setTexture(TextureNames.MISSILE_LEAF).setTotalVelocity(30))\n"},
{text: " .setFreq(200).setStartAngle(0).setStep(360/8).setNumber(8).setPeriod(-20)\n"},
{text: ");\n"},
{text: "launcher1.addLogic(\n"},
{text: " new ScatterRotate(launcher1,new EllipticalMissile().setSize(30, 30).setTexture(TextureNames.MISSILE_PETAL2).setTotalVelocity(58)\n"},
{text: " .addHandler(\n"},
{text: " new TickEventHandler(\n"},
{text: " (missile) => {missile.setTotalVelocity(missile.getVelocity() - 5);}\n"},
{text: " ).setTriggerTimes(10)\n"},
{text: " )\n"},
{text: " ).setStartAngle(0).setNumber(10).setStep(360/10).setFreq(300).setPeriod(10)\n"},
{text: ")"}
];
this.contentText.textColor = 0x000000;
this.contentText.strokeColor = 0xffffff;
this.contentText.stroke = 2;
this.contentText.fontFamily = "KaiTi";
this.contentText.textAlign = egret.HorizontalAlign.LEFT;
this.contentText.verticalAlign = egret.VerticalAlign.TOP;
this.addChild(this.contentText);

let btnTest = new ButtonWithText(550, 150, new egret.Point(Main.X * 0.5, Main.Y * 0.8), "测试");
btnTest.setAction(PageCustomStage.click_test);
this.addChild(btnTest);

let btnReturn = new ButtonWithText(550, 150, new egret.Point(Main.X * 0.5, Main.Y * 0.9), "返回");
btnReturn.setAction(PageCustomStage.click_return);
this.addChild(btnReturn);
}

public static click_test(evt:egret.TouchEvent) {
let stage_test = new Test(PageCustomStage.INSTANCE.contentText.text)
stage_test.title = "测试关卡"
stage_test.help_text = "这是你自己创建的测试关卡";
SelfMachine.INSTANCE.currentStage = stage_test;
PageCustomStage.INSTANCE.removeChildren();
Main.getMain().removeChildren();
Main.getMain().addChild(stage_test);
}

public static click_return(evt:egret.TouchEvent) {
PageCustomStage.INSTANCE.removeChildren();
Main.getMain().removeChildren();
Main.getMain().addChild(StageData.chapter_extra);
}

}
5 changes: 1 addition & 4 deletions src/scene/stage/StageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class StageData {
public static stageEX_4:StageBase;
public static stageEX_5:StageBase;
public static stageEX_6:StageBase;
public static test:StageBase;

public static init() {
StageData.initChapters();
Expand Down Expand Up @@ -164,8 +163,6 @@ class StageData {
StageData.stageEX_4 = new CEXS4();
StageData.stageEX_5 = new CEXS5();
StageData.stageEX_6 = new CEXS6();

StageData.test = new Test();
}

private static addStageToChapters() {
Expand Down Expand Up @@ -206,7 +203,7 @@ class StageData {
StageData.chapter_extra.addStage("cexs4", "4", new egret.Point(Main.X * 0.25, Main.Y * 0.4));
StageData.chapter_extra.addStage("cexs5", "5", new egret.Point(Main.X * 0.50, Main.Y * 0.4));
StageData.chapter_extra.addStage("cexs6", "6", new egret.Point(Main.X * 0.75, Main.Y * 0.4));
StageData.chapter_extra.addStage("test", "T", new egret.Point(Main.X * 0.50, Main.Y * 0.55));
StageData.chapter_extra.addStage("custom", "", new egret.Point(Main.X * 0.50, Main.Y * 0.55));

StageData.chapter1h.addStage("c1s1h", "1", new egret.Point(Main.X * 0.25, Main.Y * 0.25));
StageData.chapter1h.addStage("c1s2h", "2", new egret.Point(Main.X * 0.50, Main.Y * 0.25));
Expand Down
2 changes: 1 addition & 1 deletion src/scene/stage/extra/chapterEX/CEXS6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CEXS6 extends StageBase {
launcher1,
(launcher:Launcher) => {
let tick = SelfMachine.INSTANCE.currentStage.getCurrentTick();
let clock = tick % 100 >= 25;
let clock = tick % 100 >= 25;
let left = new RoundMissile()
.setTexture(TextureNames.MISSILE_RING_RED)
.setSize(240, 240)
Expand Down
49 changes: 9 additions & 40 deletions src/scene/stage/extra/chapterEX/Test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
class Test extends StageBase {
public constructor() {
protected _text:string;

public constructor(text:string) {
super("test", 30);
this._text = text;
}

protected initEmitters() {
//测试关卡用
let point1 = new egret.Point(540, 900);
let launcher1= LauncherFactory.texturedLauncher(TextureNames.FLOWER0, 160, 120).setInitialPos(point1);
launcher1.addLogic(
new ScatterRotate(
launcher1,
new EllipticalMissile()
.setSize(15, 120)
.setTexture(TextureNames.MISSILE_LEAF)
.setTotalVelocity(30)
)
.setFreq(200)
.setStartAngle(0)
.setStep(360/8)
.setNumber(8)
.setPeriod(-20)
);
launcher1.addLogic(
new ScatterRotate(
launcher1,
new EllipticalMissile()
.setSize(30, 30)
.setTexture(TextureNames.MISSILE_PETAL2)
.setTotalVelocity(58)
.addHandler(
new TickEventHandler(
(missile:MissileBase) => {
missile.setTotalVelocity(missile.getVelocity() - 5);
}
)
.setTriggerTimes(10)
)
)
.setStartAngle(0)
.setNumber(10)
.setStep(360/10)
.setFreq(300)
.setPeriod(10)
)
try {
eval(this._text);
} catch (error) {
console.log(error);
}
}

}

0 comments on commit 33e1e53

Please sign in to comment.