Bentley
Member
Edit solved: Sigh, what am I doing with my life.
Don't ask me why I'm posting this lol. This code is from a Pacman clone I just started.
Attempt to smoosh all the input code into one local variable declaration
I don't know why the direction defaults east "point_direction(0,0,0,0)" when I'd want it to default to the current direction. I thought I'd prevented that with the condition: max(kright + kleft…
None of what I wrote is intelligible. BUT, if anyone can dumb themselves down to my level, I'd be curious if there's a way to fix while staying true to the "cramming-it-in-one-variable-declaration" rule.
Don't ask me why I'm posting this lol. This code is from a Pacman clone I just started.
Code:
// Stack current direction
ds_stack_push(global.stack, dir);
// Get input
var dx, dy;
switch (keyboard_key)
{
case kright:
{
dx = 1;
dy = 0;
}
break;
case kleft:
{
dx = -1;
dy = 0;
}
break;
case kdown:
{
dx = 0;
dy = 1;
}
break;
case kup:
{
dx = 0;
dy = -1;
}
break;
default:
{
dx = lengthdir_x(1, dir);
dy = lengthdir_y(1, dir);
}
break;
}
// Stack new direction
var new_dir = point_direction(0, 0, dx, dy);
if (new_dir != dir)
{
ds_stack_push(global.stack, new_dir);
}
// Loop through stack, try up to 2 directions: new first, old second
repeat (ds_stack_size(global.stack))
{
var _dir = ds_stack_pop(global.stack);
dx = lengthdir_x(1, _dir);
dy = lengthdir_y(1, _dir);
if (!check_collision(dx, dy))
{
x += dx;
y += dy;
dir = _dir;
break;
}
}
ds_stack_clear(global.stack);
Attempt to smoosh all the input code into one local variable declaration
Code:
// Get input
var new_dir = (
/* no input */
max(keyboard_check(kright) + keyboard_check(kleft) + keyboard_check(kdown) + keyboard_check(kup)) == 0
||
/* Same direction */
point_direction(0, 0, keyboard_check(kright) - keyboard_check(kleft), (keyboard_check(kdown) - keyboard_check(kup)) * (keyboard_check(kright) - keyboard_check(kleft) == 0 ? 1 : 0)) == dir
?
/* new_dir = dir */
dir :
/* Otherwise, you have a new dir */
point_direction(0, 0, keyboard_check(kright) - keyboard_check(kleft), (keyboard_check(kdown) - keyboard_check(kup)) * (keyboard_check(kright) - keyboard_check(kleft) == 0 ? 1 : 0))
);
None of what I wrote is intelligible. BUT, if anyone can dumb themselves down to my level, I'd be curious if there's a way to fix while staying true to the "cramming-it-in-one-variable-declaration" rule.
Last edited: