////////////////////////////////////////////////////////////////////// // // // 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 to your code and use // // like this: // // // ////////////////////////////////////////////////////////////////////// /** * QLOAD_FONT(string fileName, int fixed) * * string fileName .fpg file containing the font * int fixed 0 -> variable width font 1 -> fixed width font * * * QDELETE_TEXT(int id_value) * * int id_value ID value of the text to delete * * * QMOVE_TEXT(int id_value,int x,int y,int center) * * int id_value ID of the text to move * int x horizontal coordinate to move the text to * int y vertical coordinate to move the text to * * * QWRITE(int qfont,int x,int y,int center,string qvar) * * int qfont font number as returned by [qload_font] * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * string qvar text to write * * * QWRITE_INT(int qfont,int x,int y,int center,int pointer qvar) * * int qfont Font to write * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * int pointer qvar integer to write * * Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text] * * NOT WORKING DUE TO FENIX ERROR => Mmnemonico no implementado 0x445(opcode taking care of negative floats not implemented in CVS before 12-12-04) * QWRITE_FLOAT(int qfont,int x,int y,int center,float pointer qvar) * * int qfont Font to write * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * float pointer qvar float to write * * Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text] ////////////////////////////////////////////////////////////////////// // Notes: // // ------ // // *The routines need NOT to be called in a loop to stay on screen.// // Usage is exactly the same as with the regular write/write_int/ // // write_float functionality. // // *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. // // *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! :-) // // // // Additional Notes: // // ----------------- // // Well, I changed pretty much, so usage is now same as you would // // normally use write and it's fella's when it comes to parameters.// // Another note, when loading there is new a parameter 'fixed' // // indicating whether or not you want the font to be treated as // // fixed width. When using variable width mind that you include an // // empty graphic for space, not doing this results in all words // // glued together. Also, in regards to qwrite_float, this still // // doesn't work because of a Fenix error. An opcode handling // // negative float values was not implemented until 12 december of // // last year, which means that only the latest Fenix release can // // be used for floats. For that reason I have not included an // // example float, it's pretty obvious how it works and this should // // keep the prg usable for everyone who still works with old // // versions like myself :). That's about it I think. And of course:// // Good work Quiest! // // // // Moogle // // // ////////////////////////////////////////////////////////////////////*/ program qwrite_test; global //Font structure struct font[10] taken; // whether or not this font index is taken fpg; // fpg in which the font is stored width; // in case of fixed width height; // maximum height of the font depth; // colourdepth fixed; // force fixed width end //IDs used for the fonts font1; font2; //IDs used for example texts sinText1,sinText2; delTexts[10]; delCursor; //texts to use: text[10] = "BANG","BOOM","YEAH","WOO","DEL","NO?","QUIEST!","GOODNESS","FOOD","
","GP2X"; //examples to demonstrate integer and float int seconds,minutes,hours; float var5=0.99; private i; begin set_mode(320,240,8); //screen init set_fps(30,0); //fps init //Load fonts font1=qload_font("font1.fpg",1); //loading FPG font font2=qload_font("font2.fpg",0); //loading FPG font //examples start============= sinText1 = qwrite(font2,160,60,4, "Quiests 'qwrite' routines"); sinText2 = qwrite(font2,160,80,4, "to realize sprite fonts."); //write the time: qwrite(font2,0,0,0, "Time:"); qwrite_int(font1,100,0,0,&hours); qwrite_int(font1,160,0,0,&minutes); qwrite_int(font1,220,0,0,&seconds); //write delText's for(i=0;i<10;i++) delTexts[i] = qwrite(font2,rand(50,280),rand(100,230),4,text[rand(0,10)]); end //examples end=============== loop //alternate the integer and float values //var5 += 0.01; if(var5 > 1.50) var5 -= 2*var5 ;end //Adjust the time seconds = time() % 60; minutes = time() /60 % 60; hours = time() / 60 / 60 % 24; //Move a few texts angle += 5000; qmove_text(sinText1,160+get_distx(angle+180000,30),60); qmove_text(sinText2,160+get_distx(angle,30),80); //Delete and write one of the 10 texts in delTexts delCursor = ++delCursor % 10; qdelete_text(delTexts[delCursor]); delTexts[delCursor] = qwrite(font2,rand(50,280),rand(100,230),4,text[rand(0,10)]); //Quit if necessary if(key(_esc)) exit("",0); end frame; end end /** * qload_font(string fileName, int fixed) * * string fileName .fpg file containing the font * int fixed 0 -> variable width font 1 -> fixed width font */ process qload_font(string fileName,int fixed) private i,j,currentFont; begin //find available font index while(currentFont < 10 and font[currentFont].taken == 1) ++currentFont; end if(currentFont == 10)return 0;end //set taken so the same index won't be used twice font[currentFont].taken = 1; //if fixed width set that if(fixed == 1) font[currentFont].fixed = 1; end //load font file font[currentFont].fpg = load_fpg(fileName); //keep track of width/height/depth for(i=1;i<127;i++) if(map_exists(font[currentFont].fpg,i)) //eventually fix the colourdepth if(graphic_info(font[currentFont].fpg,i,G_DEPTH) > font[currentFont].depth) font[currentFont].depth = graphic_info(font[currentFont].fpg,i,G_DEPTH); end //the width(for fixed width fonts) if(graphic_info(font[currentFont].fpg,i,G_WIDTH) > font[currentFont].width) font[currentFont].width = graphic_info(font[currentFont].fpg,i,G_WIDTH); end //or the maximum height if(graphic_info(font[currentFont].fpg,i,G_HEIGHT) > font[currentFont].height) font[currentFont].height = graphic_info(font[currentFont].fpg,i,G_HEIGHT); end end end //return the number(index) of the font return currentFont; end /** * qdelete_text(int id_value) * * int id_value ID value of the text to delete */ process qdelete_text(int id_value) begin //if exists, unload map and delete if(exists(id_value)) unload_map(id_value.file,id_value.graph); signal(id_value,S_KILL); return 1; end //if zero, do that for every map if(id_value == 0) while(id_value = get_id(type qwrite)) unload_map(id_value.file,id_value.graph); signal(id_value,S_KILL); end while(id_value = get_id(type qwrite_float)) unload_map(id_value.file,id_value.graph); signal(id_value,S_KILL); end while(id_value = get_id(type qwrite_int)) unload_map(id_value.file,id_value.graph); signal(id_value,S_KILL); end return 1; end//if return 0; end /** * qmove_text(int id_value,int x,int y,int center) * * int id_value ID of the text to move * int x horizontal coordinate to move the text to * int y vertical coordinate to move the text to */ process qmove_text(int id_value,x,y) begin if(exists(id_value)) id_value.x = x; id_value.y = y; end end /** * qwrite(int qfont,int x,int y,int center,string qvar) * * int qfont font number as returned by [qload_font] * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * string qvar text to write */ process qwrite(qfont,x,y,center,string qvar); private int i,j,tempMap,high,wide; int xPixels; begin graph = qgenerate_graph(qfont,center,qvar); loop frame; end end /** * qwrite_int(int qfont,int x,int y,int center,int pointer qvar) * * int qfont Font to write * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * int pointer qvar integer to write * * Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text] */ process qwrite_int(qfont,x,y,center,int pointer qvar) private int qvarValue=0; begin qvarValue = pointer qvar; graph = qgenerate_graph(qfont,center,itoa(pointer qvar)); loop if(pointer qvar != qvarValue) qvarValue = pointer qvar; unload_map(file,graph); graph = qgenerate_graph(qfont,center,itoa(pointer qvar)); end frame; end end; /** NOT WORKING DUE TO FENIX ERROR => Mmnemonico no implementado 0x445(opcode taking care of negative floats not implemented in CVS before 12-12-04) * qwrite_float(int qfont,int x,int y,int center,float pointer qvar) * * int qfont Font to write * int x horizontal coordinate to write the text to * int y vertical coordinate to write the text to * int center centering value, analog to the one in [write] * float pointer qvar float to write * * Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text] */ process qwrite_float(qfont,x,y,center,float pointer qvar) private float qvarValue; begin qvarValue = pointer qvar; graph = qgenerate_graph(qfont,center,itoa(pointer qvar)); loop if(pointer qvar != qvarValue) qvarValue = pointer qvar; unload_map(file,graph); graph = qgenerate_graph(qfont,center,itoa(pointer qvar)); end frame; end end /** INTERNAL FUNCTION -> NOT foolproof. * qgenerate_graph(int qfont,int center,string qvar) * * int qfont font to use * int center centering value, analog to the one in [write] * string qvar text to write * * Returns the position of the generated graphic in FPG 0. */ process qgenerate_graph(qfont,center,string qvar) private i,xPixels,tempMap; wide,high; begin //determine the length in pixels of the text if(font[qfont].fixed) //fixed width, simple multiplication xPixels = len(qvar) * (font[qfont].width + 1); else //not fixed width, add the lengths of all characters for(i=0;i - 62 ^ - 94 ~ - 126 // // ? - 63 _ - 95 // // // ///////////////////////////////////////////////