1101

**Coding / Re: FAQ. Frequently Asked Questions **

« **on:**May 01, 2009, 04:52:09 pm »

That save file bit is pretty useful. When I get around to adding a save function I'll definitely use it as a starting point.

Might as well make a usefull post while I'm at it. Here's a bit of code for advanced advanced movement. This will give you pixel perfect movement and it will also move you along sloped walls. I did leave out a lot of code to keep it somewhat simple. Just contact me if I left out too much. This code should be used at every step, with your speed being reset, and your speed and direction variables being calculated, beforehand.

--------------------------

// With (obj_Character_Control_Tile)

// Set VARIABLES

Test_Variable = 0;

Distance_Counter = 0;

New_X_Position = x;

New_Y_Position = y;

Total_X_Distance = 0;

Total_Y_Distance = 0;

Partial_Distance = 0;

// MOVEMENT routine

if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

if (Walking_Speed <> 0)

{

repeat (ceil(Walking_Speed))

{

if (Test_Variable = 0 and Distance_Counter < Walking_Speed)

{

// Check collision straight ahead

Distance_Counter += Partial_Distance;

if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

if (Distance_Counter = ceil(Walking_Speed)){Partial_Distance = Walking_Speed-Distance_Counter+1};

script_execute(30,Walking_Direction, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// Check collision first angle

if (((Walking_Direction+45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

script_execute(30, (Walking_Direction + 45)mod 360, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// Check collision with second angle

if (((Walking_Direction-45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

script_execute(30, (Walking_Direction - 45)mod 360, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// STOP MOVEMENT

Final_xspeed = round(New_X_Position)-New_X_Position;

Final_yspeed = round(New_Y_Position)-New_Y_Position;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

Test_Variable = 1;

};

};

};

};

};

};

// Create actual movement

parent_Character.hspeed = Total_X_Distance;

parent_Character.vspeed = Total_Y_Distance;

--------------------------------

// Script 30

// Input:

// argument[0] = Walking_Direction

// argument[1] = Partial_Distance

if (Sprite_Index_Counter = 0) {Final_xspeed = 0; Final_yspeed = 0}

else {if (argument[0] = 360) {Final_xspeed = argument[1]; Final_yspeed = 0}

else {if (argument[0] = 270) {Final_xspeed = 0; Final_yspeed = argument[1]}

else {if (argument[0] = 180) {Final_xspeed = -1*argument[1]; Final_yspeed = 0}

else {if (argument[0] = 90) {Final_xspeed = 0; Final_yspeed = -1*argument[1]}

else {if (argument[0] < 90)

{Final_xspeed=argument[1]*cos(degtorad(argument[0]));

Final_yspeed=-1*argument[1]*cos(degtorad(90-argument[0]))}

else {if (argument[0] < 180)

{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-90));

Final_yspeed=-1*argument[1]*cos(degtorad(180-argument[0]))}

else {if (argument[0] < 270)

{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-180));

Final_yspeed=argument[1]*cos(degtorad(270-argument[0]))}

else {Final_xspeed=argument[1]*cos(degtorad(argument[0]-270));

Final_yspeed=argument[1]*cos(degtorad(360-argument[0]))}

;};};};};};};};

Might as well make a usefull post while I'm at it. Here's a bit of code for advanced advanced movement. This will give you pixel perfect movement and it will also move you along sloped walls. I did leave out a lot of code to keep it somewhat simple. Just contact me if I left out too much. This code should be used at every step, with your speed being reset, and your speed and direction variables being calculated, beforehand.

--------------------------

// With (obj_Character_Control_Tile)

// Set VARIABLES

Test_Variable = 0;

Distance_Counter = 0;

New_X_Position = x;

New_Y_Position = y;

Total_X_Distance = 0;

Total_Y_Distance = 0;

Partial_Distance = 0;

// MOVEMENT routine

if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

if (Walking_Speed <> 0)

{

repeat (ceil(Walking_Speed))

{

if (Test_Variable = 0 and Distance_Counter < Walking_Speed)

{

// Check collision straight ahead

Distance_Counter += Partial_Distance;

if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

if (Distance_Counter = ceil(Walking_Speed)){Partial_Distance = Walking_Speed-Distance_Counter+1};

script_execute(30,Walking_Direction, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// Check collision first angle

if (((Walking_Direction+45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

script_execute(30, (Walking_Direction + 45)mod 360, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// Check collision with second angle

if (((Walking_Direction-45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

script_execute(30, (Walking_Direction - 45)mod 360, Partial_Distance);

if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)

{

New_X_Position += Final_xspeed;

New_Y_Position += Final_yspeed;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

}

else

{

// STOP MOVEMENT

Final_xspeed = round(New_X_Position)-New_X_Position;

Final_yspeed = round(New_Y_Position)-New_Y_Position;

Total_X_Distance += Final_xspeed;

Total_Y_Distance += Final_yspeed;

Test_Variable = 1;

};

};

};

};

};

};

// Create actual movement

parent_Character.hspeed = Total_X_Distance;

parent_Character.vspeed = Total_Y_Distance;

--------------------------------

// Script 30

// Input:

// argument[0] = Walking_Direction

// argument[1] = Partial_Distance

if (Sprite_Index_Counter = 0) {Final_xspeed = 0; Final_yspeed = 0}

else {if (argument[0] = 360) {Final_xspeed = argument[1]; Final_yspeed = 0}

else {if (argument[0] = 270) {Final_xspeed = 0; Final_yspeed = argument[1]}

else {if (argument[0] = 180) {Final_xspeed = -1*argument[1]; Final_yspeed = 0}

else {if (argument[0] = 90) {Final_xspeed = 0; Final_yspeed = -1*argument[1]}

else {if (argument[0] < 90)

{Final_xspeed=argument[1]*cos(degtorad(argument[0]));

Final_yspeed=-1*argument[1]*cos(degtorad(90-argument[0]))}

else {if (argument[0] < 180)

{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-90));

Final_yspeed=-1*argument[1]*cos(degtorad(180-argument[0]))}

else {if (argument[0] < 270)

{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-180));

Final_yspeed=argument[1]*cos(degtorad(270-argument[0]))}

else {Final_xspeed=argument[1]*cos(degtorad(argument[0]-270));

Final_yspeed=argument[1]*cos(degtorad(360-argument[0]))}

;};};};};};};};