Simple Useful Functions Topic!

Game Editor comments and discussion.

Re: Simple Useful Functions Topic!

Postby Hblade » Sat Oct 15, 2011 8:00 pm

Game A Gogo wrote:
Hblade wrote:A Simple recolor function (untested just thought I'd post it xD Might have an error or two but just small ones)
Code: Select all
void Color(, char *AName, int R, int G, int B, double ALPHA) {
    Actor *A=getclone(AName);
    A->r=R;
    A->g=G;
    A->b=B;
    A->transp=ALPHA;
}


Usage:
Code: Select all
Color("Player", 255, 255, 255, .50);


Edit: For some reason this doesn't work with "Event Actor" D: So if your using clones or bullets this wont work xD unless you simply put "Bullet".


Code: Select all
void Color(char *AName, int R, int G, int B, double ALPHA)
{
    if(strcmp(AName,"Event Actor")
    {
        r=R;
        g=G;
        b=B;
        transp=ALPHA;
    }
    else if(strcmp(AName,"Collide Actor")
    {
        collide.r=R;
        collide.g=G;
        collide.b=B;
        collide.transp=ALPHA;
    }
    else if(strcmp(AName,"Parent Actor")
    {
        parent.r=R;
        parent.g=G;
        parent.b=B;
        parent.transp=ALPHA;
    }
    else
    {
        Actor *A=getclone(AName);
        A->r=R;
        A->g=G;
        A->b=B;
        A->transp=ALPHA;
    }
}


Now it works with Event Actor, Collide Actor and Parent Actor as well as a specific one ;)

Genius
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Simple Useful Functions Topic!

Postby Hblade » Wed Oct 26, 2011 6:04 pm

Enable the keyboard and controller all in 1
Code: Select all
        //Generate Definitions
        #define true 1
        #define false 0
        #define Joy1 BUTTON[0]
        #define Joy2 BUTTON[2]
        #define Joy3 BUTTON[3]
        #define Joy4 BUTTON[4]
        #define Joy5 BUTTON[5]
        #define Joy6 BUTTON[6]
        #define Joy7 BUTTON[7]
        #define Joy8 BUTTON[8]
        #define Joy9 BUTTON[9]
        #define xaxis JoyX
        #define yaxis JoyY
       
        //Code Variables
        char *key;
        int BUTTON[10];
        double JOYX, JOYY;

    //Enable Controls
    void EnableControls(int JOY, int KBD) {
        int i;
        JOYX=GetJoystick1Axis(0);
        JOYY=GetJoystick1Axis(1);
        switch(JOY) {
            case 0:
            break; case 1:
            for (i=0;i<9;i++) {
            BUTTON[i]=GetJoystick1Button(i);
                          }
            break; }
        switch(KBD) {
            case 0:
            break; case 1:
            key=GetKeyState();
            break; }
                                          }


Usage:
Code: Select all
EnableControls(true, true);


The first true is the joystick, to disable the joystick simply put false. The second one is they keyboard.





Extra config for easier access to controls:
Code: Select all
        //Create easy name for variables
        #define var int
 
        //Offset Variable for joystick
        var Offset=10000;
 
        //Define Controls for keyboard
        #define KeyRight key[KEY_d]
        #define KeyLeft key[KEY_a]
        #define KeyUp key[KEY_w]
        #define KeyDown key[KEY_s]
        #define KeyB1 key[KEY_i]
        #define KeyB2 key[KEY_l]
        #define KeyB3 key[KEY_k]
        #define KeyB4 key[KEY_j]
        #define KeyB5 key[KEY_q]
        #define KeyB6 key[KEY_e]
        #define KeyB7 key[KEY_u]
        #define KeyB8 key[KEY_o]
        #define KeyB9 key[KEY_f]
        #define KeyB10 key[KEY_g]
 
        #define Press_DOWN (KeyDown==1 || yaxis>Offset)
        #define Press_UP (KeyUp==1 || yaxis<-Offset)
        #define Press_LEFT (KeyLeft==1 || yaxis<-Offset)
        #define Press_RIGHT (KeyRight==1 || yaxis<-Offset)
        #define Press_B1 (KeyB1==1 || BUTTON[0]==1)
        #define Press_B2 (KeyB2==1 || BUTTON[1]==1)
        #define Press_B3 (KeyB3==1 || BUTTON[2]==1)
        #define Press_B4 (KeyB4==1 || BUTTON[3]==1)
        #define Press_B5 (KeyB5==1 || BUTTON[4]==1)
        #define Press_B6 (KeyB6==1 || BUTTON[5]==1)
        #define Press_B7 (KeyB7==1 || BUTTON[6]==1)
        #define Press_B8 (KeyB8==1 || BUTTON[7]==1)
        #define Press_B9 (KeyB9==1 || BUTTON[8]==1)
        #define Press_B10 (KeyB10==1 || BUTTON[9]==1)


usage of combined codes:
Code: Select all
EnableControls(true, true);

if (Press_DOWN) {
    y+=5; }
else if (Press_UP) {
    y-=5; }


With that you can do just about anything :3
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

:D

Postby Hblade » Sat Oct 29, 2011 1:30 am

ChangeText function (Works with Cloned Text Actors without using switch or ifs)

Code: Select all
void ChangeText(char *actor, char *msg) {
    Actor*a=getclone(actor);
    sprintf(a->text, msg);}


Usage:
Code: Select all
ChangeText("TextActor.0", "Msg :3");
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Previous

Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest