A
Albumm
Guest
I'm trying to develop a grid-based roguelike engine and the step code for obj_player looks like this so far:
Script: p_survey_move:
Script: p_attempt_move:
Scripts so far:
Am I adding too many function scripts? Will this lead to problems later on in development? My first attempt at this engine became unreadable spaghetti code after a few weeks, so I'm trying to structure it better.
Code:
p_get_controls(); //saves keyboard_check -> key_x
if isSnappedToGrid() //return place_snapped(global.gridSize,global.gridSize);
stop_moving(); //motion_set(0,0);
if (isPlayersTurn() && isSnappedToGrid())
{
p_survey_move();
}
Script: p_survey_move:
Code:
if ((key_up) && (key_right))
p_attempt_move(DIR_UPRIGHT, spr_player_upright); //DIR_UPRIGHT = 45
else if ((key_up) && (key_left))
p_attempt_move(DIR_UPLEFT, spr_player_upleft); //DIR_UPLEFT = 135
//...etc
Script: p_attempt_move:
Code:
grid_direction = argument0;
new_sprite = argument1;
pointingTowards_x = 0;
pointingTowards_y = 0;
switch(grid_direction)
{
case DIR_UPRIGHT:
pointingTowards_x = x+global.gridSize;
pointingTowards_y = y-global.gridSize;
break;
case DIR_UPLEFT:
pointingTowards_x = x-global.gridSize;
pointingTowards_y = y-global.gridSize;
break;
//...etc
}
if (current_sprite != new_sprite)
set_sprite(new_sprite);
if isUnblocked(pointingTowards_x,pointingTowards_y)
move_towards(grid_direction);
Code:
/player/
p_get_controls
p_survey_move
p_attempt_move
/global_get/
getDiagonalSpeed
isSnappedToGrid
isPlayersTurn
isMoving
isUnblocked
/global_set/
set_sprite
stop_moving
move_towards
Am I adding too many function scripts? Will this lead to problems later on in development? My first attempt at this engine became unreadable spaghetti code after a few weeks, so I'm trying to structure it better.