Script

Game Editor implements a C-like script language that allows a high level of development power and flexibility.
All Actions can be activated from scripts.
When selecting an Action Function in "variable/functions" list, the respective action dialog pops-up to allow auto completion of the  script.

Internal variables: double musicVol; //Music volume (0.0 - 1.0)

//Read Only
int frame; //Game frame count
int real_fps; //Real game frame rate (frames per second)
int xmouse; //Mouse x position (screen coordinates)
int ymouse; //Mouse y position (screen coordinates)
Internal structs:

typedef struct stActorVars
{

double x; //x position relative to parent
double y; //y position relative to parent
double angle; //move angle (0 to 360, from positive x axis, counterclockwise, in degrees)
double xscreen; //horizontal screen position
double yscreen; //vertical screen position
double r; //red color (0 - 255)
double g; //green color (0 - 255)
double b; //blue color (0 - 255)
double transp; //transparency (0.0 - 1.0)
double pathxpos; //position in path x
double pathypos; //position in path y
double animpos; //actual animation frame
double xvelocity; //x velocity in pixels / frame
double yvelocity; //y velocity in pixels / frame
double diretional_velocity; //velocity in pixels / frame, in angle direction (set only when used with angle)
double textNumber; //If Actor has text, set the text number here
char text[MAX_SCRIPTTEXT]; //If Actor has text, set the text string here

//Read Only
double xprevious; //previous x position
double yprevious; //previous y position
int width; //actual animation width
int height; //actual animation height
int animindex; //actual animation index (count from 0)
int nframes; //actual animation frames
char name[ACTOR_NAME]; //Actor name
char clonename[CLONE_NAME]; //Actor clone name (Actor name followed by clone index - Ex.: ship.1, ship.2, ...)
long cloneindex; //clone index (count from 0)

} Actor;

Internal collide Actor: Actor collide;
Action functions:

int ChangeAnimation(char *actorName, char *animationName, int state)

Change animation and set initial state (FORWARD, BACKWARD, STOPPED, NO_CHANGE).
Return 1 if success, 0 on error.

animationName: animation valid for actorName.
Actor name:
- "Event Actor": Actor that is receiving the current event.
- Any Actor in game.

int ChangeAnimationDirection(char *actorName, int state)

Change animation state (FORWARD, BACKWARD, STOPPED).
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int ChangeCursor(char *actorName, char *imgName, int nFramesH, int nFramesV, int hotSpotX, int hotSpotY)

Change Actor cursor.
imgName: image file path relative to game directory.
nFramesH: number of horizontal frames.
nFramesV: number of vertical frames.
hotSpotX: cursor x hot spot.
hotSpotY: cursor y hot spot.
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- Any Actor in game.

int ChangeParent(char *actorName, char *parentName)

Change Actor parent
parentName: any Actor name (included "Event Actor", "Collide Actor" and "no parent").
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int ChangePath(char *actorName, char *pathName, int axis)

Change Actor path and set axis (X_AXIS, Y_AXIS, BOTH_AXIS).
pathName: any path name (included "no path" and "random path").
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int ChangeTransparency(char *actorName, double transp)

Change Actor transparency (0.0 - opaque, to 1.0 - transparent).
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int ChangeZDepth(char *actorName, double zdepth)

Change Actor z depth.
zdepth: 0.0 to 1.0
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int CollisionState(char *actorName, int state)

Enable or disable collision (enable = 1).
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

Actor* CreateActor(char *creatorName, char *animationName, char *parentName, char *pathName, int xpos, int ypos, int absolutePosition)

Create new Actor.
creatorName: any Actor name.
animationName: animation valid for ActorName or "no animation".
parentName: any Actor name (included "Event Actor", "Collide Actor" and "no parent").
pathName: any path name (included "no path" and "random path").
x,y: new Actor initial position.
absolutePosition: true or false.
Return Actor if success, invalid Actor (with cloneindex = -1 and name = "invalid Actor") on error.

int CreateTimer(char *actorName, char *timerName, int milliseconds)

Create new timer.
Return 1 if success, 0 on error.

timerName: new timer name.
milliseconds: new timer tempo.
Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int DestroyActor(char *actorName)

Destroy Actor
Return 1 if success, 0 on error

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int DestroyTimer(char *timerName)

Destroy timer
Return 1 if success, 0 on error

timerName: timer name

int EventDisable(char *actorName, unsigned long event)

Disable Actor event:
EVENTMOUSEBUTTONDOWN
EVENTMOUSEBUTTONUP
EVENTANIMATION
EVENTANIMATIONFINISH
EVENTPATHFINISH
EVENTKEYDOWN
EVENTKEYUP
EVENTTIMER
EVENTCOLLISION
EVENTCOLLISIONFINISH
EVENTCREATE
EVENTDESTROYACTOR
EVENTOUTOFVISION
EVENTACTIVATIONEVENT
EVENTALL
Return 1 if success, 0 on error

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int EventEnable(char *actorName, unsigned long event)

