Page 3 of 4

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 5:57 am
by lcl
SuperSonic wrote:So anyways, if James doesn't mind me asking, what's the hardest funtion you've ever had to make? :)

Well, I'm not sure which code was the hardest to make, but here's one.. :D

A function which loads bitmap file and divides it into frames by the value the user has given.
Currently only left to right pictures can be used with this, it's still under work.
Code: Select all
const int B = 0, G = 1, R = 2;
unsigned char TRANSPARENT[3]; //Array for values of transparent color
unsigned char IMG[6][200][200][3]; //Array for animations frames
int iW, iH, lim;

int readBMP(char * filePath, int images)
{
    int header[64], i, j, k, curImg = 0, value;
    FILE * bmp = fopen(filePath, "r+b");
 
    value = (fgetc(bmp) == 'B');
 
    if (value) //Check if the file exist
    {
    fseek(bmp, 0, SEEK_SET);
    for (i = 0; i < 64; i ++) //Get header info
    {
        header[i] = fgetc(bmp);
    }
 
    iW = header[18] + header[19] * 256; //Get width
    iH = header[22] + header[23] * 256; //Get height
    lim = iW/images; //Set lim equal to width / frames


   fseek(bmp, header[10], SEEK_SET); //Move pointer to the start of the actual image data
 
    for(i = iH - 1; i >= 0; i --) //Loop for y
    {
        curImg = 0;
        for(j = 0; j < iW; j ++) //Loop for x
        {
            k ++;
            IMG[curImg][i][k * (k < lim)][B] = fgetc(bmp); //Get b of current pixel
            IMG[curImg][i][k * (k < lim)][G] = fgetc(bmp); //Get g of current pixel
            IMG[curImg][i][k * (k < lim)][R] = fgetc(bmp); //Get r of current pixel
            if (i == 0 && j == 0) //If we are in the top left corner of the image,
                                  //get the transparent color
            {
                TRANSPARENT[R] = IMG[curImg][i][k * (k < lim)][R]; //Set transparent r
                TRANSPARENT[G] = IMG[curImg][i][k * (k < lim)][G]; //Set transparent g
                TRANSPARENT[B] = IMG[curImg][i][k * (k < lim)][B]; //Set transparent b
            }
            if (k == lim){curImg++; k = 0;}
        }
    }
    }
 
    fclose(bmp); //Close the bitmap file
 
    return value;
}

And a function for drawing the frames for making an animation:
Code: Select all
void drawImg(int num, float size)
{
    int i, j;
    unsigned char RR, GG, BB, tR = TRANSPARENT[R], tG = TRANSPARENT[G], tB = TRANSPARENT[B];
 
    for (i = 0; i < iH; i ++)
    {
        for (j = 0; j < lim; j ++)
        {
            RR = IMG[num][i][j][R]; //Copy current pixels r to RR
            GG = IMG[num][i][j][G]; //Copy current pixels g to GG
            BB = IMG[num][i][j][B]; //Copy current pixels b to BB
            if (RR != tR || GG != tG || BB != tB) //If some of the colours doesn't match with
                                                  //the transparent, draw the pixel
            {
                setpen(RR, GG, BB, 0, size);
                putpixel(j*size, i*size);
            }
        }
    }
}

Usage:
(time is global integer variable)
Code: Select all
readBMP("myBMPFile.bmp", 6); //get the animation with 6 horizontal frames
time ++;
if (time >= 2)
{
    img ++;
    if (img == 6){img = 0;}
    erase(0, 0, 0, 1);
    drawImg(img, 1); //draw the current frame. as time variable changes, so changes the img and the frame to be drawn. and so we achieve an effect of animation :D
    time = 0;
}


When I get this function ready, I will publish it here on forums with explanation of using it.
When this is ready, it will be possible to even make games have custom characters that everyone can make and then load them to the game.
It just requires the player actor to be canvas, but that won't be a problem, because canvas willl collide only with the parts of it where something is drawn.
One just has to remember to use erase();

:D

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 12:47 pm
by Game A Gogo
Most complicated function I made was an AI system that would fly through space while avoiding getting hit by asteroids. Very CPU intensive though and it's not even completed D:
Code: Select all
const NORMAL=0;
const APPROACH=1;
const ATTACK=2;
const ARREST=3;
const TERMINATE=4;
const ROAMING=5;
const CAPTURE=6;
int GotoAIModule(char* Target,int ClI, int Cond)
{
    //Goto AI Module V1
    //Makes a space craft fly towards a target under certain conditions.
    Actor*Tactor=NULL;
    Actor*T2actor=NULL;
    Actor*Clactor=NULL;
    double tnum,SD=16*directional_velocity+128;
    int i;
    //Big rocks
    if(ClI==-1)Tactor=getclone(Target);
    else Tactor=getclone2(Target,ClI);
    for(i=0;i<128;i++)
    {
        Clactor=getclone2("Aste_B",i);
        if(Clactor->Dead&&distance(x+32,y+32,Clactor->x,Clactor->y)<SD){T2actor=Clactor;SD=distance(x+32,y+32,Clactor->x,Clactor->y);}
    }
    //Med rocks
    for(i=0;i<512;i++)
    {
        Clactor=getclone2("Aste_M",i);
        if(Clactor->Dead&&distance(x+32,y+32,Clactor->x,Clactor->y)<SD){T2actor=Clactor;SD=distance(x+32,y+32,Clactor->x,Clactor->y);}
    }
    //Small rocks
    for(i=0;i<2024;i++)
    {
        Clactor=getclone2("Aste_S",i);
        if(Clactor->Dead&&distance(x+32,y+32,Clactor->x,Clactor->y)<SD){T2actor=Clactor;SD=distance(x+32,y+32,Clactor->x,Clactor->y);}
    }
    if(SD<16*directional_velocity+128)
    {
        tnum=getangle(angle,direction(x,y,T2actor->x,T2actor->y));
        if(abs(tnum)<45&&getangle(SC_Stat[ShipID][0]+90,direction(x,y,T2actor->x,T2actor->y))<45)
        {
            if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
            if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;ðÐ
        }
        if(directional_velocity>5)SC_Con[ShipID][3]=1;
        else SC_Con[ShipID][2]=1;
        return 0;
    }
    else
    {
    if(Tactor)
    {
        if(Cond==NORMAL||Cond==ATTACK)
        {
            if(strcmp(Tactor->name,"SPR_SpaceCraft")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft1")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft2")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft3")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft4")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft5")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft6")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft7")==0)
            {
                if(distance(x,y,Tactor->x,Tactor->y)>130)
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,direction(x,y,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
                    if(distance(x,y,Tactor->x,Tactor->y)>400)
                    {
                        if(directional_velocity<25){SC_Con[ShipID][2]=1;SC_Con[ShipID][6]=1;}
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x,y,Tactor->x,Tactor->y)>200)
                    {
                        if(directional_velocity<17)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x,y,Tactor->x,Tactor->y)>150)
                    {
                        if(directional_velocity<7)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else
                    {
                        if(directional_velocity<4)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    if(directional_velocity>1&&abs(getangle(angle,direction(x,y,Tactor->x,Tactor->y)))>=45)SC_Con[ShipID][3]=1;
                }
                else
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,225+direction(x,y,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;ðÐ
                    if(directional_velocity>5)SC_Con[ShipID][3]=1;
                    else SC_Con[ShipID][2]=1;
                }
            }
            else
            {
                if(distance(x+32,y+32,Tactor->x,Tactor->y)>130)
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,direction(x+32,y+32,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
                    if(distance(x+32,y+32,Tactor->x,Tactor->y)>400)
                    {
                        if(directional_velocity<25){SC_Con[ShipID][2]=1;SC_Con[ShipID][6]=1;}
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>205)
                    {
                        if(directional_velocity<17)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>150)
                    {
                        if(directional_velocity<7)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else
                    {
                        if(directional_velocity<4)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    if(directional_velocity>1&&abs(getangle(angle,direction(x+32,y+32,Tactor->x,Tactor->y)))>=45)SC_Con[ShipID][3]=1;
                }
                else
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,225+direction(x+32,y+32,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;ðÐ
                    if(directional_velocity>5)SC_Con[ShipID][3]=1;
                    else SC_Con[ShipID][2]=1;
                }
            }
        }
        else if(Cond==APPROACH)
        {
            if(strcmp(Tactor->name,"SPR_SpaceCraft")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft1")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft2")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft3")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft4")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft5")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft6")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft7")==0)
            {
                if(distance(x,y,Tactor->x,Tactor->y)>130)
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,direction(x,y,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
                    if(distance(x,y,Tactor->x,Tactor->y)>400)
                    {
                        if(directional_velocity<25){SC_Con[ShipID][2]=1;SC_Con[ShipID][6]=1;}
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x,y,Tactor->x,Tactor->y)>200)
                    {
                        if(directional_velocity<17)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x,y,Tactor->x,Tactor->y)>150)
                    {
                        if(directional_velocity<5)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else
                    {
                        if(directional_velocity<4)SC_Con[ShipID][3]=1;
                    }
                    if(directional_velocity>1&&abs(getangle(angle,direction(x,y,Tactor->x,Tactor->y)))>=45)SC_Con[ShipID][3]=1;
                }
                else SC_Con[ShipID][3]=1;
            }
            else
            {
                if(distance(x+32,y+32,Tactor->x,Tactor->y)>130)
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,direction(x+32,y+32,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
                    if(distance(x+32,y+32,Tactor->x,Tactor->y)>400)
                    {
                        if(directional_velocity<25){SC_Con[ShipID][2]=1;SC_Con[ShipID][6]=1;}
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>200)
                    {
                        if(directional_velocity<17)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>150)
                    {
                        if(directional_velocity<5)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else
                    {
                        if(directional_velocity<4)SC_Con[ShipID][3]=1;
                    }
                    if(directional_velocity>1&&abs(getangle(angle,direction(x+32,y+32,Tactor->x,Tactor->y)))>=45)SC_Con[ShipID][3]=1;
                }
                else SC_Con[ShipID][3]=1;
            }
        }
        if(Cond==ATTACK)
        {
            if(strcmp(Tactor->name,"SPR_SpaceCraft")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft1")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft2")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft3")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft4")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft5")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft6")==0||
               strcmp(Tactor->name,"SPR_SpaceCraft7")==0)
            {
                if(abs(getangle(SC_Stat[ShipID][0]+90,direction(x,y,Tactor->x,Tactor->y)))<=45&&distance(x,y,Tactor->x,Tactor->y)<512)SC_Con[ShipID][4]=1;
            }
            else
            {
                if(abs(getangle(SC_Stat[ShipID][0]+90,direction(x+32,y+32,Tactor->x,Tactor->y)))<=45&&distance(x+32,y+32,Tactor->x,Tactor->y)<512)SC_Con[ShipID][4]=1;
            }
        }
        if(Cond==CAPTURE)
        {
            {
                if(distance(x+32,y+32,Tactor->x,Tactor->y)>130)
                {
                    tnum=getangle(SC_Stat[ShipID][0]+90,direction(x+32,y+32,Tactor->x,Tactor->y));
                    if(tnum>(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][0]=1;
                    if(tnum<-(PI*(float)SC_SS[ShipID][7]/42))SC_Con[ShipID][1]=1;
                    if(distance(x+32,y+32,Tactor->x,Tactor->y)>400)
                    {
                        if(directional_velocity<25){SC_Con[ShipID][2]=1;SC_Con[ShipID][6]=1;}
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>200)
                    {
                        if(directional_velocity<17)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else if(distance(x+32,y+32,Tactor->x,Tactor->y)>150)
                    {
                        if(directional_velocity<5)SC_Con[ShipID][2]=1;
                        else SC_Con[ShipID][3]=1;
                    }
                    else
                    {
                        if(directional_velocity<4)SC_Con[ShipID][2]=1;
                    }
                    if(directional_velocity>1&&abs(getangle(angle,direction(x+32,y+32,Tactor->x,Tactor->y)))>=45)SC_Con[ShipID][3]=1;
                }
                else SC_Con[ShipID][2]=1;
            }
        }
 
        return 0;
 
    }
    else return -1;
    }
}

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 1:33 pm
by Hblade
Gag: how do you not get confused? I noticed when I have a lot of code I tend to get very confused on whats going on, depending on how long I've been working. like, for 3 days almost all day each day, I've been working on a game. I havent gotten confused on it but after the 3rd night, I was getting super confused about the most basic things.

