Skip to content

Commit

Permalink
Story stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Deseteral committed Jun 30, 2023
1 parent 8832cfa commit 5e3150b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 15 deletions.
127 changes: 127 additions & 0 deletions Source/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,130 @@ local function playSound(self, sound, loop)
end
____exports.Sound = Sound
____exports.playSound = playSound
return ____exports
end,
["story-stage"] = function(...)
local ____lualib = require("lualib_bundle")
local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
local __TS__StringPadStart = ____lualib.__TS__StringPadStart
local ____exports = {}
local ____font = require("engine.font")
local Font = ____font.Font
local ____input = require("engine.input")
local Input = ____input.Input
local ____sounds = require("engine.sounds")
local playSound = ____sounds.playSound
local Sound = ____sounds.Sound
local ____stage = require("engine.stage")
local Stage = ____stage.Stage
local ____textures = require("engine.textures")
local Textures = ____textures.Textures
local ____utils = require("game.utils")
local clamp = ____utils.clamp
class("StoryStage").extends(Stage)
StoryStage.init = function(self)
StoryStage.super.init(self)
self.pageNumber = 0
self.pages = {
{"You've just graduated", "from The Magic School.", "", "Congratulations!"},
{"After 10 long years", "of studying. You're", "finally free!"},
{"At the School you've", "learned everything", "about magic."},
{"You studied spell cas-", "-ting, history, making", "potions, physics and", "engineering."},
{
"When you were study-",
"-ing late at the",
"school library, you've",
"often dreamed about",
"seeing the world..."
},
{"...and living in", "Oakville."},
{"Now finally free from", "the burden of school", "life, you've decided", "to fulfill your dream."},
{
"Running away from",
"the school gate with",
"just one small bag",
"of your personal",
"belongings you head",
"to the Royal port."
},
{
"You've barely managed",
"to catch the sky ship",
"to Oakville, and after",
"a couple of days of",
"traveling you arrive",
"at your destination."
},
{"There you take a loan", "for 500 gold and open", "your own potion store."},
{"You're living the", "dream. Good luck and", "have fun!"},
{
"",
"",
"",
"",
"Press Enter to begin"
}
}
end
function StoryStage.onActivate(self)
end
function StoryStage.update(self)
if Input:getKeyDown("left") then
self.pageNumber = self.pageNumber - 1
playSound(nil, Sound.BOOK)
end
if Input:getKeyDown("right") then
self.pageNumber = self.pageNumber + 1
playSound(nil, Sound.BOOK)
end
self.pageNumber = clamp(
nil,
self.pageNumber,
0,
math.ceil(#self.pages / 2) - 1
)
if self.pageNumber == 5 and Input:getKeyDown("a") then
playSound(nil, Sound.MENU_CONFIRM)
end
end
function StoryStage.render(self)
Textures.bookTexture.normal:draw(0, 0)
local t1 = self.pages[self.pageNumber * 2 + 1]
local t2 = self.pages[self.pageNumber * 2 + 1 + 1]
if t1 ~= nil then
__TS__ArrayForEach(
t1,
function(____, line, idx)
Font:draw(line, 47, 24 + idx * (Font.charHeightSmall + 2), true)
end
)
Font:draw(
tostring(self.pageNumber * 2 + 1),
50,
200
)
end
if t2 ~= nil then
__TS__ArrayForEach(
t2,
function(____, line, idx)
Font:draw(line, 212, 24 + idx * (Font.charHeightSmall + 2), true)
end
)
Font:draw(
__TS__StringPadStart(
tostring(self.pageNumber * 2 + 2),
2,
" "
),
340,
200
)
end
end
function StoryStage.onDestroy(self)
end
____exports.StoryStage = StoryStage
return ____exports
end,
["main-menu-stage"] = function(...)
Expand All @@ -3039,6 +3163,8 @@ local ____textures = require("engine.textures")
local Textures = ____textures.Textures
local ____utils = require("game.utils")
local clamp = ____utils.clamp
local ____story_2Dstage = require("story-stage")
local StoryStage = ____story_2Dstage.StoryStage
import("CoreLibs/object")
class("MainMenuStage").extends(Stage)
MainMenuStage.init = function(self)
Expand All @@ -3061,6 +3187,7 @@ function MainMenuStage.update(self)
if Input:getKeyDown("a") then
if self.cursor == 0 then
Engine:newGame()
Engine:changeStage(StoryStage())
elseif self.hasSaveData and self.cursor == 1 then
Engine:loadGame()
elseif self.hasSaveData and self.cursor == 2 or not self.hasSaveData and self.cursor == 1 then
Expand Down
4 changes: 2 additions & 2 deletions src/main-menu-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Textures } from 'src/engine/textures';
import { clamp } from 'src/game/utils';
// import { WorkshopStage } from 'src/game/workshop-stage';
// import { HowToPlayStage } from 'src/how-to-play-stage';
// import { StoryStage } from 'src/story-stage';
import { StoryStage } from 'src/story-stage';

