To be honest, I don't know how your code works. Therefore, I will do my own thing with sprites.
// Project: interceptors
// Created: 2022-08-11
// show all errors
SetErrorMode(2)
Global GlobalHeight
GlobalHeight=GetMaxDeviceHeight ()
Global GlobalWidth
GlobalWidth=GetMaxDeviceWidth ()
// set window properties
SetWindowTitle( "interceptors" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
SetWindowSize( GlobalWidth, GlobalHeight, 1 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( GlobalWidth, GlobalHeight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
shadowMode = 3 // start with cascade shadow mapping which gives the best quality
SetShadowMappingMode( shadowMode )
SetShadowSmoothing( 2 ) // random sampling
SetShadowMapSize( 1024, 1024 )
SetShadowRange( -1 ) // use the full camera range
setcameraposition(1,0,0,500)
SetCameraLookAt( 1, 0, 0, 0, 0 )
`--------------------------------------------------------------
rem place the button in the centre of the screen..
global x
global y
x=GlobalWidth/2
y=GlobalHeight/2
global cursor
cursor=loadsprite("cursor.png")
global music
global sound
sound=loadsound("main_menu/Ok.wav")
music=loadmusic("main_menu/Space01.mp3")
PlayMusic( music, 1 )
#include "button_code.agc"
#include "main_menu.agc"
load_button()
for t=1 to 7
SetSpritePosition( button_up[t], x, y+(t-1)*32)
SetSpritePosition( button_down[t], x,y+(t-1)*32 )
setspritevisible(button_down[t],0)
next t
SetSpritePosition( button_up[8], x, y+(t-1-1-1-1)*32)
SetSpritePosition( button_down[8], x,y+(t-1-1-1-1)*32 )
setspritevisible(button_down[8],0)
setspritevisible(button_up[8],0)
SetSpritePosition( button_up[9], x, y+(t-1-1-1)*32)
SetSpritePosition( button_down[9], x,y+(t-1-1-1)*32 )
setspritevisible(button_down[9],0)
setspritevisible(button_up[9],0)
global volume_music=100
global volume_sound=100
global main_menu=1
global menu_save=0
global menu_load=0
global game=0
global start=0
global resume=0
_main_menu1:
do
if main_menu=1 then main_main_menu()
if menu_save=1 then main_save_menu()
if menu_load=1 then main_load_menu()
sync()
loop
function main_main_menu()
SetSpritePosition( cursor, getpointerx(),getpointery())
rem выход
if getspritecollision(cursor,button_up[7]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
end
endif
rem возврат в игру
if getspritecollision(cursor,button_up[1]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
game=1
resume=1
endif
rem старт игры
if getspritecollision(cursor,button_up[2]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
game=1
start=1
endif
rem загрузка игры
if getspritecollision(cursor,button_up[3]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
main_menu=0
menu_save=0
menu_load=1
for t=1 to 7
setspritevisible(button_down[t],0)
setspritevisible(button_up[t],0)
next t
for t=1 to 11
setspritevisible(button_load_down[t],0)
setspritevisible(button_load_up[t],1)
next t
endif
rem сохранение игры
if getspritecollision(cursor,button_up[4]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
main_menu=0
menu_save=1
menu_load=0
for t=1 to 7
setspritevisible(button_save_down[t],0)
setspritevisible(button_save_up[t],0)
next t
for t=1 to 11
setspritevisible(button_save_down[t],0)
setspritevisible(button_save_up[t],1)
next t
endif
rem включение выключение музыки
if getspritecollision(cursor,button_up[5]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
if volume_music>0
volume_music=0
setspritevisible(button_up[5],0)
setspritevisible(button_down[5],0)
setspritevisible(button_down[8],1)
setspritevisible(button_up[8],1)
StopMusic()
else
volume_music=100
setspritevisible(button_up[5],1)
setspritevisible(button_down[5],1)
setspritevisible(button_down[8],0)
setspritevisible(button_up[8],0)
PlayMusic( music, 1 )
endif
endif
rem включение выключение звука
if getspritecollision(cursor,button_up[6]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
if volume_sound>0
volume_sound=0
setspritevisible(button_up[6],0)
setspritevisible(button_down[6],0)
setspritevisible(button_down[9],1)
setspritevisible(button_up[9],1)
else
volume_sound=100
setspritevisible(button_up[6],1)
setspritevisible(button_down[6],1)
setspritevisible(button_down[9],0)
setspritevisible(button_up[9],0)
endif
endif
for t=1 to 4
if GetSpriteCollision( cursor, button_up[t] )=1
setspritevisible(button_down[t],1)
setspritevisible(button_up[t],0)
else
setspritevisible(button_down[t],0)
setspritevisible(button_up[t],1)
endif
next t
rem музыка включена
if volume_music>0
if GetSpriteCollision( cursor, button_up[5] )=1
setspritevisible(button_down[5],1)
setspritevisible(button_up[5],0)
else
setspritevisible(button_down[5],0)
setspritevisible(button_up[5],1)
endif
endif
rem
if volume_music=0
if GetSpriteCollision( cursor, button_up[8] )=1
setspritevisible(button_down[8],1)
setspritevisible(button_up[8],0)
else
setspritevisible(button_down[8],0)
setspritevisible(button_up[8],1)
endif
endif
rem звук включен
if volume_sound>0
if GetSpriteCollision( cursor, button_up[6] )=1
setspritevisible(button_down[6],1)
setspritevisible(button_up[6],0)
else
setspritevisible(button_down[6],0)
setspritevisible(button_up[6],1)
endif
endif
rem
if volume_sound=0
if GetSpriteCollision( cursor, button_up[9] )=1
setspritevisible(button_down[9],1)
setspritevisible(button_up[9],0)
else
setspritevisible(button_down[9],0)
setspritevisible(button_up[9],1)
endif
endif
rem выход
if GetSpriteCollision( cursor, button_up[7] )=1
setspritevisible(button_down[7],1)
setspritevisible(button_up[7],0)
else
setspritevisible(button_down[7],0)
setspritevisible(button_up[7],1)
endif
endfunction
function main_save_menu()
SetSpritePosition( cursor, getpointerx(),getpointery())
rem возврат в меню игры
if getspritecollision(cursor,button_save_up[1]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
main_menu=1
menu_save=0
menu_load=0
for t=1 to 7
setspritevisible(button_down[t],0)
setspritevisible(button_up[t],1)
next t
for t=1 to 11
setspritevisible(button_save_down[t],0)
setspritevisible(button_save_up[t],0)
next t
endif
if main_menu=0
for t=1 to 11
if GetSpriteCollision( cursor, button_save_up[t] )=1
setspritevisible(button_save_down[t],1)
setspritevisible(button_save_up[t],0)
else
setspritevisible(button_save_down[t],0)
setspritevisible(button_save_up[t],1)
endif
next t
endif
endfunction
function main_load_menu()
SetSpritePosition( cursor, getpointerx(),getpointery())
rem возврат в меню игры
if getspritecollision(cursor,button_load_up[1]) and GetPointerPressed()=1 and GetSoundsPlaying( sound ) =0
PlaySound( sound, volume_sound, 0 )
sleep(200)
main_menu=1
menu_save=0
menu_load=0
for t=1 to 7
setspritevisible(button_down[t],0)
setspritevisible(button_up[t],1)
next t
for t=1 to 11
setspritevisible(button_load_down[t],0)
setspritevisible(button_load_up[t],0)
next t
endif
if main_menu=0
for t=1 to 11
if GetSpriteCollision( cursor, button_load_up[t] )=1
setspritevisible(button_load_down[t],1)
setspritevisible(button_load_up[t],0)
else
setspritevisible(button_load_down[t],0)
setspritevisible(button_load_up[t],1)
endif
next t
endif
endfunction
function load_button()
rem главное меню
dim name$[9] as string = [ ""," Return", " Start", " Load" ," Save"," Music ON"," Sound ON"," Exit"," Music OFF"," Sound OFF"]
dim button_up[9]
dim button_down[9]
for t=1 to 9
creatbutton(0,0,196,22,2)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name$[t])
render()
image=GetImage(0,0,196,22)
button_up[t]=createsprite(image)
sync()
SetSpritePosition( button_up[t], 32+196+196, (t-1)*32)
creatbutton(0,0,196,22,1)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name$[t])
render()
image=GetImage(0,0,196,22)
button_down[t]=createsprite(image)
sync()
SetSpritePosition( button_down[t], 196,(t-1)*32 )
next t
rem загрузка игры
dim name_load$[11] as string = [ ""," Return", " Load 1", " Load 2" ," Load 3"," Load 4"," Load 5"," Load 6"," Load 7"," Load 8"," Load 9"," Load 10"]
dim button_load_up[11]
dim button_load_down[11]
for t=1 to 11
creatbutton(0,0,196,22,2)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name_load$[t])
render()
image=GetImage(0,0,196,22)
button_load_up[t]=createsprite(image)
sync()
SetSpritePosition( button_load_up[t], 32+196+196, (t-1)*32)
setspritevisible(button_load_up[t],0)
creatbutton(0,0,196,22,1)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name_load$[t])
render()
image=GetImage(0,0,196,22)
button_load_down[t]=createsprite(image)
sync()
SetSpritePosition( button_load_down[t], 196,(t-1)*32 )
setspritevisible(button_load_down[t],0)
SetSpritePosition( button_load_up[t], x, y+(t-1)*32)
SetSpritePosition( button_load_down[t], x,y+(t-1)*32 )
next t
rem сохранение игры
rem загрузка игры
dim name_save$[11] as string = [ ""," Return", " Load 1", " Load 2" ," Load 3"," Load 4"," Load 5"," Load 6"," Load 7"," Load 8"," Load 9"," Load 10"]
dim button_save_up[11]
dim button_save_down[11]
for t=1 to 11
creatbutton(0,0,196,22,2)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name_save$[t])
render()
image=GetImage(0,0,196,22)
button_save_up[t]=createsprite(image)
sync()
SetSpritePosition( button_save_up[t], 32+196+196, (t-1)*32)
setspritevisible(button_save_up[t],0)
creatbutton(0,0,196,22,1)
SetPrintColor( 0, 200, 0 )
SetPrintSize( 22 )
print(name_save$[t])
render()
image=GetImage(0,0,196,22)
button_save_down[t]=createsprite(image)
sync()
SetSpritePosition( button_save_down[t], 196,(t-1)*32 )
setspritevisible(button_save_down[t],0)
SetSpritePosition( button_save_up[t], x, y+(t-1)*32)
SetSpritePosition( button_save_down[t], x,y+(t-1)*32 )
next t
endfunction
function creatbutton(x,y,width,height,tipe)
rem set-up colour palette, for this program
white=MakeColor(255,255,255)
black=0
grey=MakeColor(192,192,192)
yellow=MakeColor(255,255,0)
darkgrey=MakeColor(104,100,128)
bc=width/2
select tipe
case 2
rem draw preselected button
` ink black,black
` box x,y,(x+width),(y+height)
DrawBox( x, y, x+width, y+height, 0, 0, 0, 0, 1 )
`` ink white,black
` box x+1,y+1,(x+width)-2,(y+height)-2
DrawBox( x+1,y+1,(x+width)-2,(y+height)-2, white, white, white, white, 1 )
` ink black,black
` box x+2,(y)+2,(x+width)-1,(y+height)-1
DrawBox( x+2,(y)+2,(x+width)-1,(y+height)-1, 0, 0, 0, 0, 1 )
` ink grey,black
` box x+2,(y+2),(x+width)-2,(y+height)-2
DrawBox( x+2,(y+2),(x+width)-2,(y+height)-2, grey, grey, grey, grey, 1 )
rem ink text colour to yellow,
`ink yellow,grey
endcase
case 1
rem draw standard button
`` ink black,black
` box x,y,(x+width)-1,(y+height)-1
DrawBox( x,y,(x+width)-1,(y+height)-1, 0, 0, 0, 0, 1 )
` ink white,black
` box x+1,(y)+1,x+width,(y+height)
DrawBox( x+1,(y)+1,x+width,(y+height), white, white, white, white, 1 )
` ink darkgrey,black
` box x+1,(y+1),(x+width)-1,(y+height)-1
DrawBox( x+1,(y+1),(x+width)-1,(y+height)-1, darkgrey, darkgrey, darkgrey, darkgrey, 1 )
rem ink text colour to yellow,
` ink yellow,darkgrey
endcase
endselect
endfunction
programming is a hobby, not a job.
P.S. in google and youtube - nikename pavelman- it is not me!