Created
January 10, 2020 17:44
-
-
Save myokoym/6c00ead01e571a9a343ef7c788734828 to your computer and use it in GitHub Desktop.
novel game sample for Love2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module("GameText", package.seeall) | |
require "libs.object" | |
local utf8 = require("utf8") | |
new = function() | |
local obj = {} | |
local x = 0 | |
local y = room_height | |
local line_margin = 2 | |
local line_width = 5 | |
local text_margin = 15 | |
local text_x = x + text_margin | |
local text_y = y + text_margin | |
local text = { | |
"五つ六つ", | |
"茶の子にならぶ", | |
"囲炉裏哉", | |
} | |
local lines = {"", "", ""} | |
local current_line = 1 | |
local t = 0 | |
local speed = 0.3 | |
local finish = false | |
obj.update = function(self, dt) | |
if finish then | |
return | |
end | |
t = t + dt | |
if t >= speed then | |
t = t - speed | |
if lines[current_line] == text[current_line] then | |
current_line = current_line + 1 | |
end | |
if text[current_line] == nil then | |
finish = true | |
return | |
end | |
local offset = utf8.offset(text[current_line], utf8.len(lines[current_line]) + 2) | |
lines[current_line] = string.sub(text[current_line], 1, offset - 1) | |
end | |
end | |
obj.draw = function() | |
love.graphics.setColor(1, 1, 1) | |
love.graphics.rectangle( | |
"fill", | |
x + line_margin, | |
y + line_margin, | |
room_width - line_margin*2, | |
wdw_h - room_height - line_margin*2, | |
10, 10) | |
love.graphics.setColor(0, 0, 0) | |
love.graphics.rectangle( | |
"fill", | |
x + line_width, | |
y + line_width, | |
room_width - line_width*2, | |
wdw_h - room_height - line_width*2, | |
10, 10) | |
love.graphics.setColor(1, 1, 1) | |
love.graphics.setFont(font_s) | |
for i, line in ipairs(lines) do | |
love.graphics.printf( | |
lines[i], | |
text_x + text_margin, | |
text_y + font_s_size*(i-1) + text_margin*i, | |
room_width - text_margin*2, "left") | |
end | |
if finish then | |
obj.draw_next_mark() | |
end | |
end | |
obj.draw_next_mark = function() | |
local base_x = room_width - 30 | |
local base_y = wdw_h - 30 | |
local size = 8 | |
love.graphics.polygon( | |
"fill", | |
base_x, base_y, | |
base_x + size*2, base_y, | |
base_x + size, base_y + size) | |
end | |
return obj | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment