Posted: Sun Sep 01, 2002 7:07 pm Post subject: [source code] Text Effects
I've seen a lot of people trying to make RPG games in turing and some turned out quite nice actually. As Dan about QFTB, he has it posted somewhere.
Most of typical RPGs have plots (atleast they should) and chats with other NPCs. Basically you'll end up displaying a lot of text. In this post I will be posting source codes for different text effects that you can use throughout your games and other applications.
Posted: Sun Sep 01, 2002 7:21 pm Post subject: Displaying text
This is the simpliest way to display text information on the screen:
code:
put "your text here"
if you didn't know that already... well you've got a long way to go.
Here's a better way to display your text -- Font.Draw
code:
var fontID:int := Font.New ("Arial:14:bold")
Font.Draw("Your text here", x,y, fontID, colour)
A bit of explanation -- fontID is a variable that stores information about the font you're using. It has to be an 'int' but can be assigned a value only through Font.New as in example. Arial is the name of the font you're using, if the name doesn't match with anything on computer, the default one is used. 14 stands for the size, you can change it to any integer number. 'bold' makes text bold and is optional. You can also add :italic and/or :underline if you want.
"Your text here" is the text that will be displayed, it can be a string variable. x and y are the coordinates of the lower-left corner where text starts. fontID is the name of the variable decleared earlier. colour is the color of the text to be displayed - place an integer value or a predefined keyword for color.
Posted: Sun Sep 01, 2002 7:36 pm Post subject: Text Delay
Text Delay is the simpliest text effect. What it does is it delays the time between each character being displayed, making it look like the text is being typed while you're reading it. Very useful, especially for games where a lot of text is displayed like RPG.
code:
procedure TextDelay(text:string)
for i : 1..length(text)
put text(i)..
delay(50)
end for
end TextDelay
var text:string
get text:*
TextDelay(text)
I bit of explanation here -- TextDelay is a procedure. This way you can use it again and again in your code just like you use "put" command.
"text" is the name of the string variable passed into the procedure. Then a forloop is run from 1 to the total number of charactes in the string. It is displayed 1 character at a time followed by a delay(50). If you increase the number, text will be typed slower, decrease it to display it quicker.
Note: after putting each character don't forget '..' to keep them all on 1 line and when getting a text string, don't forget to put ':*' to get all the characters including spaces.
And ofcourse you can just put plain text instead of the variable if you already know what to display
Posted: Sun Sep 01, 2002 7:50 pm Post subject: TextDelay -- Coloured
If you didn't know before, text from 'put' command can be colored as well as text from Font.Draw using color(i:int) and colorback(i:int)
code:
color(14)
colorback(1)
put "hello world!"
this will output "hello world!" in yellow color on a blue background.
Now we can take this one step further and include that in previosly shown TextDelay!
code:
procedure TextDelay(text:string)
for i : 1..length(text)
color(red)
locate(5,i)
put text(i)
delay(100)
color(blue)
locate(5,i)
put text(i)
end for
end TextDelay
var text:string
get text:*
TextDelay(text)
This works the same way as before, but at first the character is printed in red, then it turns blue as the next character is printed. If you understand simple TextDelay, you should understand how this one works too.
Note: This procedure uses locate to output this text. In 'locate(5,i)' 5 stands for the row where text will be outputed and should be changed to achive desired results. You should not change 'i' since its the counter for the characters being displayed.
Posted: Sun Sep 01, 2002 8:46 pm Post subject: 3D text
Here's something new for you guys -- text in 3D!
Here's the code, take a look
code:
var size:int
var text:string
put "enter text"
get text:*
put "enter size"
get size
var fontID : array 1 .. size of int
for i:size div 2 .. size
fontID(i):=Font.New("Arial:"+intstr(i))
end for
procedure Text3D(text:string)
for t:1..length(text)
for i:size div 2 .. size
Font.Draw(text(t), t*size, 100, fontID(i),20+ floor(i/size*10))
end for
end for
end Text3D
Text3D(text)
Now a bit about how this thing works... variable size is the final size of the text that will be outputed. text is the variable for the... TEXT to be outputed. fontID is just like before is used as a font ID. Though this time its an array since we need many different fonts. Each font is of a different size from small to large. Puting those fonts on top of each other will make text look 3D, here's how:
the main body runs 2 forloops. "for t" runs to count each character in the text to be outputed. "for i" puts fonts from half the size to full size on top of each other.
t*size gives us a value of character position times the final size of the font. that gives a good estimate of spacing between letters. You could adjust that number to finetune spacing for specific fonts.
The color is the tricky part. The idea behind the raycasting is to go from darker to lighter color depending on the distance. this piece of code "20+ floor(i/size*10)" will evenly destribute numbers from 20 to 30 over whatever size you chouse. Numbers 20 to 30 corespond with the gridient from black to white in turing and is the easiest one to use to make it look 3D.
Since the fontID array is decleared based on the size of text desired and is outside of procedure, this effect is generally one time use. If for some crazy reason you would need to use this as often as 'put' command, I'm sure you can rearange the source code to suit your desire.
Posted: Mon Sep 02, 2002 8:05 pm Post subject: Arched Text
This one took me a while... you better like it, or I'm not posting any more
here's the code to make your text in a form of an arch:
NOTE: This code will only work under winoot 4.0.1 or higher because it uses a new "Pic.Rotate" feature not available in previous versions.
code:
var text:string
var fontID:int := Font.New("Arial:14")
put "enter a word"
get text:*
if length(text) rem 2 = 1
then
text:= text +" "
end if
var letter : array 1.. length(text) of int
var angle : array 1.. length(text) of int
var x : array 1..length(text) of int
var y : array 1..length(text) of int
for i:1..length(text) div 2
angle(i):= round(90/length(text)*(length(text)-i))
put angle(i)
end for
for i:1..length(text) div 2
y(i):=round ( (length(text)div 2)*30*cosd(angle(i)) )
x(i):=round ( (length(text)div 2)*60 - (length(text)div 2)*60*sind(angle(i)) )
end for
cls
for i:1..length(text)
Font.Draw(text(i), 15, 15, fontID, black)
letter(i) := Pic.New (0,0,30,30)
cls
end for
letter(i+length(text) div 2):= Pic.Rotate(letter(i+length(text) div 2),360-angle((length(text)div 2)-i+1), 15,15)
Pic.Draw(letter(i+length(text) div 2),x(length(text)div 2)*2-x((length(text)div 2)-i+1),y(length(text) div 2)-y(i)+30,picMerge)
end for
I really don't feel like explaining it right now... I got really frustrated couple of times today while making this.
Basically what it does is that it takes each letter drawn using Font.Draw and saves it as a picture. Then its whole bunch of trigionometry to calculate angles and position of each character to arrangle them in an arch formation.
Calculations were done for the first half and then flipped to make values for second... I run into some problems and this seemed a better way out... might not be the best solution though.
Also, that little IF statment at the beggining of the program will add an extra character if you got an odd number of characters because otherwise last one will disappear.
Also you can change the relative height and width of the arch by messing with declaration of X and Y
in Y, *30* is a relative height of the arch...you can change that... In X, *60 - is the center of the arch, you can move the text left and right by changing this number. The *60* part is the relative width of the arch, you can change this to make the arch wider or thiner.
This effect might be a good use for generating custom arched signs for things like park entrances or something... Who knows what kind of stuff you guys are making out there, I'm just giving you source code to use.
Posted: Mon Oct 07, 2002 9:56 am Post subject: (No subject)
i liked the text delay with colour but it isn't that impressive since you're still stuck the the stupid turing run window font. think you could come up with a way to use that type of proc with Font.Draw? that would be impressive. don't worry about the text getting cut off i'd just like to see it done even with a few letters.
JayLo
Posted: Thu Mar 20, 2003 7:59 pm Post subject: (No subject)
yes tony. it would be impressive.
Sponsor Sponsor
JayLo
Posted: Thu Mar 20, 2003 8:17 pm Post subject: Font.Draw in TextDelay
here it is. not as hard as I thought.
Text Delay involving Font.Draw!
code:
var size : int
var colorText : int
var text : string
put "enter text"
get text : *
put "enter size"
get size
put "enter colour"
get colorText
var fontID : int
var text3DLetter : array 1 .. length (text) of string
fontID := Font.New ("Verdana:" + intstr (size))
procedure text3DDelay (text : string)
for i : 1 .. length (text)
text3DLetter (i) := text (i)
end for
for t : 1 .. length (text)
Font.Draw (text3DLetter (t), t * size, maxy div 2, fontID, colorText)
delay (50)
end for
end text3DDelay
text3DDelay (text)
MOD EDIT: gave you some bits for this, good work. -Dan
Asok
Posted: Thu Mar 20, 2003 9:18 pm Post subject: (No subject)
Jay Lo, there are some spacing issues with your code you should address.
Tony
Posted: Thu Mar 20, 2003 9:55 pm Post subject: (No subject)
well spacing with font.draw would be my bad... I assumed that the size of a letter in pixels would equal to its size. Which is almost accurate. Atleast it would be with a fixed width font.
Posted: Thu Mar 20, 2003 10:19 pm Post subject: (No subject)
jus tuse Font.WIdth
Catalyst
Posted: Thu Mar 20, 2003 10:21 pm Post subject: (No subject)
here i fixed the spacing issue in ur code
code:
var size : int
var colorText : int
var text : string
put "enter text"
get text : *
put "enter size"
get size
put "enter colour"
get colorText
var buff : string := ""
var fontID : int
var text3DLetter : array 1 .. length (text) of string
fontID := Font.New ("Verdana:" + intstr (size))
procedure text3DDelay (text : string)
for i : 1 .. length (text)
text3DLetter (i) := text (i)
end for
for t : 1 .. length (text)
Font.Draw (text3DLetter (t), 50 + Font.Width (buff, fontID), maxy div 2, fontID, colorText)
delay (50)
buff += text3DLetter (t)
end for
end text3DDelay
text3DDelay (text)
Mod Edit: gave some bits for the improved code - Tony
Asok
Posted: Fri Mar 21, 2003 12:43 am Post subject: (No subject)
Excellent job Catalyst!
JayLo
Posted: Fri Mar 21, 2003 6:23 pm Post subject: lol