Night Driving
1.Now with improved gyroscope usage and difficulty
2.Speedometer
3.Livestock
4.Improved visuals
5.Completely procedurally created
Video Preview
Full source no media required makes for a great template
//questions and comments https://forum.thegamecreators.com/thread/222010
#constant KEY_LEFT = 37 //the left arrow key scancode
#constant KEY_UP = 38 //the up arrow key scancode
#constant KEY_RIGHT = 39 //the right arrow key scancode
#constant KEY_DOWN = 40 //the down arrow key scancode
#constant KEY_A = 65 //the scan code for the "a" key
#constant KEY_Z = 90 //the scan code for the "z" key
#constant mapX=20 //maximum blocks on x plane CHANGE THIS TO MAKE ROAD NARROWER IE 20 WHICH WILL SPEED IT UP
#constant mapY=1 //maximum blocks on y plane
#constant mapZ=100 //maximum blocks on z plane
#constant xMaxResolution=1024
#constant yMaxResolution=768
#constant acceleration#=.05 //used to calclate the carSpeed#
#constant maxCarSpeed#=2.5 //The Maximum speed the carBlock will move
#constant textTitle=1 //the title text id
#constant textSpeed=2 //the speed text id
#constant textScore=3 //the score text id
#constant textLives=4 //the lives text id
#constant textFPS=5 // the fps text id
#constant textGameOver=6 //the game over text id
#constant textPlayAgain=7 //the Click to play again text id
#constant textHighScore=8 //the highscore text id
#constant textTopSpeed=9 //the top speed text id
#constant textHowFar=10 //the text how far can you go text id
#constant textCredit=11 //My Credit text id
#constant wireFrameTextureID =1
#constant gridTextureID =2
#constant speedoTextureID =3
#constant speedoNeedleTextureID =4
#constant sound1 =1
#constant sound2 =2
#constant cowStart=8000
//a quick run down is that the code creates all the posts and positions them on the x,y,z planes
//the movement of the car really just moves these posts once the post have reached so far off
//they start at the back again. So basically they make it never ending. There is a sinecurve that
//Is used to position them on the xplane. Cows etc move the same way and time that the posts
//do. The other car yes there is only one which starts at a distant z location calculates a vector
//to point it towards the centre of the road and moves at its own rate the same way the posts do.
//The cows on the road are always on the road the only thing that changes is a random factor that
//determines if they should be visible and collisions turned on. once they pass your car whether they
//are visible or not they are positioned back off to a distant z position some rotating and positioning
//again.
//There is a shader which uses camera offsets for the left eye and then the right eye to use the
//stereoscopic shader it needs to use Update(), Render(), Swap() to manually sync so when these
//commands are used which is only when the user presses the stereo button the sync is not called
//and they need to be done in the order as they are in code if you wish for stereoscopic 3D.
global speed# = 2.0 //the following for a sine curve to repesent hils on the yplane
global blockCount
global carBlock=10000 //carblock and carMem have the same referrence
global carMem=10000 //the carBlocks memblock id
global otherCarBlock=10006 //the otherCarblock and otherCarMem have the same referrence
global otherCarMem=10006 //the other carBlocks memblock id
global lives=3 //The actual lives of a player
global score=0 //holds the player score whiched is based on progression
global highScore=0 //holds the total high score for the day
global topSpeed#=0 //the maximun speed you have reached today
time#=timer() //holds the startTime for calculations of the sineCurve with the movements and used in calculating an acceleration curve
global offsetx as float //offsets the other car from the posta
dim blocksChanged[mapX*mapY*mapZ] as block
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Night Driving" )
SetWindowSize( xMaxResolution, yMaxResolution, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( xMaxResolution, yMaxResolution ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) // allow only 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
type vertex
xDirection as integer
yDirection as integer
zDirection as integer
endtype
type block
id as integer
xPosStart as integer
yPosStart as integer
zPosStart as integer
//the following used for my particle effect
xDirection as float
yDirection as float
zDirection as float
endtype
CreateSpeedoTexture(speedoTextureID)
CreateSprite(1,speedoTextureID)
SetSpritePosition(1,10,yMaxResolution-GetSpriteHeight(1))
CreateSpeedoNeedle(speedoNeedleTextureID)
CreateSprite(2,speedoNeedleTextureID)
SetSpritePosition(2,10,yMaxResolution-GetSpriteHeight(2))
createWireFrameTexture(wireFrameTextureID,32,32, makecolor(255,255,255))
createGridTexture(gridTextureID,32,32,4,4,makecolor(255,255,255))
num=1
for y = 1 to mapY
for x = 1 to mapX step mapX-1
for z = 1 to mapZ step 10
CreateObjectBox(num,1,4,1)
c=255:SetObjectColor(num,c,c,c,255)
//SetObjectImage(num,texture,0)
//SetObjectTransparency(num,1)
SetObjectCollisionMode( num, 1 ) //On is needed for raycasting
CreateMemblockFromObjectMesh(num,num,1) //there is exactly the same number of blocks as memblocks and each id is equal
//the shadow is set to off on each block as its only needed for the raised ones
//SetObjectCastShadow(num,0)
blocksChanged[num].id=num
//the directions are only used for the particle effect when you crash
blocksChanged[num].xDirection=Random2(-100,100)/50.0
blocksChanged[num].yDirection=Random2(-100,100)/50.0
blocksChanged[num].zDirection=Random2(-100,100)/50.0
blocksChanged[num].xPosStart=x
blocksChanged[num].yPosStart=y
blocksChanged[num].zPosStart=z
SetObjectPosition(num,x,y,z)
createCow(cowStart+(num-1)*7)
if x>10
SetObjectPosition(cowStart+(num-1)*7,blocksChanged[num].xPosStart+random(2,20),blocksChanged[num].yPosStart,blocksChanged[num].zPosStart)
else
SetObjectPosition(cowStart+(num-1)*7,blocksChanged[num].xPosStart-random(2,20),blocksChanged[num].yPosStart,blocksChanged[num].zPosStart)
RotateObjectLocalY(cowStart+(num-1)*7,180)
endif
inc num
next z
next x
next y
blockCount=num-1
//createCow(cow):SetObjectPosition(cow,getObjectX(blockCount-5)+5.0,getObjectY(blockCount-5),getObjectZ(blockCount-5))
createCar(carBlock,carMem)
createCar(otherCarBlock,otherCarMem)
createSound(sound1,1) //creates a base rumble
createSound(sound2,2) //creates white noise
//SetSunActive(1)
//SetSunColor( 255, 255,255 )
//SetFogSunColor( 20, 20, 20 )
//Add some atmosphere
SetFogMode( 1 )
SetFogColor(20,20,20)
SetFogRange(10,100)
CreatePointLight(1, getObjectX(carBlock),getObjectY(carBlock),getObjectZ(carBlock), 120, 255, 255,255 )
//SetShadowMappingMode(3 )
//SetShadowSmoothing( 0)
//SetShadowMapSize( 512, 512 )
//SetShadowRange( -1 ) // use the full camera range
//SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
setCameraPosition(1,mapX/2,10,0)
setupText()
repeat
sync()
If GetPointerPressed() or GetRawKeyPressed(32)
SetTextVisible(textGameOver,0):SetTextVisible(textPlayAgain,0):SetTextVisible(textHowFar,0)
lives=3:score=0:playGame()
if score>highScore
highScore=score
SetTextString(textHighScore,"High="+Str(highScore))
endif
if carSpeed#>topSpeed#
topSpeed#=carSpeed#
SetTextString(textTopSpeed,"Top Speed="+Str(Round(topSpeed#/maxCarSpeed#*100))+"%")
endif
endif
until GetRawKeyPressed(27)
end //exitprogram
function playGame()
global carSpeed#=.25 //car speed used for acceleration with timer
ResetTimer():time#=timer()
x=xMaxResolution/2:yAngle=0:offsetx=4.25
//yAngle=abs(GetDirectionX()*25)
x1#=GetObjectAngleX(carBlock+2)
y1#=GetObjectAngleY(carBlock+2)
z1#=GetObjectAngleZ(carBlock+2)
x2#=GetObjectAngleX(otherCarBlock+2)
y2#=GetObjectAngleY(otherCarBlock+2)
z2#=GetObjectAngleZ(otherCarBlock+2)
repeat
yAngle=abs(GetDirectionX()*25)
if GetDirectionX()<=0 //-.15 //uses gyroscope for movement
moveBlocks(abs(GetDirectionX()*2.5),0,carSpeed#)
yAngle=-abs(GetDirectionX()*25)
SetObjectRotation( carBlock,0,yAngle,0 )
SetObjectRotation(carBlock+2,x1#,yAngle*2,z1#)
SetObjectRotation(carBlock+3,x1#,yAngle*2,z1#)
SetObjectRotation(carBlock+4,x1#,y1#,z1#)
SetObjectRotation(carBlock+5,x1#,y1#,z1#)
else //if GetDirectionX()>0 //>.15 //uses gyroscope for movement
moveBlocks(-abs(GetDirectionX()*2.5),0,carSpeed#)
yAngle=abs(GetDirectionX()*25)
SetObjectRotation( carBlock,0,yAngle,0 )
SetObjectRotation(carBlock+2,x1#,yangle*2,z1#) //90
SetObjectRotation(carBlock+3,x1#,yangle*2,z1#)
SetObjectRotation(carBlock+4,x1#,y1#,z1#)
SetObjectRotation(carBlock+5,x1#,y1#,z1#)
endif
SetObjectRotation(otherCarBlock+2,x2#,y2#,z2#)
SetObjectRotation(otherCarBlock+3,x2#,y2#,z2#)
SetObjectRotation(otherCarBlock+4,x2#,y2#,z2#)
SetObjectRotation(otherCarBlock+5,x2#,y2#,z2#)
x1#=x1#+speed#:x2#=x2#-speed#
//the second raycasting is used for crashes
x#=getObjectX(carBlock)
y#=GetObjectY(carBlock)
z#=getObjectZ(carBlock)
// calculate the start of the ray cast
// a car is 2,2,4
start_x# = x#
start_y# = y#
start_z# = z#
// calculate the end of the ray cast
end_x# = x#+2.0
end_y# = y#
end_z# = z#+4.0 + carSpeed#
hit=ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
if hit>0 //player crashed
dec lives
PlaySound(sound1,100,0)
PlaySound(sound2,50,0)
blocksExplode()
restoreBlocks()
carSpeed#=.25 //Set the speed back to its default as you crashed
yAngle=0
time#=timer()
endif
if timer()>time#+.125
carSpeed#=carSpeed#+acceleration# //increase the car speed every 1 second
if speed#<20 then speed#=speed#+.5
time#=timer()
endif
if carSpeed#>maxCarSpeed# then carSpeed#=maxCarSpeed#
SetSpriteAngle(2,carSpeed#*100.0)
//SetTextString(textSpeed,"Speed="+Str(Round(carSpeed#/maxCarSpeed#*100))+"%")
SetTextString(textScore,"Score="+Str(score))
SetTextString(textLives,"Cars="+Str(lives))
//SetTextString(textFPS,"FPS="+Str(trunc(screenFPS())))
if score>highScore
highScore=score
SetTextString(textHighScore,"High="+Str(highScore))
endif
if carSpeed#>topSpeed#
topSpeed#=carSpeed#
//SetTextString(textTopSpeed,"Top Speed="+Str(Round(topSpeed#/maxCarSpeed#*100))+"%")
endif
sync()
until GetRawKeyPressed(27) or lives <1
SetTextVisible(textGameOver,1)
SetTextVisible(textPlayAgain,1)
SetTextVisible(textHowFar,1)
endfunction
function setupText()
x=xMaxResolution/2
CreateText(textTitle,"Night Driving")
SetTextSize(textTitle,50)
SetTextPosition(textTitle,x-120,5)
SetTextColor(textTitle,255,255,255,255)
CreateText(textScore,"Score=")
SetTextSize(textScore,35)
SetTextPosition(textScore,13,5)
SetTextColor(textScore,255,255,255,255)
CreateText(textLives,"Cars=")
SetTextSize(textLives,35)
SetTextPosition(textLives,26,35)
SetTextColor(textLives,255,255,255,255)
CreateText(textGameOver,"GameOver")
SetTextSize(textGameOver,55)
SetTextPosition(textGameOver,x-112,yMaxResolution/2-18)
SetTextColor(textGameOver,255,255,255,255)
SetTextVisible(textGameOver,0)
CreateText(textPlayAgain,"How far can you go?")
SetTextSize(textPlayAgain,55)
SetTextPosition(textPlayAgain,x-200,yMaxResolution/2+20)
SetTextColor(textPlayAgain,255,255,255,255)
SetTextVisible(textPlayAgain,1)
CreateText(textHowFar,"Click to Play")
SetTextSize(textHowFar,55)
SetTextPosition(textHowFar,x-126,yMaxResolution/2+58)
SetTextColor(textHowFar,255,255,255,255)
SetTextVisible(textHowFar,1)
CreateText(textHighScore,"High=0")
SetTextSize(textHighScore,35)
SetTextPosition(textHighScore,xMaxResolution-150,5)
SetTextColor(textHighScore,255,255,255,255)
CreateText(textCredit,"Programmed by fubarpk using AGK")
SetTextSize(textCredit,35)
SetTextPosition(textCredit,5,yMaxResolution-32)
SetTextColor(textCredit,255,255,255,255)
endfunction
function modifyBlock(block as integer, ammount as integer)
rem there are the following 8 vertexs that we need to modify to extend in the ydirection [0,2,4,6,8,9,10,11]
vertex as integer[7] = [0,2,4,6,8,9,10,11]
maxVertex=GetMemblockInt(block,0)-1
for index = 0 to 7
if index<=maxVertex
SetMeshMemblockVertexPosition(block,vertex[index],GetMeshMemblockVertexX(block,vertex[index]),GetMeshMemblockVertexY(block,vertex[index])+ammount,GetMeshMemblockVertexZ(block,vertex[index]))
endif
next index
SetObjectMeshFromMemblock(block,1,block)
endfunction
function moveBlocks(x as float,y as float,z as float)
rem These define the maximum and minimum an object may be placed in this example all objects
rem are 1,1,1 so defing these locations was done as following but could be calculated for
rem other objects of different dimmensions
xNum=mapX-1 //number of objects placed accross the xplane-1
yNum=mapY-1 //number of objects placed accross the yplane-1
zNum=mapZ-1 //number of objects placed accross the zplane-1
rem defing the 3d window workspace
xMin#=x:xMax#=mapX+x //the minimum and maximum xlocations for wrapping blocks on x plane
yMin=1:yMax=mapY //the minimum and maximum ylocation for wrapping blocks on the y plane
zMin#=0:zMax#=mapZ //the minimum and maximum zlocations for wrapping blocks on z plane
//time#=timer()
//myRed=random(0,255):myGreen=random(0,255):myBlue=random(0,255)
multiplier#=timer()*5:if multiplier#>150 then multiplier# =150
for num=1 to blockCount //move posts
SetObjectPosition(num,getObjectX(num)+x,getObjectY(num),getObjectZ(num))
if z>0 //move blocks toward screen
if GetObjectWorldZ(num)<zMin#
//x# = sin(timer()*speed#*2)*100 // ranges from -100 to 100
x# = sin(timer()*speed#)*multiplier# // ranges from -100 to 100
x#=x#/3.0 //if this division is set to low the raycasting needs changing 50 and 75 both work well
SetObjectPosition(num,x#+getObjectX(num),getObjectY(num),getObjectZ(num)+zNum)
else
SetObjectPosition(num,getObjectX(num),getObjectY(num),getObjectZ(num)-z)
endif
endif
next num
num=1
for cows = 0 to 19 //move cows
SetObjectPosition(cowStart+(cows*7),getObjectX(cowStart+(cows*7))+x,getObjectY(cowStart+(cows*7)),getObjectZ(cowStart+(cows*7)))
if z>0
if GetObjectWorldZ(cowStart+(cows*7))<zMin#
x# = sin(timer()*speed#)*multiplier# // ranges from -100 to 100
x#=x#/3.0 //if this division is set to low the raycasting needs changing 50 and 75 both work well
SetObjectPosition(cowStart+(cows*7),getObjectX(cowStart+(cows*7))+x#,getObjectY(cowStart+(cows*7)),getObjectZ(cowStart+(cows*7))+zNum)
else
SetObjectPosition(cowStart+(cows*7),getObjectX(cowStart+(cows*7)),getObjectY(cowStart+(cows*7)),getObjectZ(cowStart+(cows*7))-z)
endif
endif
next cows
rem block 20 is off the screen so increment score
if getObjectZ(blockCount)<zMin# //num=10
score=score+((100*carSpeed#)/2)
if random(1,2) =1
offsetx=4.25
else
offsetx=15.75
endif
endif
SetObjectPosition(otherCarBlock,getObjectX(blockCount)-offsetx,getObjectY(blockCount),getObjectZ(blockCount))
angle# = GetAngle(getObjectX(blockCount),getObjectZ(blockCount),getObjectX(blockCount-2),getObjectZ(blockCount-2))
SetObjectRotation(otherCarBlock,0,0,0)
RotateObjectGlobalY(otherCarBlock,angle#)
endfunction
function blocksExplode()
SetSpriteAngle(2,0)
maxVertex=GetMemblockInt(carBlock,0)-1
Dim CarVertex[maxVertex] as vertex
For index=0 to maxVertex
//set each vertex a random direction
CarVertex[index].xDirection=random2(-100,100)/50.0
CarVertex[index].yDirection=Random2(-100,100)/50.0
CarVertex[index].zDirection=Random2(-100,0)/50.0
next index
maxVertex=GetMemblockInt(carBlock+1,0)-1
Dim CarTopVertex[maxVertex] as vertex
For index=0 to maxVertex
//set each vertex a random direction
CarTopVertex[index].xDirection=random2(-100,100)/50.0
CarTopVertex[index].yDirection=Random2(-100,100)/50.0
CarTopVertex[index].zDirection=Random2(-100,0)/50.0
next index
maxVertex=GetMemblockInt(otherCarBlock,0)-1
Dim OtherCarVertex[maxVertex] as vertex
For index=0 to maxVertex
//set each vertex a random direction
OtherCarVertex[index].xDirection=random2(-100,100)/50.0
OtherCarVertex[index].yDirection=Random2(-100,100)/50.0
OtherCarVertex[index].zDirection=Random2(-100,0)/50.0
next index
maxVertex=GetMemblockInt(otherCarBlock+1,0)-1
Dim OtherCarTopVertex[maxVertex] as vertex
For index=0 to maxVertex
//set each vertex a random direction
OtherCarTopVertex[index].xDirection=random2(-100,100)/50.0
OtherCarTopVertex[index].yDirection=Random2(-100,100)/50.0
OtherCarTopVertex[index].zDirection=Random2(-100,0)/50.0
next index
dim wheels[7] as vertex
for wheel = 0 to 7 //8 wheels with both cars
wheels[wheel].xDirection=random2(-100,100)/50.0
wheels[wheel].yDirection=random2(-100,100)/50.0
wheels[wheel].zDirection=random2(-100,100)/50.0
next wheel
dim cowParts[6,19] as vertex
for cows=0 to 19
for cowpart = 0 to 6
cowParts[cowpart,cows].xDirection=random2(-100,100)/50.0
cowParts[cowpart,cows].yDirection=random2(-100,100)/50.0
cowParts[cowpart,cows].zDirection=random2(-100,100)/50.0
next cowpart
next cows
startTime#=Timer()
repeat
for num=1 to blockCount
//move the ground blocks in their set random directions
SetObjectPosition(num,getObjectX(num)+blocksChanged[num].xDirection,getObjectY(num)+blocksChanged[num].yDirection,getObjectZ(num)+blocksChanged[num].zDirection)
next num
//just send wheels into orbit
for wheel = 0 to 3 //your car wheels
SetObjectPosition(carBlock+2+wheel,getObjectX(carBlock+2+wheel)+wheels[wheel].xDirection,getObjectY(carBlock+2+wheel)+wheels[wheel].yDirection,getObjectZ(carBlock+2+wheel)+wheels[wheel].zDirection)
next wheel
for wheel = 4 to 7 //other car wheels
SetObjectPosition(otherCarBlock-2+wheel,getObjectX(otherCarBlock-2+wheel)+wheels[wheel].xDirection,getObjectY(otherCarBlock-2+wheel)+wheels[wheel].yDirection,getObjectZ(otherCarBlock-2+wheel)+wheels[wheel].zDirection)
next wheel
for cows=0 to 19 //there are 20 cows
for cowpart = 0 to 6 //each cow has 7 parts
SetObjectPosition((cowStart+(cows*7))+cowpart,getObjectX((cowStart+(cows*7))+cowpart)+cowParts[cowpart,cows].xDirection,getObjectY((cowStart+(cows*7))+cowpart)+cowParts[cowpart,cows].yDirection,getObjectZ((cowStart+(cows*7)))+cowParts[cowpart,cows].zDirection)
next cowpart
next cows
for index = 0 to maxVertex
//Tear the cars vertexs apart as set by there random direction
SetMeshMemblockVertexPosition(carMem,index,GetMeshMemblockVertexX(carMem,index)+CarVertex[index].xDirection,GetMeshMemblockVertexY(carMem,index)+CarVertex[index].yDirection,GetMeshMemblockVertexZ(carMem,index)+CarVertex[index].zDirection)
SetMeshMemblockVertexPosition(otherCarMem,index,GetMeshMemblockVertexX(OtherCarMem,index)+otherCarVertex[index].xDirection,GetMeshMemblockVertexY(otherCarMem,index)+OtherCarVertex[index].yDirection,GetMeshMemblockVertexZ(otherCarMem,index)+otherCarVertex[index].zDirection)
SetMeshMemblockVertexPosition(carMem+1,index,GetMeshMemblockVertexX(carMem+1,index)+CarTopVertex[index].xDirection,GetMeshMemblockVertexY(carMem+1,index)+CarTopVertex[index].yDirection,GetMeshMemblockVertexZ(carMem+1,index)+CarTopVertex[index].zDirection)
SetMeshMemblockVertexPosition(otherCarMem+1,index,GetMeshMemblockVertexX(OtherCarMem+1,index)+otherCarTopVertex[index].xDirection,GetMeshMemblockVertexY(otherCarMem+1,index)+OtherCarTopVertex[index].yDirection,GetMeshMemblockVertexZ(otherCarMem+1,index)+otherCarTopVertex[index].zDirection)
next index
SetObjectMeshFromMemblock(carBlock,1,carMem)
SetObjectMeshFromMemblock(carBlock+1,1,carMem+1)
SetObjectMeshFromMemblock(otherCarBlock,1,otherCarMem)
SetObjectMeshFromMemblock(otherCarBlock+1,1,otherCarMem+1)
sync()
until timer()>StartTime#+3
endfunction
function restoreBlocks()
//restore all the block properties after a collision
for num=1 to blockCount
//restore blocks to the starting positions
SetObjectPosition(blocksChanged[num].id,blocksChanged[num].xPosStart,blocksChanged[num].yPosStart,blocksChanged[num].zPosStart)
createCow(cowStart+(num-1)*7)
if blocksChanged[num].xPosStart>10
SetObjectPosition(cowStart+(num-1)*7,blocksChanged[num].xPosStart+random(2,20),blocksChanged[num].yPosStart,blocksChanged[num].zPosStart)
else
SetObjectPosition(cowStart+(num-1)*7,blocksChanged[num].xPosStart-random(2,20),blocksChanged[num].yPosStart,blocksChanged[num].zPosStart)
RotateObjectLocalY(cowStart+(num-1)*7,180)
endif
next num
createCar(carBlock,carMem)
createCar(otherCarBlock,otherCarMem)
speed# = 2.0
resetTimer() //need to reset time for the road curves
endfunction
function createSound(SoundId as integer,num as integer)
//create sound wave in memory
local sound as integer
local frames as integer
local data as integer
local size as integer
local mem as integer
local sec as float
sec = .4
data = sec * (44100 * (2*2)) // 176400 bytes per second
frames = data / 4
size = 2+2+4+4 + data
mem = CreateMemblock(size)
SetMemblockByte(mem,0, 2) //The first 2 bytes of the memlbock store the number of channels (1 or 2 supported)
SetMemblockByte(mem,1, 0)
SetMemblockByte(mem,2,16) //the next 2 bytes store the bits per sample (8 (1 byte) or 16 (2 byte) supported)
SetMemblockByte(mem,3, 0)
SetMemblockint(mem,4,44100) // the next 4 bytes store the samples per second, for example 44100
SetMemblockint(mem,8,frames) // The next 4 bytes are the number of frames in the sound data, the size of the sound data in bytes can be calculated from this with the formula numFrames*(bitsPerSample/8)*channels.
local i as integer
local value as integer
local Hz as float // the hertz of the sound
local w as float
value=0
w=0
local randomize as integer[8]=[80,53,-25,73,44,0,24,80] //deep base rumble
maxW=360:if num=2 then maxW=32768 //360 is normal
for i=0 to data -1 step 4
Hz=randomize[random2(1,8)] //deep base rumble
w=w+(maxW / 44100.0) * Hz
if w > maxW then w = w -maxW
value = sin(w)*(32767.0) //Max −32768 through 32767
SetMemblockShort(mem,12+i+0 ,value) // short 2 bytes −32768 through 32767
SetMemblockShort(mem,12+i+2 ,value) // short 2 bytes −32768 through 32767
next i
CreateSoundFromMemblock(SoundId,mem)
DeleteMemblock(mem)
endFunction //sound
function createWireFrameTexture(ImgId as integer,sizex as integer, sizey as integer, color)
SetClearColor(0,0,0)
ClearScreen()
Render()
drawbox(0,0,sizex-1, sizey-1, color, color,color,color, 0)
Render()
//img = getimage(0,0,sizex, sizey)
getimage(ImgId,0,0,sizex, sizey)
Swap()
endfunction //img
function createGridTexture(ImgId as integer,sizex as integer, sizey as integer,stepx as integer,stepy as integer, color)
SetClearColor(0,0,0)
ClearScreen()
Render()
for y=0 to sizey-1 step stepy
DrawLine(0,y,sizex,y,color,color)
next y
for x=0 to sizex-1 step stepx
DrawLine(x,0,x,sizey,color,color)
next x
Render():
//img = getimage(0,0,sizex, sizey)
getimage(ImgId,0,0,sizex, sizey)
Swap()
endfunction //img
function CreateSpeedoTexture(imgId as integer)
SetClearColor(0,0,0)
ClearScreen()
text1=createText("10"):SetTextSize(text1,20):SetTextPosition(text1,15,167):DrawText(text1)
text2=createText("20"):SetTextSize(text2,20):SetTextPosition(text2,0,130):DrawText(text2)
text3=createText("30"):SetTextSize(text3,20):SetTextPosition(text3,1,87):DrawText(text3)
text4=createText("40"):SetTextSize(text4,20):SetTextPosition(text4,18,46):DrawText(text4)
text5=createText("50"):SetTextSize(text5,20):SetTextPosition(text5,50,17):DrawText(text5)
text6=createText("60"):SetTextSize(text6,20):SetTextPosition(text6,90,1):DrawText(text6)
text7=createText("70"):SetTextSize(text7,20):SetTextPosition(text7,134,1):DrawText(text7)
text8=createText("80"):SetTextSize(text8,20):SetTextPosition(text8,177,17):DrawText(text8)
text9=createText("90"):SetTextSize(text9,20):SetTextPosition(text9,209,46):DrawText(text9)
text10=createText("100"):SetTextSize(text10,20):SetTextPosition(text10,226,87):DrawText(text10)
text11=createText("110"):SetTextSize(text11,20):SetTextPosition(text11,228,130):DrawText(text11)
text12=createText("120"):SetTextSize(text12,20):SetTextPosition(text12,220,167):DrawText(text12)
Render()
//img = getimage(0,0,255,255)
getimage(ImgId,0,0,255,255)
Swap()
DeleteText(text1):DeleteText(text2):DeleteText(text3):DeleteText(text4):DeleteText(text5):DeleteText(text6)
DeleteText(text7):DeleteText(text8):DeleteText(text9):DeleteText(text10):DeleteText(text11):DeleteText(text12)
endfunction //img
function CreateSpeedoNeedle(imgId as integer)
ClearScreen()
DrawLine( 125, 126, 58, 194,255,255,255 )
DrawLine( 126, 126, 59, 194,255,255,255 )
DrawLine( 127, 126, 60, 194,255,255,255 )
DrawEllipse(126,126,4,4,makecolor(255,255,255),makecolor(255,255,255),1)
Render()
//img = getimage(0,0,255,255)
getimage(ImgId,0,0,255,255)
Swap()
endfunction //img
function getAngle(x1#, y1#, x2#, y2#)
//result# = ATanFull(x1# - x2#, y1# - y2#)
result# = ATan2(x1# - x2#,y1# - y2#)
endfunction result#
function createCar(carId as integer,carMemId as integer)
DeleteObject(carId):DeleteObject(CarId+1)
DeleteObject(carId+2):DeleteObject(CarId+3)
DeleteObject(carId+4):DeleteObject(CarId+5)
DeleteMemBlock(carMemId):DeleteMemblock(carMemId+1)
vertex as integer[7] = [17,15,7,13, 1,19,3,5]
CreateObjectBox(carId,2,2,4)
CreateMemblockFromObjectMesh(carId,carMemId,1)
setObjectPosition(carId,mapX/2,mapY,10)
SetObjectImage(carId,wireFrameTextureID,0)
//SetObjectColor(carId,200,0,0,255) //red cars go faster
SetObjectColor(carId,255,255,255,255)
SetObjectTransparency(carId,1)
SetObjectCollisionMode(carId,1) //on is set or raycasting wont work
CreateObjectBox(carId+1,2,1,1) //the car top
SetObjectImage(carId+1,wireFrameTextureID,0)
SetObjectTransparency(carId+1,1)
setObjectPosition(carId+1,getObjectX(carId)-(mapX/2),getObjectY(carId)-mapY+1.5,getObjectZ(carId)-10)
CreateMemblockFromObjectMesh(carId+1,carMemId+1,1)
for i = 0 to 7
SetMeshMemblockVertexPosition(carMemId+1,vertex[i],GetMeshMemblockVertexX(carMemId,vertex[i]),GetMeshMemblockVertexY(carMemId,vertex[i])+.5,GetMeshMemblockVertexZ(carMemId,vertex[i])*.5)
next i
//SetMeshMemblockVertexPosition(carMemId+1,vertexBottom[2],GetMeshMemblockVertexX(carMemId,vertexBottom[2]),GetMeshMemblockVertexY(carMem,vertexBottom[2]),GetMeshMemblockVertexZ(carMem,vertexBottom[2])-1)
SetObjectMeshFromMemblock(carId+1,1,carMemId+1)
SetObjectColor(carId+1,255,255,255,255) //red cars go faster
SetObjectCollisionMode(carId+1,1) //on is set or raycasting wont work
FixObjectToObject(carId+1,carId)
//now for four wheels
CreateObjectCylinder(carId+2,.5,1,10) //front left
SetObjectImage(carId+2,gridTextureID,0)
SetObjectTransparency(carId+2,1)
SetObjectRotation(carId+2,0,0,90)
SetObjectPOsition(carId+2,-.75,-1,1.25)
SetObjectColor(carId+2,255,255,255,255)
FixObjectToObject(carId+2,carId)
//SetObjectCollisionMode(carId+2,1)
CreateObjectCylinder(carId+3,.5,1,10) //front right
SetObjectImage(carId+3,gridTextureID,0)
SetObjectTransparency(carId+3,1)
SetObjectRotation(carId+3,0,0,90)
SetObjectPOsition(carId+3,.75,-1,1.25)
SetObjectColor(carId+3,255,255,255,255)
FixObjectToObject(carId+3,carId)
//SetObjectCollisionMode(carId+3,1)
CreateObjectCylinder(carId+4,.5,1,10) //back left
SetObjectImage(carId+4,gridTextureID,0)
SetObjectTransparency(carId+4,1)
SetObjectRotation(carId+4,0,0,90)
SetObjectPOsition(carId+4,-.75,-1,-1.15)
SetObjectColor(carId+4,255,255,255,255)
FixObjectToObject(carId+4,carId)
//SetObjectCollisionMode(carId+4,1)
CreateObjectCylinder(carId+5,.5,1,10) //back right
SetObjectImage(carId+5,gridTextureID,0)
SetObjectTransparency(carId+5,1)
SetObjectRotation(carId+5,0,0,90)
SetObjectPOsition(carId+5,.75,-1,-1.15)
SetObjectColor(carId+5,255,255,255,255)
FixObjectToObject(carId+5,carId)
//SetObjectCollisionMode(carId+5,1)
endfunction
function createCow(cowId as integer)
DeleteObject(cowId):DeleteObject(cowId+1):DeleteObject(cowId+2):DeleteObject(cowId+3)
DeleteObject(cowId+4):DeleteObject(cowId+5):DeleteObject(cowId+6)
//cow body
CreateObjectBox(cowId,2.0,1.0,1)
SetObjectImage(cowId,wireFrameTextureID,0)
setObjectPosition(cowId,mapX/2,mapY+4,10)
SetObjectTransparency(cowId,1)
SetObjectCollisionMode(cowId,1) //on is set or raycasting wont work
//cow head
CreateObjectBox(cowId+1,0.65,0.25,.5) //head
SetObjectImage(cowId+1,wireFrameTextureID,0)
setObjectPosition(cowId+1,getObjectX(cowId)-(mapX/2)-1,getObjectY(cowId)-mapY-3.5,getObjectZ(cowId)-10)
SetObjectRotation(cowId+1,0,0,20)
SetObjectTransparency(cowId+1,1)
//SetObjectCollisionMode(cowId+1,1) //on is set or raycasting wont work
FixObjectToObject(cowId+1,cowId)
//cow tail
CreateObjectBox(cowId+2,.1,1.0,.25)
SetObjectImage(cowId+2,wireFrameTextureID,0)
setObjectPosition(cowId+2,getObjectX(cowId)-(mapX/2)+1.15,getObjectY(cowId)-mapY-4,getObjectZ(cowId)-10)
SetObjectRotation(cowId+2,0,0,20)
SetObjectTransparency(cowId+2,1)
//SetObjectCollisionMode(cowId+2,1) //on is set or raycasting wont work
FixObjectToObject(cowId+2,cowId)
//leg left front
CreateObjectBox(cowId+3,.1,.50,.25)
SetObjectImage(cowId+3,wireFrameTextureID,0)
setObjectPosition(cowId+3,getObjectX(cowId)-(mapX/2)-1.0,getObjectY(cowId)-mapY-4.75,getObjectZ(cowId)-10.25)
SetObjectRotation(cowId+3,0,0,0)
SetObjectTransparency(cowId+3,1)
//SetObjectCollisionMode(cowId+3,1) //on is set or raycasting wont work
FixObjectToObject(cowId+3,cowId)
//leg right front
CreateObjectBox(cowId+4,.1,.50,.25)
SetObjectImage(cowId+4,wireFrameTextureID,0)
setObjectPosition(cowId+4,getObjectX(cowId)-(mapX/2)+1.0,getObjectY(cowId)-mapY-4.75,getObjectZ(cowId)-10.25)
SetObjectRotation(cowId+4,0,0,0)
SetObjectTransparency(cowId+4,1)
//SetObjectCollisionMode(cowId+4,1) //on is set or raycasting wont work
FixObjectToObject(cowId+4,cowId)
//leg left back
CreateObjectBox(cowId+5,.1,.50,.25)
SetObjectImage(cowId+5,wireFrameTextureID,0)
setObjectPosition(cowId+5,getObjectX(cowId)-(mapX/2)-1.0,getObjectY(cowId)-mapY-4.75,getObjectZ(cowId)-9.75)
SetObjectRotation(cowId+5,0,0,0)
SetObjectTransparency(cowId+5,1)
//SetObjectCollisionMode(cowId+5,1) //on is set or raycasting wont work
FixObjectToObject(cowId+5,cowId)
//leg right back
CreateObjectBox(cowId+6,.1,.50,.25)
SetObjectImage(cowId+6,wireFrameTextureID,0)
setObjectPosition(cowId+6,getObjectX(cowId)-(mapX/2)+1.0,getObjectY(cowId)-mapY-4.75,getObjectZ(cowId)-9.75)
SetObjectRotation(cowId+6,0,0,0)
SetObjectTransparency(cowId+6,1)
//SetObjectCollisionMode(cowId+6,1) //on is set or raycasting wont work
FixObjectToObject(cowId+6,cowId)
endfunction
And because I thought the community needed it I added to google play but with purchased objects graphics and sound
Google Play Link https://play.google.com/store/apps/details?id=night.driver
Quote: "Anyone can use or modify the code as is."
fubar