Enable Actor event:
EVENTMOUSEBUTTONDOWN
EVENTMOUSEBUTTONUP
EVENTANIMATION
EVENTANIMATIONFINISH
EVENTPATHFINISH
EVENTKEYDOWN
EVENTKEYUP
EVENTTIMER
EVENTCOLLISION
EVENTCOLLISIONFINISH
EVENTCREATE
EVENTDESTROYACTOR
EVENTOUTOFVISION
EVENTACTIVATIONEVENT
EVENTALL
Return 1 if success, 0 on error

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int FollowMouse(char *actorName, int axis)

Make Actor follow mouse axis (X_AXIS, Y_AXIS, BOTH_AXIS, NONE_AXIS).
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int MoveTo(char *actorName, double x, double y, double velocity)

Move Actor to specified position, at specified velocity.
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int PhysicalResponse(int moveType, int massType, double massEventActor, double massCollideActor, double eventVelocityMultiplier, double collideVelocityMultiplier)

Do a physical bounce movement between Actors in a collision
Return 1 if success, 0 on error

moveType: MOVE_EVENT_ACTOR_ONLY, MOVE_COLLIDE_ACTOR_ONLY, MOVE_BOTH_ACTORS

massType: USE_CALCULATED_MASS, USE_SPECIFIED_MASS

massEventActor, massCollideActor:
When massType = USE_CALCULATED_MASS, use this vars how calculated mass multiplier. When massType = USE_SPECIFIED_MASS, use this vars how mass.
Values > 0.0

eventVelocityMultiplier, collideVelocityMultiplier: final velocity multiplier

 

int PlayMusic(char *soundPath, double volume, int loop)

Play a music file.
soundPath: relative to game directory.
volume: 0.0 to 1.0.
loop: loop count (1 to 65000)
Return the allocated chanel if success, 0 on error.

Note: The musics must be copied to specified path.

int PlayMusic2(char *soundPath, double volume, int loop, int priority)

Play a music file.
soundPath: relative to game directory.
volume: 0.0 to 1.0.
loop: loop count (1 to 65000)
priority: HIGH_PRIORITY_MUSIC, MEDIUM_PRIORITY_MUSIC or LOW_PRIORITY_MUSIC (see PlayMusic action)
Return the allocated chanel if success, 0 on error

Note: The musics must be copied to specified path.

int PlaySound(char *soundPath, double volume, int loop)

Play a sound file.
soundPath: relative to game directory.
volume: 0.0 to 1.0.
loop: loop count (1 to 65000)
Return the allocated chanel if success, 0 on error

Note: The sounds must be copied to specified path.

int PlaySound2(char *soundPath, double volume, int loop, double pan)

Play a sound file.
soundPath: relative to game directory.
volume: 0.0 to 1.0
pan: -1.0 (full left) to 1.0 (full right)
loop: loop count (1 to 65000)
Return the allocated chanel if success, 0 on error

Note: The sounds must be copied to specified path.

int ToAnteriorPosition(char *actorName)

Send Actor to anterior frame position.
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int VisibilityState(char *actorName, int state)