class MainMenuStage extends Stage {
cursor = 0;
Expand All @@ -34,7 +34,7 @@ class MainMenuStage extends Stage {
if (Input.getKeyDown('a')) {
if (this.cursor === 0) {
Engine.newGame();
// Engine.changeStage(new StoryStage());
Engine.changeStage(new StoryStage());
} else if (this.hasSaveData && this.cursor === 1) {
Engine.loadGame();
// Engine.changeStage(new WorkshopStage());
Expand Down
29 changes: 16 additions & 13 deletions src-web/story-stage.ts → src/story-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Input } from 'src/engine/input';
import { playSound, Sound } from 'src/engine/sounds';
import { Stage } from 'src/engine/stage';
import { Textures } from 'src/engine/textures';
import { WorkshopStage } from 'src/game/workshop-stage';
import { clamp } from 'src/game/utils';
// import { WorkshopStage } from 'src/game/workshop-stage';

export class StoryStage extends Stage {
class StoryStage extends Stage {
pageNumber = 0;

pages: (string[])[] = [
Expand Down Expand Up @@ -80,7 +81,7 @@ export class StoryStage extends Stage {
'',
'',
'',
'Press Enter to begin',
'Press A to begin',
],
];

Expand All @@ -96,37 +97,39 @@ export class StoryStage extends Stage {
this.pageNumber += 1;
playSound(Sound.BOOK);
}
this.pageNumber = Math.clamp(this.pageNumber, 0, Math.ceil(this.pages.length / 2) - 1);
this.pageNumber = clamp(this.pageNumber, 0, Math.ceil(this.pages.length / 2) - 1);

if (this.pageNumber === 5 && Input.getKeyDown('a')) {
Engine.changeStage(new WorkshopStage());
// Engine.changeStage(new WorkshopStage()); // TODO: impl
playSound(Sound.MENU_CONFIRM);
}
}

render(ctx: CanvasRenderingContext2D): void {
ctx.drawImage(Textures.bookTexture.normal, 0, 0);
render(): void {
Textures.bookTexture.normal.draw(0, 0);

const t1: string[] = this.pages[this.pageNumber * 2];
const t2: string[] = this.pages[this.pageNumber * 2 + 1];

if (t1) {
if (t1 !== undefined) {
t1.forEach((line, idx) => {
Font.draw(line, 47, 24 + idx * (Font.charHeightSmall + 2), ctx, true);
Font.draw(line, 47, 24 + idx * (Font.charHeightSmall + 2), true);
});

Font.draw(`${this.pageNumber * 2 + 1}`, 50, 200, ctx);
Font.draw(`${this.pageNumber * 2 + 1}`, 50, 200);
}

if (t2) {
if (t2 !== undefined) {
t2.forEach((line, idx) => {
Font.draw(line, 212, 24 + idx * (Font.charHeightSmall + 2), ctx, true);
Font.draw(line, 212, 24 + idx * (Font.charHeightSmall + 2), true);
});

Font.draw(`${(this.pageNumber * 2 + 2).toString().padStart(2, ' ')}`, 340, 200, ctx);
Font.draw(`${(this.pageNumber * 2 + 2).toString().padStart(2, ' ')}`, 340, 200);
}
}

onDestroy(): void {
}
}

export { StoryStage };
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"node_modules/*"
],
},
"lib": [
"DOM",
"es2017"
]
},
"tstl": {
"luaTarget": "5.4",
Expand Down

0 comments on commit 5e3150b

Please sign in to comment.