Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrolling Text
#1
Ok. Here is an "oldie" question.

If I were to create, not that I will mind you, an old text-based adventure game** using N7, is there a way to scroll the text up the screen when the game output goes beyond a "screen full"?

** Interactive Fiction... I think is the going genre for text adventures...

If this is too involved or difficult then it would be best to ignore the request... after letting me know of course... lol

Cheers

J
Logic is the beginning of wisdom.
Reply
#2
Hi Johnno, will you be using a game window or the console for the text output for your adventure game please? I'm confident that this can be done in a game window, but I don't think I will have time before Sunday to look at it.....Happy for others to show an example in the meantime, as I'm sure that my way will not be the most efficient.
Reply
#3
One can keep track of the line njmber and use the is the 'scroll' function combined with 'set caret', probably manage all of it in a custom print-function. If kevin doesn't beat me to it I'll post an example this weekend Smile
Reply
#4
(11-01-2024, 08:43 AM)johnno56 Wrote: Ok. Here is an "oldie" question.

Hi Johnno,

One solution using a table to hold your lines of text:

Code:
visible screen_w = 640,screen_h = 480
'Open a window
set window "Scrolling text",screen_w,screen_h
'enable double buffering
set redraw off
text = []
text_number = 0
number_of_lines = 12
##############################################################################################
#######################################   GAME LOOP  #########################################
##############################################################################################
do

'clear the screen
set color 255,255,255
cls
set color 0,0,0

if keydown(KEY_SPACE,true)
    text[sizeof(text)] = "line " + str(text_number)
    text_number = text_number + 1
endif

if sizeof(text) > 0
   
    set justification left
   
    for t = 0 to sizeof(text) - 1
        if sizeof(text) > number_of_lines
            set caret 20, 10  - (sizeof(text)- number_of_lines) * screen_h / number_of_lines + t * screen_h / number_of_lines
        else
            set caret 20,10 + t * screen_h / number_of_lines
        endif
       
        write text[t]
     
    next
endif

set caret 600,20
set justification right
write "PRESS SPACE BAR TO ADD A LINE OF TEXT"

'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60

until keydown(KEY_ESCAPE)

#########################################################################################
#################################  FUNCTIONS  ###########################################
#########################################################################################

There will of course be more elegant solutions, and I may have misunderstood your question, so I look forward to seeing alternatives....

Please let me know if there are other things needed for this task?

All the best - Kevin.
Reply
#5
Ran the example and worked like a charm... of course, I will have to "give it the once over", to see how you did it... lol

Thank you for the effort. Much appreciated.
Logic is the beginning of wisdom.
Reply
#6
(11-03-2024, 04:09 AM)johnno56 Wrote: Ran the example and worked like a charm... of course, I will have to "give it the once over", to see how you did it... lol

Thank you for the effort. Much appreciated.

Great, glad it's suitable.
You can experiment with the variable "number_of_lines" using anything between 2 to 48 to decrease / increase the number of lines of text on the screen at any one time. For larger values you will need to change these lines though, otherwise the bottom lines will not be visible - this is the correct version:

Code:
for t = 0 to sizeof(text) - 1
        if sizeof(text) > number_of_lines
            set caret 20,   - (sizeof(text)- number_of_lines) * screen_h / number_of_lines + t * screen_h / number_of_lines
        else
            set caret 20, + t * screen_h / number_of_lines
        endif
        write text[t]
next

Quick observation - the code I have provided is very inefficient as it "prints" text unnecessarily above the start of the screen, which will not be visible when looking at the game window. I don't think that this is too important in a text adventure, as the inefficiency will not be noticed. I'm sure the code can be adapted to only print lines that will be visible on the screen, but I didn't want to over-complicate the code for an example.
Reply
#7
Cool... The "number_of_lines" was the first thing I tinkered with... lol I had a crazy thought about the 'efficiency' in relation to text printing beyond the top of the screen... what if the "y" half of set caret was monitored and only display the text if it is greater than zero... or something like that... too crazy? (not sure if I worded that correctly... after all... it's been more than 8 hours since my last coffee... lol)

If I take up a text adventure, and there is no promise or guarantee of that happening, it will involve a LOT of work... I know that there are many "Interactive Fiction" engines out there, which will certainly shorten the creative time immensely, but that will reduce the amount of fun and satisfaction of creating it "by hand"...

Oh. Another use for the "scrolling"... replace the pressing of the space bar with a timer and it could be used to create a "Star Wars" crawl... of course the "shrinking" font will need to be worked on... but still...

Thanks for the code... this could be fun...
Logic is the beginning of wisdom.
Reply
#8
"what if the "y" half of set caret was monitored and only display the text if it is greater than zero... "
That would work Johnno.
I just did a quick test here, and for a table with up to 1000 items (lines to print), there is no difference between printing all lines, or just those that appear on screen (on my pc). However, by the time the table has reached 2000 items, the frame per second figure for printing all lines is 300, compared to 500 when I just print the lines that appear on screen. So, it is really down to how many lines of narrative you would want to store in the table for the text adventure. You may even have the option of removing some lines from the table if they are no longer needed?
Reply
#9
1,000 to 2,000 lines of text is a lot... String space would then begin to be a concern... In the "old days", the text that scrolled off the top of the screen, would never be seen again. The players own memory (or hand drawn map) would have to be used... therefore, if the text is being 'deleted', the only text that needs to be 'stored' is the text that appears on the screen at any given time... Usually that would be 25 lines of text... (depending on the font used)... in theory...
Room "descriptions" can be stored in a file(s) and "read" when needed...

Ever player "Zork"? (I never did get to finish it... lol) Even though it was "text based" it relied on the best graphics engine available... the imagination... I miss the old days...

Ha. The last time I tackled a "Type-in" adventure game was using Basic with line numbers... It would be fun to try something like that with N7... the only problem I have with conversions is that "goto" command that can send you out of a loop to who knows where... lol

Hmm... Food for thought...
Logic is the beginning of wisdom.
Reply
#10
This is my version of scrolling text , very simple ....

Code:
set window "scrolling text",1000,500,false
set redraw off

'color definition
visible white = [255,255,255]
visible black = [0,0,0]

Closing_Credits()

'scrolling text
function Closing_Credits()
    words = []
    words[1] = "CLOSING CREDITS"
    words[2] = ""   
    words[3] = ""
    words[4] = "A special thanks to Marcus, the creator of Naalaa" 
    words[5] = "for his dedication, support and encouragement"
    words[6] = "in the making of this tiny game."
    words[7] = ""
    words[8] = "I really appreciate his stepping in"
    words[9] = "to develop the fantastic game engine and its supporting libraries"
    words[10] = "I know he had to put in extra hours"
    words[11] = "to catch up on his own work, so thank you very much."
    words[12] = "Your expertise was vital for this tiny game."
    words[13] = ""
    words[14] = "Heartfelt thanks to all the talented artists"
    words[15] = "who created the amazing game assets"
    words[16] = "I couldn't have made this game without them"
    words[17] = ""
    words[18] = ""
    words[19] = ""
    words[20] = "Game assets"
    words[21] = "Building Pixel by LandEnd Studios https://isaquerr.itch.io/building-pixel"
    words[22] = "Free 3D Fps-Shooter Models | TurboSquid https://images.app.goo.gl/NQtoZhALCWDoYFPp6"
    words[23] = "Stealth Battle background music by Mark, meak363 from Pixabay.com"
    words[24] = "Different kinds of weapons such as trident, hands, crossbow of The Spriting Dark Carnival"
    words[25] = "  https://www.altarofstone.com/forums/viewtopic.php?t=42"   
    words[26] = "Man's Silhouette https://pixabay.com/vectors/man-silhouette-male-people-4329249/"
    words[27] = "Monster https://images.app.goo.gl/6HiZncjYoCaJ7zSr9"

    'text animation of the closing credits
    for i = height(primary)-30 to 30
        set color black; cls; set color white
        set caret width(primary)/2,i
        for j = 1 to 27
            center words[j]
        next
        redraw
        fwait 30
    next
    do; wait 1; until keydown(KEY_RETURN,true)
endfunc


Another simple text game ...
Code:
pln "=============="
pln "  Math Exam   "
pln "=============="

for a = 1 to 100
    number1 = rnd(100)
    number2 = rnd(100)
    result  = number1 + number2
   
    pln number1+" + "+number2+" = "
    answer = rln()
    if answer = result then
        pln "Genius"
    else
        pln "Wrong answer"
    endif
   
    pln
   
    wait 300
next

pln
pln "Press ENTER to exit"
tmp = rln()
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)