You can't load new game logic from a file (not in Tier 1 at least). To do what you want, you would have to use a separate game loop for each minigame. This requires structuring your entire project so as to support minigames. There are a few different ways to structure your project (such as the example posted by Supertino above). However I do it like this:
main.agc
#include "menu.agc"
#include "minigame1.agc"
#include "minigame2.agc"
global gamestate=0
gamestate=1 //1 =menu, 2=first minigame, 3 = second minigame, 4 = exit
do
select gamestate
case 1
menu()
endcase
case 2
mini1()
endcase
case 3
mini2()
endcase
case 4
exit
endcase
endselect
loop
end
minigame1.agc
function mini1()
gamestate=0
//LOAD LEVEL LAYOUT ETC HERE
repeat
//DO GAME LOGIC for minigame 1 HERE
print("Minigame 1!!!")
print("Tap screen to go back to menu")
if GetPointerReleased() then gamestate=1 //return to menu
sync()
until(gamestate<>0)
//DELETE ALL LEVEL SPRITES AND RESET VARIABLES HERE
endfunction //when the function ends, you return to the loop in main.agc which will then call menu() (since we set gamestate to 1)
minigame2.agc
function mini2()
gamestate=0
//LOAD LEVEL LAYOUT ETC HERE
repeat
//DO GAME LOGIC for minigame 2 HERE
print("Minigame 2!!!")
print("Tap screen to go back to menu")
if GetPointerReleased() then gamestate=1 //return to menu
sync()
until(gamestate<>0)
//DELETE ALL LEVEL SPRITES AND RESET VARIABLES HERE
endfunction //when the function ends, you return to the loop in main.agc which will then call menu() (since we set gamestate to 1)
menu.agc
function menu()
gamestate=0
//LOAD menu LAYOUT ETC HERE
repeat
//DO menu logic here (handle input etc
print("Game menu. ESC to exit, LEFT click for minigame 1, RIGHT click for minigame 2")
if GetRawMouseLeftReleased() then gamestate=2
if GetRawMouseRightReleased() then gamestate=3
if GetRawKeyReleased(27) then gamestate=4
sync()
until(gamestate<>0)
//DELETE ALL LEVEL SPRITES AND RESET VARIABLES HERE
endfunction //when the function ends, you return to the loop in main.agc which will then call menu() (since we set gamestate to 1)
Basically in your main.agc, you forever loop and call the next screen to go to (eg
menu()).
Each of your screens (or minigames) contains 3 parts:
1. Loading code (where you load sprites/set variables)
2. Main loop (includes sync() and any game logic/handling input etc)
3. Closing code (where you delete all sprites/reset variables etc)
You set the variable
gamestate to 0 in the loading code and exit the loop when it changes to something else (signifying that you want to change screens). Once the function ends, program flow will return to main.agc where the select game will check
gamestate and direct you to the next screen (or exit the program).
I use this game structure for all my projects. It lets you easily jump around between screens/levels etc simply by modifying the variable [i]gamestate[i].