When I compile and run the game, it sometimes just shows a black screen. Its about every ten times or so. Does anyone have a clue why?
// Project: TOWER GENERATOR
// Created: 2017-11-29 by Kasper
// set window properties
// Set some display properties
SetScissor( 0,0,0,0 )
SetWindowSize( 1024, 1024, 1 )
SetAntialiasMode( 1 ) // 1=4xMSAA
SetVSync( 1 )
//Set Text size and color as displayed to screen.
SetPrintSize( 30.0 )
SetPrintColor( 245, 245, 0 )
UseNewDefaultFonts( 1 )
//Set the error reporting for debugging.
SetErrorMode( 2 )
#constant FALSE = 0
#constant TRUE = 1
/***************************************
Simple world stuff
***************************************/
//Set Backdrop color
SetClearColor( 0,170,204 ) // light blue
SetSkyBoxVisible(1)
SetSkyBoxSunColor( 255, 255, 255 )
SetSkyBoxHorizonColor( 72, 103, 138 )
SetSkyBoxSkyColor( 121, 152, 190 )
SetSkyBoxSunVisible (1)
SetSunActive (1)
//SetSunDirection( 0.78, 0.50, 0.37 )
setSunColor(255, 255, 255)
SetAmbientColor( 15, 15, 15)
SetShadowMappingMode( 3 )
SetShadowSmoothing( 1 ) // random sampling
SetShadowMapSize( 2048, 2048 )
SetShadowRange( 30 ) // 30 meters
SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
//Set Lighting
CreatePointLight( 1, 0, 200, 0, 1000, 255, 255, 255 )
SetAmbientColor( 0, 20, 20 )
/***************************************
Camera
***************************************/
//Set camera
SetCameraRange( 1, 0.1, 50000 )
SetCameraFOV( 1, 90 ) // 70 is the default, 0 is orthographic view
SetCameraPosition( 1, 1, 2.5, 0.0 )
/***************************************
Physics
***************************************/
Create3DPhysicsWorld (1) // 40 is default
Set3DPhysicsGravity( 0, -10, 0)
/*===============================================================================
BRICKS
===============================================================================*/
Global brickWidth as Float = 0.110
Global brickHeight as Float = 0.076
Global brickLength as Float = 0.230
Global brickSpacing as Float = 0.05 // Spacing between bricks
Global rndRotationY as Float = 0.01
Global rndOffset as Float = 0.02 // How much the bricks sticks out from the wall
Type BrickType
does_brick_exist as Integer
Health as Integer
Mesh as Integer
Dif as Integer
Nrm as Integer
BirthDate as float
EndType
Brick_Mesh = CreateObjectBox (brickWidth, brickHeight, brickLength)
SetObjectColor(Brick_Mesh, 255, 230, 240, 255)
SetObjectColorEmissive (Brick_Mesh, 20, 0, 10)
SetObjectVisible (Brick_Mesh, 0)
SetObjectCollisionMode (Brick_Mesh, 0)
SetObjectScreenCulling (Brick_Mesh, 0)
global Brick as BrickType[50]
// CREATE ALL BRICKS
For E = 0 to Brick.length
Brick[E].does_brick_exist = 0
Brick[E].Health = 0
Brick[E].birthDate = Timer()
Brick[E].Mesh = cloneObject (Brick_Mesh)
setObjectPosition (Brick[E].Mesh, 0, 0, 0)
//SetObjectImage(Brick[E].Mesh, EnemyDif, 0)
//SetObjectNormalMap(Brick[E].Mesh, EnemyNrm)
SetObjectVisible (Brick[E].Mesh, 0)
SetObjectCollisionMode (Brick[E].Mesh, 0)
SetObjectScreenCulling (Brick[E].Mesh, 0)
SetObjectFogMode (Brick[E].Mesh, 0)
SetObjectCastShadow (Brick[E].Mesh, 1)
next
/*===============================================================================
FLOOR
===============================================================================*/
floorBox = createobjectPlane(32.0, 32.0)
SetObjectRotation (floorbox, 90.0, 0.0, 0.0)
setobjectposition ( floorBox, 0.0, 0.0, 0.0)
SetObjectColor(floorBox, 100, 120, 130, 255)
Create3DPhysicsStaticBody (floorBox)
for mkBricks = 1 to 20
SpawnBrick (0.0, brickHeight/2, brickLength*mkBricks)
next
do
/***************************************
Exit with ESCAPE
***************************************/
if GetRawKeyPressed( 27 )
End
endif
ControlCamera()
Step3DPhysicsWorld()
Sync()
loop
End
/*===============================================================================
FUNCTIONS
===============================================================================*/
function rndFloat (numberA as float, numberB as float)
result = random(numberA*1000, numberB*1000) / 1000
endfunction result
function SpawnBrick( SpawnX as Float, SpawnY as Float, SpawnZ as Float)
// HEADHUNT THE FIRST UNEMPLOYED BRICK
E = 0
For OffStageBrick = 0 to Brick.length
If Brick[OffStageBrick].does_brick_exist = FALSE
E = OffStageBrick
exit
endif
next
Brick[E].does_brick_Exist = TRUE
Brick[E].Health = 100
setObjectPosition (Brick[E].Mesh, SpawnX, SpawnY, SpawnZ)
SetObjectVisible (Brick[E].Mesh, TRUE)
SetObjectCollisionMode (Brick[E].Mesh, TRUE)
SetObjectScreenCulling (Brick[E].Mesh, TRUE)
Create3DPhysicsDynamicBody(Brick[E].Mesh)
SetObjectShapeBox( Brick[E].Mesh )
SetObject3DPhysicsCanSleep( Brick[E].Mesh, 0 )
endfunction
function ControlCamera()
global startx#
global starty#
global angx#
global angY#
speed#=10*GetFrameTime()
// move the camera with keys
if GetKeyboardExists()=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# )
else
JoystickSize#=GetVirtualHeight()*0.25
SetJoystickScreenPosition(GetScreenBoundsLeft()+JoystickSize#*0.5,GetScreenBoundsBottom()-JoystickSize#*0.5,JoystickSize#)
MoveCameraLocalZ( 1, -GetJoystickY() * speed# )
MoveCameraLocalX( 1, GetJoystickX() * speed# )
endif
// rotate the camera
if GetPointerPressed()=1
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
endif
if GetPointerState()=1
fDiffX# = (GetPointerX() - startx#)
fDiffY# = (GetPointerY() - starty#)
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
// Stick to floor
//SetCameraPosition ( 1, getCameraX(1), 1.80, getCameraZ(1) )
endfunction