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

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

Post by Vernostonos »

Hello! I just purchased the full version of Pure Basic after hitting my 800 lines of code limit. I'm still very much a novice coder but I've managed to slap together a few simple projects using C++ after 1 month and later on a full prototype of a 3D game using Blitz (another basic language). At this point programing is only a hobby for me but I do dream of one day making a game I could sell. It took me only 3 days to get familiarize myself with Pure Basic and I really love it so far.

I started work on a simple console based game, the game is basically Oregon Trail with ASCII graphics with a post apocalyptic twist. Everything is working well, I also attempted to add some detail using ASCII & Unicode. This is inspired by the first computer games I played on a Atnt 6300 PC. They were very basic games... (pun intended) :lol:

Image
What I want to do is further extend the graphics by including my own fonts, but instead using them to draw sprite characters. The console is limited to using files with the ".fon" extension so after a long search I found a program that can edit/create new fonts in this format.
Image

After much trial and error I have the "highway" sprite using 8x12 pixels correctly loaded into the Windows font folder and showing correctly in the Char map, indexed as 0x54.
Image

Now this is were I'm stuck. Pure Basic still copies in a "T" instead of my new font. Pure Basic and the console have no idea how to load or use my new font. I was wondering if I could invoke such a change by using the Win32 api? But I have no idea how to do this. Of course I could simply edit the "terminal" font but since this is a Windows font used by the OS it could be dangerous make system changes like this. Another solution would be to create the game within a gui window and instead mimic the entire look and feel of console using True type fonts, but it would ruin some of the nostalgic appeal to me, I really want to make a console only game.
Image

I've looked up a few C++ examples I think could solve my issue but again I have no idea how to implement them. Any advice would be appreciated! :)
https://stackoverflow.com/questions/353 ... -font-size
Maybe worth noting that SetCurrentConsoleFontEx requires Vista or later ( _WIN32_WINNT >= 0x0500). Also, the documentation is not clear on how exactly cfi.nFont = 0; works ("nFont = The index of the font in the system's console font table.")

Code: Select all

// THIS IS C++
#include <cwchar>
#include <windows.h>
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0;                   // Width of each character in the font
cfi.dwFontSize.Y = 24;                  // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
std::cout << "Font: Consolas, Size: 24\n";
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 »

Nice project :)

Try this:

Code: Select all

EnableExplicit

Import "kernel32.lib"
  SetCurrentConsoleFontEx.i(hConsoleOutput.i,bMaximumWindow.i,*lpConsoleCurrentFontEx)
EndImport

Structure CONSOLE_FONT_INFO_EX
  cbSize.l
  nFont.l
  dwFontSize.COORD
  FontFamily.l
  FontWeight.l
  FaceName.w[#LF_FACESIZE]
EndStructure

Procedure.i ConsoleFont(*Buffer,BufferSize.i,FontName.s,FontSize.i)
  Protected cfiex.CONSOLE_FONT_INFO_EX
  Protected res.i
  Protected length.i
  Protected font_resource.i
  With cfiex
    length = Len(FontName)
    If length < #LF_FACESIZE
      \cbSize = SizeOf(CONSOLE_FONT_INFO_EX)
      \nFont = #Null
      \dwFontSize\x = #Null
      \dwFontSize\y = FontSize
      \FontFamily = #FF_DONTCARE
      \FontWeight = #FW_DONTCARE
      If *Buffer And BufferSize
        AddFontMemResourceEx_(*Buffer,BufferSize,#Null,@res)
      EndIf
      length << 1
      CopyMemory(@FontName,@\FaceName[0],length)
      ProcedureReturn SetCurrentConsoleFontEx(GetStdHandle_(#STD_OUTPUT_HANDLE),#False,@cfiex)
    EndIf
    ProcedureReturn #False
  EndWith
EndProcedure

Procedure.i Main()
  If OpenConsole()
    Debug ConsoleFont(#Null,#Null,"Lucida Console",10)
    PrintN("Hello World!")
    Input()
    PrintN("Teststring!")
    Input()
    CloseConsole()
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End
Use IncludBinary and try to load your font from memory:

Code: Select all

ConsoleFont(?myfont,?eod - myfont,"myfont",10);<- name shoud be exact!

DataSection
  myfont:
  IncludeBinary "myfont.fon"
  eod:
EndDataSection
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

ups... to slow :cry:

Code: Select all

Structure CONSOLE_FONT_INFOEX
  cbSize.l
  nFont.l
  dwFontSize.COORD
  FontFamily.i
  FontWeight.i
  FaceName.u[#LF_FACESIZE]
EndStructure

Import "kernel32.lib"
  SetCurrentConsoleFontEx.i(hConsoleOutput.i, bMaximumWindow.i, lpConsoleCurrentFontEx.i)
EndImport


Define cfi.CONSOLE_FONT_INFOEX

cfi\cbSize = SizeOf(CONSOLE_FONT_INFOEX)
cfi\nFont = 0
cfi\dwFontSize\X = 0            ; Width of each character in the font
cfi\dwFontSize\Y = 24           ; Height
cfi\FontFamily = #FF_DONTCARE
cfi\FontWeight = #FW_NORMAL

PokeS(@cfi\FaceName[0], "Consolas")
;PokeS(@cfi\FaceName[0], "Arial")

OpenConsole()

SetCurrentConsoleFontEx(GetStdHandle_(#STD_OUTPUT_HANDLE), #False, @cfi)

PrintN("Hello")
PrintN("1234567890")

Delay(5000)
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 »

Wow thank you!!! This helped me out a lot. Your second code example ended up doing exactly what I needed!

That also took care of possible scaling issues in the future, so players can use the option settings to set the font to whatever they want.
I still cannot get my custom .fon file to display but I may be missing something when I create my .fon file.
::EDIT::
Okay, so either I'm doing something wrong or this Sib font editor is bugged. If I edit an existing font I can install it to the font folder, and it will show in the Char map. But when called into my code it doesn't work. If I make a font from scratch I get this message when installing the font "The 'E| €' font is already installed." which is NOT what I named the font file or the header information. I contacted the software vendor to see what the issue is.


When the code selects "Arial" how does it know to use the regular style of the font? From within the Windows font folder, "Arial" there are 15 files. (bold,Italic,Narrow, etc...)
I'm trying to understand what is actually happening. Is this literally just ripping the chunk of data out of the memory? If it fails to find the font I notice it just goes back to the default terminal size and normal font. Which is great!

Code: Select all

Import "kernel32.lib"
  SetCurrentConsoleFontEx.i(hConsoleOutput.i, bMaximumWindow.i, lpConsoleCurrentFontEx.i)
EndImport
Here is where is looks for the data and assigns it a variable?

Code: Select all

PokeS(@cfi\FaceName[0], "Arial")
Here is where it puts it into my program?

Thank you again so much for helping me out. I can't wait to add more polish to my little game project. :)
Last edited by Vernostonos on Sat Jul 04, 2020 8:02 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Hi,

the Import stuff is needed becsue PB by default does not import this function from the windows librarries.
So we do this 'by hand' with all the parameters, so that the compiler later knows what he has to check.

per declaration of the structure CONSOLE_FONT_INFOEX the FaceName is only a reserved memory space with
LF_FACESIZE (32) elements of 2 bytes each.

So we can not assign directly a string to it, the compiler would show you an error cause of different types.
We need to Poke the string into this memory.

I forgot to check the length of the string. The Poked string should not be longer than LF_FACESIZE.
You should use a check before or

Code: Select all

PokeS(@cfi\FaceName[0], #LF_FACESIZE - 1)
The -1 is for the terminating 0 of the string

You can read here:
https://docs.microsoft.com/en-us/window ... ont-infoex

about the structure and how to select bold (FontWeight)
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

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

Post by BarryG »

Your game looks great! Looking forward to the end product. I've always loved turn-based "management" games like this.
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 finally started work on the battle system, here I am trying out a few things.
But I'm perplexed as to why sometimes the screen will draw more than one of the "possible" occupied spaces with the character "B" which represents a bandit.
I rewrote the logic a few times and tried changing when it calls ClearConsole() but it still seems to be doing it at random.

Code: Select all

OpenConsole()
ConsoleTitle ("ROAD WARRIOR - V.001")   ; Title of application.                                            
EnableGraphicalConsole(1)               ; Enable Graphical Consoles - allows for more flexibility.
ConsoleColor(7, 0)                      ; Console Color.
                                        ; COMBAT SCREEN
Global Coordinate.s ="                          "

Global A1.s = "∙"
Global A1_occupied.a = 0

Global B1.s = "∙"
Global B1_occupied.a = 0

Global C1.s = "∙"
Global C1_occupied.a = 0

Global Placement.i = 0

 Restart:
 ClearConsole()
 PrintN (" ┌────────────────────────────────────────────────────────────────────────────┐")
 PrintN (" │ "+Coordinate+" Placement Rolled: "+Placement+"    *** BATTLE SCREEN ***    │")
 PrintN (" └────────────────────────────────────────────────────────────────────────────┘")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙"+A1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+B1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙/███∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙O∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+C1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ───────────────────────────────────────────────────────────────────────────── ")
 PrintN ("  7  8  9       ┌─── COMMANDS ────────────────┐ Name: Max                      ")
 PrintN ("   \ | /        │M  - Move        L - Look    │ Health: 100 %                  ")
 PrintN (" 4 ─ 5 ─ 6      │S  - Shoot       W - Wait    │ Action Points: 12              ")
 PrintN ("   / | \        │T  - Throw       E - End     │                                ")
 PrintN ("  1  2  3       │U  - Use         F - Flee    │                                ")
 PrintN ("                └─────────────────────────────┘                                ")
 PrintN ("                 What do you do?                                               ")
 Delay(1000)
;Delay (300)
;Number_of_enemies = Random(8, 1)
Placement = Random(9, 1)

If Placement = 1 ;And Number_of_enemies => 1
  ClearConsole()
  A1="B"
  A1_occupied = 1
  Coordinate = "Coordinate A1 is occupied."
  
ElseIf Placement = 2 ;2 And Number_of_enemies => 2
  ClearConsole()
  B1="B"
  B1_occupied = 1
  Coordinate = "Coordinate B1 is occupied."
  
ElseIf Placement = 3 ;And Number_of_enemies => 3
  ClearConsole()
  C1="B"
  C1_occupied = 1
  Coordinate = "Coordinate C1 is occupied."
  
Else
  ClearConsole()
  A1="∙"
  A1_occupied = 0
  B1="∙"
  B1_occupied = 0
  C1="∙"
  C1_occupied = 0 
  Coordinate="                          "
EndIf
Goto Restart
 
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Hm...

works here.

Better with:

Code: Select all

 ;ClearConsole()
 ConsoleLocate(0, 0)
For the one after Restart:

And remove all other ClearConsole()
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 went overboard with the ClearConsole() command struggling to figure out why it wouldn't clear the play field, with the occasional string left behind.
I made the changes you suggested and its still happening. lol
Trust me watch it for like 1 minute.

Code: Select all

OpenConsole()
ConsoleTitle ("ROAD WARRIOR - V.001")   ; Title of application.                                            
EnableGraphicalConsole(1)               ; Enable Graphical Consoles - allows for more flexibility.
ConsoleColor(7, 0)                      ; Console Color.
; COMBAT SCREEN *************************************************************************************************************
Global Coordinate.s ="                          "

Global A1.s = "∙"
Global A1_occupied.a = 0

Global B1.s = "∙"
Global B1_occupied.a = 0

Global C1.s = "∙"
Global C1_occupied.a = 0

Global Placement.i = 0

 Restart:
 ;ClearConsole()
 ConsoleLocate(0,0)
 PrintN (" ┌────────────────────────────────────────────────────────────────────────────┐")
 PrintN (" │ "+Coordinate+" Placement Rolled: "+Placement+"    *** BATTLE SCREEN ***    │")
 PrintN (" └────────────────────────────────────────────────────────────────────────────┘")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙"+A1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+B1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙/███∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙O∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+C1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ───────────────────────────────────────────────────────────────────────────── ")
 PrintN ("  7  8  9       ┌─── COMMANDS ────────────────┐ Name: Max                      ")
 PrintN ("   \ | /        │M  - Move        L - Look    │ Health: 100 %                  ")
 PrintN (" 4 ─ 5 ─ 6      │S  - Shoot       W - Wait    │ Action Points: 12              ")
 PrintN ("   / | \        │T  - Throw       E - End     │                                ")
 PrintN ("  1  2  3       │U  - Use         F - Flee    │                                ")
 PrintN ("                └─────────────────────────────┘                                ")
 PrintN ("                 What do you do?                                               ")
 Delay(1000)
;Delay (300)
;Number_of_enemies = Random(8, 1)
Placement = Random(9, 1)

If Placement = 1 ;And Number_of_enemies => 1
  A1="B"
  A1_occupied = 1
  Coordinate = "Coordinate A1 is occupied."
  
ElseIf Placement = 2 ;2 And Number_of_enemies => 2
  B1="B"
  B1_occupied = 1
  Coordinate = "Coordinate B1 is occupied."
  
ElseIf Placement = 3 ;And Number_of_enemies => 3
  C1="B"
  C1_occupied = 1
  Coordinate = "Coordinate C1 is occupied."
  
Else
  A1="∙"
  A1_occupied = 0
  B1="∙"
  B1_occupied = 0
  C1="∙"
  C1_occupied = 0 
  Coordinate="                          "
EndIf
Goto Restart
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 »

If the placement is true and a position was also set in the last cycle the old position of the bandit is not cleared.

To better illustrate the problem change the this part of the code:

Code: Select all

Placement = Random(9, 1)
to this:

Code: Select all

If Placement = 3
 Input()
EndIf
Placement + 1
To fix this clear all old positions before setting new ones.
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 I got it working using your advice, it clears the values at the end. I also realized I needed to put the "if" statements before drawing the rest of the console.

But why is this preferred?

Code: Select all

ConsoleLocate(0,0)
Over this? I thought ClearConsole() forces a refresh of the screen?

Code: Select all

ClearConsole()
I do not understand why you want me to call an Input() here? Other than this has the effect of pressing "any key" to advance the code.
I read that Pure Basic can not use a string Boolean, thus it treats a 0 as false and a 1 as true. So why would I want to add +1 to my variable called placement?

Code: Select all

If Placement = 3
Input()
EndIf
Placement + 1

This 4th version works without the issue from earlier. Thanks!

Code: Select all

OpenConsole()
ConsoleTitle ("ROAD WARRIOR - V.001")   ; Title of application.                                            
EnableGraphicalConsole(1)               ; Enable Graphical Consoles.
ConsoleColor(7, 0)                      ; Console Color.
; COMBAT SCREEN *********************************************************************************
Global Coordinate.s ="                          "
Global A1.s = "∙"
Global A1_occupied.a = 0
Global B1.s = "∙"
Global B1_occupied.a = 0
Global C1.s = "∙"
Global C1_occupied.a = 0
Global D1.s = "∙"
Global D1_occupied.a = 0
Global E1.s = "∙"
Global E1_occupied.a = 0
Global F1.s = "∙"
Global F1_occupied.a = 0
Global G1.s = "∙"
Global G1_occupied.a = 0
Global H1.s = "∙"
Global H1_occupied.a = 0
Global I1.s = "∙"
Global I1_occupied.a = 0
Global Placement.i = 0

Restart:
;ClearConsole()
ConsoleLocate(0,0)
Placement = Random(15, 1)

If Placement = 1
  A1="B"
  A1_occupied = 1
  Coordinate = "Coordinate A1 is occupied."
  
  ElseIf Placement = 2
  B1="B"
  B1_occupied = 1
  Coordinate = "Coordinate B1 is occupied."
  
  ElseIf Placement = 3
  C1="B"
  C1_occupied = 1
  Coordinate = "Coordinate C1 is occupied."
  
  ElseIf Placement = 4
  D1="B"
  D1_occupied = 1
  Coordinate = "Coordinate D1 is occupied."
  
  ElseIf Placement = 5
  E1="B"
  E1_occupied = 1
  Coordinate = "Coordinate E1 is occupied."
  
  ElseIf Placement = 6
  F1="B"
  F1_occupied = 1
  Coordinate = "Coordinate F1 is occupied."
  
  ElseIf Placement = 7
  G1="B"
  G1_occupied = 1
  Coordinate = "Coordinate G1 is occupied."
  
  ElseIf Placement = 8
  H1="B"
  H1_occupied = 1
  Coordinate = "Coordinate H1 is occupied."
  
  ElseIf Placement = 9
  I1="B"
  F1_occupied = 1
  Coordinate = "Coordinate I1 is occupied."
  
Else
  Coordinate = "No coordinate is active.  "
EndIf
 PrintN ("")
 PrintN ("                               *** BATTLE SCREEN ***")
 PrintN (" ──────────────────────────────────────────────────────────────────────────────")
 PrintN ("  "+Coordinate+"                                Placement Rolled:"+Placement+" ")
 PrintN (" ──────────────────────────────────────────────────────────────────────────────")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙"+A1+"∙∙∙∙∙∙∙∙∙∙∙∙"+I1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+B1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+E1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙/███∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙O∙∙∙∙0███0∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+C1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+H1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+F1+"∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙"+D1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙"+G1+"∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ")
 PrintN (" ────────────────────────────────────────────────────────────────────────────── ")
 Delay(1000)
 Placement = 0
 A1_occupied = 0
 B1_occupied = 0
 C1_occupied = 0
 A1="∙"
 B1="∙"
 C1="∙"
 D1="∙"
 E1="∙"
 F1="∙"
 G1="∙"
 H1="∙"
 I1="∙"
 Coordinate="                          "
 Goto Restart
; To fix this clear all old positions before setting new ones.
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 »

Vernostonos wrote: But why is this preferred?

Code: Select all

ConsoleLocate(0,0)
Over this? I thought ClearConsole() forces a refresh of the screen?

Code: Select all

ClearConsole()
Since you draw the to the whole screen (buffer) clearing is unnecessary :)
Vernostonos wrote: I do not understand why you want me to call an Input() here? Other than this has the effect of pressing "any key" to advance the code.
I read that Pure Basic can not use a string Boolean, thus it treats a 0 as false and a 1 as true. So why would I want to add +1 to my variable called placement?
This was just to illustrate the problem you had before (to make it easier to see).
The game would get paused and you would see all 3 Bandits at once on the screen.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

If you clear the console, than it is cleared and afterwards filled again.
You see this as flickering.

If you use ConsoleLocate()) and you write the whole area, than you see less flickering.
Because a dot is replaced by a dot and not first by a space and then by a dot.
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 »

Thank you both again for the help. :)


I've been playing around creating fonts and still have had no luck getting them to show up within the console. Both programs Sib Font editor and Raster font editor don't correctly save .fon or .font files or I'm simply not using the program correctly. I ended up deleting my fonts and started over... Strangely in both code examples provided above I cannot get any fonts to load other than what is shown in the examples.

Here are additional fonts shown in my system that do not display in the Windows font folder.
Image

So "Consolas" loads fine in infratec's example code ( a TFF font) but when I try "Terminal" nothing happens, it just reverts to the standard text. When I check the Terminal ( .fon file) font inside the windows font folder, I see that it's actually called "vgaoem" by windows. So then I try that but it also doesn't work. If I try another TFF font like "Arial" its the same story.
Image

In Mijikai's example I have the same problem, the "Lucida Console" loads fine but nothing else will display on my system.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Read this:

https://superuser.com/questions/920440/ ... le-windows

https://www.techrepublic.com/blog/windo ... nd-prompt/


In my registry only "Lucida Console" and "Consolas" and 2 chinese? fonts are listed as TrueTypeFont

But if I open a CMD and look in the properties font settings I see more TrueType fonts and ...
all of them work:

Code: Select all

;PokeS(@cfi\FaceName[0], "Consolas")
;PokeS(@cfi\FaceName[0], "Courier New")
;PokeS(@cfi\FaceName[0], "DejaVu Sans Mono")
;PokeS(@cfi\FaceName[0], "Liberation Mono")
;PokeS(@cfi\FaceName[0], "Lucida Console")
;PokeS(@cfi\FaceName[0], "MS Gothic")
;PokeS(@cfi\FaceName[0], "Noto Mono")
;PokeS(@cfi\FaceName[0], "NSim Sun")

A module for registry stuff:
viewtopic.php?p=512775#p512775
Post Reply