How could you write a script that long without confusing the crap out of yourself? XD

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 3:32 pm
by Game A Gogo
I don't really know... but I get such a rush when working with codes like that
All I know is I can easily wrap my head around large concept, and keep them categorized in my head.
Like this code has basically 4 sections to it. The first section is the evade functions that makes the space ship move out of the way of asteroids.
The three other sections are code for the AI controls, depending on what they should do

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 3:43 pm
by Hblade
Ahhhh =)

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 3:55 pm
by lcl
Game A Gogo wrote:All I know is I can easily wrap my head around large concept, and keep them categorized in my head.

That's something I should try to learn!

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 4:34 pm
by Game A Gogo
lcl wrote:
Game A Gogo wrote:All I know is I can easily wrap my head around large concept, and keep them categorized in my head.

That's something I should try to learn!


My problem is I can only apply this in my head for code. I can't put it out on paper or use it for school. D:

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 4:37 pm
by Hblade
same o.o

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 5:36 pm
by hunter84
i realized that game a gogo doesnt have a bunny

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 6:13 pm
by SuperSonic
@Gogo: Wow, you are like a code freak. I can't even comprehend coding something like what you've done :D

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 7:22 pm
by JamesLeonardo32
Im a lil late, but the hardest thing i had to program was getting the ground collision on Sarah right (in AXRIA).

It required 3 actors,
-sarah (with all animations)
-sarahX
-sarahX2


sarahX 1-2 were both thin lines. Both 'sarah' and X2 are parent with X1.
X1 inherits almost all events.
X2 is 2 or 3 pixels down from X1. This is used when colliding with the ground, so it changes the animation for sarah. This is because it wouldn't collide properly with X1.

Confused?

Also i am working on a gameboy style game, 'AXRIA pocket edition'. I started work on it yesterday, using similar but simpler programming to AXRIA. It shouldn't take long X)

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 7:31 pm
by SuperSonic
Ooh, very nice. It looks like fun :P

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 8:28 pm
by JamesLeonardo32
Um, wow.
Coding sure is... How to put it?...Strange? A unique thing? both?

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 10:29 pm
by NightOfHorror
First off the bunnies are my enemy and I must exterminate them and second off uhh, never mind.

Re: Best game you made?

PostPosted: Tue Nov 15, 2011 10:50 pm
by JamesLeonardo32
...kay.