Long time no posts from me here, sorry
Don't have free time (finishing my custom resource pack - write help files right now).
Well, small FREE contrib, or just the idea about game size minimizing (for small advert or other games that distributed over the internet). I think many of you use this, but forget to write about it.
In short - let's assume you have a project with many buttons for UI, you haven't to produce all 3 state images (on, off, over) to simulate a 'click' action on a button. You can process images by function ingame and reduce game size. You can use this technique not for buttons only, I think. And hey, c-scripters, all this stuff works without any plugin while you are learning C or C++!
Code:
bmap pan_map = "pan.tga";
bmap btn_map = "but.tga"; //look, all buttons are the same
bmap btnon_map = "but.tga";
bmap btnover_map = "but.tga";
bmap curs_map = "cursor.tga";
bmap pan_curs_map = "pancursor.tga";
font _font = "font.tga", 16, 23;
text hint = { //text over the panel
font = _font;
layer = 15;
pos_x = 15;
pos_y = 20;
size_y = 100;
offset_y = 0;
strings = 1;
flags = center_x, narrow, transparent, visible;
}
function test_on(btn_num,pnl){ //display button number
str_for_num(hint.string[0], btn_num);
}
panel _pan{ //simple 2 buttons panel
bmap = pan_map;
mouse_map = pan_curs_map;
layer = 10;
button = 40, 15, btnon_map, btn_map, btnover_map, test_on, NULL,NULL;
button = 150, 15, btnon_map, btn_map, btnover_map, test_on, NULL,NULL;
pos_x = 1; pos_y = 1; flags = VISIBLE,OVERLAY, REFRESH;
}
function mouse_startup // switches the mouse on
{
Mouse_Map = curs_map;
Mouse_Mode = 2;
while (1){
Mouse_Pos.X = Pointer.X;
Mouse_Pos.Y = Pointer.Y;
wait(1);
}
}
// This function is for example only,
// I didn't optimize it specially for clearness
// you can write a function to scroll, deform, hilight, etc.
bmap* tmp; //temp bitmap
function SimplifiedEmboss(Bitmap, Amount)
{
var format;
var x; var y; var i;
var p1; var p2; var p3;
var c1[3]; var c2[3]; var c3[3];
var a1; var a2; var a3;
tmp = Bitmap;
format=bmap_lock(tmp,0);
i = 0;
while (i <= Amount){
y = 0;
while(y <= bmap_height(tmp)-2){
x = 0;
while(x <= bmap_width(tmp)-2){
p1 = pixel_for_bmap(tmp, x, y); p2 = pixel_for_bmap(tmp, x, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3 = pixel_for_vec(c3, a3, format);
pixel_to_bmap(tmp, x, y, p3);
//additional passes
p1 = pixel_for_bmap(tmp, x + 1, y); p2 = pixel_for_bmap(tmp, x + 1, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3 = pixel_for_vec(c3,a3,format);
pixel_to_bmap(tmp, x + 1, y, p3);
p1 = pixel_for_bmap(tmp, x + 2, y); p2 = pixel_for_bmap(tmp, x + 2, y + 1);
pixel_to_vec(c1, a1, format, p1); pixel_to_vec(c2, a2, format, p2);
c2.red = c2.red ^ -1;
c2.green = c2.green ^ -1;
c2.blue = c2.blue ^ -1;
vec_add(c1, c2);
c3 = c1 >> 1; a3 = (a1 + a2) / 2;
p3=pixel_for_vec(c3,a3,format);
pixel_to_bmap(tmp, x + 2,y, p3);
x += 1;
}
y += 1;
}
i += 1;
}
bmap_unlock(tmp);
return;
}
function main() //your main function
{
max_loops = 200000; //you really need this, and don't try to process tons of full screen images ;)
SimplifiedEmboss(btnover_map,3); //create over and clicked states for buttons
SimplifiedEmboss(btnon_map,1);
level_load(level_load); //load level
wait(3);
mouse_tgl(); //show the mouse
}
I've used 32 bit tga with alpha channel for the button image.