3d arcade simulator of space ship. Collected from different examples. Thanks to all who helped to understand this complex programming language
// Project: space
// Created: 2018-08-21
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "space" )
SetWindowSize( 1024, 512, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 512 ) // 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
global newgame1 `` image new game
global newgame2 `` sprite newgame
global exit1 `` image exit
global exit2 `` sprite exit
global cursor1 `` image cursor
global cursor2 `` sprite cursor
global game `` if game started
global hudnofire1 `` hud image
global hudfire1 `` hud image
global hudnofire2 ``hud sprite
global hudfire2 `` hud sprite
dim ufoammo[20]
dim time[20]
// enable the sky box
SetSkyBoxVisible( 1 )
SetAmbientColor( 128,128,128 )
// add some atmospheric fog
SetFogMode( 1 )
SetFogColor( 161,183,209 )
SetFogRange( 50, 700 )
SetFogSunColor( 255,230,179 )
SetSkyBoxHorizonColor( 0, 0, 0 )
SetSkyBoxSkyColor( 0, 0, 0 )
spacebox=CreateObjectBox( 1000, 1000, 1000 )
spaceimage=loadImage("space\space-stars-1.png")
SetObjectImage( spacebox, spaceimage, 0 )
SetObjectPosition( spacebox, 100000, 0, 100000 )
SetObjectCullMode(spacebox,0)
SetObjectAlphaMask( spacebox, 1 )
target=CreateObjectBox(1,1,1)
SetObjectVisible( target, 0 )
// make enemy force
ufo=CreateObjectPlane( 20, 20 )
ufoimage=loadImage("ufo\ufo-1.png")
SetObjectImage( ufo, ufoimage, 0 )
SetObjectCullMode(ufo,0)
SetObjectAlphaMask( ufo, 1 )
SetCameraPosition( 1, 100000, 0, 100000 )
SetObjectPosition( ufo, GetCameraX(1)+100, GetCameraY(1), GetCameraZ(1)+100 )
SetObjectLookAt(ufo,GetCameraX(1),GetCameraY(1),GetCameraZ(1),0)
loadmenu()
loadammoufo()
do
if game =1
alfaufo=alfaufo+1
if alfaufo>360 then alfaufo=alfaufo-360
SetObjectPosition( ufo, GetCameraX(1)+150*cos(alfaufo), GetCameraY(1)+200*cos(alfaufo)*sin(alfaufo), GetCameraZ(1)+150*sin(alfaufo) )
SetSpriteVisible ( exit2, 0 )
SetSpriteVisible ( newgame2, 0 )
SetSpriteVisible ( hudnofire2, 1 )
SetSpriteVisible ( hudfire2, 0 )
// move the camera
speed# = 1.0
if ( GetRawKeyState( 16 ) ) then speed# = 0.1
if ( GetRawKeyState( 87 ) ) then MoveCameraLocalZ( 1, speed# )
if ( GetRawKeyState( 83 ) ) then MoveCameraLocalZ( 1, -speed# )
if ( GetRawKeyState( 65 ) ) then MoveCameraLocalX( 1, -speed# )
if ( GetRawKeyState( 68 ) ) then MoveCameraLocalX( 1, speed# )
if ( GetRawKeyState( 81 ) ) then MoveCameraLocalY( 1, -speed# )
if ( GetRawKeyState( 69 ) ) then MoveCameraLocalY( 1, speed# )
// rotate the camera
SetRawMousePosition( 1024/2, 768/2 )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
Print( ScreenFPS() )
sync()
fDiffX# = (GetRawMouseX() - startx#)/4.0
fDiffY# = (GetRawMouseY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
if rew>10000000
SetObjectPosition( ufo, GetCameraX(1)+500-Random(0,1000), GetCameraY(1)+500-Random(0,1000), GetCameraZ(1)+500-Random(0,1000) )
SetObjectLookAt(ufo,GetCameraX(1),GetCameraY(1),GetCameraZ(1),0)
rew=0
endif
rew=rew+1
SetObjectLookAt(ufo,GetCameraX(1),GetCameraY(1),GetCameraZ(1),0)
ufoangle#=GetCameraAngleY(1)
xufo#=GetObjectX( ufo )
yufo#=GetObjectY( ufo )
zufo#=GetObjectZ( ufo )
camx#=GetCameraX( 1 )
camy#=GetCameraY( 1 )
camz#=GetCameraZ( 1 )
gipotez#=abs(sqrt((xufo#-camx#)^2+(zufo#-camz#)^2))
if xufo#=>camx# and zufo#>=camz# then alfa1#=0
if xufo#<camx# and zufo#>camz# then alfa1#=90
if xufo#<camx# and zufo#<camz# then alfa1#=180
if xufo#>camx# and zufo#<camz# then alfa1#=270
MoveCameraLocalZ( 1, 10 )
SetObjectPosition( target,GetCameraX(1),GetCameraY(1),GetCameraZ(1))
MoveCameraLocalZ( 1, -10 )
SetCameraLookAt( 1, GetObjectX(ufo), GetObjectY(ufo), GetObjectZ(ufo), 0 )
angy1# = GetCameraAngleY(1)
SetCameraLookAt( 1, GetObjectX(target), GetObjectY(target), GetObjectZ(target), 0 )
DrawEllipse( cos(angy1#-angy#-90)*(gipotez#)+1024/2, sin(angy1#-angy#-90)*(gipotez#)+768/2, 5, 5, 255, 255, 0 )
Print( ScreenFPS() )
print (angy1#-angy# )
print (GetObjectX( ufo ) )
print (GetObjectY( ufo ) )
print (GetObjectZ( ufo ) )
print (aaa)
print ( GetCameraX(1))
print (GetCameraY(1))
print (GetCameraZ(1))
endif
if game=0 then menuwork()
if GetRawKeyPressed(27)=1 then game=0
if game=1
alo=alo+1
if alo>20
alo=0
for aaa=1 to 20
if time[aaa]<1
SetObjectPosition( ufoammo[aaa],GetObjectX(ufo), GetObjectY(ufo), GetObjectZ(ufo))
SetObjectLookAt( ufoammo[aaa],GetCameraX(1),GetCameraY(1),GetCameraZ(1), 0 )
SetObjectVisible( ufoammo[aaa], 1 )
time[aaa]=200
goto _labelexitloop
endif
next aaa
endif
_labelexitloop:
endif
for aaa=1 to 20
if time[aaa]<1 then SetObjectVisible( ufoammo[aaa], 0 )
if getobjectvisible(ufoammo[aaa])=1
time[aaa]=time[aaa]-1
MoveObjectLocalZ( ufoammo[aaa], 10 )
endif
next aaa
Sync()
loop
function loadammoufo()
for a=1 to 20
ufoammo[a]=CreateObjectSphere( 1, 5, 5 )
next a
endfunction
function loadmenu()
hudnofire1=loadImage("hud\Cockpit1.png")
hudfire1=loadImage("hud\Cockpit2.png")
newgame1=loadImage("menu\newgame.png")
exit1=loadImage("menu\exit.png")
cursor1=loadimage("menu\cursor.png")
newgame2=createsprite(newgame1)
exit2=createsprite(exit1)
cursor2=createsprite(cursor1)
hudnofire2=createsprite(hudnofire1)
hudfire2=createsprite(hudfire1)
SetSpriteVisible ( hudnofire2, 0 )
SetSpriteVisible ( hudfire2, 0 )
SetSpriteVisible ( cursor2, 0 )
SetSpritePosition(hudnofire2,(1024-1152)/2 ,512-256 )
SetSpritePosition(hudfire2,(1024-1152)/2 ,512-256 )
endfunction
function menuwork()
SetSpriteVisible ( exit2, 1 )
SetSpriteVisible ( newgame2, 1 )
SetSpriteVisible ( hudnofire2, 0 )
SetSpriteVisible ( hudfire2, 0 )
SetSpritePosition(newgame2, 500, 100)
SetSpritePosition(exit2, 500, 300)
SetSpritePosition(cursor2,GetRawMouseX() ,GetRawMouseY() )
if GetSpriteCollision( newgame2, cursor2 ) =1 and GetRawMouseLeftPressed()=1 then game=1
if GetSpriteCollision( exit2, cursor2 ) =1 and GetRawMouseLeftPressed()=1
DeleteAllSprites()
deleteallimages()
deleteallobjects()
end
endif
endfunction
programming is a hobby, not a job.