It was added to make random player movement easier...
you know there are 4 dirs a player can have
0 up
1 left
2 down
3 right
so now u watch the table:
NPC Code:
Dir value for vecx value for vecy
0 0 -1
1 -1 0
2 0 1
3 1 0
so if you have the player looking up and u want him to move in this direction you need to substract a value from the players y-Position but the players X-Position has to be the same value so you don't have to add or substract something from the value
ok lets say players x pos is 32 and the players y pos is 25 and he is looking up
playerx+=vecx(playerdir); //nothing will happen to the players x-value
playery+=vecy(playerdir); // oh wonder there is 1 substracted from players y-value and he has gone upwards
so one simple in-use-example (some Staff-Boots)
NPC Code:
if (playertouchsme) toweapons StaffBoots;
// Activating the weapon
if (weaponfired) {
if (this.active==1) this.active=0;
else {
this.active=1;
timeout=.05;
}
}
if (timeout) {
if (this.active==1) {
//now there comes our movement part
for (i=0;i<4;i++) {
if (keydown(i)) {
playerx+=vecx(i);
playery+=vecy(i);
}
}
timeout=.05;
}
}
the for loop is just used to get an easier use for a keydow routine wit less code i is always the value of the dir your char is looking at so while pressing a key your charackter gets faster and he can walk over walls...