| 1 |
function scr_autowalk_statescr_autowalk_statefunction scr_autowalk_state()
{
var hsp = 0;
var vsp = 0;
if (autowalk_direction == "right")
{
if (place_free(x + global.player_speed, y))
{
hsp = global.player_speed;
image_speed = 0.2;
global.walking = true;
}
if (global.debugmove == true)
hsp = global.player_speed;
}
if (autowalk_direction == "left")
{
if (place_free(x - global.player_speed, y))
{
hsp = -global.player_speed;
image_speed = 0.2;
global.walking = true;
}
if (global.debugmove == true)
hsp = -global.player_speed;
}
if (autowalk_direction == "down")
{
if (place_free(x, y + global.player_speed))
{
vsp = global.player_speed;
image_speed = 0.2;
global.walking = true;
}
if (global.debugmove == true)
vsp = global.player_speed;
}
if (autowalk_direction == "up")
{
if (place_free(x, y - global.player_speed))
{
vsp = -global.player_speed;
image_speed = 0.2;
global.walking = true;
}
if (global.debugmove == true)
vsp = -global.player_speed;
}
if (vsp == 0 && hsp == 0)
{
image_speed = 0;
image_index = 0;
global.walking = false;
}
if (place_meeting(x + global.player_speed, y + global.player_speed, obj_dr))
{
x = xprevious;
y = yprevious;
if (keyboard_check(vk_right) && keyboard_check(vk_down) == false)
{
if (place_free(x + global.player_speed, y))
hsp = global.player_speed;
if (place_free(x, y - global.player_speed))
vsp = -global.player_speed;
}
if (keyboard_check(vk_right) == false && keyboard_check(vk_down))
{
if (place_free(x - global.player_speed, y))
hsp = -global.player_speed;
if (place_free(x, y + global.player_speed))
vsp = global.player_speed;
}
}
if (place_meeting(x - global.player_speed, y + global.player_speed, obj_dl))
{
x = xprevious;
y = yprevious;
if (keyboard_check(vk_left) && keyboard_check(vk_down) == false)
{
if (place_free(x - global.player_speed, y))
hsp = -global.player_speed;
if (place_free(x, y - global.player_speed))
vsp = -global.player_speed;
}
if (keyboard_check(vk_left) == false && keyboard_check(vk_down))
{
if (place_free(x + global.player_speed, y))
hsp = global.player_speed;
if (place_free(x, y + global.player_speed))
vsp = global.player_speed;
}
}
if (place_meeting(x - global.player_speed, y - global.player_speed, obj_ul))
{
x = xprevious;
y = yprevious;
if (keyboard_check(vk_left) && keyboard_check(vk_up) == false)
{
if (place_free(x - global.player_speed, y))
hsp = -global.player_speed;
if (place_free(x, y + global.player_speed))
... () |
| 2 |
{ |
| 3 |
var hsp = 0; |
| 4 |
var vsp = 0; |
| 5 |
if (autowalk_direction == "right") |
| 6 |
{ |
| 7 |
if (place_free(x + global.player_speed, y)) |
| 8 |
{ |
| 9 |
hsp = global.player_speed; |
| 10 |
image_speed = 0.2; |
| 11 |
global.walking = true; |
| 12 |
} |
| 13 |
if (global.debugmove == true) |
| 14 |
hsp = global.player_speed; |
| 15 |
} |
| 16 |
if (autowalk_direction == "left") |
| 17 |
{ |
| 18 |
if (place_free(x - global.player_speed, y)) |
| 19 |
{ |
| 20 |
hsp = -global.player_speed; |
| 21 |
image_speed = 0.2; |
| 22 |
global.walking = true; |
| 23 |
} |
| 24 |
if (global.debugmove == true) |
| 25 |
hsp = -global.player_speed; |
| 26 |
} |
| 27 |
if (autowalk_direction == "down") |
| 28 |
{ |
| 29 |
if (place_free(x, y + global.player_speed)) |
| 30 |
{ |
| 31 |
vsp = global.player_speed; |
| 32 |
image_speed = 0.2; |
| 33 |
global.walking = true; |
| 34 |
} |
| 35 |
if (global.debugmove == true) |
| 36 |
vsp = global.player_speed; |
| 37 |
} |
| 38 |
if (autowalk_direction == "up") |
| 39 |
{ |
| 40 |
if (place_free(x, y - global.player_speed)) |
| 41 |
{ |
| 42 |
vsp = -global.player_speed; |
| 43 |
image_speed = 0.2; |
| 44 |
global.walking = true; |
| 45 |
} |
| 46 |
if (global.debugmove == true) |
| 47 |
vsp = -global.player_speed; |
| 48 |
} |
| 49 |
if (vsp == 0 && hsp == 0) |
| 50 |
{ |
| 51 |
image_speed = 0; |
| 52 |
image_index = 0; |
| 53 |
global.walking = false; |
| 54 |
} |
| 55 |
if (place_meeting(x + global.player_speed, y + global.player_speed, obj_dr)) |
| 56 |
{ |
| 57 |
x = xprevious; |
| 58 |
y = yprevious; |
| 59 |
if (keyboard_check(vk_right) && keyboard_check(vk_down) == false) |
| 60 |
{ |
| 61 |
if (place_free(x + global.player_speed, y)) |
| 62 |
hsp = global.player_speed; |
| 63 |
if (place_free(x, y - global.player_speed)) |
| 64 |
vsp = -global.player_speed; |
| 65 |
} |
| 66 |
if (keyboard_check(vk_right) == false && keyboard_check(vk_down)) |
| 67 |
{ |
| 68 |
if (place_free(x - global.player_speed, y)) |
| 69 |
hsp = -global.player_speed; |
| 70 |
if (place_free(x, y + global.player_speed)) |
| 71 |
vsp = global.player_speed; |
| 72 |
} |
| 73 |
} |
| 74 |
if (place_meeting(x - global.player_speed, y + global.player_speed, obj_dl)) |
| 75 |
{ |
| 76 |
x = xprevious; |
| 77 |
y = yprevious; |
| 78 |
if (keyboard_check(vk_left) && keyboard_check(vk_down) == false) |
| 79 |
{ |
| 80 |
if (place_free(x - global.player_speed, y)) |
| 81 |
hsp = -global.player_speed; |
| 82 |
if (place_free(x, y - global.player_speed)) |
| 83 |
vsp = -global.player_speed; |
| 84 |
} |
| 85 |
if (keyboard_check(vk_left) == false && keyboard_check(vk_down)) |
| 86 |
{ |
| 87 |
if (place_free(x + global.player_speed, y)) |
| 88 |
hsp = global.player_speed; |
| 89 |
if (place_free(x, y + global.player_speed)) |
| 90 |
vsp = global.player_speed; |
| 91 |
} |
| 92 |
} |
| 93 |
if (place_meeting(x - global.player_speed, y - global.player_speed, obj_ul)) |
| 94 |
{ |
| 95 |
x = xprevious; |
| 96 |
y = yprevious; |
| 97 |
if (keyboard_check(vk_left) && keyboard_check(vk_up) == false) |
| 98 |
{ |
| 99 |
if (place_free(x - global.player_speed, y)) |
| 100 |
hsp = -global.player_speed; |
| 101 |
if (place_free(x, y + global.player_speed)) |
| 102 |
vsp = global.player_speed; |
| 103 |
} |
| 104 |
if (keyboard_check(vk_left) == false && keyboard_check(vk_up)) |
| 105 |
{ |
| 106 |
if (place_free(x + global.player_speed, y)) |
| 107 |
hsp = global.player_speed; |
| 108 |
if (place_free(x, y - global.player_speed)) |
| 109 |
vsp = -global.player_speed; |
| 110 |
} |
| 111 |
} |
| 112 |
if (place_meeting(x + global.player_speed, y - global.player_speed, obj_ur)) |
| 113 |
{ |
| 114 |
x = xprevious; |
| 115 |
y = yprevious; |
| 116 |
if (keyboard_check(vk_right) && keyboard_check(vk_up) == false) |
| 117 |
{ |
| 118 |
if (place_free(x + global.player_speed, y)) |
| 119 |
hsp = global.player_speed; |
| 120 |
if (place_free(x, y + global.player_speed)) |
| 121 |
vsp = global.player_speed; |
| 122 |
} |
| 123 |
if (keyboard_check(vk_right) == false && keyboard_check(vk_up)) |
| 124 |
{ |
| 125 |
if (place_free(x - global.player_speed, y)) |
| 126 |
hsp = -global.player_speed; |
| 127 |
if (place_free(x, y - global.player_speed)) |
| 128 |
vsp = -global.player_speed; |
| 129 |
} |
| 130 |
} |
| 131 |
if (place_meeting(x, y, obj_stairs)) |
| 132 |
{ |
| 133 |
x = xprevious; |
| 134 |
y = yprevious; |
| 135 |
if (keyboard_check(vk_right)) |
| 136 |
{ |
| 137 |
if (place_free(x + global.player_speed, y)) |
| 138 |
hsp = global.player_speed; |
| 139 |
if (place_free(x, y - 2)) |
| 140 |
vsp = -2; |
| 141 |
} |
| 142 |
if (keyboard_check(vk_left)) |
| 143 |
{ |
| 144 |
if (place_free(x - global.player_speed, y)) |
| 145 |
hsp = -global.player_speed; |
| 146 |
if (place_free(x, y + 2)) |
| 147 |
vsp = 2; |
| 148 |
} |
| 149 |
if (keyboard_check(vk_up) && !keyboard_check(vk_right)) |
| 150 |
{ |
| 151 |
if (place_free(x, y - 3)) |
| 152 |
vsp = -global.player_speed; |
| 153 |
} |
| 154 |
if (keyboard_check(vk_down) && !keyboard_check(vk_left)) |
| 155 |
{ |
| 156 |
if (place_free(x, y + 3)) |
| 157 |
vsp = global.player_speed; |
| 158 |
} |
| 159 |
} |
| 160 |
if (vsp > global.player_speed) |
| 161 |
vsp = global.player_speed; |
| 162 |
if (hsp > global.player_speed) |
| 163 |
hsp = global.player_speed; |
| 164 |
if (vsp < -global.player_speed) |
| 165 |
vsp = -global.player_speed; |
| 166 |
if (hsp < -global.player_speed) |
| 167 |
hsp = -global.player_speed; |
| 168 |
x += hsp; |
| 169 |
y += vsp; |
| 170 |
if (dirStore == false) |
| 171 |
{ |
| 172 |
if (autowalk_direction == "right") |
| 173 |
{ |
| 174 |
direction = 0; |
| 175 |
dirStore = true; |
| 176 |
} |
| 177 |
if (autowalk_direction == "left") |
| 178 |
{ |
| 179 |
direction = 180; |
| 180 |
dirStore = true; |
| 181 |
} |
| 182 |
if (autowalk_direction == "down") |
| 183 |
{ |
| 184 |
direction = 270; |
| 185 |
dirStore = true; |
| 186 |
} |
| 187 |
if (autowalk_direction == "up") |
| 188 |
{ |
| 189 |
direction = 90; |
| 190 |
dirStore = true; |
| 191 |
} |
| 192 |
} |
| 193 |
else |
| 194 |
{ |
| 195 |
if (direction == 0) |
| 196 |
{ |
| 197 |
if (autowalk_direction != "right") |
| 198 |
dirStore = false; |
| 199 |
if (autowalk_direction == "left") |
| 200 |
direction = 180; |
| 201 |
if (hsp == 0 && vsp != 0) |
| 202 |
{ |
| 203 |
if (autowalk_direction == "up") |
| 204 |
direction = 90; |
| 205 |
if (autowalk_direction == "down") |
| 206 |
direction = 270; |
| 207 |
} |
| 208 |
} |
| 209 |
if (direction == 90) |
| 210 |
{ |
| 211 |
if (autowalk_direction == "up") |
| 212 |
dirStore = false; |
| 213 |
if (vsp == 0 && hsp != 0) |
| 214 |
{ |
| 215 |
if (autowalk_direction == "left") |
| 216 |
direction = 180; |
| 217 |
if (autowalk_direction == "right") |
| 218 |
direction = 0; |
| 219 |
} |
| 220 |
} |
| 221 |
if (direction == 180) |
| 222 |
{ |
| 223 |
if (autowalk_direction != "left") |
| 224 |
dirStore = false; |
| 225 |
if (hsp == 0 && vsp != 0) |
| 226 |
{ |
| 227 |
if (autowalk_direction == "up") |
| 228 |
direction = 90; |
| 229 |
if (autowalk_direction == "down") |
| 230 |
direction = 270; |
| 231 |
} |
| 232 |
} |
| 233 |
if (direction == 270) |
| 234 |
{ |
| 235 |
if (autowalk_direction != "down") |
| 236 |
dirStore = false; |
| 237 |
if (autowalk_direction == "up") |
| 238 |
direction = 90; |
| 239 |
if (vsp == 0 && hsp != 0) |
| 240 |
{ |
| 241 |
if (autowalk_direction == "left") |
| 242 |
direction = 180; |
| 243 |
if (autowalk_direction == "right") |
| 244 |
direction = 0; |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
} |