Page 1 of 2

questions

PostPosted: Sat Jan 22, 2011 7:29 pm
by Fojam
1.) I am not quite sure how to explain this, but i want to be able to make level packs for my games, and have each level pack to have a custom icon.
I want to create an executable file and never have to edit it, just make level packs for it.
I have already layed out 100 possible levels with the path of where I would put the level pack (ex: when i click on level 1, it will open /levels/level1/level1.dat)
I want when I mouse over a level to select it, the icon in the levels folder will popup on the left, without having to include that icon in the original executable. If that level hasn't been added to the levels folder yet, the icon will simply say unavailable.

I know its kind of confusing what im saying but i couldnt think of an easier way to put that

2.) is there a variable or function that detirmines whether a certain file exists? for example:
if filedoesntexist;
{
information.textNumber=file unavailable
}

not exactly like that but you get my point

3.) is it possible to only allow an actor to move along the x coordinate or only move along the y coordinate, even when the mouse is dragging the actor?

Re: questions

PostPosted: Sat Jan 22, 2011 8:10 pm
by Game A Gogo
2)
Code: Select all
if(fopen(FILENAME,"r+b")==NULL)
{
     //action;
}

3) don't use Mouse Button -> Drag.

do this instead, create a variable called MouseB, make it equal 1 on mouse button down and 0 on mouse up. in draw actor do this:
Code: Select all
if(MouseB)x=max(-50,min(xmouse-parent.xscreen,50));

NOTE: Make the slider parent to the Background of the slider, this code is for 0 to 100, so the slider will go from -50 to 50 from it's parent actor, no matter where it is. To get a value from the slide is also easy:
Code: Select all
textNumber=SliderFG.x+50;

Re: questions

PostPosted: Sat Jan 22, 2011 8:13 pm
by Fojam
thank you so much

Re: questions

PostPosted: Sat Jan 22, 2011 8:16 pm
by Game A Gogo
To have custom icons, you'll need to load an external bitmap with a bitmap loading function, heres one I made:
Code: Select all
short int BG_BMP[1024][1024][4],BGImgBPP;
int BGImgW,BGImgH;
void ImpBmp(char*dir)
{
    int BmpHeader[64], i,j;
    FILE*TBMP=fopen(dir, "r+b");
    for(i=0; i<64; i++)
    {
        BmpHeader[i]=fgetc(TBMP);
    }
    if(BmpHeader[0]==66 && BmpHeader[1]==77)//Checks if this really is a bmp!
    {
        BGImgW=BmpHeader[18]+BmpHeader[19]*256;
        BGImgH=BmpHeader[22]+BmpHeader[23]*256;
        BGImgBPP=BmpHeader[28];
        fseek(TBMP, BmpHeader[10], SEEK_SET);
        for(i=BGImgH-1; i>=0; i--)
        {
            for(j=0; j<BGImgW; j++)
            {
                BG_BMP[j][i][0]=fgetc(TBMP);
                BG_BMP[j][i][1]=fgetc(TBMP);
                BG_BMP[j][i][2]=fgetc(TBMP);
                if(BGImgBPP==32){BG_BMP[j][i][3]=fgetc(TBMP);fseek(TBMP, BGImgW%4, SEEK_CUR);}
                else fseek(TBMP, BGImgW%4, SEEK_CUR);
            }
        }
    }
fclose(TBMP);
}

it works for 24-bit and 32-bit bitmaps and can load a file from 1x1 to 1024x1024, any size (402x395 would work)
Just access BGImgW and BGImgH for width and height

Re: questions

PostPosted: Sat Jan 22, 2011 8:21 pm
by Fojam
i replace FILE with the bitmaps path, right? but what do i replace TBMP and what else do i have to replace?

Re: questions

PostPosted: Sat Jan 22, 2011 8:25 pm
by Game A Gogo
Nothing needs to be replaced! unless you want to change the BG_BMP name :P
you'll use the function like this:
Code: Select all
ImpBmp("Image.bmp");
goes in a create actor, if you want a way to display the bitmap here:
Code: Select all
void DrawBmp()
{
    int i,j;
    for(i=0;i<BGImgW;i++)
    {
        for(j=0;j<BGImgH;j++)
        {
            setpen(BG_BMP[i][j][2],BG_BMP[i][j][1],BG_BMP[i][j][0],0,1);
            putpixel(i,j);
        }
    }
}

Re: questions

PostPosted: Sat Jan 22, 2011 8:27 pm
by Fojam
ok that works but when i do the scroll code, it just goes becck to its original position every time i click on it.
the slider i am using is set as y infinite if that is what is affecting it

Re: questions

PostPosted: Sat Jan 22, 2011 8:28 pm
by Game A Gogo
want a simple almost-no cpu costing way to resize the icon?
Code: Select all
void DrawBmp(double Size)
{
    int i,j;
    for(i=0;i<BGImgW;i++)
    {
        for(j=0;j<BGImgH;j++)
        {
            setpen(BG_BMP[i][j][2],BG_BMP[i][j][1],BG_BMP[i][j][0],0,Size);
            putpixel(i*Size,j*Size);
        }
    }
}

Re: questions

PostPosted: Sat Jan 22, 2011 8:29 pm
by Game A Gogo
Fojam wrote:ok that works but when i do the scroll code, it just goes becck to its original position every time i click on it.
the slider i am using is set as y infinite if that is what is affecting it

This is not suppose to happen... are you sure it's parented to it's Background? since it uses it's parent as a point of origination. You can always have a variable name "IntXP" on create actor it would be:
Code: Select all
IntXP=xscreen;
and instead of parent.xscreen you'd use IntXP. This would require no parent

Re: questions

PostPosted: Sat Jan 22, 2011 8:35 pm
by Fojam
its not parent issue. Ive uploaded the file so you can see what I mean

Re: questions

PostPosted: Sat Jan 22, 2011 8:38 pm
by Game A Gogo
oh, should of told me it was that kind of slider, simply add
Code: Select all
IntYP=yscreen;
on mouse button up, my first exemple (with parent) shouldn't work for this

EDIT: Nvm this seem to not work, I'll get back to you when I have something :P

Re: questions

PostPosted: Sat Jan 22, 2011 8:43 pm
by Fojam
ok just PM me then

thanks for everything else

Re: questions

PostPosted: Sat Jan 22, 2011 8:46 pm
by Game A Gogo
why PM? let the others harvest from this :)
ok, remove the create actor event (if you have one), and remove the IntYP variable (if you had it) and create mouseS and put this in draw actor:
Code: Select all
if(MouseB)y+=ymouse-mouseS;
mouseS=ymouse;

on mouse button down add:
Code: Select all
mouseS=ymouse;


I tested it, this should work :)

Re: questions

PostPosted: Sat Jan 22, 2011 8:59 pm
by Fojam
works perfectly thanks!

Re: questions

PostPosted: Sat Jan 22, 2011 9:03 pm
by Game A Gogo
great! :)