Developers Club geek daily blog

2 years, 3 months ago
In one rainy Petersburg afternoon my project ceased to be loaded into UE4, and because of it I wanted to make the own engine. And one short story pushed me to make the engine for short stories. If you want to learn more and you are not afraid of goto, gosub and other horrors, welcome under kat.
image




Table of contents






image
Everything began with how after passing N-oh of the short story the friend recommended me Katawa Shoujo. As it appeared the official version in App Store is not present and it is not expected, only .ipa on 4pda.

The same friend knowing that I try to create game already the third month suggested me to port Katava on iPad without Jailbreak. The choice fell on smart BASIC as I use this program one and a half years and I know syntax of its internal programming language (also smart BASIC have SDK for XCode).

The archive with all files of game except the text was at once downloaded. But it not I did not know that it will lead to creation of the engine for convenience of development.

Act 2. Development


image

1. Text


For a start I created folders (spoiler).
Folders
/ Sprites
/ Event
/ BGs
/ Music
/ Scenario
/ Scripts
/ Scripts/Ren_sB
/ Scripts/Ren_sB/Functions
/ UI
/ UI/main
/ VFX

The Katawa Shoujo Port.txt file will load all scripts.
scenario$ = “Habr”
{Scripts/colorcodes.txt}
{Scripts/Ren_sB/render.txt}

The colorcodes.txt file will contain RGB colors of names for a render, for an example I will take Sidzune and its blue selection:
data "Сидзунэ","107","174","239"
dim colors$(1,2)
read colors$(color,0)

The main preparations are made, now it is possible to write a script for demonstration of the text. In Katava, as well as in any visual short story, the text is shown in the field, and over the text the name of the character from whose person this text is written.

speak.txt script will be responsible for it.

For a start in the load.txt file I registered loading of bg-say.png sprite (a field for remarks) and the playtime_cyrillic font:
font "Font/playtime_cyrillic2.ttf" load a$
sprite "bg-say" load "UI/bg-say.png"
sprite "bg-say" resize 1024,205
sprite "bg-say" at 0,screen_height()-205
sprite "bg-doublespeak" load "UI/bg-doublespeak.png"
sprite "bg-doublespeak" resize 1024,205
sprite "bg-doublespeak" at 0,screen_height()-205
sprite "ctc-strip" load "UI/ctc-strip.png"
get sprite "ctc_strip" size w,h
sprite "ctc_strip" resize w*1.28,h*1.28
sprite "ctc_strip" at screen_width()-w*1.28-15,screen_height()-52
sprite "ctc_strip" delay 0.05


After I decided to use in a scenario script the sign "|" as a divider of command, the purpose of command, the secondary purpose, action and attribute.

Demonstration of the text: "1|pers|tekst"
1|Сейдзунэ|[Привет, Хабр]


The render.txt file reads out this command and redirects on alone tag
render.txt
graphics
set toolbar off
set orientation landscape

file "Scenario/"&scenario;$&".txt" readline hmm$
count = count+1
end = file_end("Scenario/"&scenario;$&".txt")
if end = 0 then goto count

file "Scenario/"&scenario;$&".txt" setpos 0

dim info$(count,5)

for l=0 to count-1
file "Scenario/"&scenario;$&".txt" readline line$

splite line$ to temp$,n with "|"
for m = 0 to n-1
info$(l,m) = temp$(m)
next m
next l

'Разбор массива текста, перенаправления на подпрограммы
'
show:
for y = 0 to count-1
if info$(y,0) = "1" then gosub alone
...
alone:
{Scripts/Ren_sB/Functions/Speak.txt}
return


speak.txt
sprite "bg-say" show
name$ = info$(y,1)
text$ = info$(y,2)

'Поиск кода цвета данного персонажа
'
for color = 0 to 6
if name$ = colors$(color,0) then
r = colors$(color,1)
g = colors$(color,2)
b = colors$(color,3)
endif
next color

'Создание двух полей
'
field 1 text name$ at 20,575 size 600,40 ro
field 1 back alpha 0
field 1 font color r/255,g/255,b/255
field 1 font name a$
field 1 font size 28

field 2 text render$ at 20,615 size screen_width()-20,130 ro ml
field 2 back alpha 0
field 2 font color 1,1,1
field 2 font size 28
field 2 font name a$

'Анимация текста
'
for k = 0 to len(text$)-1
'Использование касания для пропуска анимации
'
gosub 3
render$ = substr$(text$,0,k)
field 2 text render$
pause 0.025
next k

'Ожидание касания для перехода
'
sprite "ctc_strip" show ! sprite "ctc_strip" loop
gosub 1
sprite "ctc_strip" hide


1
1
x1 = touch_x(0)
y1 = touch_y(0)
if x1 > -1 or y1 > -1 then goto 2
slowdown
goto 1

2
x1 = touch_x(0)
y1 = touch_y(0)
if x1 = -1 or y1 = -1 then
return
endif
slowdown
goto 2


3
3
x1 = touch_x(0)
y1 = touch_y(0)
if x1 > -1 or y1 > -1 then
tapped = 1
endif

if tapped = 1 then
if x1 = -1 or y1 = -1 then
tapped = 0
if len(text$) = 0 then
k = lengthmax - 1
else
k = len(text$) - 1
endif
return
else
return
endif
endif
return


Result:

image

"But in Katava two characters at the same time can speak!" For this purpose there is a separate command: “2|перс1&перс2|текст1&текст2”:
2|Хисао&Лилли| "Hi!" &”Здравствуйте!"

Let's add to render.txt of a line:
render.txt
...
show:
...
if info$(y,0) = 2 then gosub together
...
together:
{Scripts/Ren_sB/Functions/Double_Speak.txt}
return


Double_Speak.txt executes these commands:
Double_Speak.txt
sprite "bg-doublespeak" show
names$ = info$(y,1)
'Имена и тексты
'
nd = instr(names$,"&")
name1$ = substr$(names$,0,nd-1)
name2$ = substr$(names$,nd+1,len(names$)-1)
texts$ = info$(y,2)
td = instr(texts$,"&")
text1$ = substr$(texts$,0,td-1)
text2$ = substr$(texts$,td+1,len(texts$)-1)
'Определение цвета для каждого персонажа
'
for color = 0 to 6
if name1$ = colors$(color,0) then
r1 = colors$(color,1)
g1 = colors$(color,2)
b1 = colors$(color,3)
endif
next color

for color = 0 to 6
if name2$ = colors$(color,0) then
r2 = colors$(color,1)
g2 = colors$(color,2)
b2 = colors$(color,3)
endif
next color
'Создание полей
'
field 11 text name1$ at 20,575 size 300,40 ro
field 11 back alpha 0
field 11 font color r1/255,g1/255,b1/255
field 11 font name a$
field 11 font size 28

field 12 text name2$ at 535,575 size 300,40 ro
field 12 back alpha 0
field 12 font color r2/255,g2/255,b2/255
field 12 font name a$
field 12 font size 28

field 21 text render1$ at 20,615 size screen_width()/2-20,130 ro ml
field 21 back alpha 0
field 21 font color 1,1,1
field 21 font size 28
field 21 font name a$

field 22 text render2$ at 535,615 size screen_width()/2-20,130 ro ml
field 22 back alpha 0
field 22 font color 1,1,1
field 22 font size 28
field 22 font name a$

'Определение максимальной и минимальной длинны
'
lengthmax = max(len(text1$),len(text2$))
lengthmin = min(len(text1$),len(text2$))

'Анимация текста
' 
if len(text1$) = len(text2$) then
for k = 0 to lengthmax-1
gosub 3
render1$ = substr$(text1$,0,k)
field 21 text render1$
render2$ = substr$(text2$,0,k)
field 22 text render2$
pause 0.025
next k
endif

if len(text1$) > len(text2$) then
for k = 0 to lengthmax-1
gosub 3
render1$ = substr$(text1$,0,k)
field 21 text render1$
if k < lengthmin then
render2$ = substr$(text2$,0,k)
field 22 text render2$
endif
pause 0.025
next k
endif

if len(text2$) > len(text1$) then
for k = 0 to lengthmax-1
gosub 3
render2$ = substr$(text2$,0,k)
field 22 text render2$
if k < lengthmin then
render1$ = substr$(text1$,0,k)
field 21 text render1$
endif
pause 0.025
next k
endif

'Ожидание касания
'
sprite "ctc_strip" show ! sprite "ctc_strip" loop
gosub 1
sprite "ctc_strip" hide



Result:

image

On it the first day of development okonchatsya, so also the first part of my article okanchatsya. In the second part I will describe the second day, namely I will add graphics (sprayta, backgrounds and iventa) and music.

Thanks to all those who read up until the end of article. To a meeting in the following part!

This article is a translation of the original post at habrahabr.ru/post/274399/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus