Changing the Font in the Console & My First new game.

Just starting out? Need help? Post your questions and find answers here.
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

Demivec wrote:
Vernostonos wrote:I would like to increase the console window and buffer size. I found the API function but have no idea how to implement it, does anyone have a simple example?
The complexity of my program has exceeded the usefulness of what a 80x25 character display can offer.

https://docs.microsoft.com/en-us/window ... windowinfo
From my observations it doesn't seem as if you are using any of the other functions of a console besides display and keyboard input. Perhaps it may be useful to create your own mock console. You would only have to implement functions that you specifically need and doing so would give you the added benefit of using a custom font easily. In addition I think it would allow porting of your game to Linux or MAC OS, if that is desired, a little easier.
I see this suggested often regarding projects similar to mine.
Creating a 2D application to simulate a console is beyond both the scope of this project and likely my abilities at this time, despite the obvious benefits it offers.
In effort to keep the file size and requirements as low as possible I want to compile this game as a real console application.

@Mijikai
What makes that code example you posted x64? Its calling in the kernel32.lib which I thought was a subset of 32bit / X86?
It looks like it could do what I need, but want my application to run on older systems so 64bit I must avoid.

I messing around with Infratec's example to see what it can do.

Code: Select all

OpenConsole()
ConsoleTitle ("INFRATEC CONSOLE - WINDOW SIZE EXAMPLE")                                        
EnableGraphicalConsole(1)
ConsoleColor(7, 0)


Import "kernel32.lib"
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    GetConsoleWindow_.i() As "_GetConsoleWindow@0"
    SetCurrentConsoleFontEx_.i(hConsoleOutput.i, bMaximumWindow.i, *lpConsoleCurrentFontEx) As "_SetCurrentConsoleFontEx@12"
  CompilerElse
    GetConsoleWindow_.i() As "GetConsoleWindow"
    SetCurrentConsoleFontEx_.i(hConsoleOutput.i,bMaximumWindow.i,*lpConsoleCurrentFontEx) As "SetCurrentConsoleFontEx"
  CompilerEndIf
EndImport

Repeat
  key$ = Inkey()
  If key$ <> ""
    If key$ = #CR$ ; HIT ENTER
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
      PrintN("text here makes the window bigger it can scroll!")
    Else
      Print(key$)
    EndIf
  Else
    Delay(10)
  EndIf
Until key$ = #ESC$
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Changing the Font in the Console & My First new game.

Post by Mijikai »

The code posted was for x64, to make it run in x86 use infratecs import code.
Just be aware that i have not figured out how to do it reliable - sometimes it doesnt work.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Changing the Font in the Console & My First new game.

Post by infratec »

Code: Select all

EnableExplicit

#Cols = 80
#Rows = 50


Structure CONSOLE_SCREEN_BUFFER_INFOEX ;Align #PB_Structure_AlignC
  cbSize.l
  dwSize.COORD
  dwCursorPosition.COORD
  wAttributes.w
  srWindow.SMALL_RECT
  dwMaximumWindowSize.COORD
  wPopupAttributes.w
  bFullscreenSupported.i
  ColorTable.l[16]
EndStructure


Import "kernel32.lib"
  SetConsoleScreenBufferInfoEx.i(hConsoleOutput.i, *lpConsoleScreenBufferInfoEx) ;As "SetConsoleScreenBufferInfoEx@8"
  GetConsoleScreenBufferInfoEx.i(hConsoleOutput.i, *lpConsoleScreenBufferInfoEx)
  GetConsoleWindow.i()
EndImport


Define.i console_out, x, y, console_window
Define rect.SMALL_RECT
Define ConsoleScreenBufferInfoEx.CONSOLE_SCREEN_BUFFER_INFOEX


;Define CSBI.CONSOLE_SCREEN_BUFFER_INFO