state: ENABLE, DISABLE and DONT_DRAW_ONLY (Don't draw, but allow events)
Return 1 if success, 0 on error.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

Drawing Functions:

Drawing Functions must be used into actions of a canvas Actor.
The (x, y) coordinates are relative to the Actor's upper left corner

void setpen(int r, int g, int b, double transp, int pensize)
Define the actual pen for the Event Actor

r: red component (0 - 255)
g: green component (0 - 255)
b: blue component (0 - 255)
transparency: (0.0 - 1.0)
pensize: size of pen (1 - 15)

void moveto(int x, int y)
Move Event Actor pen to (x, y) coordinates

void lineto(int x, int y)
Draw a line on Event Actor to (x, y) coordinates using actual pen

void putpixel(int x, int y)
Draw a single pixel on Event Actor in (x, y) coordinates using actual pen

void erase(int r, int g, int b, double transp)
Erase all Actor with specified color

r: red component (0 - 255)
g: green component (0 - 255)
b: blue component (0 - 255)
transparency: (0.0 - 1.0)

void screen_to_actor(int *x, int *y)
Convert from screen coordinates to Actor coordinates (use to convert mouse coordinates, for example)

void actor_to_screen(int *x, int *y)
Convert from Actor coordinates to screen coordinates

void savecanvas()
Save canvas on the memory

void restorecanvas()
Restore canvas from the memory

Sound functions:

Sound functions uses the channel returned by PlayMusic, PlayMusic2, PlaySound, PlaySound2

void setPan(int channel, double pan)
Set the pan of sounds (Don't works with music)
pan: -1.0 (full left) to 1.0 (full right)

void setVolume(int channel, double volume)
Set a volume of a sound or music
volume: 0.0 to 1.0

void stopSound(int channel)
Stop the sound or music played on the specified channel

Save functions:

void saveVars(char *file, char *group)
Save all variables in the group to the specified file.
The file will be saved on the game directory


void loadVars(char *file, char *group)
Load all variables in the group from specified file

Helper functions:

double radtodeg(double a)
Convert an angle from radians to degrees.

double degtorad(double a)
Convert an angle from degrees to radians.

double round(double a)
Round a number to nearest integers.

double min(double a, double b)
Returns minimal value between two numbers.

double max(double a, double b)
Returns maximal value between two numbers.

double distance(double x1, double y1, double x2, double y2)
Returns distance between points (x1, y1) and (x2, y2).

double direction(double x1, double y1, double x2, double y2)
Returns direction between points (x1, y1) and (x2, y2) (in degrees, 0 to 360, from positive x axis, counterclockwise, in degrees).

void vectoradd(double *angle1, double *magnitude1, double angle2, double magnitude2)
Add vector2 (angle2, magnitude2) to vector1 (angle1, magnitude1) and returns result in vector1 (angles in degrees).

Actor *getclone(char *cloneName)
Get Actor with name cloneName
cloneName: nameactor.cloneindex (Ex.: ship.1, ship.2, ...)
Return Actor if success, invalid Actor (with cloneindex = -1 and name = "invalid Actor") on error.

Actor *getactor(long x, long y)
Returns Actor at position (x,y) (in game coordinates) if success, invalid Actor (with cloneindex = -1 and name = "invalid Actor") on error.

int getLastKey()
Returns the last pressed key

char *getKeyText(int key)
Returns the key description

void remapKey(int fromKey, int toKey)
Redirect fromKey to toKey (User config keys)
Reseted in LoadGame

char *GetKeyState()
Returns array with keyboard state.

Valid key entries:

KEY_BACKSPACE
KEY_TAB
KEY_CLEAR
KEY_RETURN
KEY_PAUSE
KEY_ESCAPE
KEY_SPACE
KEY_EXCLAIM
KEY_QUOTEDBL
KEY_HASH
KEY_DOLLAR
KEY_AMPERSAND
KEY_QUOTE
KEY_LEFTPAREN
KEY_RIGHTPAREN
KEY_ASTERISK
KEY_PLUS
KEY_COMMA
KEY_MINUS
KEY_PERIOD
KEY_SLASH
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_COLON
KEY_SEMICOLON
KEY_LESS
KEY_EQUALS
KEY_GREATER
KEY_QUESTION
KEY_AT
KEY_LEFTBRACKET
KEY_BACKSLASH
KEY_RIGHTBRACKET
KEY_CARET
KEY_UNDERSCORE
KEY_BACKQUOTE
KEY_a
KEY_b
KEY_c
KEY_d
KEY_e
KEY_f
KEY_g
KEY_h
KEY_i
KEY_j
KEY_k
KEY_l
KEY_m
KEY_n
KEY_o
KEY_p
KEY_q
KEY_r
KEY_s
KEY_t
KEY_u
KEY_v
KEY_w
KEY_x
KEY_y
KEY_z
KEY_PAD_0
KEY_PAD_1
KEY_PAD_2
KEY_PAD_3
KEY_PAD_4
KEY_PAD_5
KEY_PAD_6
KEY_PAD_7
KEY_PAD_8
KEY_PAD_9
KEY_PAD_PERIOD
KEY_PAD_DIVIDE
KEY_PAD_MULTIPLY
KEY_PAD_MINUS
KEY_PAD_PLUS
KEY_PAD_ENTER
KEY_PAD_EQUALS
KEY_UP
KEY_DOWN
KEY_RIGHT
KEY_LEFT
KEY_INSERT
KEY_HOME
KEY_END
KEY_PAGEUP
KEY_PAGEDOWN
KEY_F1
KEY_F2
KEY_F3
KEY_F4
KEY_F5
KEY_F6
KEY_F7
KEY_F8
KEY_F9
KEY_F10
KEY_F11
KEY_F12
KEY_F13
KEY_F14
KEY_F15
KEY_NUMLOCK
KEY_CAPSLOCK
KEY_SCROLLOCK
KEY_RSHIFT
KEY_LSHIFT
KEY_RCTRL
KEY_LCTRL
KEY_RALT
KEY_LALT
KEY_RMETA
KEY_LMETA
KEY_LWINDOWS
KEY_RWINDOWS
KEY_ALT_GR
KEY_HELP
KEY_PRINT
KEY_SYSREQ
KEY_BREAK
KEY_MENU
KEY_MAC_POWER
KEY_EURO
KEY_POCKET_UP
KEY_POCKET_DOWN
KEY_POCKET_LEFT
KEY_POCKET_RIGHT
KEY_POCKET_A
KEY_POCKET_B
KEY_POCKET_C
KEY_POCKET_START
KEY_POCKET_AUX1
KEY_POCKET_AUX2
KEY_POCKET_AUX3
KEY_POCKET_AUX4
KEY_POCKET_AUX5
KEY_POCKET_AUX6
KEY_POCKET_AUX7
KEY_POCKET_AUX8

int ExitGame()

End game and return to system.
Return 1 if success, 0 on error.

int LoadGame(char *gamePath)

Load a game.
gamePath: game file path relative to actual game directory .
Return 1 if success, 0 on error.

int ActorCount(char *actorName)

Return number of Actors with actorName.

Actor name:
- Any Actor in game.

int CollisionFree(char *actorName, int x, int y)

Check if position x,y is collision free for ActorName.

Return 1 if not collide, 0 otherwise.

Actor name:
- "Event Actor": Actor that is receiving the current event.
- "Collide Actor": Actor that collided with the event Actor.
- Any Actor in game.

int SendActivationEvent(char *cloneName)

Send a Activation Event to Actor cloneName.
Return 1 if success, 0 on error.

cloneName: nameactor.cloneindex (Ex.: ship.1, ship.2, ...)

Actor *getAllActorsInCollision(char *cloneName, int *nActors)

cloneName: nameactor.cloneindex (Ex.: ship.1, ship.2, ...), "Event Actor" or "Collide Actor"

Return Actor's array with all Actors colliding with cloneName if success or NULL if don't have collisions
Actor count will be returned in nActors

The returned array will be valid until the next call to getAllActorsInCollision
The returned array is read only.

Sample: Make "Event Actor" the parent of all colliding Actors

int n;
Actor *actors;

actors = getAllActorsInCollision("Event Actor", &n);

		if(actors)
        {
         int i;
         for(i = 0; i < n; i++)
         {
          ChangeParent(actors[i].clonename, "Event Actor");
         }
        }
Internal C functions (Please, refer to C manual for more info):

double abs(double a)
double sign(double a)
double rand(double a) //returns a value betwen 0 and a
double acos(double a)
double asin(double a)
double atan(double a)
double atan2(double a, double b)
double cos(double a)
double sin(double a)
double tan(double a)
double cosh(double a)
double sinh(double a)
double tanh(double a)
double exp(double a)
double frexp(double a, int * b)
double ldexp(double a, int b)
double log(double a)
double log10(double a)
double modf(double a, double *b)
double pow(double a, double b)
double sqrt(double a)
double ceil(double a)
double floor(double a)
double fmod(double a, double b)

void *malloc(size_t size)
void *calloc(size_t num, size_t size)
void *realloc(void *memblock, size_t size)
void free(void *memblock)
void *memcpy( void *dest, const void *src, size_t count )
void *memmove( void *dest, const void *src, size_t count )
int memcmp( const void *buf1, const void *buf2, size_t count )
void *memset( void *dest, int c, size_t count )

int atoi(const char *string)
double atof(const char *string)
long atol(const char *string)

long ftell(FILE *fp)
int feof (FILE *stream)
int sprintf(char *buf, const char * fmt, ...)
int fprintf(FILE * fp,const char *fmt, ...)
int fgetc(FILE * fp)
int fputc(int c, FILE * fp)
int fputs(const char *s, FILE *fp)
char * fgets(char *s, int n, FILE *fp)
size_t fread(void *buf, size_t elsize, size_t nelems, FILE * fp)
size_t fwrite(const void *buf, size_t elsize, size_t nelems, FILE * fp)
FILE *freopen(const char *name, const char *mode, FILE *fp)
FILE *fopen(const char *name, const char *mode)
int fclose(FILE * fp)
int fscanf(FILE *fp, const char *fmt, ...)
int sscanf(const char *str,const char *fmt, ...)
int fseek(FILE *fp, long off, int origin)
int rename(const char *oldname, const char *newname)

char *strcpy(char * dst, const char * src)
char *strncpy(char * dst, const char * src, size_t n)
char *strcat(char * s1, const char * s2)
char *strncat(char * s1, const char *s2, size_t n)
int strcmp(const char * s1, const char * s2)
int strncmp(const char * s1, const char *s2, size_t n)
char *strchr(const char *s, int c)
size_t strlen(const char *s)