Hi, guys long time no see!
I have this problem with certain code i have where there is a lot of repetitions and i can not think of a way to put it in a function.
Some legend first:
plain is used to check which plain is in collision with the mouse
rotation is used to check if rotation is in progress
msxdif and msydif are mousex and mousey differences checked agains each other, if msxdif is bigger it's horizontal rotation and vise versa
group_object is selected object
msy and msx defines direction of rotation
rotations are processed by frames every frame rotates the group of objects with 18 degrees, fra is positive 5, frb is -5 frame if the game sees that frame is equal to fra or frb it stops rotation
last_rotation$ points what rotation is occuring for other part of the code
global rotation function rotates the objects in group
I need some elegant solution to the problem as i can't think of one.I can tell for myself that i'm not much refined programmer.And this is some really old code i wish to change but all the game logic revolves around it.
So let's present the problematic piece of code:
if rotation = 1 and msxdif > msydif
for i = 0 to 3
if group_object = orange_group(i)
if msx => 0 and frame < fra and msxdif > msydif
last_rotation$ = "Right Orange" : inc frame
for n = 0 to 3
global_rotate_y(orange_group(n),-angle) `CCW
next n
endif
if msx <= 0 and frame >frb and msxdif > msydif
last_rotation$ = "Left Orange" : dec frame
for n = 0 to 3
global_rotate_y(orange_group(n),angle) `CW
next n
endif
endif
next i
endif
if rotation = 1 and msxdif > msydif
for i = 0 to 3
if group_object = red_group(i)
if msx => 0 and frame < fra and msxdif > msydif
last_rotation$ = "Right Red" : inc frame
for n = 0 to 3
global_rotate_y(red_group(n),-angle) `CCW
next n
endif
if msx <= 0 and frame > frb and msxdif > msydif
last_rotation$ = "Left Red" : dec frame
for n = 0 to 3
global_rotate_y(red_group(n),angle) `CW
next n
endif
endif
next i
endif
if plain = 120
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = blue_group(i)
if msy => 0 and frame < fra and msxdif < msydif
last_rotation$ = "CCW Blue 120" : inc frame
for n = 0 to 3
global_rotate_x(blue_group(n),-angle) `CCW
next n
endif
if msy <= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CW Blue 120" : dec frame
for n = 0 to 3
global_rotate_x(blue_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 121
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = blue_group(i)
if msy =< 0 and frame < fra and msxdif < msydif
last_rotation$ = "CCW Blue 121" : inc frame
for n = 0 to 3
global_rotate_x(blue_group(n),-angle) `CCW
next n
endif
if msy >= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CW Blue 121" : dec frame
for n = 0 to 3
global_rotate_x(blue_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 122
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = green_group(i)
if msy => 0 and frame < fra and msxdif < msydif
last_rotation$ = "CW Green 122" : inc frame
for n = 0 to 3
global_rotate_x(green_group(n),-angle) `CCW
next n
endif
if msy <= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CCW Green 122" : dec frame
for n = 0 to 3
global_rotate_x(green_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 123
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = green_group(i)
if msy =< 0 and frame < fra and msxdif < msydif
last_rotation$ = "CW Green 123" : inc frame
for n = 0 to 3
global_rotate_x(green_group(n),-angle) `CCW
next n
endif
if msy >= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CCW Green 123" : dec frame
for n = 0 to 3
global_rotate_x(green_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 124
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = yellow_group(i)
if msy => 0 and frame < fra and msxdif < msydif
last_rotation$ = "CCW Yellow 124" : inc frame
for n = 0 to 3
global_rotate_z(yellow_group(n),angle) `CCW
next n
endif
if msy <= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CW Yellow 124" : dec frame
for n = 0 to 3
global_rotate_z(yellow_group(n),-angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 125
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = yellow_group(i)
if msy =< 0 and frame < fra and msxdif < msydif
last_rotation$ = "CW Yellow 125" : inc frame
for n = 0 to 3
global_rotate_z(yellow_group(n),angle) `CCW
next n
endif
if msy >= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CCW Yellow 125" : dec frame
for n = 0 to 3
global_rotate_z(yellow_group(n),-angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 126
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = white_group(i)
if msy => 0 and frame < fra and msxdif < msydif
last_rotation$ = "CCW White 126" : inc frame
for n = 0 to 3
global_rotate_z(white_group(n),-angle) `CCW
next n
endif
if msy <= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CW White 126" : dec frame
for n = 0 to 3
global_rotate_z(white_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
if plain = 127
if rotation = 1 and msxdif < msydif
for i = 0 to 3
if group_object = white_group(i)
if msy =< 0 and frame < fra and msxdif < msydif
last_rotation$ = "CW White 127" : inc frame
for n = 0 to 3
global_rotate_z(white_group(n),-angle) `CCW
next n
endif
if msy >= 0 and frame > frb and msxdif < msydif
last_rotation$ = "CCW White 127" : dec frame
for n = 0 to 3
global_rotate_z(white_group(n),angle) `CW
next n
endif
endif
next i
endif
endif
Coding is My Kung Fu!
And My Kung Fu is better than Yours!