Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit f94c2f5

Browse files
committedNov 18, 2021
Switching text over to palettes and created a new custom font.
1 parent c293917 commit f94c2f5

11 files changed

+56
-17
lines changed
 

‎Game/Src/code-display-text.lua

+12-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function CreateTextDisplay(rect)
2727
data.textTime = 0
2828
data.currentChar = 0
2929
data.totalChars = 0
30-
data.nextY = rect.y
30+
data.nextY = rect.y/8
3131
data.drawText = false
3232
data.paused = false
3333

@@ -90,13 +90,18 @@ function DrawTextDisplay(data)
9090
end
9191

9292
function DrawNextLine(data)
93+
94+
-- We need a reference ot the current line we are on
9395
local line = data.lines[data.currentLine]
94-
local colorOffset = data.colorOffsets[data.currentLine]
95-
-- print("offsets", dump(data.colorOffsets))
9696

97+
-- Ge the current character to draw
9798
local char = line:sub(data.currentChar, data.currentChar)
9899

99-
DrawText(char, data.currentChar * 8, data.nextY, DrawMode.TilemapCache, "large", colorOffset[data.currentChar])
100+
-- Get the color offset for the current character and default it to 0 if the value is nil which happens when there is a space
101+
local colorOffset = data.colorOffsets[data.currentLine][data.currentChar] or 0
102+
103+
-- Draw the character to the tilemap
104+
DrawText(char, data.currentChar, data.nextY, DrawMode.Tile, "terminal", colorOffset)
100105

101106
data.currentChar = data.currentChar + 1
102107

@@ -108,15 +113,15 @@ function DrawNextLine(data)
108113
data.drawText = false
109114
end
110115

111-
data.nextY = data.nextY + 8
116+
data.nextY = data.nextY + 1
112117

113118
if(data.drawText == true and data.nextY > (data.rect.y + (data.rect.h - 16))) then
114119

115120
if(data.paused == false) then
116121

117122
data.paused = true
118123

119-
DrawText("...", data.rect.x, data.nextY, DrawMode.TilemapCache, "large", 15)
124+
DrawText("...", data.rect.x, data.nextY, DrawMode.TilemapCache, "terminal", 15)
120125

121126
-- reset some of the text display's values
122127
data.nextY = data.rect.y
@@ -159,7 +164,7 @@ function DisplayText(data, text, clear)
159164
-- Get the lines
160165
local newLines = SplitLines(wrap)
161166

162-
print("lines", dump(newLines))
167+
-- print("lines", dump(newLines))
163168

164169
local offset = 0
165170

‎Game/Src/code-map-generator.lua

+24-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ function ClearMap(data)
5656
end
5757
end
5858

59+
local bitFlagTable =
60+
{
61+
"0000",
62+
"0001",
63+
"0010",
64+
"0011",
65+
"0100",
66+
"0101",
67+
"0110",
68+
"0111",
69+
"1000",
70+
"1001",
71+
"1010",
72+
"1011",
73+
"1100",
74+
"1101",
75+
"1110",
76+
"1111"
77+
}
78+
5979
function GenerateMap(data)
6080
-- ClearMap(data)
6181

@@ -80,10 +100,12 @@ function GenerateMap(data)
80100
local c = i-1
81101
local r = j-1
82102

83-
print("tile", c, r, calId(c, r, data.width), dump(data.maze[i][j]))
103+
local tile = data.maze[i][j]
104+
local sides = tostring(tile.down) .. tostring(tile.right) .. tostring(tile.left) .. tostring(tile.up)
84105

85-
end
106+
print("tile", c, r, calId(c, r, data.width), sides, table.indexOf(bitFlagTable, sides), dump(tile))
86107

108+
end
87109

88110
end
89111

‎Game/Src/code-simple-input-field.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function DrawInputField(data)
6969
local tmpX = data.rect.x + (#data.text * data.spriteSize.x)
7070

7171
if(tmpX < data.rect.w) then
72-
DrawText(data.blinkChar, tmpX, data.rect.y, DrawMode.Sprite, "large", 15)
72+
DrawText(data.blinkChar, tmpX, data.rect.y, DrawMode.Sprite, "terminal", 46)
7373
end
7474

7575
end
@@ -110,7 +110,7 @@ function DrawInputField(data)
110110
local text, colorOffsets = colorizeText(data.suggestedTest, 6)
111111

112112
-- Draw the text to the display
113-
DrawColoredText(text, data.rect.x, data.rect.y, DrawMode.TilemapCache, "large", colorOffsets)
113+
DrawColoredText(text, data.rect.x, data.rect.y, DrawMode.TilemapCache, "terminal", colorOffsets)
114114

115115
end
116116

‎Game/Src/code-utils.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ function string.replaceTokens(text, data)
7272

7373
end
7474

75+
TOTAL_COLORS = 15
76+
7577
function colorizeText(text, defaultColor, tokens)
7678

7779
-- local tokens = {}
@@ -84,8 +86,10 @@ function colorizeText(text, defaultColor, tokens)
8486

8587
local colorString = ""
8688

87-
for i = 1, #text do
89+
local defaultColor = ((defaultColor or 15) * 2) + TOTAL_COLORS + 1
8890

91+
for i = 1, #text do
92+
8993
local char = string.sub(text, i, i)
9094

9195
-- Look to see if we are at the start of a token
@@ -103,13 +107,13 @@ function colorizeText(text, defaultColor, tokens)
103107
elseif(colorString == "") then
104108

105109
-- This is a special case to take into account for a token in the text or just come characters wrapped in open and closed brakes
106-
colorString = tostring(defaultColor)
110+
colorString = tostring(15)
107111
token = "{" .. token .. "}"
108112

109113
end
110114

111115
-- Time to apply the color so convert the color string into a number
112-
local color = tonumber(colorString)
116+
local color = ((tonumber(colorString) or 0) * 2) + TOTAL_COLORS + 1
113117

114118
-- Add the token to the text
115119
newText = newText .. token

‎Game/code.lua

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ LoadScript("code-message-bar")
2020
LoadScript("code-inventory")
2121
LoadScript("code-combat")
2222

23-
2423
-- This this is an empty game, we will the following text. We combined two sets of fonts into
2524
-- the default.font.png. Use uppercase for larger characters and lowercase for a smaller one.
2625
local message = textTemplates.intro
@@ -41,8 +40,6 @@ function Init()
4140
-- Here we are manually changing the background color
4241
BackgroundColor(0)
4342

44-
45-
4643
inputField = CreateInputField({x = 8, y = 224, w = 240})
4744

4845
textDisplay = CreateTextDisplay({x = 8, y = 8, w = 240, h = 200})

‎Game/colors.png

254 Bytes
Loading

‎Game/data.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ColorChip":
3+
{
4+
"total": 32,
5+
"maxColors": 128,
6+
"backgroundColor": 0,
7+
"maskColor": "#FF00FF",
8+
"unique": false,
9+
"debug": false
10+
}
11+
}

‎Game/large.font.png

1.47 KB
Loading

‎Game/terminal.font.png

1.47 KB
Loading

‎Resources/palette-mapping.aseprite

7.69 KB
Binary file not shown.

‎Resources/terminal.ase

1.63 KB
Binary file not shown.

0 commit comments

Comments
 (0)
This repository has been archived.