TGC Codebase Backup



2D Text Modifications to screen by fubarpk

11th Apr 2018 6:56
Summary

Creates a graphical effect with text by subtracting a value from one ascii value to another



Description

Creates a graphical effect with text by subtracting a value from one ascii value to another



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    // Project: TextFun
// Created: 2016-12-29

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TextFun" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )

Words as string = "HELLO WORLD is a great place to start programming it teaches people the very basics and is used as a common starting program by many people all over the world. Hello world has been the starter program for most programmers for many years. Its not the best program in the world laughs but it helps people get the drive to start learning"
i=1
i=CreateText(Words)
SetTextSize(i,Random(50,60))
SetTextColor(i,255,255,255,255)
SetTextPosition(i,10,10)
SetTextMaxWidth( i,1020 )
sync()
sleep(500)
global dontDo as integer
dontDo=0

start_time = GetMilliseconds()

do

	current_time = GetMilliseconds()

	if current_time - start_time > 100

		start_time = current_time

		if dontDo=0
			Words=subtractAscii(Words)
			SetTextString(i,Words)
			//keep subtracting the alpha value until black
			alpha=GetTextColorAlpha(i)
			if alpha>5 then SetTextColorAlpha(i,alpha-5)
		endif
	endif
    Sync()
loop

function subtractAscii (word as string)

	//Each letter or a string passed is replaced with the character 1 less than previous
	newWord as String
	newWord=""
	length=len(word)
	empty=0

	for i = 1 to length
		a$=Mid(word,i,1)
		a=asc(a$)
		if a$<>chr(32)
			a=a-1
		else
			empty=empty+1
		endif
		if empty=length then dontDo=1
		newWord=newWord+chr(a)
	next i

endfunction  newWord