BATCH 101 (version 1.3)
Posted: Mon Jun 28, 2010 7:44 pm
Version 1.3 includes updated scripts written by lcl.
|About BATCH 101
How to use - and What they do:
The code:
Put this in Global Code
Youtube Video: (Water physics in the video uses deflect, the fire uses col) Collision is lag free!
[/b]
|About BATCH 101
- | BATCH 101 is pretty much a list of voids that were made by various users to aid people in scripting by simplifying things and placing them into voids, which can later be called with only 1 line.
- Col(position, multiplier);
deflect(Axis, divider);
to_i(value);
getTextNumber(actor);
-lcl's scripts--------------------------------------------------------------------------------------------------------------------
Move("charRight", "(none)", RIGHT, 5);
Jump(10);
EnableJump();
Follow("actor that follows", "actor to follow", axis, speed);
ViewFollowActor("actor to follow", how much player can move on x axis before view starts moving, same for y, speed);
CollisionJump("jumping actors name", key, jump height);
----------------------------------------------------------------------------------------------------------------------------------
How to use - and What they do:
- Col("TOP", 1.2); - This will act as a lag free physical response, while not being as accurate, it still comes in handy if your lagging with your current physical response and you want something simple and lag free
- Code: Select all
Follow("enemy", "Player", AXIS_X, 5);
- Code: Select all
ViewFollowActor("Player", 100, 100, 5);
- Code: Select all
CollisionJump("Player", KEY_UP, 10);
Uses:
- "TOP"
"BOTTOM"
"LEFT"
"RIGHT"
deflect(Y, 1.8); - This will make yvelocity opposite plus the divider to rebound or slowly decrease in falling / bounce speed (Setting it to 0 will make it completely deflect, use anything below 0 to adjust bounce velocity, and above 0 to make it slower. Example:
deflect(BOTH, -9);
This will make it bounce higher or farther but not as much as the defailt velocity
Uses:
- X
Y
BOTH
to_i(2.40); - This will return a double or float (decimal) value to an integer and store it in a variable called Vstore, which can be used in many usefull ways. In this case, 2.40 will be turned into 2, becuase it'll be rounded off to the nearest 1
Usage:
- to_i(89.690);
Uses:
- getTextNumber("player_HP");
Move("charRight", "(none)", RIGHT, 5);
- This will move the character according to the set speed, and change his animations according to the animation names.
lcl wrote:[b]
"charRight" is the animation
"(none)" this is for second animation, it's usable for commanding animations when two keys are pressed
RIGHT is the way to move, there is many alternatives
5 is speed of move
Jump(10);
- Allows the person or AI to jump according to the height set. In this case, 10
lcl wrote:This will make actor jump to the height of 10.
EnableJump();
- This re-enables jump. Call this function when you land on the ground again or anything else that enables the player to jump.
lcl wrote:For now, last function is for enabling the jump again, for example when colliding with ground:
Follow("actor that follows", "actor to follow", axis, speed);
- Select an actor to follow another actor, great for making RPG parties !
lcl wrote:
This will make actor called enemy to chase actor Player, following only Players x axel with speed of 5.
This code work for every individual actor, you just must remember to type different value to the numberin middle of the code.
ViewFollowActor("actor to follow", how much player can move on x axis before view starts moving, same for y, speed);
- Prettymuch, you set the offset X and Y for the view to be moving when the player reaches that. Example:
ViewFollowActor("Player", 9, 9, 4);
This will move the view at a speed of 4 when the player has a 9 pixel offset from the center of the screen.
lcl wrote:
This will make view follow actor Player with speed of 5. Remember to use this only
in view actors draw actor code.
CollisionJump("jumping actors name", key, jump height);
- While the key you set is being pressed, the actor will jump to the height you set.
lcl wrote:
This will make actor called Player to jump to height of 10 while on actor Ground and key up is pressed.
You can use any key on keyboard to use this function!!!
The code:
Put this in Global Code
- Code: Select all
#define X 0
#define Y 1
#define BOTH 2
#define LEFT 11
#define RIGHT 22
#define UP 33
#define DOWN 44
#define STOP_LEFT 55
#define STOP_RIGHT 66
#define TWO_KEYS 77
int Vstore, retStore, tnStore;
int jump;
int dir;
void Col(char *AREA, double multiplyer)
{
if (strcmp(AREA, "LEFT"))
{
xvelocity = (-xvelocity/2) * -multiplyer;
if (multiplyer!=0)
{
yvelocity = -yvelocity - rand(multiplyer+(multiplyer/2)) + rand(multiplyer+(multiplyer/2));
}
else if(multiplyer == 0)
{
yvelocity = rand(multiplyer+1) - rand(multiplyer+1);
}
}
if (strcmp(AREA, "RIGHT"))
{
xvelocity = (-xvelocity/2) * multiplyer;
if (multiplyer!=0)
{
yvelocity = -yvelocity - rand(multiplyer+(multiplyer/2)) + rand(multiplyer+(multiplyer/2));
}
else if(multiplyer == 0)
{
yvelocity = rand(multiplyer+1) + rand(multiplyer+1);
}
}
if (strcmp(AREA, "TOP"))
{
yvelocity = (-xvelocity/2) * multiplyer;
if (multiplyer!=0)
{
xvelocity = -xvelocity - rand(multiplyer+(multiplyer/2)) + rand(multiplyer+(multiplyer/2));
}
else if(multiplyer == 0)
{
xvelocity = rand(multiplyer+1) + rand(multiplyer+1);
}
}
if (strcmp(AREA, "BOTTOM"))
{
yvelocity = (-xvelocity/2) * multiplyer;
if (multiplyer!=0)
{
xvelocity = -xvelocity - rand(multiplyer+(multiplyer/2)) + rand(multiplyer+(multiplyer/2));
}
else if(multiplyer == 0)
{
xvelocity = rand(multiplyer+1) + rand(multiplyer+1);
}
}
}
void to_i(double v1)
{
Vstore = round(v1);
}
void getTextNumber(char *actor)
{
Actor * a = getclone(actor);
tnStore = a->textNumber;
}
void deflect(int t, double devider)
{
if (t == 0)
{
if (devider == 0)
{
xvelocity = -xvelocity;
}
else if(devider!=0)
{
xvelocity = -(xvelocity - devider);
}
}
if (t == 1)
{
if (devider == 0)
{
yvelocity = -yvelocity;
}
else if(devider!=0)
{
yvelocity = -(yvelocity - devider);
}
}
if (t == 2)
{
if (devider == 0)
{
yvelocity = -yvelocity;
xvelocity = -xvelocity;
}
else if(devider!=0)
{
yvelocity = -(yvelocity - devider);
xvelocity = -(xvelocity - devider);
}
}
}
//--------------SCRIPTS BY LCL------------------//
long jump[1000];
int dir;
int moving;
int stop;
int stopWay;
#define LEFT 11
#define RIGHT 22
#define UP 33
#define DOWN 44
#define STOP_LEFT 55
#define STOP_RIGHT 66
#define TWO_KEYS 77
#define AXIS_X 88
#define AXIS_Y 99
#define AXIS_BOTH 110
//----------EASY TO USE FUNCTIONS----------
/*These are easy functions for beginners to use
for making their games easier way.*/
//-----MOVING THE PLAYER-----
/*This allows you to change animations and move player
with speed that you can decide yourself.
-----ABOUT USING-----
Moving functions must be used in key down events
following way:
Move("Animation name", "Second animation name" Direction, Speed with numbers);
There are 4 moving directions; left, right, up, down,
and also directions stop left, stop right, and two keys pressed.
To call some of these directions, type:
- LEFT
- RIGHT
- UP
- DOWN
- STOP_LEFT
- STOP_RIGHT
- TWO_KEYS
- JUMP
*/
void Move(char*anim, char*anim2, int moveWay, int speed)
{
switch(moveWay)
{
case LEFT:
x-=speed;
if(moving==0)
{
if(dir!=1 && stop==0)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=1;
stopWay=1;
}
}
moving=1;
break;
case RIGHT:
x+=speed;
if(moving==0)
{
if(dir!=2 && stop==0)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=2;
stopWay=2;
}
}
moving=1;
break;
case UP:
y-=speed;
if(moving==0)
{
if(dir!=3)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=3;
}
}
moving=1;
break;
case DOWN:
y+=speed;
if(moving==0)
{
if(dir!=4)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=4;
}
}
moving=1;
break;
case STOP_LEFT:
moving=0;
if(dir!=5)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=5;
stop=0;
}
break;
case STOP_RIGHT:
moving=0;
if(dir!=6)
{
ChangeAnimation("Event Actor", anim, FORWARD);
dir=6;
stop=0;
}
break;
case TWO_KEYS:
moving=0;
if(!stop)
{
switch(stopWay)
{
case 1:
ChangeAnimation("Event Actor", anim, FORWARD);
stop=1;
break;
case 2:
ChangeAnimation("Event Actor", anim2, FORWARD);
stop=1;
}
}
break;
}
}
//-----JUMPING-----
/*This allows you to make your player jump easily
to the height that you can decide. Function also
disables jumping after one jump. Use the function
EnableJump(); to enable it again ex. in collision with ground.
-----ABOUT USING-----
This function can be used in key down event
following way:
Jump(Set the height with numbers);
*/
void Jump(char*name, int number, int power)
{
Actor*actor=getclone(name);
if(jump[number]==0)
{
actor->yvelocity=-power;
jump[number]=1;
}
}
void EnableJump(int number)
{
jump[number]=0;
}
void Follow(char*name2, char*name, int way, int speed)
{
Actor*actor=getclone(name);
Actor*follower=getclone(name2);
switch(way)
{
case AXIS_X:
if(follower->x<actor->x-speed)
{
follower->x+=speed;
}
if(follower->x>actor->x+speed)
{
follower->x-=speed;
}
break;
case AXIS_Y:
if(follower->y<actor->y-speed)
{
follower->y+=speed;
}
if(follower->y>actor->y+speed)
{
follower->y-=speed;
}
break;
case AXIS_BOTH:
if(follower->x<actor->x-speed)
{
follower->x+=speed;
}
if(follower->x>actor->x+speed)
{
follower->x-=speed;
}
if(follower->y<actor->y-speed)
{
follower->y+=speed;
}
if(follower->y>actor->y+speed)
{
follower->y-=speed;
}
break;
}
}
void ViewFollowActor(char*name, int Fx, int Fy, int speed)
{
Actor*actor=getclone(name);
int X=view.width/2;
int Y=view.height/2;
if(x+X<actor->x-speed && actor->xscreen>xscreen+X+Fx)
{
x+=speed;
}
if(x+X>actor->x+speed && actor->xscreen<xscreen+X-Fx)
{
x-=speed;
}
if(y+Y<actor->y-speed && actor->yscreen>xscreen+Y+Fy)
{
y+=actor->yvelocity;
}
if(y+Y>actor->y+speed && actor->yscreen<xscreen+Y-Fy)
{
y-=speed;
}
}
void CollisionJump(char*name, int that, int height)
{
Actor*actor=getclone(name);
char*key=GetKeyState();
strcpy(key, getKeyText(that));
if(key[that]==1)
{
actor->yvelocity=-height;
}
}
Youtube Video: (Water physics in the video uses deflect, the fire uses col) Collision is lag free!
[/b]