OpenConsole()
EnableGraphicalConsole(#True)

console_window = GetConsoleWindow()
SetWindowLong_(console_window, #GWL_STYLE, GetWindowLong_(console_window, #GWL_STYLE) & ~#WS_MAXIMIZEBOX &~#WS_SIZEBOX)

console_out = GetStdHandle_(#STD_OUTPUT_HANDLE)


ConsoleScreenBufferInfoEx\cbSize = SizeOf(CONSOLE_SCREEN_BUFFER_INFOEX)
If GetConsoleScreenBufferInfoEx(console_out, @ConsoleScreenBufferInfoEx)
  
  Debug "----"
  Debug ConsoleScreenBufferInfoEx\dwSize\x
  Debug ConsoleScreenBufferInfoEx\dwSize\y
  Debug "----"
  
  ConsoleScreenBufferInfoEx\bFullscreenSupported = #False
  
  ConsoleScreenBufferInfoEx\dwSize\x = #Cols
  ConsoleScreenBufferInfoEx\dwSize\y = #Rows
  
  ConsoleScreenBufferInfoEx\dwMaximumWindowSize\x = #Cols
  ConsoleScreenBufferInfoEx\dwMaximumWindowSize\y = #Rows
  
  SetConsoleScreenBufferInfoEx(console_out, @ConsoleScreenBufferInfoEx)
EndIf

rect\left = 0
rect\top = 0
rect\right = #Cols - 1
rect\bottom = #Rows - 1

SetConsoleWindowInfo_(console_out, #True, @rect)

For x = 0 To #Cols - 1
  Print(Str(x % 10))
Next
For y = 1 To #Rows - 1
  ConsoleLocate(0, y)
  Print(Str(y))
Next y


Repeat : Delay(10) : Until Inkey() = #ESC$
Last edited by infratec on Sun Aug 02, 2020 7:38 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Changing the Font in the Console & My First new game.

Post by infratec »

Extended the example above to remove the scrollbars.
Now also maximize and resize is disabled, because else it looses its optic.
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

I'm going to put you both in the credits of my game if I finish it.
Your insight has been vital to my development, I cannot seem to thank you enough! :)
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

Here are some of the latest screens. The first is a mock up of what the game I imagine would look like with EGA styled graphics.
The mock up isn't that great and not very true to EGA but I think if I practice enough it's a style I could emulate. It's no secret I love old DOS games which is the main driving force behind my desire to do this. I want to keep the graphics subdued with high levels of dithering. Which just add to the dark gritty atmosphere of a post apocalyptic themed game. The graphics are still going to be based upon Font/Sprites but if I'm clever enough it will look great.
Image

I've been steadily working on the "scavenging" part of the game. Which is a scaled down text parser with automatically generated descriptions based upon a range of variables.
When something happens you are presented with a choice. Which can end in reward, failure, and extreme cases death. Your characters physical stats will help you avoid the negative effects of certain events. For example if you have high agility, a random event of a floor collapsing from within a building results in you "evading the collapsing hole" as things fall apart. When you are not exploring a building you make your way through the streets on foot (or in a vehicle) and are subject to a possible combat event for every hour that occurs in game. Every choice you make takes time, weather, day and night cycles all being a factor in this simulation.


Here is the hidden screen displaying the current building stats:
Image

I forget to set the variables to #True but normally this location would have possible Food, Tools, Books, and Armed weapons which could be looted. Rooms & Floors are randomly generated based upon the various conditions of the building. Totally devastated buildings are more dangerous to loot and often yield less items. You have to weigh the risks as the player depending on how dire your needs are.
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

Okay so this works fine:
Image

Code: Select all

          Case 6
            ConsoleLocate(0,42)
            Print(" Are you sure you want to leave the city? Y/N: ")
            ConsoleLocate(46,42)
     
            
            ;Goto LEAVING_CITY
            ;UserInput$ = Input()  ; **** ERROR ***** WHY IS THIS CRASHING !?!?!?!?!
            UserInput = ValF(Input())  ; <--- DOESNT CRASH WITH INTEGER!! WHY!!!!
   
            
             If UserInput = 1
              BUILDING_RANDOMIZER_HAS_RAN = #False
             Goto Begin_Scav
             Else
            ConsoleLocate(0,42)
             Print(" Command?                                                              ");BLANK THE USER INPUT AREA / CRUDE BUT IT WORKS.
             Goto SCAVAGING_USERINPUT
             EndIf
But this wont, only running once before crashing.
Image

Code: Select all

          Case 6
            ConsoleLocate(0,42)
            Print(" Are you sure you want to leave the city? Y/N: ")
            ConsoleLocate(46,42)
     
            ;Goto LEAVING_CITY
            UserInput$ = Input()  ; **** ERROR ***** WHY IS THIS CRASHING !?!?!?!?!
            ;UserInput = ValF(Input())  ; <--- DOESNT CRASH WITH INTEGER!! WHY!!!!
   
            
             If UserInput$ = "y"
              BUILDING_RANDOMIZER_HAS_RAN = #False
             Goto Begin_Scav
             Else
             ConsoleLocate(0,42)
             Print(" Command?                                                              ");BLANK THE USER INPUT AREA / CRUDE BUT IT WORKS.
             Goto SCAVAGING_USERINPUT
             EndIf
Can you not call INPUT() with string data from within a case statement? I know a case statement itself can only use Integers. The weird thing is the code works, but only once before it will crash.
I tried breaking it out of the case statement but it still crashes.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Changing the Font in the Console & My First new game.

Post by Marc56us »

Can you not call INPUT() with string data from within a case statement?
You can.

A full example

Code: Select all

OpenConsole()

a = 6

Select a
    Case 0
        End
    Case 6
        ConsoleLocate(0,42)
        Print(" Are you sure you want to leave the city? Y/N: ")
        ConsoleLocate(46,42)
        UserInput$ = Input()
EndSelect

PrintN("User input: " + UserInput$)

Print("<Hit any key>")
Input()
Case and Input are working as expected.
The error is elsewhere :wink:

(With Goto's programming, it's easy to get lost.) :?
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

Thanks!

I do not think the problem is the GOTO, because I call the same GOTO in 3 of the possible cases within the case statement. The others work without issue, it simply returns to the top of the Menu and refreshes the screen. Unless I'm missing something super obvious...

Here is the entire case statement for review:

Code: Select all

 BUILDING_RANDOMIZER_HAS_RAN = #True
        SCAVAGING_USERINPUT:
        UserInput.i = 0
        ConsoleLocate(9,42)
        UserInput = ValF(Input())

        Select UserInput
            
          Case 1
            ClearConsole()
            Goto YES_EXPLORE_THE_BUILDING
            
            
          Case 2
            BUILDING_RANDOMIZER_HAS_RAN = #False        ; Make this FALSE so the randomizer will run again and create new buildings.
            SKIP_PREVIOUS_BUILDING_CONTAINER = #False   ; <--- this doesn't work yet...
            CLEAR_BLD_ITEM_CATEGORY()                   ; Clear Item Category : So that a new building can be set with items.
            NUM_EXPLORED + 1
            ClearConsole()
            
            If DISPLAY_ROOM_NUM = #True
              
            PrintN("")
            PrintN(""+CitySizeMessage+"")
            EndIf
          
            ;PrintN(" There are "+EXPLORABLE_BUILDINGS+" out of the possible "+BUILDINGS_MAX+" buildings to explore.")
            Goto EXPLORING_BUILDINGS_BEGIN; Advance and then re-roll what building you come across.  DISPLAY_CITY
            
          Case 4
            DISPLAY_BUILDING_STATS = #True            ; Make this TRUE so the randomizer will NOT run again. Holding the current values of the building in view.
            BUILDING_RANDOMIZER_HAS_RAN = #True
            Goto EXPLORING_BUILDINGS_BEGIN;EXPLORING_BUILDINGS_ON_ELSE
            
          Case 6
            ConsoleLocate(0,42)
            Print(" Are you sure you want to leave the city? Y/N: ")
            ConsoleLocate(46,42)
     
            
            ;Goto LEAVING_CITY
            ;UserInput$ = Input()  ; **** ERROR ***** WHY IS THIS CRASHING !?!?!?!?!
            UserInput = ValF(Input())  ; <--- DOESNT CRASH WITH INTEGER!! WHY!!!!
   
            
             If UserInput = 1
              BUILDING_RANDOMIZER_HAS_RAN = #False
             Goto Begin_Scav
             Else
            ConsoleLocate(0,42)
             Print(" Command?                                                              ");BLANK THE USER INPUT AREA / CRUDE BUT IT WORKS.
             Goto SCAVAGING_USERINPUT
             EndIf
           

          Case 9
            ClearConsole()
            PrintN(" Restarting...")
            Delay(400)
            BUILDING_RANDOMIZER_HAS_RAN = #False  ; Without this here the BUILDING was not being found during reset. Triggering the OOPS!
            Goto Begin_Scav
            
          Default ; If anything else is selected, redraw everything above with the current values.
            ConsoleLocate(9,42);(9,42)
            Print("                                                                      ");BLANK THE USER INPUT AREA / CRUDE BUT IT WORKS.
            Goto SCAVAGING_USERINPUT;EXPLORING_BUILDINGS_BEGIN ;SCAVAGING_USERINPUT
            
            EndSelect
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Changing the Font in the Console & My First new game.

Post by infratec »

Since I can not see the complete code or test it, it is not possible to tell you the reason.

But select works also with strings:

Code: Select all

OpenConsole()

Repeat
  test$ = Input()
  
  Select test$
    Case "hello"
      PrintN("hello again")
    Case "bye"
      Break
  EndSelect
ForEver
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Changing the Font in the Console & My First new game.

Post by Kiffi »

Vernostonos wrote:I do not think the problem is the GOTO
PB-Help wrote:Syntax: Goto <label>

Description: This command is used to transfer the program directly to the labels position. Be cautious when using this function, as incorrect use could cause a program to crash...

Note: To exit a loop safely, you always must use Break instead of Goto, and never use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)
Hygge
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

@Kiffi

I appreciate the help but unless you can explain where the improper use of the "Goto" is, simply pasting the help file won't solve the issue. I'm fully aware using GOTO is taboo to most. lol!
Whats even stranger is the "ELSE" also crashes after it runs twice. I'll try rewriting some of the code before I paste in 5000+ lines to review.

Edit:
I changed the input string into a global, this fixed the issue but I do not know why. I really don't like ass extra Globals for something so basic... When I tried to put in "Break" it complained about being "too high" in the loop.

Code: Select all

Global Question1.s = #Empty$
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Changing the Font in the Console & My First new game.

Post by Demivec »

With a view to this quote:
PB-Help wrote:Syntax: Goto <label>

Description: This command is used to transfer the program directly to the labels position. Be cautious when using this function, as incorrect use could cause a program to crash...

Note: To exit a loop safely, you always must use Break instead of Goto, and never use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)
and also this quote :
Vernostonos wrote:@Kiffi

I appreciate the help but unless you can explain where the improper use of the "Goto" is, simply pasting the help file won't solve the issue. I'm fully aware using GOTO is taboo to most. lol![/code]
Kiffi wrote:
Vernostonos wrote:I do not think the problem is the GOTO
The improper use of Goto is to "ever use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)". This is illustrated by the following code sample:

Code: Select all

;improper use of Goto inside a Select/EndSelect block:
Before:
Num = Random(10)

Select Num
  Case 1
    ;code
   Inside:
    ;code
  Case 2
   Goto After
  Default 
    ;code
    If num > 6
      Goto Before 
    Else
      Goto Inside
    EndIf
EndSelect 
;code
After:
;code

;///////////////////////////////////////////////////////////////////////////
;proper use of Goto inside a Select/EndSelect block if you don't have the ability to manage the stack correctly 
Num = Random(10)

Select Num
  Case 1
    ;code
  Case 2
  Default 
    ;code
EndSelect 
;code
As you have noticed,, Improper use can cause errors that are hard to debug. The errors don't happen near the source of the problem *improper use of Goto inside a Select/EndSelect block).
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: Changing the Font in the Console & My First new game.

Post by BarryG »

How's this game going? Hope you haven't given up on it - I was looking forward to it.
User avatar
Vernostonos
User
User
Posts: 58
Joined: Thu Jul 02, 2020 9:52 pm

Re: Changing the Font in the Console & My First new game.

Post by Vernostonos »

BarryG wrote: Wed Mar 31, 2021 4:08 am How's this game going? Hope you haven't given up on it - I was looking forward to it.
Oh wow looking back at my humble beginning is a bit embarrassing lol!!!

I haven't Barry! I've actually made quite a few console games since this one. But after setting this project aside for a long time I decided to go back and totally revamp it, putting together all that I have learned since first starting this. It's not only a game but a full simulation of a Ms-dos environment complete with retro computer noises. All of the graphics are text mode but carefully stitched together as sprites.

The game music was made in 4 different styles. Pc speaker (2 square but close enough), Sound Blaster (Scream Tracker), Roland MT32 (with real samples downloaded from a Roland device) and CD audio tracks. So the faux sound setup below isn't just for looks its actually functional which will change your game experience. Looking forward to hearing feedback from you! :)

You can view my full post about the game here:
https://www.purebasic.fr/english/viewtopic.php?t=78845

My previous Console/Terminal Game:
https://www.purebasic.fr/english/viewtopic.php?t=78844

Work in progress Box art:
Image
Computer Boot up:
Image
Sound Setup program:
Image
Image
Overworld Screen (WIP):
Image
Post Reply