Qwrite For Using Sprite Fonts In Fenix


Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
40
Location
Dteuschland ;)
Code:
//////////////////////////////////////////////////////////////////////
//
//  Routines to realize the use of sprite fonts
//                                    by Quiest
// 
// 
//  Usage:
//  ------
//  Make your own fonts and store them in a seperate FPG.
//  Look below for a list of what number every symbol,letter,
//  etc., should have in the font FPG.
// 
//  Then just copy&paste the processes qwrite, qwrite_int,
//  qwrite_float, qwrite_graph to your code and use like this: 
// 
//  qwrite(font,int x, int y, int qdist, string qvar);
//   -font        == the ID for the font fpg
//   -int x       == x coord of the first letter
//   -int y       == y coord of the first letter
//   -int qdist   == distance between the sprites 
//   -string qvar == the string you want to be displayed on screen
// 
//  qwrite_int(font,int x, int y, int qdist, int qvar);
//   -font        == the ID for the font fpg
//   -int x       == x coord of the first letter 
//   -int y       == y coord of the first letter
//   -int qdist   == distance between the sprites
//   -int qvar == the integer you want to be displayed on screen
// 
//  qwrite_float(font,int x, int y, int qdist, float qvar);
//   -font        == the ID for the font fpg
//   -int x       == x coord of the first letter
//   -int y       == y coord of the first letter 
//   -int qdist   == distance between the sprites
//   -float qvar == the float you want to be displayed on screen
//
//  Notes:
//  ------
//  *The routines need to be called in a loop to stay on screen.
//  *I used racemaniacs standart fpg, which is included in the
//   zip file, for the included fonts
//   Note that the font fpgs need to have the same palette as
//   the fpgs used for your game.
//  *What is still missing is the ability for the routines to
//   get the proper distance between the sprites by themselves
//   and to align them to the center or the right of the x value
//   you give to the processes.
//  *Do whatever you want with this prg.
//   If you can optimize it or add more functions to it, do so! 
//   But please let me know! :-)

process qwrite(qfont,x,y,int qdist,string qvar);
 private
   int qcounter=0;
   string qdisplay;
 begin
   while(qcounter<len(qvar))
     qwrite_graph(qfont,x+(qdist*qcounter),y,asc(substr(qvar,qcounter,1)));
     qcounter++;
    end;
  end;
  
process qwrite_int(qfont,x,y,int qdist,int qvar);
 private
   int qcounter=0;
   string qdisplay;
 begin   
   while(qcounter<len(itoa(qvar)))
     qwrite_graph(qfont,x+(qdist*qcounter),y,asc(substr(itoa(qvar),qcounter,1)));
     qcounter++;
    end;
  end;

process qwrite_float(qfont,x,y,int qdist,float qvar);
 private
   int qcounter=0;
   string qdisplay;
 begin   
   while(qcounter<len(ftoa(qvar)))
     qwrite_graph(qfont,x+(qdist*qcounter),y,asc(substr(ftoa(qvar),qcounter,1)));
     qcounter++;
    end;
  end;
    
process qwrite_graph(file,x,y,graph);
 begin z=text_z; frame; end;

3.jpg


Here is a zip which includes a compilable source, two example fonts, racemaniacs standard palette fpg and
a ascii table at the end of the source.

I hope that someone can make use of this :D
It also needs only minor modification to enable easy vertical text.
Not that shit with the maps who fucked up the lates version of the minigame project...

If someone can improve/optimize this code or add functions, please post your results here. :D

I also plan to release a font pack with around 20 to 30 different fonts to use
in the near future.
And here you can find a lot of free fonts you can use for your games.
 
WOW!

Thanks, this will be of great help.

EDIT: Already included/used in my game. Works like a charm! Thanks :)
 
Right, had today off so I fixed some stuff. It turned out to kind of uh, change everything so here is a version of Qwrite with all functions compatible with the regular write functions, blitting to map which drastically reduces CPU intensity
and fixed width/variable width modes. Not sure if I should post the whole thing here, since the linecount went up over 500, so I'll post a link.

Syntax highlighted online version:
HERE

.prg
HERE

Only known error is the Fenix error existing in all versions but the last one prohibiting float variables being assigned negative values. So only use that in the newest version. Same bug occurred in the original too though, so not much changes :).
 
Great Moogle, thanks alot!

I know my version was very plain, and very slow on the gp32 for much text,
I will try out your version tomorrow and look at it to see how you realize everything.
 
Back
Top