I had a look at your code, that's a pretty good start so far.
Here's a brief example of a maze game where the next level is initiated when the player hits the red cube. Use arrow keys to move, you're the green sphere:
sync on
sync rate 60
gosub initiate_stuff
rem main loop
do
gosub start_game
rem play game loop
repeat
gosub load_level
repeat
gosub move_player
gosub hud
sync
until current_game_state = game_state_level_over
gosub delete_level
gosub manage_game_state
until current_game_state = game_state_game_over
loop
end
initiate_stuff:
rem put anything that is fixed throughout the game here
rem game states
game_state_play_game = 1
game_state_level_over = 2
game_state_game_over = 3
rem how many levels are there
max_number_of_levels = 3
rem load player object
player_obj = 101
make object sphere player_obj, 20,16,16
color object player_obj, rgb(0,255,0)
rem load end marker object
end_marker_obj = 102
make object cube end_marker_obj, 30
color object end_marker_obj, rgb(255,0,0)
return
start_game:
rem put anything here that needs to be reset at the start of the game here
rem set the current level to zero
current_level = 0
return
load_level:
rem increment the current level
inc current_level
select current_level
case 1
restore level_1
endcase
case 2
restore level_2
endcase
case 3
restore level_3
endcase
endselect
rem this holds the number of cubes that makes up the map
number_of_walls = 0
rem read the level data and construct the level
for z = 0 to 6
for x = 0 to 6
read value
rem either position a wall, the player or the end marker
select value
rem create and position a cube to act as a wall for the maze
case 1
inc number_of_walls
make object cube number_of_walls, 40
position object number_of_walls, x*40,25,z*40
endcase
rem position the player
case 2
position object player_obj, x*40,10,z*40
endcase
rem position end marker object
case 3
position object end_marker_obj, x*40,15,z*40
endcase
endselect
next x
next z
rem set the game state to play
current_game_state = game_state_play_game
return
move_player:
rem save old position
old_xpos# = object position x(player_obj)
old_zpos# = object position z(player_obj)
rem move the player
move object player_obj, (upkey() - downkey())*3
move object right player_obj, (rightkey() - leftkey())*3
rem player collision
collide = object collision(player_obj,0)
if collide <> 0
rem if the player collides with a wall then put player at old position
if collide <= number_of_walls
position object player_obj, old_xpos#, 10, old_zpos#
endif
rem if the player collides with the end marker object then the level is over
if collide = end_marker_obj
current_game_state = game_state_level_over
endif
endif
rem position the camera
position camera object position X(player_obj), 200, object position Z(player_obj)
point camera object position X(player_obj), 0, object position Z(player_obj)
return
hud:
set cursor 0,0
print "current_level : ", current_level
print "current_game_state : ", current_game_state
return
delete_level:
rem delete all the cubes that make up the level
for i = 1 to number_of_walls
delete object i
next i
return
manage_game_state:
if current_level => max_number_of_levels
current_game_state = game_state_game_over
endif
return
rem level data
level_1:
data 1,1,1,1,1,1,1
data 1,0,0,3,0,0,1
data 1,0,0,0,0,0,1
data 1,0,0,0,0,0,1
data 1,0,0,0,0,0,1
data 1,0,0,2,0,0,1
data 1,1,1,1,1,1,1
level_2:
data 1,1,1,1,1,1,1
data 1,0,0,0,1,3,1
data 1,0,1,0,1,0,1
data 1,0,1,0,1,0,1
data 1,0,1,0,1,0,1
data 1,2,1,0,0,0,1
data 1,1,1,1,1,1,1
level_3:
data 0,0,1,1,1,1,1
data 0,0,1,2,0,0,1
data 1,1,1,1,1,0,1
data 1,0,0,0,0,0,1
data 1,0,1,1,1,1,1
data 1,0,0,3,1,0,0
data 1,1,1,1,1,0,0
I hope this gives you some ideas.