Posted: 10th Apr 2018 17:32
Some Shaders with full source created at runtime with example code
2D dissolve shader color tints a whole image (needs an image)
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
 
LoadImage(1,"texture1.jpg") 

createShader()
CreateSprite(1,1)
LoadSpriteShader(1, "dissolve.ps")
SetSpriteShader( 1,1 )
resetTimer()
do
	time#=Timer()
        //SetShaderConstantByName(1,"myColor",-time#-,time#,-time#,0.2) //this will make the channels brighter
	SetShaderConstantByName(1,"myColor",time#,time#,time#,0.2) //red green blue factor
	if Timer()>7.0 
		resetTimer()
	endif
	print (time#)
	sync()	

loop
 
function createShader()

file = OpenToWrite("dissolve.ps")
WriteLine(file,"uniform sampler2D texture0;")
//WriteLine(file,"uniform float agk_time;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 color = texture2D(texture0, uvVarying).rgba;")
WriteLine(file,"//color=color-vec4(100.0/255.0);") // (no branching) make 255 steps as the color in shaders go from 0 to 1
WriteLine(file,"color.r-=(myColor.x*myColor.w);")
WriteLine(file,"color.g-=(myColor.y*myColor.w);")
WriteLine(file,"color.b-=(myColor.z*myColor.w);")
WriteLine(file,"color = clamp(color,0.0,1.0);") //restricts color range
WriteLine(file,"gl_FragColor = color;")
WriteLine(file,"}")
CloseFile(file)
endfunction

2D dissolve shader2 color tints a whole image and becomes totally transparent(needs 2 images)
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
 
LoadImage(1,"test.png") 
LoadImage(2,"world.png")

createShader()
CreateSprite(1,1)
LoadSpriteShader(1, "dissolve.ps")
SetSpriteShader( 1,1 )

CreateSprite(2,2)
SetSpriteDepth(2,11)
resetTimer()
SetShaderConstantByName(1,"factor",.20,.20,.20,.20) //factor red blue green alpha
do
	time#=Timer()
        //SetShaderConstantByName(1,"myColor",-time#-,time#,-time#,0.2) //this will make the channels brighter
	SetShaderConstantByName(1,"myColor",time#,time#,time#,time#) //red green blue alpha
	if Timer()>7.0 
		resetTimer()
	endif
	print (time#)
	sync()	

loop
 
function createShader()

file = OpenToWrite("dissolve.ps")
WriteLine(file,"uniform sampler2D texture0;")
//WriteLine(file,"uniform float agk_time;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"uniform vec4 factor;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 color = texture2D(texture0, uvVarying).rgba;")
WriteLine(file,"//color=color-vec4(100.0/255.0);") // (no branching) make 255 steps as the color in shaders go from 0 to 1
WriteLine(file,"color.r-=(myColor.r*factor.r);")
WriteLine(file,"color.g-=(myColor.g*factor.b);")
WriteLine(file,"color.b-=(myColor.b*factor.g);")
WriteLine(file,"color.a-=(myColor.a*factor.a);")
WriteLine(file,"color = clamp(color,0.0,1.0);") //restricts color range
WriteLine(file,"gl_FragColor = color;")
WriteLine(file,"}")
CloseFile(file)
endfunction

with the 2dShaders you could change this line SetShaderConstantByName(1,"myColor",time#,time#,time#,time#) replacing time with a color amount between 0 and 1.0
for example SetShaderConstantByName(1,"myColor",1.0,0,0,0) would make the pic red without changing alpha similar can be done to the 3D ones
3D dissolve shader allows a method of color tinting a group of objects a set amount in one step
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
#constant fadeShader =1

SetFogMode( 1 ) 
SetFogColor(10,10,10)
SetFogRange(6,16)

createTexture()
createShader()
LoadShader(fadeShader,"fade.vs", "fade.ps")
num=1
for y = 1 to 20	
for x = y to 20-y
for z = y to 20-y
	CreateObjectBox(num,1,1,1)
	SetObjectImage( num, random(1,20), 0) 
	SetObjectPosition(num,x-10,y,-z)
	SetObjectShader( num, fadeShader)
	inc num
next z
next x
next y
mask=CreateObjectBox(1.1,1.1,1.1)
SetObjectColor(mask,255,255,255,180)
SetObjectTransparency(mask,1)
SetObjectFogMode(mask,0)

fadeIn()
do
    
	selectedObj=mouseOver()
	if GetObjectExists(selectedObj) 
		SetObjectVisible( mask, 1 ) 
		SetObjectPosition (mask,GetObjectX(selectedObj),GetObjectY(selectedObj),GetObjectZ(selectedObj))
		lastObj=selectedObj
	endif
	if GetObjectExists(lastObj) and lastObj<>selectedObj 
		SetObjectVisible( mask, 0 ) 
		lastObj=selectedObj
	endif
    if getpointerpressed()=1
		fadeOut()
		end
	endif
	SetShaderConstantByName(fadeShader,"pointPos",1,1,1,1)
	sync()	

loop

function createTexture ()

	for num = 1 to 20
		r=random(50,255): g=random(50,255):b=random(50,255)
		DrawBox(0,0,32,32,MakeColor(r,g,b),MakeColor(r,g,b),MakeColor(r,g,b),MakeColor(r,g,b),1)
		render()
		GetImage(num,0,0,32,32)
	next num	
endfunction

function fadeIn()
resetTimer()
time#=Timer()
repeat
	time#=Timer()
	r#=7-time#
	g#=7-time#
	b#=7-time#
	SetShaderConstantByName(fadeShader,"myColor",r#,g#,b#,0.2) //red green blue factor
	sync()	
until timer()>7.0
endfunction	

function fadeOut()
resetTimer()
time#=Timer()
repeat
	time#=Timer()
	r#=time#
	g#=time#
	b#=time#
	SetShaderConstantByName(fadeShader,"myColor",r#,g#,b#,0.2) //red green blue factor
	sync()	
until timer()>7.0
endfunction	


function mouseOver()
        
    myX as float
    myY as float
    my3dX as float
    my3dY as float
    my3dZ as float
    rayStartX as float
    rayStartY as float
    rayStartZ as float
    rayEndX as float
    rayEndY as float
    rayEndZ as float 
        
    myX=GetPointerX()
    myY=GetPointerY()
        
    my3dX=Get3DVectorXFromScreen(myX,myY)
    my3dY=Get3DVectorYFromScreen(myX,myY)
    my3dZ=Get3DVectorZFromScreen(myX,myY)
        
    rayStartX=my3dX+GetCameraX(1)
    rayStartY=my3dY+GetCameraY(1)
    rayStartZ=my3dZ+GetCameraZ(1)
        
    rayEndX=800*my3dX+GetCameraX(1)
    rayEndY=800*my3dY+GetCameraY(1)
    rayEndZ=800*my3dZ+GetCameraZ(1) 
        
    theObjectHit= ObjectRayCast(0,rayStartX,rayStartY,rayStartZ,rayEndX,rayEndY,rayEndZ)      
endfunction theObjectHit

function createShader()
file = OpenToWrite("fade.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{") 
WriteLine(file,"    uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"    highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file,"    gl_Position = agk_ViewProj * pos;")
WriteLine(file,"    mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file,"    posVarying = pos.xyz;")
WriteLine(file,"    normalVarying = norm;")
WriteLine(file,"    lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}")	
CloseFile(file)

//pixel shader
file = OpenToWrite("fade.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"uniform mediump vec3 agk_MeshDiffuse;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"mediump vec3 norm = normalize(normalVarying);")
WriteLine(file,"mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying );")
WriteLine(file,"vec3 colorA = texture2D(texture0, uvVarying).rgb*light *agk_MeshDiffuse;")
WriteLine(file,"colorA.r-=(myColor.x*myColor.w);")
WriteLine(file,"colorA.g-=(myColor.y*myColor.w);")
WriteLine(file,"colorA.b-=(myColor.z*myColor.w);")
WriteLine(file,"colorA = clamp(colorA,0.0,1.0);") //restricts color range
WriteLine(file,"mediump vec3 color = ApplyFog( colorA, posVarying );")
WriteLine(file,"gl_FragColor = vec4(color,1.0);")
WriteLine(file,"}")
CloseFile(file)
endfunction


For those that want to play with Shaders in AGK There is some great documentation available here
https://www.appgamekit.com/documentation/guides/13_shaders.htm

Please feel free to share any of your own tools, effects and snippets


I have included the links to the relevant pages so as people may have discussions on the appropriate page to help make it
easier for people to find helpful code should this thread get larger


My webpage where it showcases all of my AppGameKit developments that are available free to download from Google Play
http://users.tpg.com.au/subarpk/index.htm

another 2D tinter shader great for colour to black and white
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
 
LoadImage(1,"yourimage.png") 

createShader()
CreateSprite(1,1)
LoadSpriteShader(1, "bw.ps")
SetSpriteShader( 1,1 )
 
CreateSprite(2,2)
SetSpriteDepth(2,11)
resetTimer()
SetShaderConstantByName(1,"factor",0,0,0,0) //factor red blue green alpha
do
    time#=Timer()
        //SetShaderConstantByName(1,"myColor",-time#-,time#,-time#,0.2) //this will make the channels brighter
    SetShaderConstantByName(1,"factor",time#,time#,time#,time#) //red green blue alpha
    if Timer()>7.0 
        resetTimer()
    endif
    print (time#)
    sync()  
 
loop
  
 
function createShader()
file = OpenToWrite("bw.ps")
WriteLine(file,"uniform sampler2D texture0;")
//WriteLine(file,"uniform float agk_time;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"uniform vec3 factor;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 color = texture2D(texture0, uvVarying).rgba;")
WriteLine(file,"float grey = 0.21 * color.r + 0.71 * color.g + 0.07 * color.b;")
WriteLine(file,"gl_FragColor = vec4(color.rgb * (1.0 - factor) + (grey * factor), 1.0);")
WriteLine(file,"}")
CloseFile(file)
endfunction
Posted: 10th Apr 2018 19:03
2D Text modifications on screen by subtracting ascii values
https://forum.thegamecreators.com/thread/218514
+ Code Snippet
// Project: TextFun
// Created: 2016-12-29

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TextFun" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )

Words as string = "HELLO WORLD is a great place to start programming it teaches people the very basics and is used as a common starting program by many people all over the world. Hello world has been the starter program for most programmers for many years. Its not the best program in the world laughs but it helps people get the drive to start learning"
i=1
i=CreateText(Words)
SetTextSize(i,Random(50,60))
SetTextColor(i,255,255,255,255)
SetTextPosition(i,10,10)
SetTextMaxWidth( i,1020 )
sync()
sleep(500)
global dontDo as integer
dontDo=0

start_time = GetMilliseconds()

do

	current_time = GetMilliseconds()

	if current_time - start_time > 100

		start_time = current_time

		if dontDo=0
			Words=subtractAscii(Words)
			SetTextString(i,Words)
			//keep subtracting the alpha value until black
			alpha=GetTextColorAlpha(i)
			if alpha>5 then SetTextColorAlpha(i,alpha-5)
		endif
	endif
    Sync()
loop

function subtractAscii (word as string)

	//Each letter or a string passed is replaced with the character 1 less than previous
	newWord as String
	newWord=""
	length=len(word)
	empty=0

	for i = 1 to length
		a$=Mid(word,i,1)
		a=asc(a$)
		if a$<>chr(32)
			a=a-1
		else
			empty=empty+1
		endif
		if empty=length then dontDo=1
		newWord=newWord+chr(a)
	next i

endfunction  newWord

2D Multi direction scrolling with wrapping
https://forum.thegamecreators.com/thread/216193
+ Code Snippet
SetVirtualResolution(1024,768)
 
GLOBAL Block as integer[5,4]

for y=  1 to 4
for x = 1 to 5
    Block[x,y] = createSprite(0)
    setSpriteSize(Block[x,y],300,300)
    setSpritePosition(Block[x,y],(x-1)*300,(y-1) * 300)
	setSpriteColor(Block[x,y],random(1,255),random(1,255),random(1,255),255)

next x
next y 

do
 
	speed#=10
	if GetRawKeyState(37) //left arrow pressed
		ScrollRight(speed#)
	endif
	if GetRawKeyState(39) //right arrow pressed
		ScrollLeft(-speed#)
	endif
 
	if GetRawKeyState(38) //up arrow key pressed
		
		ScrollDown(speed#)
	endif
	
	if GetRawKeyState(40) //Down arrow pressed
		ScrollUp(-speed#)		
	endif  

 Sync ()
loop

function ScrollUp(y# as integer)
	for y=1 to 4
	for x = 1 to 5
		SetSpritePosition (Block[x,y], getSpritex(Block[x,y]), GetSpriteY (Block[x,y]) + y#)
	next x
 
	for x = 1 to 5
      if getSpriteY(Block[x,y])<-300
         SetSpritePosition (Block[x,y], getSpritex(Block[x,y]), GetSpriteY (Block[x,y]) + 1200)
      endif
    next x
    next y
endfunction
function ScrollDown(y# as integer)
	for y=1 to 4
	for x = 1 to 5
		SetSpritePosition (Block[x,y], getSpritex(Block[x,y]), GetSpriteY (Block[x,y]) + y#)
	next x
 
	for x = 1 to 5
        if getSpriteY(Block[x,y]) > GetVirtualHeight() 
            SetSpritePosition (Block[x,y], getSpriteX(Block[x,y]), GetSpriteY (Block[x,y]) - 1200)
        endif
    next x
    next y
EndFunction
function ScrollLeft(x# as integer)
	for y=1 to 4
	for x = 1 to 5
		SetSpritePosition (Block[x,y], GetSpriteX (Block[x,y]) + x#, GetSpriteY (Block[x,y]) )
	next x
	for x = 1 to 5
      if getSpriteX(Block[x,y])<-300
         SetSpritePosition (Block[x,y], GetSpriteX (Block[x,y]) + 1500, GetSpriteY (Block[x,y]))
      endif
    next x
	next y
endfunction
function ScrollRight(x# as integer)
	for y=1 to 4
	for x = 1 to 5
		SetSpritePosition (Block[x,y], GetSpriteX (Block[x,y]) + x#, GetSpriteY (Block[x,y]) )
	next x
 
	for x = 1 to 5
      if getSpriteX(Block[x,y])> getVirtualWidth()
         SetSpritePosition (Block[x,y], GetSpriteX (Block[x,y]) - 1500, GetSpriteY (Block[x,y]))
      endif
    next x
    next y
endfunction

Rotating a group of sprites around one location with help from CJB
https://forum.thegamecreators.com/thread/216392
+ Code Snippet
SetWindowTitle( "rotatetest" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )

CentrePointX = 512
CentrePointY = 384

maxsprites = 1

for t = 1 to maxsprites
	createsprite(t,0)
	SetSpriteColor(t,random(50,255),random(50,255),random(50,255),255)
	SetSpritePosition(t,random(0,400)+312,random(0,400)+184)
	SetSpriteOffset(t,CentrePointX-getspritex(t),CentrePointY-getspritey(t))
next t

Angle#=0.0

do

	for t=1 to maxsprites
		SetSpriteAngle(t,Angle#)
	next t
	
	Angle#=Angle#+1.5
	print("x:" + str(GetSpriteX(1))+"  y:"+str(GetSpriteY(1)))
	print("xByOffset:" + str(GetSpriteXByOffset(1))+"  yByOffset:"+str(GetSpriteYByOffset(1)))
	print("WorldX:" + str(GetWorldXFromSprite(1,0-GetSpriteOffsetX(1),0-GetSpriteOffsetY(1))) +"  WorldY:" + str(GetWorldYFromSprite(1,0-GetSpriteOffsetX(1),0-GetSpriteOffsetY(1))))

    Print( ScreenFPS() )
    Sync()
loop
Posted: 10th Apr 2018 19:15
2d Physics motion game
https://forum.thegamecreators.com/thread/218886
+ Code Snippet
rem Bubble Madness
#constant xMax=1024
#constant yMax=768
#constant Bg=1000
gravity=50
global ang#=0
counter=0
rem balls from 1 to 20 
rem triangles from 21 to 30
rem text sprites from 100 to string length
rem rotators from 31 to 35
 
SetWindowTitle( "Bubble Madness" )
SetWindowSize( 1024, 768, 0 )
setVirtualResolution(1024,768)
SetOrientationAllowed( 0, 0, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
 
type mySprite
    id as integer       :rem id of sprite
    PointX as integer   :rem makes it move
    centreX as integer  :rem centre of sine wave x axis
    yPosition as integer:rem yPosition on y-axis
    amplitude as integer:rem the heaight of the wave
    speedX# as float    :rem how fast sine travels on x-axis
    WaveWidth as integer:rem how wide the sinewave is
    frequency# as float :rem speed sprite should move up and down (0.0 to 6.0)
    img as integer      :rem holds the image number for the sprite
endtype
 
type ball
    id as integer
    x as float
    y as float
endtype
 
//SetPhysicsDebugOn()
SetPhysicsScale( 0.1)
SetPhysicsGravity(0,gravity)
SetPhysicsWallTop(0)
SetPhysicsWallBottom(0)
 
global dim balls[20] as ball
SetClearColor(0,0,0)
img=createEllipse()
setupballs(img)
text$=invertText("FUBARPK presents Bubble Madness"):strlen=len(text$)
dim spr[strlen] as mySprite
for num=1 to strlen 
    spr[num].id=num+100:spr[num].img=num
    spr[num].centreX=xMax/2
    spr[num].yPosition=yMax/2
    spr[num].amplitude=20
    spr[num].speedX#=.51
    spr[num].WaveWidth=xMax
    spr[num].frequency#=1.4
    spr[num].PointX=90-(num*3)
    createTextImage(Mid(text$,num,1),spr[num].img)
    createSprite(spr[num].id,spr[num].img)
    SetSpriteColor(spr[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
    SetSpriteTransparency(spr[num].id,1)
    SetSpritePhysicsOn(spr[num].id,1)
next num 
placeRotators()
high=0:score=0
myString$="Bubble Madness"
CreateText(1,myString$)
SetTextSize(1,50)
SetTextPosition(1,300,0)
myHigh$="High :"+str(high)
CreateText(2,myHigh$)
SetTextSize(2,40)
SetTextPosition(2,800,0)
myScore$="Score:"+str(score)
CreateText(3,myScore$)
SetTextSize(3,40)
SetTextPosition(3,800,40)
 
/*bg=500
createsprite(Bg,0)
setspritesize(Bg,800 ,600)
SetSpriteColor(Bg,0,0,0,65)
EnableClearColor(0)   
*/
//ResetTimer()
//time#=timer()
flag=1
intro(strlen)
deleteTextSprites(strlen)
getReady()
img2=createTriangle() 
setupBase(img2)
sync()
exitBtn=1
AddVirtualButton(exitBtn,40,30,60) //make a button
SetVirtualButtonText( exitBtn, "Exit" ) //set number to image 
SetVirtualButtonColor( exitBtn,200,200,200)  //random colour 
//left side boundary
createSprite(36,0)
SetSpriteSize(36,10,yMax)
SetSpriteColor(36,255,255,255,255)
SetSpriteDepth ( 36, 0 ) 
SetSpritePositionByOffset(36,5,yMax/2)
SetSpritePhysicsOn(36,1)
SetSpriteGroup(36,3)
//right side boundary
createSprite(37,0)
SetSpriteSize(37,10,yMax)
SetSpriteColor(37,255,255,255,255)
SetSpriteDepth ( 37, 0 )
SetSpritePositionByOffset(37,xMax-5,yMax/2)
SetSpritePhysicsOn(37,1)
SetSpriteGroup(37,3)
if GetSpriteExists(Bg) then DeleteSprite(Bg)
createsprite(Bg,0)
setspritesize(Bg,xMax ,yMax)
SetSpriteColor(Bg,0,0,0,5)
EnableClearColor(0) ///Adds blur effect
render()
ClearScreen()
gravity=4
SetPhysicsGravity(0,gravity)
ResetTimer()
time#=timer()
repeat
    DrawSprite (Bg)
    for num=1 to 20
        if GetSpriteYByOffset(balls[num].id) > yMax
            balls[num].y =-150
            balls[num].x=random(100,xMax)
            SetSpriteColor( balls[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
            SetSpriteVisible(balls[num].id,1)
            SetSpritePositionByOffset(balls[num].id,balls[num].x,balls[num].y)
        endif
 
        for num2check=21 to 30
            if GetSpriteExists(num2check)
            if GetSpriteCollision(balls[num].id,num2check) 
                hit(balls[num].id,100,img)
                hit(num2Check,200,img2)
                inc counter
            endif
            endif
        next num2check   
    next num
    ang#=ang#+.5
    SetSpriteAngle( 31, ang# ) :rem centre rotator
    SetSpriteAngle( 32, -ang# ):rem top left
    SetSpriteAngle( 33, -ang# ):rem top right
    SetSpriteAngle( 34, -ang# ):rem bottom Left
    SetSpriteAngle( 35, -ang# ):rem bottom right
         
    if ( GetPointerPressed ( ) = 1 )
        hit = GetSpriteHitGroup( 1,ScreenToWorldX(GetPointerX()), ScreenToWorldY(GetPointerY()) )
    endif
    if hit<>0
        //SetSpriteVisible(hit,0):
        //Print( hit)
        hit(hit,100,img)
        score=score+(10*(11-counter)): myScore$="Score:"+str(score)
        SetTextString( 3,myScore$) 
        hit=0
    endif
    if Timer()-time#>2
        ResetTimer()
        if GetTextExists(100) then DeleteText(100)
        if gravity<50 
            inc gravity
            SetPhysicsGravity(0,gravity)
        endif
    endif
    if counter>9
        bonus=gravity*100
        score=score+bonus: myScore$="Score:"+str(score)
        SetTextString(3 ,myScore$) 
        if score>high then high=score
        SetTextString( 3,myScore$) :bonus=0:counter=0:ResetTimer()
        myHigh$="High :"+str(high):SetTextString( 2,myHigh$)
        gameOver():setupballs(img):setupBase(img2)
        score=0:gravity=4:SetPhysicsGravity(0,gravity)
        getReady():myScore$="Score:0":SetTextString(3 ,myScore$)
        ResetTimer() 
    endif
    Sync()
until GetVirtualButtonPressed(exitBtn)=1
end
 
function createEllipse()
    Render()
    DrawEllipse(50,50,25,25,MakeColor(255,255,255),MakeColor(100,100,100),1)
    Swap()
    img = getimage(0,0,100,100)
    sync()
endfunction img
 
function createTriangle()
    createSprite(600,0)
    SetSpriteSize(600,120,120)
    SetSpriteColor(600,0,0,0,255)
    DrawSprite(600)
    ClearScreen()
    Render()
    x=50:xx=50 //draw filled triangle
    for y = 0 to 50
        DrawLine(x,y,xx,y,255,255,255)
        dec x:inc xx
    next y
    Swap()
    Render()
    img = getimage(0,0,100,60)
    SetImageTransparentColor( img,0,0,0 )
    sync()
    DeleteSprite(600)
endfunction img
 
function createTextImage (myString as string,imgNum as integer)
CreateSprite(bg,0)
SetSpriteSize(bg,150,150)
SetSpriteColor(bg,0,0,0,255)
clearscreen()
CreateText(100,myString)
SetTextSize(100,50)
SetTextPosition(100,0,0)
drawSprite(100)
//if myString <> 
Render():If GetImageExists(imgNum) then DeleteImage(imgNum)
GetImage(imgNum,0,0,50,50):ClearScreen()
SetImageTransparentColor( imgNum,0,0,0 )
DrawSprite(bg)
ClearScreen()
DeleteText(100):deleteSprite(bg)
endfunction
 
function invertText(myString as string)
    resultString as string
    for num =len(myString) to 1 step -1
        resultString=resultString+Mid(myString,num,1)
    next num    
endfunction resultString
 
function getReady()
    myString$="Get Ready"
    if GetTextExists(100) then DeleteText(100)
    CreateText(100,myString$)
    SetTextSize(100,50)
    SetTextColor(100,0,200,0,255)
    SetTextPosition(100,375,300)
endfunction
 
function gameOver()
    myString$="GameOver"
    if GetTextExists(100) then DeleteText(100)
    CreateText(100,myString$)
    SetTextSize(100,50)
    SetTextColor(100,200,0,0,255)
    SetTextPosition(100,375,300)
    Sleep(20)
    repeat 
        sync()
    until GetPointerPressed() = 1
    DeleteText(100)
endfunction
 
function setupBase(img as integer)
multiplier=0
for num =21 to 30
    if GetSpriteExists(num) then DeleteSprite(num)
    CreateSprite(num,img)
    //SetSpriteSize(num,75,75)
    SetSpriteColor(num,255,255,255,255)
    SetSpriteTransparency(num,1)
    SetSpriteShape( num,3 ) 
    SetSpritePositionByOffset(num,(multiplier*100)+60,747)
    SetSpritePhysicsOn(num,1)
    SetSpriteGroup(num,2)
    inc multiplier
next num
endfunction
 
function hit(hit as integer,multiplier as integer, img as integer)
    DeleteParticles(hit+multiplier)
    CreateParticles(hit+multiplier,100,100)
    SetParticlesImage(hit+multiplier,img)
    SetParticlesSize(hit+multiplier,16)
    SetParticlesFrequency(hit+multiplier,25)
    SetParticlesLife(hit+multiplier,2.5)
    SetParticlesVelocityRange(hit+multiplier,1,10)
    SetParticlesMax(hit+multiplier,25)
    SetParticlesPosition(hit+multiplier,GetSpriteXByOffset(hit),GetSpriteYByOffset(hit))
    AddParticlesColorKeyFrame(hit+multiplier,0,GetSpriteColorRed(hit),GetSpriteColorGreen(hit),GetSpriteColorBlue(hit),255) 
    if multiplier = 100
        AddParticlesScaleKeyFrame( hit+multiplier,0,2 )
        balls[hit].y =-150
        balls[hit].x=random(100,GetDeviceWidth()-100)
        SetSpriteColor( hit, Random(1,255),Random(1,255), Random(1,255), 255 ) 
        SetSpriteVisible(hit,1)
        SetSpritePositionByOffset(hit,balls[hit].x,balls[hit].y)
    else
        AddParticlesScaleKeyFrame( hit+multiplier,0,1 )
        SetSpriteVisible(hit,0)
        SetSpriteActive(hit,0)
        DeleteSprite(hit)
    endif
endfunction
 
function setupballs (img as integer)
for num =1 to 20
    balls[num].id=num
    if GetSpriteExists(num) then DeleteSprite(num)
    CreateSprite(num,img)
    SetSpriteColor(num, Random(1,255),Random(1,255), Random(1,255), 255 ) 
    SetSpritePositionByOffset(num,random(100,xMax-100),-random(100,yMax/3))
    SetSpriteShapeCircle(num,0,0,25)
    SetSpritePhysicsOn(num,2)
    SetSpritePhysicsRestitution(num,.1 ) 
    SetSpriteGroup(num,1)
next num 
endfunction
 
function intro(strlen as integer)
exitBtn=1   
resetTimer()
delay#=Timer()
repeat
//if delay# > .05 
for num = 1 to strlen
    xWave=Sin(spr[num].PointX)*(spr[num].wavewidth/2)+spr[num].centreX
    yWave=sin(xWave*spr[num].frequency#)*(spr[num].amplitude)+spr[num].yposition
    SetSpritePosition(spr[num].id,xWave,yWave)
   
    if spr[num].PointX >-90
        spr[num].PointX = spr[num].PointX - spr[num].speedX#
        if spr[num].amplitude<250 and flag=1 
            spr[num].amplitude=spr[num].amplitude+2
            if spr[num].amplitude>=250 then flag=0
        endif
        if spr[num].amplitude >0 and flag=0 
            spr[num].amplitude=spr[num].amplitude-2
            if spr[num].amplitude<=20 then flag=1
        endif 
    else
        spr[num].PointX = 90
    endif
    ang#=ang#+.05
    SetSpriteAngle( 31, ang# ) :rem centre rotator
    SetSpriteAngle( 32, -ang# ):rem top left
    SetSpriteAngle( 33, -ang# ):rem top right
    SetSpriteAngle( 34, -ang# ):rem bottom Left
    SetSpriteAngle( 35, -ang# ):rem bottom right
     
next num
sync()
until Timer()-delay#>8
endfunction
 
function deleteTextSprites(strlen as integer)
for num = 1 to strlen
    deleteSprite(num+100)
next num    
endfunction 
     
 
function placeRotators()
    //rotating shape 1 (centre)
createSprite(31,0)
SetSpriteSize(31,250,10)
SetSpriteColor(31,255,255,255,255)
SetSpritePositionByOffset(31,xMax/2,yMax/2)
SetSpritePhysicsOn(31,1)
SetSpriteGroup(31,3)
 
//rotating shape 2 (top left)
createSprite(32,0)
SetSpriteSize(32,100,10)
SetSpriteColor(32,255,255,255,255)
SetSpritePositionByOffset(32,xMax/4,yMax/4)
SetSpritePhysicsOn(32,1)
SetSpriteGroup(32,3)
//rotating shape (top right)
createSprite(33,0)
SetSpriteSize(33,100,10)
SetSpriteColor(33,255,255,255,255)
SetSpritePositionByOffset(33,(xMax/4)*3,yMax/4)
SetSpritePhysicsOn(33,1)
SetSpriteGroup(33,3)
//rotating shape (bottom left)
createSprite(34,0)
SetSpriteSize(34,100,10)
SetSpriteColor(34,255,255,255,255)
SetSpritePositionByOffset(34,xMax/4,(yMax/4)*3)
SetSpritePhysicsOn(34,1)
SetSpriteGroup(34,3)
//rotating shape (top right)
createSprite(35,0)
SetSpriteSize(35,100,10)
SetSpriteColor(35,255,255,255,255)
SetSpritePositionByOffset(35,(xMax/4)*3,(yMax/4)*3)
SetSpritePhysicsOn(35,1)
SetSpriteGroup(35,3)
endfunction

2D Platform Tile Editor need to have your own tiles named 1 to 50 for example
https://forum.thegamecreators.com/thread/219932
+ Code Snippet
// Project: platform 
// Created: 2015-02-17

// set window properties
#constant xMaxView=1024 //maximum x viewing window
#constant yMaxView=600  //maximum y viewing window
#constant xMax=6148		//maximum width of level
#constant yMax=600		//maximum height of level

SetWindowTitle( "platform Editor" )
SetWindowSize( xMax, yMax, 0 )
SetScreenResolution( xMaxView, yMaxView ) 

// set display properties
SetVirtualResolution( xMaxView, yMaxView )
SetOrientationAllowed( 0, 0, 1, 1 )

//force sync rate to 60 for best cross platform support.
SetSyncRate(60,0)

rem ***** set up constants ******
#constant objectlimit = 300 : //Limit how many objects we can create so as to not go over the arrays size,which would
							// cause an error.
#constant    KEY_F1       =    112 : // these are scancode values for the keypresses,using variables rather than just values
#constant    KEY_F2       =    113 : // is good practice and makes the code more readable for future modifying.
#constant    KEY_C        =    67
#constant    KEY_G        =    71
#constant    KEY_H        =    72
#constant    KEY_Z        =    90
#constant    KEY_X        =    88
#constant    KEY_U        =    85
#constant    KEY_I        =    73
#constant    KEY_Left	  =	   37
#constant    KEY_Right	  =	   39
#constant    KEY_Up	  	  =	   38
#constant    KEY_Down	  =	   40
#constant    KEY_Backspace=8

#constant cursorsprite=1000
#constant displaysprite = 1001
 
	
// define a type for the objects
type objecttype
	sprite as integer
	x as integer
	y as integer
	group as integer
	image as integer
endtype
dim object[objectlimit] as objecttype
// define a type for our mouse and screen coordinates
type TMouse
     x1#
     y1#
     x2#
     y2#
     x3
     y3
 endtype
 global Mouse as TMouse
 global gridx#=64
 global gridy#=64
 global group=0 : // starting group number, we can use group numbers as a
				 //  simple way to say what type of sprite you want,this
				 // depends on you the programmer to keep track of
				 // when it comes to using the saved level data...
				 // I will explain this when I write that very part!
				 // A hint here is to do it old style and write notes
				 // down on a physical paper notepad! again another good
				 // practice in programming. Especially when you are old'ish
				 //like me and have fried a few million brain cells so far! ;)
				 
 global objectnumber=1 : // starting sprite number
 global image=1 : //starting sprite image number
 global lev$="" : //string used to display current level number being edited
 global obj$=""
 global group$="" : //string to display the current group number
 global viewoffsetX$=""
 global viewoffsetY$=""
 global level=1 : //actual level number,we use this for the conversion for lev$
 global objectcount=0
 global imagelimit = 120 : // set an image limit,depending how many we have!
 global magnetic=1
 global magnetic$="Magnetic =Off" //Magnetic on keeps the tile placement only within the grid
 // I use functions where I can, another good practice! functions can be re-used
 // and can keep clear of the main loop to make the whole code more readable, 
 // they have a very powerful feature of being able to have parameters
 // As you learn more about programming, if you are an absolute beginner that is,
 // then you will see how it all makes for wonderful programming structure!
 
 init(): // no parameters to pass here! I always find it good practice to call a 
        // function like this and do whatever things need doing first just before we
        // get to the main game loop which is next!
global x=0:global y=0    
#constant Backdrop=500
LoadImage(Backdrop,"BG1.png")
CreateSprite(Backdrop,Backdrop)
SetSpriteDepth(Backdrop,20)
SetSpriteGroup(Backdrop,5)
SetSpritePosition(Backdrop,0,yMax-GetSpriteHeight(Backdrop))    
FixSpriteToScreen(Backdrop,1)
	
do
    control()
    SetViewOffset (x, y)
	
	lev$="Level Number = "+str(level)
	SetTextString(1,lev$)
	settextposition(1,10,10)
	FixTextToScreen(1,1)
	obj$="Object count = "+str(objectcount)
	SetTextString(2,obj$)
	settextposition(2,10,30)
	FixTextToScreen(2,1)
	group$="Group number = "+str(group)
	settextstring(3,group$)
	settextposition(3,10,50)
	FixTextToScreen(3,1)
	viewoffsetX$="View offset X="+str(x)
	settextstring(4,viewoffsetX$)
	settextposition(4,10,70)
	FixTextToScreen(4,1)
	viewoffsetY$="View offset Y="+str(y)
	settextstring(5,viewoffsetY$)
	settextposition(5,10,90)
	FixTextToScreen(5,1)
	
	if magnetic=0
		magnetic$="Magnetic = Off"
	else
		magnetic$="Magnetic = On"
	endif
	settextstring(6,magnetic$)
	settextposition(6,10,110)
	FixTextToScreen(6,1)
		
	setspriteposition(cursorsprite,Mouse.x3,Mouse.y3)
    ///////////////////
    //SetSpriteImage(cursorsprite,image)
    SetSpriteSize(cursorsprite,GetImageWidth(image),GetImageHeight(image))

    Sync()
loop

function init()
	load_images() : //a small function to load in images that have been save numerically
	rem *************** Create cursor sprite ***************
	createsprite(cursorsprite,1) : // Create the cursor sprite using the variable we predifined
								   // within the globals
	SetSpriteDepth(cursorsprite,0)
	//setspritesize(cursorsprite,64,64) : // We will stick to a set size of 64 wide and 64 tall
	

	
	createtext(1,lev$) : 	// Create the text to display current level number ******
	createtext(2,obj$): //create the text to keep track of how many objects we have so far	
	createtext(3,group$)
	createtext(4,viewoffsetX$)
	createtext(5,viewoffsetY$)
	createtext(6,magnetic$)
	CreateText(7,"F1 Load")
	CreateText(8,"F2 Save")
	CreateText(9,"C Clear")
	CreateText(10,"G Dec Level")
	CreateText(11,"H Inc Level")
	CreateText(12,"Z Dec Image")
	CreateText(13,"X Inc Image")
	CreateText(14,"U Dec Group")
	CreateText(15,"I Inc Group")
	CreateText(16,"M Magnetic")
	CreateText(17,"BackSpace Undo")
	

	settextsize(1,20)    // set the size of the lev$ text
	settextsize(2,20)    //set the size of the obj$ text
	settextsize(3,20)
	settextsize(4,20)
	SetTextSize(5,20)
	settextsize(6,20)
	settextsize(7,20)
	settextsize(8,20)
	settextsize(9,20)
	settextsize(10,20)
	settextsize(11,20)
	settextsize(12,20)
	settextsize(13,20)
	settextsize(14,20)
	settextsize(15,20)
	settextsize(16,20)
	settextsize(17,20)

	settextposition(7,10,140)
	settextposition(8,10,160)
	settextposition(9,10,180)
	settextposition(10,10,200)
	settextposition(11,10,220)
	settextposition(12,10,240)
	settextposition(13,10,260)
	settextposition(14,10,280)
	settextposition(15,10,300)
	settextposition(16,10,320)
	settextposition(17,10,340)

	FixTextToScreen(7,1)
	FixTextToScreen(8,1)
	FixTextToScreen(9,1)
	FixTextToScreen(10,1)
	FixTextToScreen(11,1)
	FixTextToScreen(12,1)
	FixTextToScreen(13,1)
	FixTextToScreen(14,1)
	FixTextToScreen(15,1)
	FixTextToScreen(16,1)
	FixTextToScreen(17,1)
	
			
	createsprite(displaysprite,image)
	//setspritesize(displaysprite,128,128)
	setspriteposition(displaysprite,850,10)
	setspritedepth(displaysprite,0)
	FixSpriteToScreen(displaysprite,1)
	
endfunction


function control()
	//FillMouse(gridx#,gridy#): // variable to Check if user has just pressed the pointer
	
	FillMouse(getSpritewidth(cursorsprite),getSpriteHeight(cursorsprite)): // variable to Check if user has just pressed the pointer
	//FillMouse(16,16)
	state=GetPointerReleased()
	if state = 1 and objectnumber<objectlimit : // a value of 1 means it is pressed, and if within the array limit
												// we can proceed to make another object
		makeobject(objectnumber,Mouse.x3,Mouse.y3)
		inc objectnumber
		inc objectcount
	endif
	
	if getrawkeypressed(KEY_Backspace) and objectnumber>1
		DeleteSprite(objectnumber-1)
		//object.remove(objectnumber-1)
		dec objectnumber
		dec objectcount	
	endif
	
	//Check for keypressed
	if GetRawKeyReleased(KEY_F2) : // If we have just pressed the F2 key then we save the level
		save_level(level)
	endif
	if getrawkeypressed(KEY_F1) : // If we have just pressed the F1 key then we load the level
								  // It will load the level according to whatever the current level
								  // number is set to,if it exists!
		load_level(level)
	endif
	if getrawkeypressed(KEY_C)
		clear_level() : // If the user presses the c key then we clear the level, this also gets called
					   //  within the load_level function so we can clear out the types and
					   //  values set to the defaults ready to receive a new or saved level
	endif
	if getrawkeyreleased(KEY_G) and level>1 : // If the user presses the G key then decrement the value of the 
											 //variable level, and we also check that we do not go below a value
											 //of 1 or you would be going to level zero and lower!
		dec level
	endif
	if getrawkeyreleased(KEY_H) : // If user presses key H then increment the variable level *************
		inc level
	endif
	if getrawkeyreleased(KEY_Z) //and image>1
		if image>1
			dec image
		else
			image=imagelimit
		endif	
		setspriteimage(displaysprite,image)
		SetSpriteSize(displaysprite,GetImageWidth(image),GetImageHeight(image))
	endif
	if getrawkeyreleased(KEY_X) //and image<imagelimit
		if image<imagelimit
			inc image
		else
			image=1
		endif
		setspriteimage(displaysprite,image)
		SetSpriteSize(displaysprite,GetImageWidth(image),GetImageHeight(image))
	endif
	if getrawkeypressed(KEY_U) and group>0 : // if U key is pressed then decrement group variable
		dec group
	endif
	if getrawkeypressed(KEY_I) : // if I key is pressed then inccrement group variable
		inc group
	endif

    if GetRawKeyPressed(KEY_Left) and x>=gridx#  //left
		x=x-gridx#
	endif
	if GetRawKeyPressed(KEY_Right) and x<=(xMax-gridx#)  //right
		x=x+gridx#
	endif
	if GetRawKeyPressed(KEY_Up) and y>=gridy#  //up
		y=y-gridy#
	endif
	if GetRawKeyPressed(KEY_Down) and y<=(yMax-gridy#)  //down
		y=y+gridy#
	endif
		
	if GetRawKeyPressed(77) //M
		if magnetic=0
			magnetic=1
		else
			magnetic=0
		endif
	endif


endfunction

function FillMouse(x#,y#)
     Mouse.x1#=getpointerx()
     Mouse.y1#=getpointery()
     Mouse.x2#=screentoworldx(Mouse.x1#)
     Mouse.y2#=screentoworldy(Mouse.y1#)
     if magnetic=1
		Mouse.x3=floor(Mouse.x2#/x#)*x# //keeps it working in a tileable grid
		Mouse.y3=floor(Mouse.y2#/y#)*y#+addToPlacement(y#) //grid placement allowing for flat on ground
	 else												   //remove addToPlacement if you want to place tiles from the top  
		Mouse.x3=(Mouse.x2#/x#)*x#
		Mouse.y3=(Mouse.y2#/y#)*y#
	endif	
 endfunction
 
function addToPlacement(y#)
	yy=floor(yMax/y#)
	result#=yMax-(yy*floor(y#))	
endfunction result#
 
 function makeobject(objectnumber,x,y)
	 createsprite(objectnumber,image)
	 SetSpritePosition(objectnumber,x,y)
	 //setspritesize(objectnumber,64,64)
	 object[objectnumber].x=x
	 object[objectnumber].y=y 
	 object[objectnumber].image=image
	 object[objectnumber].sprite=objectnumber
	 object[objectnumber].image=image
	 object[objectnumber].group=group
endfunction
 
 function load_images()
	// because I have saved the images numerically,in other words they are named
	// 1.png, 2.png. etc... I can make a simple loop to check if any exists using a simple 
	// value to string conversion, if it does we load it!
	for n=1 to imagelimit
		f$=str(n) + ".png"
		if getfileexists(f$)
			loadimage (n,f$)
		endif
	next
endfunction



function save_level(level)
	f$=""
	f$="level"
	f$=f$+str(level)
	f$=f$+".lev"
	myfile=opentowrite(f$,0)
	for n=1 to objectlimit
		writeinteger(myfile,object[n].sprite)
		writeinteger(myfile,object[n].x)
		writeinteger(myfile,object[n].y)
		writeinteger(myfile,object[n].group)
		writeinteger(myfile,object[n].image)
	next n
	closefile(myfile)
endfunction

function load_level(level)
	backImg$="BG"+str(level)+".png"
	if GetFileExists(backImg$) 
		DeleteSprite(Backdrop)
		DeleteImage(Backdrop)
		LoadImage(Backdrop,backImg$)
		CreateSprite(Backdrop,Backdrop)
		SetSpriteDepth(Backdrop,20)
		SetSpriteGroup(Backdrop,5)
		SetSpritePosition(Backdrop,0,yMax-GetSpriteHeight(Backdrop))    
		FixSpriteToScreen(Backdrop,1)  
	endif
	f$=""
	f$="level"
	f$=f$+str(level)
	f$=f$+".lev"
	if GetFileExists(f$)
	clear_level()
	myfile=opentoread(f$)
	for n=1 to objectlimit
		objnum = readinteger(myfile)
		xpos=readinteger(myfile)
		ypos=readinteger(myfile)
		gr=readinteger(myfile)
		im=readinteger(myfile)
		if objnum>0
			createsprite(objnum,im)
			//setspritesize(objnum,64,64)
			setspriteposition(objnum,xpos,ypos)
			object[n].sprite=objnum
			object[n].x=xpos
			object[n].y=ypos
			object[n].image=im
			object[n].group=gr
			inc objectcount
		endif
	next n
	objectnumber=objectcount+1
	closefile(myfile)
	else
		e$="Error... File does not exist!"
		createtext(20,e$)
		settextsize(20,20)
		settextposition(20,50,50)
		sync()
		sleep(2000)
		deletetext(20)
		
	endif
	
endfunction

function clear_level()
	for n=1 to objectlimit
		object[n].sprite = 0
		object[n].x=0
		object[n].y=0
		object[n].image=0
		object[n].group=0
		if getspriteexists(n) = 1
			deletesprite(n)
		endif
	next n
	objectnumber=1
	objectcount=0
endfunction

2D Path Editor using Clonkex Bezier Curve
https://forum.thegamecreators.com/thread/221096
+ Code Snippet
// Project: Path Editor 
// Created: 2017-10-30

// show all errors
SetErrorMode(2)

#constant clearBtn=1
#constant test1Btn=2
#constant test2Btn=3
#constant closedBtn=4
#constant loadBtn=5
#constant saveBtn=6
#constant exitBtn=7
#constant spr=1
#constant xMax=1024
#constant yMax=768
#constant horizontalGrid=64
#constant verticalGrid=64

global renderImg=100
global closed=1 //whether or not to draw as open or closed curve

type object
	x as float
	y as float
endtype

type mySpr 
	id as integer
	x as float
	y as float
	xOffset as float
	yOffset as float
	closed as integer
endtype

global testSpr as mySpr
testSpr.id=2
testSpr.closed=closed
#include "include/Bezier Curve Library.agc"
Global dim stuff#[0]
global totalLength# = 0

gosub _bc_setup //this has to be called before any BC command, preferably before anything at all

// set window properties
SetWindowTitle( "Path Editor" )
SetWindowSize( xMax, yMax, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // 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

loadimage (1,"06.png")

CreateSprite (spr,0)
SetSpriteSize (spr,10,10)
//CreateSprite (testSpr.id,1)
CreateSprite (testSpr.id,1)
//SetSpriteSize (testSpr.id,200,200)
//SetSpriteColor (testSpr.id,0,255,0,255)
SetSpritePositionByOffset(testSpr.id,xMax/2,yMax/2)

AddVirtualButton(clearBtn,40,30,60) //make a button
SetVirtualButtonText( clearBtn, "Clear" ) //set to exit text 
SetVirtualButtonColor( clearBtn,200,200,200)  //grey colour 
AddVirtualButton(test1Btn,40,90,60) //make a button
SetVirtualButtonText( test1Btn, "Test Points" ) //set to music text 
SetVirtualButtonColor( test1Btn,200,200,200)  //grey colour 
AddVirtualButton(test2Btn,40,150,60) //make a button
SetVirtualButtonText( test2Btn, "Test Bezier" ) //set to music text 
SetVirtualButtonColor( test2Btn,200,200,200)  //grey colour 
AddVirtualButton(closedBtn,40,210,60) //make a button
if closed=1 
	SetVirtualButtonText( closedBtn, "Closed" ) //set to music text 
else
	SetVirtualButtonText( closedBtn, "Open" ) //set to music text
endif
SetVirtualButtonColor( closedBtn,200,200,200)  //grey colour 
AddVirtualButton(saveBtn,40,270,60) //make a button
SetVirtualButtonText( saveBtn, "Save" ) //set to music text 
SetVirtualButtonColor( saveBtn,200,200,200)  //grey colour 
AddVirtualButton(loadBtn,40,330,60) //make a button
SetVirtualButtonText( loadBtn, "Load" ) //set to music text 
SetVirtualButtonColor( loadBtn,200,200,200)  //grey colour 
AddVirtualButton(exitBtn,40,390,60) //make a button
SetVirtualButtonText( exitBtn, "Exit" ) //set to sound text 
SetVirtualButtonColor( exitBtn,200,200,200)  //grey colour 

CreateRenderImage (renderImg,xMax,yMax,0,0) 
CreateSprite(350,renderImg) 

dim path[100] as object
SetSpriteVisible(testSpr.id,0)
SetSpriteDepth(testSpr.id,9)
clearPoints():count=1
SetRenderToImage (renderImg,0) 
drawCrosshairAndGrid(horizontalGrid,verticalGrid)

repeat
    mx#=GetPointerX()
	my#=GetPointerY()
	SetSpritePositionByOffset(spr,mx#,my#) 
	if GetRawMouseLeftPressed() 
		path[count].x=mx#:path[count].y=my#
		SetRenderToImage (renderImg,0) 
		drawSprite(spr)
		bc_addcurvepoint(getrawmousex(),getrawmousey())
		if closed=0
			bc_calculateopencurvesegmentpoints()
		else
			bc_calculateclosedcurvesegmentpoints()
		endif
		//////////////////////////////////////////////////
        // Added these two lines here
        //////////////////////////////////////////////////
        a=bc_getcurvesegmentpointcount():dim stuff#[a]
        totalLength# = calculateLength()
		inc count
    endif
	if GetVirtualButtonPressed(clearBtn)
		clearPoints()
		count=1
		SetRenderToImage (renderImg,0) 
		drawCrosshairAndGrid(horizontalGrid,verticalGrid)
	endif
		
	Update(0)
	Render()
	setrendertoscreen () 
	
	SetSpriteSize(350,1024,768)

	Update(0)
	Render()
	swap()
	
	if GetVirtualButtonPressed(closedBtn)
		if closed=1 
			closed=0:testSpr.closed=closed
			SetVirtualButtonText( closedBtn, "Open" ) // 
		else
			closed=1:testSpr.closed=closed
			SetVirtualButtonText( closedBtn, "Closed" ) //
		endif
	endif
	
	if GetVirtualButtonPressed(test1Btn)
		testPaths()
	endif

	if GetVirtualButtonPressed(test2Btn)
		drawBezier()
		testBezierCurve()
		//Bezier2()
	endif
	
	if GetVirtualButtonPressed(saveBtn)
		saveArray(count)
	endif
	if GetVirtualButtonPressed(loadBtn)
		clearPoints()
		SetRenderToImage (renderImg,0) 
		drawCrosshairAndGrid(horizontalGrid,verticalGrid)
		count=loadArray()
	endif
		
until GetVirtualButtonPressed(exitBtn)
end

function drawCrosshairAndGrid(gridX, gridY)
	for y=0 to yMax step gridX
		drawline(0,y,xMax,y,0,255,0)
	next y
	for x=0 to xMax step gridY
		drawline(x,0,x,yMax,0,255,0)
	next x
    drawline(0,yMax/2,xMax,yMax/2,255,0,0)
	drawline(xMax/2,0,xMax/2,yMax,255,0,0)		
endfunction

function clearPoints ()
for t = 0 to 100
	path[t].x=0:path[t].y=0
next t
BC_RemoveCurvePoints()
DeleteSprite(350):DeleteImage(renderImg)
renderImg=CreateRenderImage (xMax,yMax,0,0) 
CreateSprite(350,renderImg) 
endfunction

function drawBezier()
if bc_getcurvesegmentpointcount()>0
	SetRenderToImage (renderImg,0) 
	for i=0 to bc_getcurvesegmentpointcount()-2 //normally use -1, but I want to stop 1 early of the end of the array
		drawline(bc_getcurvesegmentpointx(i),bc_getcurvesegmentpointy(i),bc_getcurvesegmentpointx(i+1),bc_getcurvesegmentpointy(i+1),255,0,0)
 	next i
endif
Update(0)
Render()
setrendertoscreen () 
Update(0)
Render()
swap()
	
endfunction

function testBezierCurve()
testSpr.xOffset=0:testSpr.yOffset=0
SetSpriteVisible(testSpr.id,1)
if bc_getcurvesegmentpointcount()>0
	for i=0 to bc_getcurvesegmentpointcount()-1 //normally use -1, but I want to stop 1 early of the end of the array
		
	//////////////////////////////////////////////////
    // Constant speed around the bezier curve
    //////////////////////////////////////////////////
		if bc_getcurvesegmentpointcount() > 0
        // Simply to control an even time update
			if timestamp <= getMilliseconds()
				// A point on the bezier curver lies between 0 and 1.
				t# = t# + 0.001
				// If time goes beyond 1, subtract 1. This will provide
				// a more even movement.
				if t# > 1 then t# = t# - 1
 
				// How far from the beginning of the curve are we
				seg# = totalLength# * t#
				// Find the point at the beginning of the line segment that we are currently on
				s = getCurveSegmentPointAtDistance(seg#)
				// Calculate the length of this line segment
				segLength# = stuff#[s+1] - stuff#[s]
				// Calculate how far along this single line segment we are
				partSegLength# = seg# - stuff#[s]
				n# = partSegLength# / segLength#
				print(n#)
				// Use some linear interpolation to determine the coordinates on this line segment
				x = bc_getcurvesegmentpointx(s) + (bc_getcurvesegmentpointx(s+1)-bc_getcurvesegmentpointx(s))*n#
				y = bc_getcurvesegmentpointy(s) + (bc_getcurvesegmentpointy(s+1)-bc_getcurvesegmentpointy(s))*n#
				// Position the sprite
				SetSpritePositionByOffset(testSpr.id,bc_getcurvesegmentpointx(i)+testSpr.xOffset,bc_getcurvesegmentpointy(i)+testSpr.yOffset)			
				// Update timer
				timestamp = getMilliseconds() + 20
			endif
		endif
 		
		//SetSpritePositionByOffset(testSpr.id,bc_getcurvesegmentpointx(i)+testSpr.xOffset,bc_getcurvesegmentpointy(i)+testSpr.yOffset)
		//add following to point to centre
		angle#=getAngle(bc_getcurvesegmentpointx(i),bc_getcurvesegmentpointy(i),bc_getcurvesegmentpointx(i+1),bc_getcurvesegmentpointy(i+1))
		SetSpriteAngle(testSpr.id,getAngle(GetSpriteXByOffset(testSpr.id),GetSpriteYByOffset(testSpr.id),xMax/2,yMax/2)):rem point to middle of screen
		sync()
 	next i
endif
SetSpriteVisible(350,1)
SetSpriteVisible(testSpr.id,0)
endfunction

function testPaths()
//testSpr.x=xMax/2:testSpr.y=yMax/2
testSpr.xOffset=0:testSpr.yOffset=0

testSpr.x=path[1].x+testSpr.xOffset:testSpr.y=path[1].y+testSpr.yOffset
count=1:speed#=5
//SetSpriteVisible(350,0)
SetSpriteVisible(testSpr.id,1)
rem move sprite X steps
repeat
	SetSpritePositionByOffset(testSpr.id,testSpr.x,testSpr.y)	
	//SetSpriteSize(testspr,200,200)
	while getDistance(testSpr.x,testSpr.y,path[count+1].x,path[count+1].y)>5
		angle#=getAngle(testSpr.x,testSpr.y,path[count+1].x,path[count+1].y)
		testSpr.x=testSpr.x-sin(angle#)*speed#:testSpr.y=testSpr.y+cos(angle#)*speed#
		SetSpritePositionByOffset(testSpr.id,testSpr.x+testSpr.xOffset,testSpr.y+testSpr.yOffset)
		SetSpriteAngle(testSpr.id,getAngle(GetSpriteXByOffset(testSpr.id),GetSpriteYByOffset(testSpr.id),xMax/2,yMax/2)):rem point to middle of screen
		//SetSpriteAngle(testspr,angle#):rem point to way point
		print( getDistance(testSpr.x,testSpr.y,path[count+1].x,path[count+1].y))
		sync()
		
	endwhile	
	//x=path[count+1].x:y=path[count+1].y
	inc count	
	
until path[count+1].x=0 and path[count+1].y=0
rem move sprite to first point if closed path
if testSpr.closed=1
	while getDistance(testSpr.x,testSpr.y,path[1].x,path[1].y)>5
		angle#=getAngle(testSpr.x,testSpr.y,path[1].x,path[1].y)
		testSpr.x=testSpr.x-sin(angle#)*speed#:testSpr.y=testSpr.y+cos(angle#)*speed#
		SetSpritePositionByOffset(testSpr.id,testSpr.x+testSpr.xOffset,testSpr.y+testSpr.yOffset)
		SetSpriteAngle(testSpr.id,getAngle(GetSpriteXByOffset(testSpr.id),GetSpriteYByOffset(testSpr.id),xMax/2,yMax/2)):rem point to middle of screen
		//SetSpriteAngle(testspr,angle#):rem point to way point
		print( getDistance(testSpr.x,testSpr.y,path[count+1].x,path[count+1].y))
		sync()
	endwhile	
endif	

SetSpriteVisible(350,1)
SetSpriteVisible(testSpr.id,0)

endfunction	

function getAngle(x1#, y1#, x2#, y2#)
    result# = ATanFull(x1# - x2#, y1# - y2#)
endfunction result#


function getDistance (x1#,y1#,x2#,y2#) 
	dx#=x1#-x2#
	dy#=y1#-y2#
	distance#=sqrt((dx#*dx#)+(dy#*dy#)):rem distance object to path point
endfunction distance#

function difference(x as float ,y as float)
diff as float
diff = (x-y)
endfunction diff


function saveArray(count as integer)
write = OpenToWrite("arrayPath.txt" ,0)
length=count 
String$ = Str(length-1)
WriteLine (write,String$)
WriteLine (write,Str(closed))
for num=1 to length
	StringX$ = Str(path[num].x-(xMax/2))
	StringY$ = Str(path[num].y-(yMax/2))
	WriteLine (write,StringX$)
	WriteLine (write,StringY$)
next num
Closefile(write)
write = OpenToWrite("arrayBezier.txt" ,0)
length=bc_getcurvesegmentpointcount()-1 
String$ = Str(length-1)
WriteLine (write,String$)
WriteLine (write,Str(closed))
if bc_getcurvesegmentpointcount()>0
	for i=1 to bc_getcurvesegmentpointcount()-2 //normally use -1, but I want to stop 1 early of the end of the array
		StringX$ = Str((bc_getcurvesegmentpointx(i)+testSpr.xOffset)-(xMax/2))
		StringY$ = Str((bc_getcurvesegmentpointy(i)+testSpr.yOffset)-(yMax/2))
		WriteLine (write,StringX$)
		WriteLine (write,StringY$)
 	next i
endif
Closefile(write)

endfunction

function loadArray()
for t = 0 to 100
	path[t].x=0:path[t].y=0
next t

If GetFileExists("arrayPath.txt")
	read = OpenToRead("arrayPath.txt")
	String1$ = ReadLine(read)
	length=val(String1$)
	String2$ = ReadLine(read)
	closed=val(String2$):testSpr.closed=closed
	BC_RemoveCurvePoints()
	//dim path[length] as object
	for num =1 to length
		StringX$ = ReadLine(read)
		StringY$ = ReadLine(read)
		path[num].x=((xMax/2)+val(StringX$))
		path[num].y=((yMax/2)+val(StringY$))	
		
		SetRenderToImage (renderImg,0) 
		SetSpritePosition(spr,path[num].x,path[num].y)
		drawSprite(spr)
		bc_addcurvepoint(path[num].x,path[num].y)
		if closed=0
			bc_calculateopencurvesegmentpoints()
		else
			bc_calculateclosedcurvesegmentpoints()
		endif
		
		//////////////////////////////////////////////////
        // Added these two lines here
        //////////////////////////////////////////////////
        a=bc_getcurvesegmentpointcount()
        dim stuff#[a]
        totalLength# = calculateLength()
		
		Update(0)
		Render()
		setrendertoscreen () 
	
		SetSpriteSize(350,1024,768)

		Update(0)
		Render()
		swap()
	next num
	Closefile(read)
	if closed=1 
		SetVirtualButtonText( closedBtn, "Closed" ) //set to music text 
	else
		SetVirtualButtonText( closedBtn, "Open" ) //set to music text
	endif
	count=length
	
endif
endfunction count

//////////////////////////////////////////////////
// Calculates the distance of each point from the
// beginning of the curve.
// Returns total length of the curve.
//////////////////////////////////////////////////
function calculateLength()
    total# = 0
    if bc_getcurvesegmentpointcount() > 0
        for i = 0 to bc_getcurvesegmentpointcount() - 2
            x# = (bc_getcurvesegmentpointx(i)-bc_getcurvesegmentpointx(i+1))^2
            y# = (bc_getcurvesegmentpointy(i)-bc_getcurvesegmentpointy(i+1))^2
            d# = sqrt(x# + y#)
            total# = total# + d#
            stuff#[i] = total#
        next i
    endif
endfunction total#
 
 
//////////////////////////////////////////////////
// Finds which line segment that 'd#' falls on.
// Since this array is technically a sorted list,
// it can be modified into a binary search for
// improved lookup speeds.
//////////////////////////////////////////////////
function getCurveSegmentPointAtDistance(d#)
    for i = 0 to bc_getcurvesegmentpointcount() - 2
        if d# >= stuff#[i] and d# < stuff#[i+1] then exitfunction i
    next i
endfunction 0

If you want to see something how I have combined both the tile editor and path editor
to make a never ending scrolling game visit https://forum.thegamecreators.com/thread/221096#msg2614055
Posted: 10th Apr 2018 19:20
2d Snow without particles
builds up
https://forum.thegamecreators.com/thread/219225
+ Code Snippet
// Project: Snow 
// Created: 2017-04-21
// Project: test3 
// Created: 2017-03-22
#constant xMax=1024
#constant yMax=600
#constant Bg=1000
#constant maxSnow=50

gravity=50
// show all errors
//SetErrorMode(2)

// set window properties
SetWindowTitle( "test3" )
SetWindowSize( xMax, yMax, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( xMax, yMax ) // 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
renderImg=1000
CreateRenderImage(renderImg,xMax,yMax,0,0)
//snowImg = loadImage("Snow.png")
snowImg=createEllipse()
SetClearColor(0,0,0)
for num=1 to maxSnow
	CreateSprite(num,snowImg)
	SetSpriteSize(num,8,8)
	SetSpritePositionByOffset(num,random(5,xMax-5),random(1,yMax-100))
	//back slower snow
	CreateSprite(num+499,snowImg)
	SetSpriteSize(num+499,6,6)
	SetSpriteColor(num+499,250,250,250,255):rem a slighter different shade to help with collisions
	SetSpritePositionByOffset(num+499,random(5,xMax-5),random(1,yMax-100))
	//even further Back snow
	CreateSprite(num+599,snowImg)
	SetSpriteSize(num+599,4,4)
	SetSpriteColor(num+599,245,245,245,255):rem a slighter different shade to help with collisions
	SetSpritePositionByOffset(num+599,random(5,xMax-5),random(1,yMax-100))
next num

CreateSprite(350,renderImg) 
SetSpriteSize(350,xMax,yMax)
SetSpritePosition(350,0,0)
SetSpriteDepth(350,9999)


flag=1
do
for num = 1 to maxSnow
	//front snow
	SetSpritePositionByOffset(num,GetSpriteXByOffset(num),GetSpriteYByOffset(num)+8)
	//back snow
	SetSpritePositionByOffset(499+num,GetSpriteXByOffset(499+num),GetSpriteYByOffset(499+num)+6)
	//further back snow
	SetSpritePositionByOffset(599+num,GetSpriteXByOffset(599+num),GetSpriteYByOffset(599+num)+4)
	
	//checks to see if the front white snow has collided with other white snow
	if pickColor(GetSpriteXByOffset(num),GetSpriteYByOffset(num)+6)="255,255,255" //and GetSpriteHit(GetSpriteXByOffset(num),GetSpriteYByOffset(num))<>num  
		SetSpritePositionByOffset(num,GetSpriteXByOffset(num),GetSpriteYByOffset(num)+2)
		SetRenderToImage(renderImg,0)
		DrawSprite(num)
		SetRenderToScreen()

		SetSpriteImage(350,renderImg)
		SetSpritePositionByOffset(num,random(5,xMax-5),-random(0,20))
	endif 	
	//checks if front snow hits bottom of screen
	if GetSpriteYByOffset(num)>yMax-2
		SetRenderToImage(renderImg,0)
		DrawSprite(num)
		SetRenderToScreen()
		SetSpriteImage(350,renderImg)
		SetSpritePositionByOffset(num,random(5,xMax-5),-random(0,20))
	endif
	
	//check if the back parallax snow hits bottom
	if GetSpriteYByOffset(499+num)>yMax-2
		SetSpritePositionByOffset(499+num,random(5,xMax-5),-random(0,20))
	endif
	if GetSpriteYByOffset(599+num)>yMax-2
		SetSpritePositionByOffset(599+num,random(5,xMax-5),-random(0,20))
	endif
next num
Sync()
loop

function createBox()
	Render()
	DrawBox( 0, 0, xMax, 5, MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), 1 ) 
	Swap()
	img = getimage(0,0,25,768)
	sync()
endfunction img

function createEllipse()
	Render()
	DrawEllipse(25,25,25,25,MakeColor(255,255,255),MakeColor(255,255,255),1)
	Swap()
	img = getimage(0,0,50,50)
	sync()
endfunction img


Function pickColor(X,Y)
	rem prepare image grab area
	clearScreen()
	setScissor(X,Y,X+1,Y+1)
	render()

	rem get image
	img = getImage(x,y,1,1)

	rem create memblock
	mem = createMemblockfromImage(img)

	rem get memblock data
	r = getMemblockbyte(mem,12):rem gets red channel data
	g = getMemblockbyte(mem,13):rem gets green channel data
	b = getMemblockbyte(mem,14):rem gets blue channel data
	s$ = str(r)+","+str(g)+","+str(b)

	rem tidy up
	deletememblock(mem)
	deleteimage(img)
	setScissor(0,0,getDeviceWidth(),getDeviceHeight())
	clearScreen()
endfunction s$

2D snow with particles
+ Code Snippet
Setvirtualresolution(1024,600)
id = CreateParticles(512,0) 	:rem the location of the emitter
SetParticlesSize(id,2.0)		:rem size of particles
SetParticlesLife(id,100.0)		:rem how long the particles live for
SetParticlesFrequency(id,50)
SetParticlesDirection(id,0,20 )	:rem how fast the particles move 
SetParticlesAngle( id, 180 ) 	:rem Sets all particles to move downward
SetParticlesStartZone(id,-512,0,512,0):rem the location from the emitter they start at
Do
	UpdateParticles(id,0)
	Render()
	SetSpriteImage(350,renderImg)
	Print(ScreenFPS())
    Sync()
Loop
End 

2D Fireworks with trails
https://forum.thegamecreators.com/thread/218535
+ Code Snippet
SetWindowTitle( "fireworks" )
SetWindowSize( 640, 480, 0 )
   
// set display properties
SetVirtualResolution( 640, 480 )
SetOrientationAllowed( 0, 0, 1, 1 )
SetVSync(1)
  
#constant maxNumberFireworks=5
#constant speed=1.0
#constant frequency=3.14
  
type fireworkType
    flag as integer //1 do firework 0 dont do
    startTime as integer
endtype
 
 
dim fire [maxNumberFireworks] as fireworkType //variable to hold the present particle emmitter
for num = 1 to maxNumberFireworks
    setupFirework(num)
    fire[num].flag=0
next num
  
dim blackFire [maxNumberFireworks] as fireworkType
for num = 1 to (maxNumberFireworks)
    blackFire[num].flag=0
    setupFirework(num+100)
    AddParticlesColorKeyFrame(num+100,1,0,0,0,255)
next num
  
 bg = createsprite(0)
 setspritesize(bg,GetVirtualWidth(), GetVirtualHeight())
 SetSpriteColor(bg,0,0,0,8)
  
start_time = GetMilliseconds()
  
CreateRenderImage (1,640,480,0,0) 
ClearScreen()
  
do
SetRenderToImage (1,0) 
 
DrawSprite(bg)
 
for num=1 to maxNumberFireworks 
    if (fire[num].flag=0) and random(1,100)<10 //a 5 percent chance of that particle being emitted
        doFirework(num)
        fire[num].flag=1
        blackFire[num].flag=0
        fire[num].startTime= GetMilliseconds()
        UpdateParticles(num,0)
    endif
    current_time = GetMilliseconds()
    if fire[num].flag=1 and(current_time-fire[num].startTime)>50
        blackFire[num].flag=1
     //   doBlackFirework(num+100,num)
     //   UpdateParticles(num+100,0)
    endif
      
    if GetParticlesMaxReached(num)=1 //and GetParticlesMaxReached(num+100)=1
        fire[num].flag=0
        blackFire[num].flag=0
        //ClearScreen()
    endif
      
next num
  
//ClearScreen()
Update(0)
Render()
setrendertoscreen () 
createsprite(2,1) 
Update(0)
Render()
swap()
loop
  
function setupFirework(obj as integer)
    CreateParticles(obj,100,100) //id,x,y
    SetParticlesSize(obj,2)      //pixel size of particles  
    SetParticlesLife(obj,5)      //sets the length of 5 seconds the particles live
    SetParticlesMax(obj,75)      //max number of particles set to 75 f
    `SetParticlesActive(1,0)
    AddParticlesForce(obj,1,4,0,15) //The time a particle has to wait before forces apply 
    SetParticlesFrequency(obj,100)  //Sets the frequency of new particle generation
    SetParticlesVelocityRange(obj,2,4)  //velocity factor of particles ranging from min of 2 to 4
    SetParticlesColorInterpolation(obj,0) //1 smooth 0 none
    SetParticlesVisible( obj, 0 )       //hide particles when they first created so as timer can be used
    //SetParticlesFaceDirection( obj,1 ) 
endfunction
  
function doFirework (obj as integer)
    SetParticlesVisible( obj, 1 ) //make particle visible 
    SetParticlesPosition(obj,Random(100,GetVirtualWidth()-100),Random(100,GetVirtualHeight()-100))
    ResetParticleCount(obj)
  
    AddParticlesColorKeyFrame(obj,1,Random(100,250),Random(100,250),Random(100,250),255)
    AddParticlesColorKeyFrame(obj,2,Random(100,200),Random(100,200),Random(100,200),200)
    AddParticlesColorKeyFrame(obj,4,Random(50,100),Random(50,100),Random(50,100),25)   
endfunction
  
function doBlackFirework (obj as integer,obj2 as integer)
    SetParticlesVisible( obj, 1 ) //make particle visible 
    SetParticlesPosition(obj,GetParticlesX(obj2),GetParticlesY(obj2))
    ResetParticleCount(obj)
endfunction
Posted: 10th Apr 2018 19:25
3D Modifying a mesh height in real time with some help from puzzler
https://forum.thegamecreators.com/thread/221994
+ Code Snippet
// Project: coordinate 
// Created: 2018-04-06

// show all errors
SetErrorMode(2)
#constant screenWidth=1024
#constant screenHeight=768
#constant perlinw = 200
#constant perlinh = 200
#constant perlinz = 200  
#constant mapX=2048
#constant mapY=50
#constant mapZ=1024

  
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
SetScissor(0,0,0,0)
SetCameraRange( 1, 0.1, 900000 )
SetGlobal3DDepth(10000)

type _heights
	meshposition
	height
endtype
global heights as _heights[]

 
global TerrainImageID
  
  
// start perlin map data
NoiseInit()
TerrainImageID=generatePerlinImages()
mapsprite = CreateSprite(TerrainImageID)
SetSpriteSize(mapsprite,100,100)
SetSpritePosition(mapsprite,screenWidth-100,0)
HeightMapTextureMemblock = CreateMemblockFromImage(TerrainImageID)
HeightMapTextureWidthMemblock = GetMemblockInt(HeightMapTextureMemblock, 0)
HeightMapTextureHeightMemblock = GetMemblockInt(HeightMapTextureMemblock, 4)
TerrainImageID =CreateImageFromMemblock(HeightMapTextureMemblock)
  
  
//the following three lines only used if not updating on fly
//HeightImageMemblock=CreateMemblockFromImage(HeightImage)
//HeightImageWidthMemblock=GetMemblockInt(HeightImageMemblock, 0)
//HeightImageHeightMemblock=GetMemblockInt(HeightImageMemblock, 4)
  
global TerrainObjectID
  
// create the terrain object from a height map
TerrainObjectID=CreateObjectFromHeightMap( "height.png", mapX,mapY, mapZ, 0, 0 )
SetObjectCollisionMode( TerrainObjectID, 1 ) //On needed for object raycasting
SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
SetObjectTransparency(TerrainObjectID,0)
TerrainMemblock=createMapMemblock(TerrainObjectID)
//DeleteObject(TerrainObjectID)
//createObjectFromMeshMemblock(TerrainObjectID,TerrainMemblock)
//SetObjectPosition(TerrainObjectID,x,y,z) 
//SetObjectCollisionMode( TerrainObjectID, 1 ) 
//SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
//SetObjectTransparency(TerrainObjectID,0)
  
  
//SetCameraRange(1,1,2000 ) 
SetCameraPosition(1, 805, 378, -41)
  
//SetObjectMeshNormalMapScale( TerrainObjectID, 0, 1.0, 1.0 ) 
  
do
    checkCameraMovement()
      
    pointerState=GetRawMouseLeftState() 
    if pointerState = 1
  
        pointer_x = GetPointerX()
        pointer_y = GetPointerY()
        //pointer_y2 =screenHeight-GetPointerY()
    // get the x, y and z unit vectors based on the pointer position
        unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
        unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
        unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
  
        // calculate the start of the ray cast, which is the unit vector + the camera position
        start_x# = unit_x# + GetCameraX(1)
        start_y# = unit_y# + GetCameraY(1)
        start_z# = unit_z# - GetCameraZ(1)
  
        // calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
        end_x# = 1000*unit_x# + GetCameraX(1)
        end_y# = 1000*unit_y# + GetCameraY(1)
        end_z# = 1000*unit_z# - GetCameraZ(1)
  
  
        // determine which object has been hit
        object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
        Print ("objhit" + str(object_hit)+"="+str(TerrainObjectID))
          
        if object_hit = TerrainObjectID
            xPixel# = GetObjectRayCastX(0)
        
    yPixel# = GetObjectRayCastZ(0) 
            for y = -5 to 5 step 1
                for x = -5 to 5 step 1
                    writePixelMemblock(HeightMapTextureMemblock,HeightMapTextureWidthMemblock,HeightMapTextureHeightMemblock,xPixel#+x,yPixel#+y,1,1,1,255)     
                    //i=xpixel#+x
                    //SetMeshMemblockVertexPosition(TerrainMemblock,i,GetMeshMemblockVertexX(TerrainMemblock,i),GetMeshMemblockVertexY(TerrainMemblock,i)+1,GetMeshMemblockVertexZ(TerrainMemblock,i)) //make it flat
                    //i=i+ypixel#+y
                    //SetMeshMemblockVertexPosition(TerrainMemblock,i,GetMeshMemblockVertexX(TerrainMemblock,i),GetMeshMemblockVertexY(TerrainMemblock,i)+1,GetMeshMemblockVertexZ(TerrainMemblock,i)) //make it flat

               next x      
            next y

					
          // index of this vertex is (Vertices start back left and go right  then down to next line etc....
          yPixel#=screenHeight-yPixel#/1.2
          maxX=(SQRT(GetMemblockInt(TerrainMemblock,0)))*1.5
          maxZ=(SQRT(GetMemblockInt(TerrainMemblock,0)))*.95
          x=xPixel#/(mapX/maxX):z=(yPixel#)/(mapZ/MaxZ)
          x=xPixel#/(mapX/perlinw):z=(yPixel#)/(mapZ/perlinz)
          i=floor((x) + (z*maxX))
          if i>0 and i<=GetMemblockInt(terrainMemblock,0)  
           
         //  i = floor(xPixel# + (yPixel#*MapX)*GetMemblockInt(TerrainMemblock,0))
           print (i)
			posy=1
//			for posy=-1 to 1
			for posx=-1 to 1 
				if (i+posx)*posy >0 or (i+posx) * posy<GetMemblockSize(TerrainMemBlock)
            SetMeshMemblockVertexPosition(TerrainMemblock,heights[(i+posx) * posy].meshposition,GetMeshMemblockVertexX(TerrainMemblock,(i+posx)*posy),GetMeshMemblockVertexY(TerrainMemblock,(i+posx)*posy)+heights[i].height/10,GetMeshMemblockVertexZ(TerrainMemblock,(i+posx)*posy))
            dec heights[(i+posx) * posy].height,1
			endif
  //         next
           
           next
            SetObjectMeshFromMemblock(TerrainObjectID,1,TerrainMemblock) 

         endif 


       endif
              
        // update the image from the memblock
        CreateImageFromMemblock(TerrainImageID,HeightMapTextureMemblock)
          
    endif
    if GetRawMouseRightPressed()
        resetTerrain(TerrainMemblock)
    endif
      
    // show some information
    Print( "FPS: " + str(ScreenFPS(),1) )
    Print("MsxX="+str(GetObjectSizeMaxX(terrainObjectID)))
    Print( "Polygons: " + str(GetPolygonsDrawn()))
    print( "CameraPos: " + str(GetCameraX(1)) + ", " + str(GetCameraY(1)) +", " + str(GetCameraZ(1)))
    print("vertices="+str(GetMemblockInt(terrainMemblock,0)))
    print("maxX="+str(maxX))
  print("maxZ="+str(maxZ))
    print("X="+str(X))
    print("Z="+str(z))
    print("i ="+str(i))
      
      
          
    sync()
      
loop
  
function createMapMemblock(newobj as integer)
    chk = CreateMemblockFromObjectMesh(newobj,1)
endfunction chk
  
function checkCameraMovement()
  
if GetRawKeyState(37) then MoveCameraLocalX(1,-5) //Left
if GetRawKeyState(39) then MoveCameraLocalX(1,5) //Right
if GetRawKeyState(38) then MoveCameraLocalZ(1,5) //Forward
if GetRawKeyState(40) then MoveCameraLocalZ(1,-5) //Backward
if GetRawKeyState(87) then MoveCameraLocalY(1,-5) //87 W
if GetRawKeyState(83) then MoveCameraLocalY(1,5) //87 S
//if GetRawKeyState(65) then RotateCameraLocalY(1,1)
//if GetRawKeyState(68) then RotateCameraLocalY(1,-1)
  
// if cameray#<(blocksizey*10) then cameray#=(blocksizey*10)
if GetRawKeyPressed(27) then end
/*
        // rotate the camera
if ( GetPointerPressed()=1 )
    startMouseX# = GetPointerX()
    startMouseY# = GetPointerY()
    angx# = GetCameraAngleX(1)
    angy# = GetCameraAngleY(1)
  
endif
if ( GetPointerState() = 1 )
    fDiffX# = (GetPointerX() - startMouseX#)/4.0
    fDiffY# = (GetPointerY() - startMouseY#)/4.0
  
    newX# = angx# + fDiffY#
    if ( newX# > 89 ) then newX# = 89
    if ( newX# < -89 ) then newX# = -89
    SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
*/
  
endfunction
  
  
  
function writePixelMemblock(memblockId as integer,memblockWidth,memblockHeight,x as integer,y as integer,R as integer, G as integer, B as integer, A as integer)
    if (mapX/perlinw)>1 and (mapZ/perlinz)>1
        x=x/(mapX/perlinw):y=y/(mapZ/perlinz)
    else 
        x=x/perlinw:y=y/perlinz
    endif
         
    if x<0 then exitfunction
    if y<0 then exitfunction
    R =R+ GetMemblockByte(memblockId,12+(x*4)+((memblockHeight-y)*4*memblockWidth))
    G =G+ GetMemblockByte(memblockId,13+(x*4)+((memblockHeight-y)*4*memblockWidth))
    B =B+ GetMemblockByte(memblockId,14+(x*4)+((memblockHeight-y)*4*memblockWidth))
    A =A+ GetMemblockByte(memblockId,15+(x*4)+((memblockHeight-y)*4*memblockWidth))
      
    if R>255 then R=255
    if G>255 then G=255
    if B>255 then B=255
    if A>255 then A=255
      
    SetMemblockByte(memblockId,12+(x*4)+((memblockHeight-y)*4*memblockWidth),R) // Write Red 
    SetMemblockByte(memblockId,13+(x*4)+((memblockHeight-y)*4*memblockWidth),G) // Write Green 
    SetMemblockByte(memblockId,14+(x*4)+((memblockHeight-y)*4*memblockWidth),B) // Write Blue 
    SetMemblockByte(memblockId,15+(x*4)+((memblockHeight-y)*4*memblockWidth),A) // Write Alpha full opaque (255)
      
endfunction
  
function resetTerrain (msblk as integer) 
  
    count = GetMemblockInt( msblk ,0 )
    for i = 0 to count  
        SetMeshMemblockVertexPosition(msblk,i,GetMeshMemblockVertexX(msblk,i),0,GetMeshMemblockVertexZ(msblk,i)) //make it flat
    next
    SetObjectMeshFromMemblock(TerrainObjectID,1,msblk)
Endfunction
  
   
function generatePerlinImages()
// Generate image from memblock
  
size = perlinw * perlinh * 4 + 12
mem = CreateMemblock(size) //the colour texture image
SetMemblockInt(mem,0,perlinw)
SetMemblockInt(mem,4,perlinh)
SetMemblockInt(mem,8,32)
mem2 = CreateMemblock(size) //the black and white height image
SetMemblockInt(mem2,0,perlinw)
SetMemblockInt(mem2,4,perlinh)
SetMemblockInt(mem2,8,32)
     
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
     
meshposition=0
for y = 0 to perlinh - 1
    for x = 0 to perlinw - 1
        a = a + 0.0001
        b = b + 0.002
             
        // Try out these two noise methods
        //noise = 255.0*Noise2D(x/10.0,y/10.0)
        noise = 255.0*Noise2D(x/255.0,y/255.0)
             
        noise = abs(noise)
		
		// add to array
		height as _heights
		height.meshposition=meshposition
		height.height = noise
		heights.insert(height)
		// end of adding to array
		
		inc meshposition
        //clouds
        if noise>255
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
            
     
         //greenary
        if noise>100 and noise<=255
            SetMemblockByte(mem, offset, 0)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        //sand
        if noise>50 and noise<=100  
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        // water
        if noise<=50 
            SetMemblockByte(mem, offset, noise/2)
            SetMemblockByte(mem, offset+1, 0)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
        //mem2 is the black and white image
        SetMemblockByte(mem2, offset, noise)
        SetMemblockByte(mem2, offset+1, noise)
        SetMemblockByte(mem2, offset+2, noise)
        SetMemblockByte(mem2, offset+3, 255)
        offset = offset + 4
    next
next
     
map=CreateImageFromMemblock(mem)
//heightImage=CreateImageFromMemblock(heightImage)
saveImage(mem,"height.png")
DeleteObject(mem):DeleteObject(mem2)
endfunction map
  
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you 
    
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
    
Type sPNVECTOR
    x as float
    y as float
    z as float
endtype
    
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
    
    
Function NoiseInit()
    Local n as integer, rn as integer
    For n=0 To 255
        PNHash[n] = n
    Next n 
    For n=0 To 255
        rn=Random(0, 255) 
        PNHash.swap(n,rn)
    Next n
    For n=0 To 255
        PNHash[256 + n] = PNHash[n]
    Next n
    PNHash[511] = PNHash[0]
    
    For n=0 To 15
        PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
        PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
        PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
        PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
    
        PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
        PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
        PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
        PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
    
        PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
        PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
        PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
        PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
    
        PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
        PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
        PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
        PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
    Next n 
endfunction
    
function Noise2D(xin as float, yin as float)
    local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
    local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
    local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
        
    s = (xin + yin) * PN3DF2
    xs = xin + s
    i = floor(xs)
    ys = yin + s
    j = floor(ys)
    t = (i + j) * PN3DG2
    x0 = xin - (i - t)
    y0 = yin - (j - t)
    if x0>y0
        i1=1
        j1=0
    else
        i1=0
        j1=1
    endif
    x1 = x0 - i1 + PN3DG2
    y1 = y0 - j1 + PN3DG2
    x2 = x0 - 1.0 + 2.0 * PN3DG2
    y2 = y0 - 1.0 + 2.0 * PN3DG2
    i = i && 255
    j = j && 255
    gi0 =  PNHash[i + PNHash[j]] && 15
    gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
    gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
    t0 = 0.5 - x0*x0-y0*y0
    if t0<0
        n0 = 0.0
    else
        t0 = t0 * t0
        n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
    endif
    t1 = 0.5 - x1*x1-y1*y1
    if t1<0
        n1 = 0.0
    else
        t1 = t1 * t1
        n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
    endif
    t2 = 0.5 - x2*x2-y2*y2
    if t2<0
        n2 = 0.0
    else
        t2 = t2 * t2
        n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
    endif  
endfunction  70.0 * (n0 + n1 + n2)


An easier way to modify mesh great for building a terrain but not for real time
+ Code Snippet
//3D Modifying a mesh height by modifying texture and re loading

// Project: coordinate 
// Created: 2018-04-06

// show all errors
SetErrorMode(2)
#constant screenWidth=1024
#constant screenHeight=768
#constant perlinw = 200
#constant perlinh = 200
#constant perlinz = 200  
#constant mapX=2048
#constant mapY=100
#constant mapZ=1024

  
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
SetScissor(0,0,0,0)
SetCameraRange( 1, 0.1, 900000 )
SetGlobal3DDepth(10000)

type _heights
	meshposition
	height
endtype
global heights as _heights[]

global TerrainImageID
  
// start perlin map data
NoiseInit()
TerrainImageID=generatePerlinImages()
mapsprite = CreateSprite(TerrainImageID)
SetSpriteSize(mapsprite,100,100)
SetSpritePosition(mapsprite,screenWidth-100,0)
HeightMapTextureMemblock = CreateMemblockFromImage(TerrainImageID)
HeightMapTextureWidthMemblock = GetMemblockInt(HeightMapTextureMemblock, 0)
HeightMapTextureHeightMemblock = GetMemblockInt(HeightMapTextureMemblock, 4)
TerrainImageID =CreateImageFromMemblock(HeightMapTextureMemblock)
  
  
//the following three lines only used if not updating on fly
//createBlankTexture(heightImage,200,200,makecolor(0,0,0))
HeightImage=loadImage("height.png")
HeightImageMemblock=CreateMemblockFromImage(HeightImage)
HeightImageWidthMemblock=GetMemblockInt(HeightImageMemblock, 0)
HeightImageHeightMemblock=GetMemblockInt(HeightImageMemblock, 4)
  
Local TerrainObjectID
  
// create the terrain object from a height map
TerrainObjectID=CreateObjectFromHeightMap( "height.png", mapX,mapY, mapZ, 0, 0 )
SetObjectCollisionMode( TerrainObjectID, 1 ) //On needed for object raycasting
SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
SetObjectTransparency(TerrainObjectID,0)
//TerrainMemblock=CreateMemblockFromObjectMesh(TerrainObjectID,1)

//SetCameraRange(1,1,2000 ) 
SetCameraPosition(1, 805, 378, -41)
  
  
do
    checkCameraMovement()
      
    if GetPointerState()=1
  
        pointer_x = GetPointerX()
        pointer_y = GetPointerY()
        //pointer_y2 =screenHeight-GetPointerY()
    // get the x, y and z unit vectors based on the pointer position
        unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
        unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
        unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)
  
        // calculate the start of the ray cast, which is the unit vector + the camera position
        start_x# = unit_x# + GetCameraX(1)
        start_y# = unit_y# + GetCameraY(1)
        start_z# = unit_z# - GetCameraZ(1)
  
        // calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
        end_x# = 1000*unit_x# + GetCameraX(1)
        end_y# = 1000*unit_y# + GetCameraY(1)
        end_z# = 1000*unit_z# - GetCameraZ(1)
  

        // determine which object has been hit
        object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
        Print ("objhit=" + str(object_hit))
          
        if object_hit = TerrainObjectID
            xPixel# = GetObjectRayCastX(0)
 			yPixel# = GetObjectRayCastZ(0) 
            for y = -5 to 5 step 1
                for x = -5 to 5 step 1
                    writePixelMemblock(HeightImageMemblock,HeightImageWidthMemblock,HeightImageHeightMemblock,xPixel#+x,yPixel#+y,1,1,1,255)     
                next x      
            next y
			DeleteImage(HeightImage)
			HeightImage=CreateImageFromMemblock(HeightImageMemblock)
			saveImage(HeightImage,"height.png")
			DeleteObject(TerrainObjectID)
			TerrainObjectID=CreateObjectFromHeightMap( "height.png", mapX,mapY, mapZ, 0, 0 )
			SetObjectCollisionMode( TerrainObjectID, 1 )
			SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
		endif
    endif
    sync()      
loop
  
  
function checkCameraMovement()
  
if GetRawKeyState(37) then MoveCameraLocalX(1,-5) //Left
if GetRawKeyState(39) then MoveCameraLocalX(1,5) //Right
if GetRawKeyState(38) then MoveCameraLocalZ(1,5) //Forward
if GetRawKeyState(40) then MoveCameraLocalZ(1,-5) //Backward
if GetRawKeyState(87) then MoveCameraLocalY(1,-5) //87 W
if GetRawKeyState(83) then MoveCameraLocalY(1,5) //87 S

if GetRawKeyPressed(27) then end

endfunction
  
  
  
function writePixelMemblock(memblockId as integer,memblockWidth,memblockHeight,x as integer,y as integer,R as integer, G as integer, B as integer, A as integer)
    if (mapX/perlinw)>1 and (mapZ/perlinz)>1
        x=x/(mapX/perlinw):y=y/(mapZ/perlinz)
    else 
        x=x/perlinw:y=y/perlinz
    endif
         
    if x<0 then exitfunction
    if y<0 then exitfunction
    R =R+ GetMemblockByte(memblockId,12+(x*4)+((memblockHeight-y)*4*memblockWidth))
    G =G+ GetMemblockByte(memblockId,13+(x*4)+((memblockHeight-y)*4*memblockWidth))
    B =B+ GetMemblockByte(memblockId,14+(x*4)+((memblockHeight-y)*4*memblockWidth))
    A =A+ GetMemblockByte(memblockId,15+(x*4)+((memblockHeight-y)*4*memblockWidth))
      
    if R>255 then R=255
    if G>255 then G=255
    if B>255 then B=255
    if A>255 then A=255
      
    SetMemblockByte(memblockId,12+(x*4)+((memblockHeight-y)*4*memblockWidth),R) // Write Red 
    SetMemblockByte(memblockId,13+(x*4)+((memblockHeight-y)*4*memblockWidth),G) // Write Green 
    SetMemblockByte(memblockId,14+(x*4)+((memblockHeight-y)*4*memblockWidth),B) // Write Blue 
    SetMemblockByte(memblockId,15+(x*4)+((memblockHeight-y)*4*memblockWidth),A) // Write Alpha full opaque (255)
      
endfunction
  
   
function generatePerlinImages()
// Generate image from memblock
  
size = perlinw * perlinh * 4 + 12
mem = CreateMemblock(size) //the colour texture image
SetMemblockInt(mem,0,perlinw)
SetMemblockInt(mem,4,perlinh)
SetMemblockInt(mem,8,32)
mem2 = CreateMemblock(size) //the black and white height image
SetMemblockInt(mem2,0,perlinw)
SetMemblockInt(mem2,4,perlinh)
SetMemblockInt(mem2,8,32)
     
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
     
meshposition=0
for y = 0 to perlinh - 1
    for x = 0 to perlinw - 1
        a = a + 0.0001
        b = b + 0.002
             
        // Try out these two noise methods
        //noise = 255.0*Noise2D(x/10.0,y/10.0)
        noise = 255.0*Noise2D(x/255.0,y/255.0)
             
        noise = abs(noise)
		
		// add to array
		height as _heights
		height.meshposition=meshposition
		height.height = noise
		heights.insert(height)
		// end of adding to array
		
		inc meshposition
        //clouds
        if noise>255
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
            
     
         //greenary
        if noise>100 and noise<=255
            SetMemblockByte(mem, offset, 0)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        //sand
        if noise>50 and noise<=100  
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        // water
        if noise<=50 
            SetMemblockByte(mem, offset, noise/2)
            SetMemblockByte(mem, offset+1, 0)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
        //mem2 is the black and white image
        SetMemblockByte(mem2, offset, noise)
        SetMemblockByte(mem2, offset+1, noise)
        SetMemblockByte(mem2, offset+2, noise)
        SetMemblockByte(mem2, offset+3, 255)
        offset = offset + 4
    next
next
     
map=CreateImageFromMemblock(mem)
heightImg=CreateImageFromMemblock(mem2)
saveImage(heightImg,"height.png")
DeleteObject(mem):DeleteObject(mem2)
endfunction map
  
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you 
    
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
    
Type sPNVECTOR
    x as float
    y as float
    z as float
endtype
    
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
    
    
Function NoiseInit()
    Local n as integer, rn as integer
    For n=0 To 255
        PNHash[n] = n
    Next n 
    For n=0 To 255
        rn=Random(0, 255) 
        PNHash.swap(n,rn)
    Next n
    For n=0 To 255
        PNHash[256 + n] = PNHash[n]
    Next n
    PNHash[511] = PNHash[0]
    
    For n=0 To 15
        PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
        PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
        PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
        PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
    
        PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
        PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
        PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
        PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
    
        PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
        PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
        PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
        PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
    
        PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
        PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
        PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
        PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
    Next n 
endfunction
    
function Noise2D(xin as float, yin as float)
    local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
    local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
    local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
        
    s = (xin + yin) * PN3DF2
    xs = xin + s
    i = floor(xs)
    ys = yin + s
    j = floor(ys)
    t = (i + j) * PN3DG2
    x0 = xin - (i - t)
    y0 = yin - (j - t)
    if x0>y0
        i1=1
        j1=0
    else
        i1=0
        j1=1
    endif
    x1 = x0 - i1 + PN3DG2
    y1 = y0 - j1 + PN3DG2
    x2 = x0 - 1.0 + 2.0 * PN3DG2
    y2 = y0 - 1.0 + 2.0 * PN3DG2
    i = i && 255
    j = j && 255
    gi0 =  PNHash[i + PNHash[j]] && 15
    gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
    gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
    t0 = 0.5 - x0*x0-y0*y0
    if t0<0
        n0 = 0.0
    else
        t0 = t0 * t0
        n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
    endif
    t1 = 0.5 - x1*x1-y1*y1
    if t1<0
        n1 = 0.0
    else
        t1 = t1 * t1
        n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
    endif
    t2 = 0.5 - x2*x2-y2*y2
    if t2<0
        n2 = 0.0
    else
        t2 = t2 * t2
        n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
    endif  
endfunction  70.0 * (n0 + n1 + n2)

function createBlankTexture(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()
    saveImage(imgId,"height.png")
 endfunction 


Complete 3D minigame showing a never ending world by wrapping objects in a predefined workspace
https://forum.thegamecreators.com/thread/222010
+ Code Snippet
//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=40 //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=40 //maximum blocks on z plane
#constant raiseAmmount=8 //the ammount to raise or lower each blocks vertexs
#constant speed#  = 10.0 //the following for a sine curve to repesent hils on the yplane
#constant xMaxResolution=1024
#constant yMaxResolution=768
#constant acceleration#=.025 //used to calclate the carSpeed#
#constant maxCarSpeed#=2.0 //The Maximum speed the carBlock will move 
#constant minRand=50  // the minimum the randmoness# can get hence and create more obstacles
#constant maxRand=350 // the maximum the randmoness# can get hence and create less obstacles
#constant decRand=1   // the degree the radomness decreased by to create more obstacle
#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


global randomness = maxRand //the lower this value the harder it gets its decreased over time automatically
global blockCount 
global carBlock=10000 //carblock and carMem have the same referrence
global carMem=10000   //the 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 texture1 	  //the detailed texture
global texture2 	  //the texture without detail
global texture3       //the checkpoint Image   
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 sound1 as integer
global sound2 as integer
//global y# as float = 0.0
dim blocksChanged[mapX*mapY*mapZ] as block

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Mini 3d driving game with blocks" )
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
	colorFlag as integer
	yPos as integer
    checkpointFlag 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

num=1:texture1=createtexture(32,32, makecolor(255,255,255),155):texture2=createtexture(32,32,makecolor(255,255,255),5)
for y = 1 to mapY 	
for x = 1 to mapX
for z = 1 to mapZ
	CreateObjectBox(num,1,1,1)
	c=random(100,150)
	SetObjectColor(num,c,c,c,255)
	SetObjectImage(num,texture1,0)
	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].yPos=y
	blocksChanged[num].xPosStart=x
	blocksChanged[num].yPosStart=y
	blocksChanged[num].zPosStart=z
	blocksChanged[num].colorFlag=0
	blocksChanged[num].checkpointFlag=0
	//SetObjectImage( num, random(1,20), 0) 
	SetObjectPosition(num,x,y,z)
	inc num
next z
next x
next y
blockCount=num-1

CreateObjectBox(carBlock,1,1,2)
CreateMemblockFromObjectMesh(carBlock,carMem,1)
SetObjectCastShadow(carBlock, 1 ) //set shadows on for the carBlock
setObjectPosition(carBlock,mapX/2,mapY+3,10)
SetObjectColor(carBlock,200,0,0,255) //red cars go faster 
SetObjectCollisionMode(carBlock,1) //on is set or raycasting wont work

sound1=createSound(1) //creates a base rumble
sound2=createSound(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)

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:randomness = maxRand 
		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#=1.0          //car speed used for acceleration with timer
ResetTimer():time#=timer():yAngle=0
x=xMaxResolution/2
repeat
		
	if GetDirectionX()<-.25 //uses gyroscope for movement
		moveBlocks(abs(GetDirectionX()*2.5),0,0) 
		yAngle=-abs(GetDirectionX()*20)
		SetObjectRotation( carBlock,0,yAngle,0 )
	elseif GetDirectionX()>.25 //uses gyroscope for movement
		moveBlocks(-abs(GetDirectionX()*2.5),0,0)
		yAngle=abs(GetDirectionX()*20)
		SetObjectRotation( carBlock,0,yAngle,0 )
	else
		if yAngle<0 
			inc yAngle
			SetObjectRotation( carBlock,0,yAngle,0 )
		elseif yAngle>0
			dec yAngle
			SetObjectRotation( carBlock,0,yAngle,0 )
		endif
	endif
	
	moveBlocks(0,0,carSpeed#)

	//The first raycast is used to set the height of the carBlock
	x#=getObjectX(carBlock)
	y#=GetObjectY(carBlock)
	z#=getObjectZ(carBlock)
	// calculate the start of the ray cast
	start_x# = x#
	start_y# = y#
	start_z# = z# 
    // calculate the end of the ray cast
	end_x# = x#+1.0
	end_y# = y#-6.0
	end_z# = z#+2   
	hit=ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
	if hit>0 
		rem move car according to hill height
		SetObjectPosition(carBlock,GetObjectX(carBlock),GetObjectY(hit)+2,GetObjectZ(carBlock))
		SetObjectCastShadow(carBlock, 1 )
	endif

	//the second raycasting is used for crashes
	x#=getObjectX(carBlock)
	y#=GetObjectY(carBlock)+2
	z#=getObjectZ(carBlock)
	// calculate the start of the ray cast
	start_x# = x#
	start_y# = y#
	start_z# = z# 
    // calculate the end of the ray cast
	end_x# = x#+1.0
	end_y# = y#-2.0
	end_z# = z#+2   
	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#=1.0  //Set the speed back to its default as you crashed
		yAngle=0
		time#=timer()  
	endif

	if timer()>time#+1.0
		//randomness is used to determine if blocks should be raised and colored or not increases with time
		if randomness>minRand then randomness=randomness-decRand //increase the probability of getting an obstacle
		carSpeed#=carSpeed#+acceleration# //increase the car speed every 1 second
		time#=timer()
	endif
	if carSpeed#>maxCarSpeed# then carSpeed#=maxCarSpeed#
	
	SetTextString(textSpeed,"Speed="+Str(Round(carSpeed#/maxCarSpeed#*100))+"%")
	SetTextString(textScore,"Score="+Str(score))
	SetTextString(textLives,"Lives="+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,"Mini 3D Driving Game")
SetTextSize(textTitle,50)
SetTextPosition(textTitle,x-180,5)
SetTextColor(textTitle,220,50,50,255)

CreateText(textSpeed,"Speed=")
SetTextSize(textSpeed,35)
SetTextPosition(textSpeed,5,5)
SetTextColor(textSpeed,255,255,255,255)

CreateText(textScore,"Score=")
SetTextSize(textScore,35)
SetTextPosition(textScore,13,35)
SetTextColor(textScore,255,255,255,255)

CreateText(textLives,"Lives=")
SetTextSize(textLives,35)
SetTextPosition(textLives,18,65)
SetTextColor(textLives,255,255,255,255)

CreateText(textFPS,"FPS=")
SetTextSize(textFPS,35)
SetTextPosition(textFPS,36,95)
SetTextColor(textFPS,255,255,255,255)

CreateText(textGameOver,"GameOver")
SetTextSize(textGameOver,55)
SetTextPosition(textGameOver,x-112,yMaxResolution/2-18)
SetTextColor(textGameOver,255,5,5,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(textTopSpeed,"Top Speed=0")
SetTextSize(textTopSpeed,35)
SetTextPosition(textTopSpeed,xMaxResolution-222,35)
SetTextColor(textTopSpeed,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)
	for num=1 to blockCount
		if x<0 //move blocks right
			if GetObjectWorldX(num)<xMin#
				SetObjectPosition(num,getObjectX(num)+(xNum+x),getObjectY(num),getObjectZ(num)) 
			else
				SetObjectPosition(num,getObjectX(num)+x,getObjectY(num),getObjectZ(num))
			endif
		endif
		if x>0 //move blocks Left
			if GetObjectWorldX(num)>xMax#
				SetObjectPosition(num,getObjectX(num)-(xNum-x),getObjectY(num),getObjectZ(num)) 
			else
				SetObjectPosition(num,getObjectX(num)+x,getObjectY(num),getObjectZ(num))
			endif
		endif
		if z>0 //move blocks toward screen
			if GetObjectWorldZ(num)<zMin
				SetObjectPosition(num,getObjectX(num),blocksChanged[num].yPos,getObjectZ(num)+zNum)
				//x# = sin(timer()*speed#)*200
				y# = sin(timer()*speed#*2)*100.0 // ranges from -100 to 100 
				y#=y#/50.0 //if this division is set to low the raycasting needs changing 50 and 75 both work well
				moveBlockYDirection(num,y#)		

				//if blocksChanged[num].checkpointFlag=0 and 
				if getObjectWorldz(1)<=zMin //for white checkpoint line
					//SetObjectColor(num,255,255,255,255)
					SetObjectColor(num,myRed,myGreen,myBlue,255)
					SetObjectImage(num,texture2,0) 
					blocksChanged[num].checkpointFlag=1
					if blocksChanged[num].colorflag=1 //do not allow raised blocks at check points
						blocksChanged[num].colorFlag=0
						modifyBlock(num,-raiseAmmount) //lower block
						SetObjectCastShadow(num,0) 
					endif
				else 
					c=random(100,150)
					SetObjectColor(num,c,c,c,255)
					SetObjectImage(num,texture1,0)
					blocksChanged[num].checkpointFlag=0
					//if blocksChanged[num].colorflag=1 //
					//	blocksChanged[num].colorFlag=0
					//	modifyBlock(num,-raiseAmmount) //lower block
					//	SetObjectCastShadow(num,0) 
					//endif
				endif
				
				if blocksChanged[num].colorflag=0 //random color then raise block 
					if Random(0,randomness)<1
						modifyBlock(num,raiseAmmount)
						blocksChanged[num].colorFlag=1
						blocksChanged[num].checkpointFlag=0
						SetObjectCastShadow(num,1)
						SetObjectColor(num,random(1,255),random(1,255),random(1,255),255)
						SetObjectImage(num,texture2,0)
					endif
				else
					modifyBlock(num,-raiseAmmount) //lower block
					blocksChanged[num].colorFlag=0
					blocksChanged[num].checkpointFlag=0
					SetObjectCastShadow(num,0) 
					c=random(100,150):SetObjectColor(num,c,c,c,255)
					SetObjectImage(num,texture1,0)
				endif	 
			else
				SetObjectPosition(num,getObjectX(num),getObjectY(num),getObjectZ(num)-z)
				rem block 40 is off the screen so increment score
				if num=40 then inc score 
			endif
		endif
	next num
endfunction	

function moveBlockYDirection(num,y as float)
	//move blocks on the yplane as set by the sine curve
	blocksChanged[num].yPos=y
	SetObjectPosition(num,getObjectX(num),blocksChanged[num].yPos,getObjectZ(num))
endfunction

function blocksExplode()
	//vertexFront as integer[4] = [0,1,2,3] rem front face
	//vertexRight as integer[4] = [4,5,6,7] rem right face
	//vertexTop as integer[4] = [8,9,10,11] rem top face
	//vertexLeft as integer[4] = [12,13,14,15] rem left face
	//vertexBottom as integer[4] = [20,21,22,23] rem bottom face
	//vertexBack as integer[4] = [16,17,18,19] rem back face
	//if you just want to seperate each face from the car set the same directions for each face as described above

	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	
	
	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
		
		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)
		next index
		
		SetObjectMeshFromMemblock(carBlock,1,carMem)
    
		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)
	    SetObjectCastShadow(num,0) 	//set all blocks to no shadows 
	    rem the blocks that have been raised return them back to how they started 
	    if blocksChanged[num].colorflag=1     
			modifyBlock(num,-raiseAmmount)
			c=random(100,150)
			SetObjectColor(num,c,c,c,255)
			SetObjectImage(num,texture1,0)
		endif
		blocksChanged[num].colorFlag=0
		blocksChanged[num].checkpointFlag=0
			
	next num
	randomness = maxRand //restore the obstacles randomness back to easy after a crash
	rem because the cars vertexs are destroyed delete the car and memblock and recreate them
	DeleteObject(carBlock)
	DeleteMemblock(carMem)
	CreateObjectBox(carBlock,1,1,2)
	CreateMemblockFromObjectMesh(carBlock,carMem,1)
	SetObjectCastShadow(carBlock, 1 )
	setObjectPosition(carBlock,mapX/2,mapY+3,10)
	SetObjectRotation(carBlock,0,0,0)
	SetObjectColor(carBlock,200,0,0,255) //red cars go faster 
	SetObjectCollisionMode(carBlock,1)
	resetTimer() //need to reset time for the road curves
endfunction

function createSound(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
sound = CreateSoundFromMemblock(mem)
DeleteMemblock(mem)
endFunction sound

// 102, 51, 0
// Function to create a texture
// by Puzzler
// Inputs - Sizex - size of the texture to create - width
//          Sizey - size of the texture to create - height
//          Color - is the main color of the image
//          Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
// 
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100,  makecolor(0,0,255), 100)
//          This could create a DEEP water effect texture?
   
function createtexture(sizex# as float, sizey# as float, color, density as integer)
    swap()
    drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
    render()
    img = getimage(0,0,sizex#, sizey#)
       
    memblockid = CreateMemblockFromImage (img)
    imgwidth = GetMemblockInt(memblockid, 0)
    imgheight = GetMemblockInt(memblockid, 4)
       
    size=GetMemblockSize(memblockid)
	for offset=12 to size-4 step 4
         
        r=GetMemblockByte(memblockid, offset)
        g=GetMemblockByte(memblockid, offset+1)
        b=GetMemblockByte(memblockid, offset+2)
        a=GetMemblockByte(memblockid, offset+3)
               
           
        strength=random(1,density)
   
        SetMemblockByte (memblockid, offset, r-strength)
        SetMemblockByte (memblockid, offset+1, g-strength)
        SetMemblockByte (memblockid, offset+2, b-strength )
		SetMemblockByte (memblockid, offset+3, a-strength)
    next
    deleteimage (img)
    img = CreateImageFromMemblock(memblockid)
    DeleteMemblock(memblockid)
endfunction img
Posted: 10th Apr 2018 19:38
Hi

A really nice thought to create something iike this, 2D an 3D tools and things al under one thread

Movement of Camera in a 3D world would be a good one cause its asked all the time.

Well done - im sure if and when I can think of something ill post my examples but you got a good starting block for the moment

-)

EDIT - the last example with shadow etc is some really good and powerful work there, well done.

Just a small critism - maybe start slow at beginning and proressively speeds up through out the levels

Really good use of particals too
Posted: 10th Apr 2018 20:14
Thanks puzzler I changed the code to include speed increasing over time to the 3D minigame

The following were part of my contributions to the minecraft thread which is very long and can be off putting to someone to search through
the whole thread, but there is much useful code and teachings on that thread so below is the link
https://forum.thegamecreators.com/thread/221407

3D snowman artifact
+ Code Snippet
// Project: snowman
// Created: 2018-03-04
 
// show all errors
SetErrorMode(2)
 
// set window properties
SetWindowTitle( "snowman" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
 
// set display properties
SetVirtualResolution( 1024, 768 ) // 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
 
snowmanSize#=3
lowerBody=CreateObjectSphere(snowmanSize#,12,12)
SetObjectColor(lowerBody,255,255,255,255)
 
upperBody=CreateObjectSphere(snowmanSize#*.70,8,8)
SetObjectColor(upperBody,255,255,255,255)
SetObjectPosition(upperBody,0,snowmanSize#*.70,0)
FixObjectToObject(upperBody,lowerBody)

button1=CreateObjectCylinder( .1, .2, 5 ) 
SetObjectColor(button1,255,0,0,255)
SetObjectRotation(button1,90,0,0)
SetObjectPosition(button1,0,.75,snowmanSize#*.25)
FixObjectToObject(button1,upperBody)

button2=CreateObjectCylinder( .1, .2, 5 ) 
SetObjectColor(button2,255,0,0,255)
SetObjectRotation(button2,90,0,0)
SetObjectPosition(button2,0,.25,snowmanSize#*.35)
FixObjectToObject(button2,upperBody)

button3=CreateObjectCylinder( .1, .2, 5 ) 
SetObjectColor(button3,255,0,0,255)
SetObjectRotation(button3,90,0,0)
SetObjectPosition(button3,0,-.25,snowmanSize#*.35)
FixObjectToObject(button3,upperBody)


head=CreateObjectSphere(snowmanSize#*.50,7,7)
SetObjectColor(head,255,255,255,255)
SetObjectPosition(head,0,snowmanSize#*.50,0)
FixObjectToObject(head,upperBody)

nose=CreateObjectCone( .5, .3, 5 ) 
SetObjectColor(nose,230,126,34,255)
SetObjectRotation(nose,90,0,0)
SetObjectPosition(nose,0,.175,snowmanSize#*.3)
FixObjectToObject(nose,head)

eye1=CreateObjectSphere( .25, .25, 5 ) 
SetObjectColor(eye1,133,193,233,255)
SetObjectPosition(eye1,.30,.450,.45)
FixObjectToObject(eye1,head)

eye2=CreateObjectSphere( .25, .25, 5 ) 
SetObjectColor(eye2,133,193,233,255)
SetObjectPosition(eye2,-.30,.450,.45)
FixObjectToObject(eye2,head)

mouth=CreateObjectSphere( .5, .25, 5 ) 
SetObjectColor(mouth,133,0,0,255)
SetObjectPosition(mouth,0,-.25,.60)
FixObjectToObject(mouth,head)

lowerHat=CreateObjectCylinder( .1, snowmanSize#*.50, 8 ) 
SetObjectColor(lowerHat,0,0,200,255)
SetObjectPosition(lowerHat,0,.75,0)
FixObjectToObject(lowerHat,head)

upperHat=CreateObjectCylinder( 1, snowmanSize#*.3, 8 ) 
SetObjectColor(upperHat,0,0,200,255)
SetObjectPosition(upperHat,0,.3,0)
FixObjectToObject(upperHat,lowerHat)
x#=0:y#=100:z#=0
do
     
    SetObjectRotation(lowerbody,x#,y#,z#)
    inc y#
//    inc z#
 
    Print( screenFPS() )
    Sync()
loop

Rolling menu code snippet just copy paste and run
+ Code Snippet
#constant xMax=1024
#constant yMax=600
#constant friction 0.09 
#constant inventoryTotal=10

global oldsc 
global sc=0
global level
   
xspd as float `X speed of tiles
xpos as float `X position of tiles
cpx as float `Current Pointer X  `(from this frame)
lpx as float `Last Pointer X  `(from last frame)

// set window properties
SetWindowSize( xMax, yMax, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( xMax, yMax ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) // allow both portrait and landscoreape 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

for num = 100 to 99+inventoryTotal
	CreateSprite(num,0)
	SetSpriteSize(num,256,256)
	SetSpriteColor(num,random(1,255),random(1,255),random(1,255),255)
next num	
	
loadInventoryImages() //need a routine here to grab the images
setInventorySprites() //position them
vw=GetVirtualWidth():vh=GetVirtualHeight():iw=GetImageWidth(100):ih=GetImageHeight(100)

xpos=0
xspd=0
cpx=0
lpx=0
oldsc=-1
level=1
exitSelected=0
rollingMenu=1	

repeat
	lpx=cpx
    cpx=GetPointerX()
    `
    if GetPointerState()
		xspd=cpx-lpx
	endif 
	
	//friction
	for k=1 to 3
        if xspd<-friction*k*2
            xspd=xspd+friction
        elseif xspd>friction*k*2
            xspd=xspd-friction
        else
            xspd=0
        endif
    next
    
        
    //limits
    if xpos>5
        xspd=xspd/2
        if GetPointerState()=0
            xspd=xspd-1.5
        endif
    endif
    if xpos<-(256*(inventoryTotal-4))
        xspd=xspd/2
        if GetPointerState()=0
            xspd=xspd+1.5
        endif
    endif
    
    xpos=xpos+xspd
   
    count=0
    for t = 100 to 99+inventoryTotal
		SetSpritePosition(t,xpos+(count*256),vh-ih)
		if GetPointerReleased()
			exit
		endif
		inc count
	next t    
	
	if  GetPointerReleased()
		num=GetSpriteHit(GetPointerX(),GetPointerY())
		if num>=100 and num <=99+inventoryTotal
			//place the object here
			id=CloneSprite( num )
			SetSpriteVisible(id,0)
			SetSpriteImage(700,GetSpriteImageID(num))
			rollingMenu=0
		endif
	endif
	
	if rollingMenu=0 
		SetSpritePositionByOffset(id,GetPointerX(),GetPointerY())
		if GetPointerPressed()
			rollingMenu=1
		endif
	endif
	sync()
until exitSelected=1
end

function loadInventoryImages() 
	for num = 100 to 199
		createtexture(num,256,256,MakeColor(random(1,255),random(1,255),random(1,255)))
	next num
	
endfunction

function setInventorySprites()
	vw=GetVirtualWidth():vh=GetVirtualHeight():iw=GetImageWidth(100):ih=GetImageHeight(100)

	for num=100 to 99+inventoryTotal	
		SetSpritePositionByOffset(num,(num-100)*iw,vh-ih)
	next num
endfunction

function createTexture(ID as integer,width as integer, height as integer,color)
ClearScreen()
Render()
DrawBox(0,0,width,height,color,color,color,color,1)
Swap()
getimage(ID,0,0,width,height)
endfunction

moving a 3D object in 3D Space with Mouse
+ Code Snippet
#constant width=1024
#constant height=768
 
SetWindowSize(width,height,0)
Setvirtualresolution(width,height)
CreateObjectBox(1,16,16,16)
SetObjectPosition(1,50,1,50)
CreateObjectBox(2,10*16,1*16,10*16)
SetObjectColor(2,0,255,0,255)
SetObjectPosition(2,50,-15,50)
//SetCameraPosition(1,50,50,-10)
global angx#=30
global angy#=0
global camerax#=50
global cameray#=50
global cameraz#=-10
global startx#=512
global starty#=384
#constant Depth#=48
do
			moveblockwithmouse()
			//movecamerawithmouse()
			sync()
loop 

function movecamerawithmouse()
     
    fDiffX# = (GetPointerX() - startx#)/6.0
    fDiffY# = (GetPointerY() - starty#)/6.0
 
    newX# = angx# + fDiffY#
    if ( newX# > 89 ) then newX# = 89
    if ( newX# < -89 ) then newX# = -89
    SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
    SetCameraPosition(1,camerax#,cameray#,cameraz#)
 
endfunction


function moveblockwithmouse()

VectorX# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
VectorY# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
VectorZ# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY()*2 )
 
// get a vector that points in the direction the camera is looking
VectorX2# = Get3DVectorXFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorY2# = Get3DVectorYFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorZ2# = Get3DVectorZFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
 
// normalise Vector in the direction of Vector2
Dot# = VectorX#*VectorX2# + VectorY#*VectorY2# + VectorZ#*VectorZ2#
if ( Dot# > 0 )
    VectorX# = VectorX# / Dot#
    VectorY# = VectorY# / Dot#
    VectorZ# = VectorZ# / Dot#
endif
 
WorldX# = VectorX# * Depth# + GetCameraX(1)
WorldY# = VectorY# * Depth# + GetCameraY(1)
WorldZ# = VectorZ# * Depth# + GetCameraZ(1)
SetObjectPosition(1,WorldX#,GetObjectY( 1) ,WorldZ#)
endfunction


A 3D Apple (fruit) really needs a texture created instead of color
but does slope in at the top
+ Code Snippet
//low polly apple
type object 
    objMesh as integer
    objMem as integer
    maxVertex as integer
endtype

CreateObjectSphere(1,20,10,10)
SetObjectPosition(1,25,0,0)

// position and orientate the camera
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)

numMeshes=GetObjectNumMeshes(1)
myObject as object
myObject.objMem=CreateMemblockFromObjectMesh(1,1)
myObject.maxVertex=GetMemblockInt(myObject.objMem,0)-1

for index = 0 to 21//myObject.maxVertex
	if index <=9 
		SetMeshMemblockVertexPosition(myObject.objMem,index,GetMeshMemblockVertexX(myObject.objMem,index),GetMeshMemblockVertexY(myObject.objMem,index)-8,GetMeshMemblockVertexZ(myObject.objMem,index))
	else
		SetMeshMemblockVertexPosition(myObject.objMem,index,GetMeshMemblockVertexX(myObject.objMem,index),GetMeshMemblockVertexY(myObject.objMem,index)-4,GetMeshMemblockVertexZ(myObject.objMem,index))
	endif	
next index
SetObjectMeshFromMemblock(1,1,myObject.objMem)
DeleteMemblock(myObject.objMem)
SetObjectColor(1,200,0,0,255)
//SetObjectScale(1,.5,.5,.5)

CreateObjectBox(2,2,10,2)
vertex as integer[7] = [17,15,7,13, 1,19,3,5]
numMeshes=GetObjectNumMeshes(2)
myObject.objMem=CreateMemblockFromObjectMesh(2,1)
myObject.maxVertex=GetMemblockInt(myObject.objMem,0)-1
for i = 0 to 7
    SetMeshMemblockVertexPosition(myObject.objMem,vertex[i],GetMeshMemblockVertexX(myObject.objMem,vertex[i])+1,GetMeshMemblockVertexY(myObject.objMem,vertex[i]),GetMeshMemblockVertexZ(myObject.objMem,vertex[i]))
next i   
SetObjectMeshFromMemblock(2,1,myObject.objMem)
DeleteMemblock(myObject.objMem)
SetObjectColor(2,160,80,45,255)
SetObjectPosition(2,0,7,0)
FixObjectToObject(2,1)
sync()
// main loop
do

        // rotate all the spheres
        RotateObjectLocalX(1,.5)
        print(numMeshes)
        print(myObject.maxVertex)
        sync()

loop

If I spent a bit of time working out a cylinder for a twig instead of the box I could bend it with a sinecurve and perhaps add a leaf lol
Posted: 11th Apr 2018 1:59
Added some useful tutorials ive found across forums

AGK First Video Tutorial - Random number guessing game

https://forum.thegamecreators.com/thread/188244

[Video Tutorial] ScribbleSquash (Full game tutorial)
https://forum.thegamecreators.com/thread/188387

How to add in-app purchase in your games. a step by step tutorial.
https://forum.thegamecreators.com/thread/191568

AGK online help file
https://www.appgamekit.com/documentation/home.html

AGK video tutorial one hello world sprites and more
https://www.youtube.com/watch?v=CbC7ju2kew8&list=PL62008E8509FB652B&feature=plcp

AGK Video tutorial two physics sounds sprites
https://www.youtube.com/watch?v=NR9sutVdBmg&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial three scrolling sprites
https://www.youtube.com/watch?v=rQ1-Zw6SGbk&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial four cameras and more
https://www.youtube.com/watch?v=kWAfHgrBb-M&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial five putiing your app in xCode
https://www.youtube.com/watch?v=EF5liNrFxMY&feature=BFa&list=PL62008E8509FB652B

Dans video tutorial sprite shadows
https://forum.thegamecreators.com/thread/204491

Smackit lite video tutorial
https://forum.thegamecreators.com/thread/204969

Working with UV coordinates in AGK
http://www.zimnox.com/resources/articles/tutorials/?ar=t004

Basic Parallax scrolling Video tutorial
https://forum.thegamecreators.com/thread/206458

Parallax scrolling tutorial 2
https://forum.thegamecreators.com/thread/206518

Pinch Zoom code and mini Tutorial
https://forum.thegamecreators.com/thread/205033

Scrolling lists tutorial
https://forum.thegamecreators.com/thread/207792

Dvaders video tutorials
https://forum.thegamecreators.com/thread/206716

Creating a simple GUI Tutorial
https://www.gamedev.net/articles/programming/general-and-gameplay-programming/creating-a-very-simple-gui-system-for-small-games-part-i-r3652

Free platformer code and tutorial
https://forum.thegamecreators.com/thread/211652

2D Tile engine tutorial with code
https://forum.thegamecreators.com/thread/212717

Blender to AppGameKit Tutorial
https://forum.thegamecreators.com/thread/221714

Newsletter with introduction to server code
https://www.thegamecreators.com/pages/newsletters/newsletter_issue_147.html
Posted: 11th Apr 2018 4:22
I really hope people will post code here they are willing to share, including tools, effects, snippets and perhaps links to useful
tutorials with some title as to what they are about. Preferably code that doesn't require downloading as over time when
someone visits this thread these links may not work. One of the main reasons I like to create examples that may create
media on the fly or don't use media. The ones that need media and cant just be copied pasted and run are commented
above appropriately. THANKS


APOLOGIES if the quotes sound like rules they're not, but firstly going through long threads can be off putting for
someone that just needs a small example to kickstart their code. I've been searching allot through some long threads lately
and it can be disheartening when you finally find what you believe is the perfect example for what you want but the
download link no longer works and there's probably plenty useful code already been shared, so people ask the same
question again.

For new people to AGK I recommend the following page its rather long but def has some great code shared
AGK Code Challengehttps://forum.thegamecreators.com/thread/218129 all code there is just copy
paste run
Posted: 11th Apr 2018 5:25
I would have used either Github or the codebase here to share all this.
Posted: 11th Apr 2018 7:15
I would have used either Github or the codebase here to share all this.

Thanks Mikehart I forgot all about the codebase

The code base for those interested it also has a good search ability
https://www.thegamecreators.com/codebase

I added some of the above

Manage Codebase Entries you can manage your own entries in the codebase at
https://www.thegamecreators.com/codebase/manage
Posted: 11th Apr 2018 10:51
Always usefull to find when you are lazy
Posted: 12th Apr 2018 15:08
3D UV shifting
+ Code Snippet
#constant KEY_UP =  38    //the up arrow key scancode
#constant KEY_DOWN  =  40 //the down arrow key scancode
#constant KEY_LEFT  =  37 //the left arrow key scancode
#constant KEY_RIGHT = 39  //the right arrow key scancode

// show all errors
SetErrorMode(2)

// set window properties
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // 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

textureImage1=createtexture(256,256, makecolor(255,255,255),155) //must be power of 2
textureImage2=createtexture(32,32, makecolor(255,255,255),50)    //must be power of 2

leftPlane=CreateObjectPlane(40, 40 ) 
SetObjectImage(leftPlane,textureimage1,0)
SetObjectColor(leftPlane,0,200,0,255)
SetObjectRotation(LeftPlane,0,-90,0 ) 
SetObjectPosition(leftPlane,1,0,40)
SetObjectUVScale(LeftPlane,0,1,1) 

rightPlane=CreateObjectPlane(40, 40 ) 
SetObjectImage(rightPlane,textureimage1,0)
SetObjectColor(rightPlane,0,200,0,255)
SetObjectRotation(rightPlane,0,-90,0 ) 
SetObjectPosition(rightPlane,40,0,40)
SetObjectUVScale(rightPlane,0,1,1) 

bottomPlane=CreateObjectPlane(40, 40 ) 
SetObjectImage(bottomPlane,textureimage1,0)
SetObjectRotation(bottomPlane,90,0,0 ) 
SetObjectPosition(bottomPlane,20,-20,40)
SetObjectUVScale(bottomPlane,0,1,1) 

backPlane=CreateObjectPlane(40, 40 ) 
SetObjectImage(backPlane,textureimage2,0)
SetObjectColor(backPlane,0,0,200,255)
SetObjectPosition(backPlane,20,0,60)

SetImageWrapU( textureimage1, 1 )
SetImageWrapV( textureimage1, 1 )
setCameraPosition(1,40/2,10,2)

SetSunActive(1)
SetSunColor( 255, 255,255 )
SetFogSunColor( 20, 20, 20 ) 
//Add some atmosphere
//SetFogMode( 1 ) 
//SetFogColor(20,20,20)
//SetFogRange(10,100)

SetShadowMappingMode(3 )
SetShadowSmoothing( 0) 
SetShadowMapSize( 512, 512 )
SetShadowRange( -1 ) // use the full camera range

leftU#=0:rightU#=0:bottomU#=0:bottomV#=0 
do
	if GetRawKeyState (KEY_Up)
		leftU#=leftU#+.1:rightU#=rightU#-.1:bottomV#=bottomV#-.1
		SetObjectUVOffset(leftPlane,0,leftU#,0  ) 
		SetObjectUVOffset(rightPlane,0,rightU#,0 ) 
		SetObjectUVOffset(bottomPlane,0,bottomU#,bottomV# ) 		
	endif
	if GetRawKeyState (KEY_Down)
		leftU#=leftU#-.1:rightU#=rightU#+.1:bottomV#=bottomV#+.1
		SetObjectUVOffset(leftPlane,0,leftU#,0 ) 
		SetObjectUVOffset(rightPlane,0,rightU#,0 ) 		
		SetObjectUVOffset(bottomPlane,0,bottomU#,bottomV# ) 		
	endif
	if GetRawKeyState (KEY_Left)
		bottomU#=bottomU#-.1
		SetObjectUVOffset(bottomPlane,0,bottomU#,bottomV# ) 		
	endif
	if GetRawKeyState (KEY_Right)
		bottomU#=bottomU#+.1
		SetObjectUVOffset(bottomPlane,0,bottomU#,bottomV# ) 		
	endif
	
    Print( ScreenFPS() )
    Sync()
loop
// 102, 51, 0
// Function to create a texture
// by Puzzler
// Inputs - Sizex - size of the texture to create - width
//          Sizey - size of the texture to create - height
//          Color - is the main color of the image
//          Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
// 
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100,  makecolor(0,0,255), 100)
//          This could create a DEEP water effect texture?
   
function createtexture(sizex# as float, sizey# as float, color, density as integer)
    swap()
    drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
    render()
    img = getimage(0,0,sizex#, sizey#)
       
    memblockid = CreateMemblockFromImage (img)
    imgwidth = GetMemblockInt(memblockid, 0)
    imgheight = GetMemblockInt(memblockid, 4)
       
    size=GetMemblockSize(memblockid)
	for offset=12 to size-4 step 4
         
        r=GetMemblockByte(memblockid, offset)
        g=GetMemblockByte(memblockid, offset+1)
        b=GetMemblockByte(memblockid, offset+2)
        a=GetMemblockByte(memblockid, offset+3)
               
           
        strength=random(1,density)
   
        SetMemblockByte (memblockid, offset, r-strength)
        SetMemblockByte (memblockid, offset+1, g-strength)
        SetMemblockByte (memblockid, offset+2, b-strength )
		SetMemblockByte (memblockid, offset+3, a-strength)
    next
    deleteimage (img)
    img = CreateImageFromMemblock(memblockid)
    DeleteMemblock(memblockid)
endfunction img

Create Sound From Memblocks
+ Code Snippet
hz=random2(1,32767)
soundHz=createSound(hz)
repeat
	Print("Press Space to play sound esc to exit")
	Print("the last played sound was Hz="+str(hz))
	if GetRawKeyPressed(32)
		PlaySound(soundHz,100,0)
	endif
	if GetSoundsPlaying(soundHz)=0
		deleteSound(soundHz)
		hz=random2(1,32767)
		soundHz=createSound(hz)
		//PlaySound(soundHz,100,0)
	endif
	sync()
until GetRawKeyPressed(27)
end

function createSound(hz 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 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 
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
sound = CreateSoundFromMemblock(mem)
DeleteMemblock(mem)
endFunction sound

A Different Algorithm to make sounds from memblocks
+ Code Snippet
//converted from the following darkbasic file in the code base
//https://www.thegamecreators.com/codebase/view/6c6649b8ae9a696be762832e939e2913

createsound(1,2995,2000,8000,0.02,0.1,0.60,3,0.64,5,10)  	//sound effect
createsound(2,6200,200,2000,20,0.2,0,0,0,0,10)				//explosion
createsound(3,1200,600,3000,10,0.1,0,0,0,0,10)				//explosion2
createsound(4,800,700,8000,-0.02,0.2,0,0,0,0,10)			//powerup
createsound(5,800,1000,6000,0.5,0.1,0,0,0,0,5)				//warning
createsound(6,500,2000,8000,0,0.1,0.05,0.2,0,0,1)			//vibrato1
createsound(7,400,2000,8000,0,0.1,0.05,0.2,0,0,1)			//vibrato2
createsound(8,600,2000,8000,0,0.1,0.05,0.2,0,0,1)			//vibrator3
createsound(9,30,50,16000,0.00,1.5,.0,0,0,0,100)			//bass hit
createsound(10,80,1000,5000,70.06,2.5,.1,0,0,0,2)			//hihat				
createsound(11,200,20,8000,.1,4.0,2.1,10,9.2,9.2,10)		//door knock
createsound(12,500,80,8000,0.06,0.2,.1,0,0,0,10)			//vinyl scratch
createsound(13,250,50,2500,0.00001,0.1,4.0,0.4,0,0,10)		//cb1
createsound(14,500,50,2500,0.00001,0.1,4.0,0.4,0,0,10)		//cb2
createsound(15,437.5,150,1500,0.0001,0.1,0.0,4.0,0.4,0,10)	//cb3
createsound(16,573.75,150,1500,0.0,0.1,4.0,0.4,0.1,0.1,10)	//cb4
createsound(17,50,80,6000,-.4,2.0,0.1,10,1.2,0.2,10)		//bubbleburst
Hz=0
do

	if GetRawKeyPressed(49) then PlaySound(1,100,0)
	if GetRawKeyPressed(50) then PlaySound(2,100,0)
	if GetRawKeyPressed(51) then PlaySound(3,100,0)
	if GetRawKeyPressed(52) then PlaySound(4,100,0)
	if GetRawKeyPressed(53) then PlaySound(5,100,0)
	if GetRawKeyPressed(54) 
		PlaySound(6,100,0):PlaySound(7,100,0):PlaySound(8,100,0)
	endif
	if GetRawKeyPressed(55) then PlaySound(9,100,0)
	if GetRawKeyPressed(56) then PlaySound(10,100,0)
	if GetRawKeyPressed(57) then PlaySound(11,100,0)
	if GetRawKeyPressed(58) then PlaySound(12,100,0)
	if GetRawKeyPressed(48) 
		PlaySound(13,100,0):PlaySound(14,100,0):PlaySound(15,100,0):PlaySound(16,100,0)
	endif
	if GetRawKeyPressed(189) then PlaySound(17,100,0)
	
	If GetRawKeyPressed(13)
	//rain effect
		for i =10 to 25
			createsound(18+i,12*i,60*i,300+i,10*i,1.1*i,10*i,i,i,i,100*i)    
			PlaySound(18+i,100,0) //:sleep(300)
		next i
	Endif

	
	if GetRawKeyPressed(32) 
		Hz=random(0,32767)
		createsound(20,Hz,1000,6000,0.5,0.1,0,0,0,0,5)	
		PlaySound(20,100,1)
	endif 
	Print("Press keys 1 upwards:")
	Print("1: sound effect")
	Print("2: explosion1")
	Print("3: explosion2")
	Print("4: powerup")
	Print("5: warning")
	Print("6: vibrato")
	Print("7: bass hit")
	Print("8: hihat")
	Print("9: door knock")
	Print("0: vinyl scratch")
	Print("-: cowbell")
	Print("+: bubble burst")
	Print("Hz="+str(Hz))
sync()
loop


function createsound(soundnumber as integer,frequency as float,length as float,loudness as float,bend as float,decay as float, 
				 vibratospeed as float,vibratodepth as float,tremelospeed as float,tremelodepth as float,attack as float)


//local sound as integer
local frames as integer
local data as integer 
local size as integer
local mem as integer
local sec as float
local i as integer
local value as integer
//local Hz as float // the hertz of the sound
local w as float

sec = length/1000
sec=1
data = sec * (44100 * (2*2)) // 176400 bytes per second
frames = data / 4
size = 2+2+4+4 + data
mem = CreateMemblock(size)

//samples = ((length / 1000) * 44100)
//mem=CreateMemblock(samples * 2 + 28)


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.
//rem generate and write wave
local theta as float
local phi as float
local fallinloudness as float 
local riseinloudness as float 
theta = 0 
phi = 0 
fallinloudness = loudness
riseinloudness = loudness
position=0
for i=0 to data-1 step 4

   outInteger = ceil(Sin(( i / 122.5) * (frequency + vibratodepth * Sin(theta))) * (loudness - fallinloudness - riseinloudness + tremelodepth * Sin(phi))) * 3.0
  if(outInteger < -32767) then outInteger = -32767	// gg query: is this the valid range?
  if(outInteger > 32767) then outInteger = 32767	// gg query:       (ditto)          ?
  outWord = outInteger
  theta =theta+ vibratospeed
  phi =phi+ tremelospeed
  frequency =frequency-bend
  if(fallinloudness < loudness)
     fallinloudness =fallinloudness+ decay
  endif
  if(riseinloudness > 0)
     riseinloudness = riseinloudness-attack
  endif
  SetMemblockShort(mem,12+position,outWord)
  position = position+2
  //SetMemblockShort(mem,12+i+0,outWord)
  //SetMemblockShort(mem,12+i+2 ,outWord) // short 2 bytes ?32768 through 32767
next 

if getsoundexists(soundnumber)=1 then deletesound (soundnumber)
CreateSoundFromMemblock(soundnumber,mem)
DeleteMemblock(mem)
endfunction   

3D Snow Example
+ Code Snippet
rem Snow Fall Example
#constant screenwidth=1024
#constant screenheight = 768
// set window properties
SetWindowTitle( "SNOW FALL" )
SetWindowSize( screenwidth, screenheight, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
    
// set display properties
SetVirtualResolution( screenwidth, screenheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 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

#constant maxSnowX=512
#constant maxSnowY=334
#constant maxSnowZ=300
 
Type TPar
	id as integer
    x as float
    y as float
    z as float
    speed as float
EndType
 
global Snow as TPar[200]
 
obj=CreateObjectSphere(1,1,1) 
for i=1 to 200
    SnowRenew(i)
next
 
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)
 
Do
 
    for i=1 to 200
        //Snow[i].x = Snow[i].x + Rnd(-0.1,0.1)
        Snow[i].y = Snow[i].y - Snow[i].speed
        //Snow[i].z = Snow[i].z + Rnd(-0.1,0.1)
        SetObjectPosition(Snow[i].id,Snow[i].x,Snow[i].y,Snow[i].z)
        if Snow[i].y < -maxSnowY then SnowRenew(i)
    next
     
    sync()
Loop
 
Function SnowRenew(i)
    Snow[i].x = Rnd(-maxSnowX,maxSnowX) 
    Snow[i].y = maxSnowY-Rnd(0,maxSnowY) 
    Snow[i].speed = Rnd(0.01,0.1) 
	Snow[i].id=i	
    CreateObjectSphere(i,2,3,3)
	SetObjectPosition(Snow[i].id,Snow[i].x,Snow[i].y,Snow[i].z)
	SetObjectScale( Snow[i].id,2,2,2 ) 
EndFunction 
 
Function Rnd(a as float,b as Float)
    c as float
    c = Random2(a*100,b*100)
    c = c / 100.0     
EndFunction c
Posted: 12th Apr 2018 15:20
@fubarpk

We recently updated the forum AUP to require the use of properly formatted code blocks please update your code blocks to use the AppGameKit language code block tags instead of the default ones. You can do this by using [code lang="agk"]

This will help with code readability for everyone.
Posted: 12th Apr 2018 21:22
We recently updated the forum AUP to require the use of properly formatted code blocks please update your code blocks to use the AppGameKit language code block tags instead of the default ones. You can do this by using [code lang="agk"]

Apologies @The next I do remember seeing the new comment blocks but not that it was a requirement
but then I haven't been in a good headspace lately so that is probably me. But I have changed the necessary
codeblocks and I Agree it does make it easier to read.

I also notice now we have a mark as answer to forum questions, what a great idea
Posted: 12th Apr 2018 22:57
Scrolling TechDemo like in the past Does alsorts of stuff with sinewaves text and particles easier to just try no media required
which I used as an intro in my game Smiley Madness available free https://play.google.com/store/apps/details?id=smiley.Madness
+ Code Snippet
Rem fubarpk techDemo
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Demo" )
SetWindowSize( xMax, yMax, 0 )

// set display properties
SetVirtualResolution( xMax, yMax )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 ) // 
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

rem data dictionary
rem sprites 1 to x is the sprites in the circle
rem sprites (spr) 100 to x is the sprites in the sinewave
rem sprites (spr2) 200 to x falling bouncy balls balls
rem sprites 800 and 801 curtain

#constant xMax=960
#constant yMax=540
#constant Bg=1000 :rem for the rubout sprite
#constant gravity=50 :rem the gravity to set for the physics
angle#=0

rem for falling bouncing balls
type ball
	id as integer
	x as float
	y as float
endtype

rem for circle
type textSpr
	id as integer
	angle as integer
	img as integer
endtype 

rem for sinewave
type myText
	id as integer		:rem id of sprite
	PointX as integer	:rem makes it move
	centreX as integer  :rem centre of sine wave x axis
	yPosition as integer:rem yPosition on y-axis
	amplitude as integer:rem the heaight of the wave
	speedX# as float	:rem how fast sine travels on x-axis
	WaveWidth as integer:rem how wide the sinewave is
	frequency# as float	:rem speed sprite should move up and down (0.0 to 6.0)
	img as integer		:rem holds the image number for the sprite
endtype
do 
	FubarpkTechDemo()
loop	

function FubarpkTechDemo()
//SetPhysicsDebugOn()
SetPhysicsScale( 0.1)
SetPhysicsGravity(0,gravity)
SetPhysicsWallTop(0)
SetPhysicsWallBottom(0)

CreateSprite(800,fubarpkCreateCurtain(1))
//SetSpriteSize(200,10,yMax)
SetSpriteOffset(800,xMax,0)
SetSpriteTransparency(800,0)
SetSpriteDepth(800,0)
SetSpritePositionByOffset(800,0,0)
CreateSprite(801,fubarpkCreateCurtain(2))
//SetSpriteSize(201,10,yMax)
SetSpriteOffset(801,0,0)
SetSpriteTransparency(801,0)
SetSpriteDepth(801,0)
SetSpritePositionByOffset(801,xMax,0)

SetClearColor(0,0,0)

rem the circle text
text$=fubarpkInvertText("2017 Scrolling Mega Demo by fubarpk using AGK "):strlen=len(text$)	
global dim spr[strlen] as textSpr
Rem Move a sprite around a circle
for num = 0 to strlen
	spr[num].id=num+1:rem the id to rotate
	spr[num].img=num+1:rem holds the image
	spr[num].angle=num*8:rem the angle of the rotation(0 - 360)/A point around the circumference(the circle)
	fubarpkCreateTextImage(Mid(text$,num+1,1),spr[num].img)
	CreateSprite(spr[num].id,spr[num].img)
	SetSpriteColor(spr[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
	SetSpriteTransparency(spr[num].id,1)
	SetSpriteGroup(spr[num].id,1)
	SetSpritePhysicsOn(spr[num].id,1)
next num

rem sine text
text$=fubarpkInvertText("Just another sine scrolling text"):strlen2=len(text$)
global dim spr2[strlen2] as myText
for num=1 to strlen2 
	spr2[num].id=num+100:spr2[num].img=num+100
	spr2[num].centreX=xMax/2
	spr2[num].yPosition=yMax/2
	spr2[num].amplitude=20
	spr2[num].speedX#=.51
	spr2[num].WaveWidth=xMax
	spr2[num].frequency#=1.4
	spr2[num].PointX=90-(num*3)
	fubarpkCreateTextImage(Mid(text$,num,1),spr2[num].img)
	createSprite(spr2[num].id,spr2[num].img)
	SetSpriteColor(spr2[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
	SetSpriteTransparency(spr2[num].id,1)
	SetSpriteDepth(spr2[num].id,10)
	SetSpriteGroup(spr2[num].id,1)
	SetSpritePhysicsOn(spr2[num].id,1)
next num 

global dim balls[20] as ball
img=fubarpkCreateEllipse()
fubarpkSetupballs(img)

Rem set up the variables. Variables is used here for explanation and reuseability
rem the diameter of the circle (the width or height)
` using the same value for diameterX and DiameterY will create a circle
` using different values will create an oval
diameterX = 200
diameterY = 200
rem The x Value of the centre of the circle
centreX = xMax/2
 rem The Y Value of the centre of the circle
centreY = yMax/2
Rem Steps is how fast the sprite should move (a Value of 1 draws the sprite at every point around the circle)
steps = -1


iAlpha=0
yFlag=1
fadeFlag=0
flag=1
ResetTimer()
time#=timer()
repeat
	// circle scroller
	if yFlag=1 
		dec diameterY
		if diameterY <=-200 then yFlag=0
	elseif yFlag=0
		inc diameterY
		if diameterY >=200 then yFlag=1
	endif
	
	rem Position the sprite using the math commands Sin and Cos (Sin for x and Cos for y)
	for num = 0 to strlen 
		//setspritePosition(spr[num].id,Sin(spr[num].angle)*diameterX+centreX,Cos(Sin(spr[num].angle)*diameterY+centreY))
		setspritePosition(spr[num].id,Sin(spr[num].angle)*diameterX+centreX,Cos(spr[num].angle)*diameterY+centreY)
		rem check if the sprite has moved full circle (360 degrees) then set it back to zero if it has.
		` Use greater than -360 ( > -360 ) and subtract before steps ( angle - steps ) to move opposite direction
		` It is possible to skip the check for 360 (full circle) and only decreas/increase the angle
		` but then the angle value will decrease or increase forever
		if spr[num].angle < 360
			spr[num].angle = spr[num].angle + steps
		else
			spr[num].angle = 0
		endif
		SetSpriteColorAlpha(spr[num].id,iAlpha)
	next num
	
	//sine scroller
	flag=fubarpkTextScroll(strlen2,flag,iAlpha)
	if fadeFlag=0
		if iAlpha<255 then inc iAlpha
	else
		if iAlpha>1 then dec iAlpha
	endif	
	for num=1 to 20
		if GetSpriteYByOffset(balls[num].id) > yMax
			balls[num].y =-150
			balls[num].x=random(100,xMax-100)
			SetSpriteColor( balls[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
			SetSpriteVisible(balls[num].id,1)
			SetSpritePositionByOffset(balls[num].id,balls[num].x,balls[num].y)
		endif
		
		for hitCheck=1 to strlen
			If GetSpriteCollision(balls[num].id,hitCheck)
				SetSpriteVisible(hitCheck,0):SetSpriteVisible(num,0)
				SetSpriteActive(hitCheck,0):SetSpriteActive(num,0)
				SetSpritePhysicsOff(hitCheck):SetSpritePhysicsOff(num)
				fubarpkSpriteHit(hitCheck,img)
			endif
		next hitCheck
		for hitCheck=1 to strlen2
			If GetSpriteCollision(balls[num].id,hitCheck+100)
				SetSpriteVisible(hitCheck+100,0):SetSpriteVisible(num,0)
				SetSpriteActive(hitCheck+100,0):SetSpriteActive(num,0)
				SetSpritePhysicsOff(hitCheck+100):SetSpritePhysicsOff(num)
				fubarpkSpriteHit(hitCheck+100,img)
			endif
		next hitCheck
	next num
 Sync()
until Timer()-time#>15
fubarpkTheEnd(strlen,strlen2)
end
endfunction

function fubarpkCreateTextImage (myString as string,imgNum as integer)
CreateSprite(bg,0)
SetSpriteSize(bg,150,150)
SetSpriteColor(bg,0,0,0,255)
clearscreen()
CreateText(100,myString)
SetTextSize(100,50)
SetTextPosition(100,0,0)
//drawSprite(100)
//if myString <> 
Render():If GetImageExists(imgNum) then DeleteImage(imgNum)
GetImage(imgNum,0,0,50,50):ClearScreen()
SetImageTransparentColor( imgNum,0,0,0 )
DrawSprite(bg)
ClearScreen()
DeleteText(100):deleteSprite(bg)
endfunction

function fubarpkInvertText(myString as string)
	resultString as string
	for num =len(myString) to 1 step -1
		resultString=resultString+Mid(myString,num,1)
	next num	
endfunction resultString

function fubarpkTextScroll(strlen as integer,flag as integer, iAlpha as integer)
//if delay# > .05 
for num = 1 to strlen
	xWave=Sin(spr2[num].PointX)*(spr2[num].wavewidth/2)+spr2[num].centreX
	yWave=sin(xWave*spr2[num].frequency#)*(spr2[num].amplitude)+spr2[num].yposition
	SetSpritePosition(spr2[num].id,xWave,yWave)
  
	if spr2[num].PointX >-90
		spr2[num].PointX = spr2[num].PointX - spr2[num].speedX#
		if spr2[num].amplitude>=20 and flag=1  
			spr2[num].amplitude=spr2[num].amplitude+2
			if spr2[num].amplitude>=180 then flag=0
		endif
		if spr2[num].amplitude >0 and flag=0 
			spr2[num].amplitude=spr2[num].amplitude-2
			if spr2[num].amplitude<=20 then flag=1
		endif
	else
		spr2[num].PointX = 90
	endif
	SetSpriteColorAlpha(spr2[num].id,iAlpha)
		
	If GetSpriteX(spr2[num].id)<xMax/2 
		SetSpriteDepth(spr2[num].id,15)
	else 
		SetSpriteDepth(spr2[num].id,5)
	endif
next num
endfunction flag

function fubarpkCreateEllipse()
    Render()
    DrawEllipse(50,50,25,25,MakeColor(255,255,255),MakeColor(100,100,100),1)
    Swap()
    img = getimage(0,0,100,100)
    sync()
endfunction img

function fubarpkSetupballs (img as integer)
for num =1 to 20
	balls[num].id=(num-1)+200
	if GetSpriteExists(balls[num].id) then DeleteSprite(balls[num].id)
	CreateSprite(balls[num].id,img)
	SetSpriteColor(balls[num].id, Random(1,255),Random(1,255), Random(1,255), 255 ) 
	SetSpriteOffset(balls[num].id,50,50)
	SetSpritePositionByOffset(balls[num].id,random(100,xMax-100),-random(100,yMax*4))
	SetSpriteShapeCircle(balls[num].id,0,0,25)
	SetSpritePhysicsOn(balls[num].id,2)
	SetSpritePhysicsRestitution(balls[num].id,.75 ) 
	SetSpriteGroup(balls[num].id,2)
	SetSpriteDepth(spr2[num].id,1)

next num 
endfunction

function fubarpkSpriteHit(hit as integer, img as integer)
	//DeleteParticles(hit)
	id=CreateParticles(100,100)
	SetParticlesImage(id,img)
	SetParticlesSize(id,16)
	SetParticlesFrequency(id,10)
	SetParticlesLife(id,2)
	SetParticlesVelocityRange(id,1,10)
	SetParticlesMax(id,15)
	SetParticlesPosition(id,GetSpriteXByOffset(hit),GetSpriteYByOffset(hit))
	AddParticlesColorKeyFrame(id,0,GetSpriteColorRed(hit),GetSpriteColorGreen(hit),GetSpriteColorBlue(hit),255) 
	updateParticles(id,0)
endfunction

function fubarpkCreateCurtain(direction as integer)
ClearScreen() 
Render()
if direction = 1 :rem left curtain
	DrawBox( 0,0,xMax-6,yMax, MakeColor(0,0,0),MakeColor(0,0,0), MakeColor(0,0,0),MakeColor(0,0,0),1 ) 
	DrawBox( xMax-5,0,xMax,yMax, MakeColor(255,255,255),MakeColor(255,255,255), MakeColor(255,255,255),MakeColor(255,255,255),1 ) 
endif
if direction = 2 :rem Right curtain
	DrawBox( 0,0,5,yMax, MakeColor(255,255,255),MakeColor(255,255,255), MakeColor(255,255,255),MakeColor(255,255,255),1 ) 
	DrawBox( 6,0,xMax,yMax, MakeColor(0,0,0),MakeColor(0,0,0), MakeColor(0,0,0),MakeColor(0,0,0),1 ) 
endif
Swap()
img = getimage(0,0,xMax,yMax)
sync()
endfunction img

function fubarpkTheEnd(strlen as integer,strlen2 as integer)
amount=5	
x=0:xx=xMax
w# as float:w#=0
moveIn=1:flag=0

for num=1 to strlen
	if GetSpriteExists(num) then DeleteSprite(num)
next num
for num=1 to strlen2
	if GetSpriteExists(num+100) then DeleteSprite(num+100)
next num

repeat
	//DrawSprite (Bg)
	SetSpritePositionByOffset(800,x,0)
	SetSpritePositionByOffset(801,xx,0)
	if GetSpriteCollision(800,801) = 0 and moveIn=1
		x=x+amount:xx=xx-amount
	else
		moveIn=0
		flag=1	 
	endif
	if flag=1
		EnableClearColor(1)
		DeleteText(999)
		CreateText(999,"THE END")
		SetTextSize(999,150)
		SetTextPosition(999,xMax/2-230,yMax/2-100)
		flag=3
	endif
	if moveIn=0 and x>0
		x=x-amount:xx=xx+amount
	endif
	Sync()
until moveIn=0 and x<=0
ResetTimer()
for num=255 to 0 step -1
	SetTextColorAlpha(999,num)
	time#=timer()
	repeat
		sync()
	until Timer()-time#>.0005
next num
endFunction


Some Code demonstrating my fadein and fadeout functions requires 2 background images to test
+ Code Snippet
#constant xMax=1024
#constant yMax=600

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "fade in fade out functions" )
SetWindowSize( xMax,yMax,0)
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( xMax, yMax ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 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

backgroundImg0 = LoadImage ("Background0.png")
backgroundImg1 = LoadImage ("Background1.png")
ellipse=LoadImage ("Ellipse.png")

createSprite(1,0)
SetSpriteDepth(1,1)

createSprite(2,ellipse)
SetSpriteSize(2,2,2)
SetSpriteDepth(2,0)
SetSpritePositionByOffset(2,xMax/2,yMax/2)


createSprite(3,backgroundImg0)
SetSpriteSize(3,xMax,yMax)
SetSpriteDepth(3,2)
SetSpritePositionByOffset(3,xMax/2,yMax/2)


createSprite(4,backgroundImg1)
SetSpritePositionByOffset(4,xMax/2,yMax/2)
SetSpriteDepth(4,3)

rubAwayColor(1,0,0,1)
DeleteSprite(1)
fadeIn(4,backgroundImg0,backGroundImg1)
fadeOut(4,backgroundImg0,backGroundImg1)
fadeIn2(2,3,ellipse,backGroundImg0)

do 
	Print(999)
	sync()

loop
Function rubAwayColor(spr1 as integer,r as integer,g as integer,b as integer)
	rem this function you pass a sprite you wish to use to gradually color the screen in the chosen color
	radiusX as integer
	radiusY as integer
	SetSpriteColor(spr1,r,g,b,255)
	SetSpriteSize(spr1,2,2)
	SetSpriteDepth(spr1,1)
	SetSpritePositionByOffset(spr1,xMax/2,yMax/2)
	repeat 
		inc radiusX:inc radiusY
		SetSpriteSize(spr1,radiusX,radiusY)
		sync()
	until radiusX>xMax and radiusY>yMax
endfunction

Function fadeIn(spr1 as integer,img1 as integer,img2 as integer)
	rem this function fades in the background sprite passed by gradually covering the screen with img2 
	rem could be used to remove splash screens etc and fade in game from behind
	x=(xMax/2)-1
	y=(yMax/2)-1
	width=2:height=2
	
	SetSpriteSize(spr1,width,height)
	SetSpritePositionByOffset(spr1,xMax/2,yMax/2)
	SetSpriteDepth(spr1,1)
	repeat 
		if x>0 
			dec x:width=width+2	
		endif
		if y>0
			dec y:height=height+2
		endif
		img1=copyImage(img2,x,y,width,height)
		SetSpriteImage(spr1,img1)
		SetSpriteSize(spr1,width,height)
		sync()
	until x<=0 and y<=0

endfunction

Function fadeIn2(spr1 as integer,spr2 as integer,img1 as integer,img2 as integer)
	rem this function fades in the background sprite spr2 passed by gradually 
	rem the sprite spr1 with the background image2
	x=(xMax/2)-1
	y=(yMax/2)-1
	width=2:height=2
	SetSpriteSize(spr1,width,height)
	SetSpritePositionByOffset(spr1,xMax/2,yMax/2)
	SetSpriteDepth(spr1,0)
	
	SetSpriteSize(spr2,width,height)
	SetSpritePositionByOffset(spr2,xMax/2,yMax/2)
	SetSpriteDepth(spr2,1)
	repeat 
		if x>0 
			dec x:width=width+2	
		endif
		if y>0
			dec y:height=height+2
		endif
		img1=copyImage(img2,x,y,width,height)
		SetSpriteImage(spr2,img1)
		SetSpriteSize(spr2,width,height)
		SetSpriteSize(spr1,width,width)
		sync()
	until x<=0 and y<=0
endfunction

	
function fadeOut(spr1 as integer,img1 as integer,img2 as integer)
	rem this function fades out the foreground sprite passed by gradually covering the screen with img2
	Rem could be used for end of scene game over etc
	x=1:y=1
	width=xMax-1:height=yMax-1
	
	SetSpriteSize(spr1,width,height)
	SetSpritePositionByOffset(spr1,xMax/2,yMax/2)
	SetSpriteDepth(spr1,1)
	repeat 
		if x>0 
			inc x:
			if width>4 then width=width-2	
		endif
		if y>0
			inc y
			if height>4 then height=height-2
		endif
		img1=copyImage(img2,x,y,width,height)
		SetSpriteImage(spr1,img1)
		SetSpriteSize(spr1,width,height)
		sync()
	until width<=4 and height<=4
	SetSpriteVisible(spr1,0)
endfunction	


These were my submissions in the AGK code challenge a very handy place to look for stuff
https://forum.thegamecreators.com/thread/218129?page=1
Posted: 13th Apr 2018 2:11
My frogger clone
video of what I did with it is shown below


and available free from google play here
https://play.google.com/store/apps/details?id=my.frogger

My Frogger Template no media required
in this version movement is done with the arrow keys and there
is one screen for the road and one screen for the river.
+ Code Snippet
// Project: Frogger Template by fubarpk
// Created: 2017-03-22
#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 xMax=1024
#constant yMax=600
#constant timePerGame=120
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Frogger" )
SetWindowSize( xMax,yMax,0)
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( xMax, yMax ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) // 
//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

playFrogger()
end

function playFrogger()
deleteSprite(900)
//createSprite(900,ellipse)
createSprite(900,0)
setSpritecolor(900,0,0,0,255)
SetSpriteSize(900,xMax,yMax)
SetSpriteDepth(900,9997)
//SetSpritePositionByOffset(900,xMax/2,yMax/2)
//DeleteSprite(901)
repeat
	Print ("My Frogger template click space to Play")
	sync()
until GetRawKeyPressed(32) = 1 //click mouse to play

high=0:score=0:bonusTime=0
bonusTime$="Time Left :"+str(bonusTime)
CreateText(1,bonusTime$)
SetTextSize(1,40)
SetTextPosition(1,10,0)
myHigh$="High :"+str(high)
CreateText(2,myHigh$)
SetTextSize(2,40)
SetTextDepth(2,0)
SetTextPosition(2,600,0)
myScore$="Score:"+str(score)
CreateText(3,myScore$)
SetTextSize(3,40)
SetTextDepth(3,0)
SetTextPosition(3,820,0)

frogSpr = CreateSprite(0)
SetSpriteSize(frogSpr,64,64)
changeFrogColor(frogSpr,1)

SetSpriteDepth(frogSpr,15)
do
	elapsedTime#=Timer()
	resetTimer()

	repeat
		SetSpriteDepth(900,10000)
		
		score=crossRoadLevel(frogSpr,score)
		if high<score then high = score
		myScore$="Score:"+str(score):myHigh$="High :"+str(high)
		SetTextString(2,myHigh$):SetTextString(3,myScore$)

		sync()
		//resetTimer()
		score=crossRiverLevel(frogSpr,score)
		if high<score then high = score
		myScore$="Score:"+str(score):myHigh$="High :"+str(high)
		SetTextString(2,myHigh$):SetTextString(3,myScore$)
		//SetSpriteDepth(901,9998):SetSpriteDepth(902,9999)
	
		SetSpriteAngle(frogSpr,0)
		sync()
		elapsedTime#=Timer()
	until elapsedTime#>timePerGame //limited time per attempt
	sync()
	setSpritecolor(900,0,0,0,255)
	gameOver()
	score=0:changeFrogColor(frogSpr,1)
	myScore$="Score:"+str(score)
	SetTextString(3,myScore$)
loop
endfunction 

function crossRoadLevel(frogSpr as integer,score as integer)
setSpritecolor(900,150,150,150,255)
for num = 1 to 5
	DeleteSprite(num):deleteSprite(num+5):deleteSprite(num+10)
	DeleteSprite(num+15):DeleteSprite(num+20)
	rem top road moving right cars and trucks
	createSprite(num,0)
	SetSpriteSize(num,60,128)
	SetSpriteColor(num,Random(1,255),Random(1,255),Random(1,255),255)
	SetSpriteAngle(num,90)
	createSprite(num+5,0)
	SetSpriteSize(num+5,60,148)
	SetSpriteColor(num+5,Random(1,255),Random(1,255),Random(1,255),255)
	SetSpriteAngle(num+5,90)
	rem bottom road moving left cars and trucks
	createSprite(num+10,0)
	SetSpriteSize(num+10,60,128)
	SetSpriteColor(num+10,Random(1,255),Random(1,255),Random(1,255),255)
	SetSpriteAngle(num+10,270)
	createSprite(num+15,0)
	SetSpriteSize(num+15,60,148)
	SetSpriteColor(num+15,Random(1,255),Random(1,255),Random(1,255),255)
	SetSpriteAngle(num+15,270)
	placeVehicles(num)
next num
changeColor=placeBonusFruit(500)
SetSpriteDepth(frogSpr,15)
time#=timer()
repeat 
until timer()-time#>1
FrogAnimNum=1
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
bonusTime=timePerGame-timer()
while GetSpriteYByOffset(frogSpr)-35>0 and bonusTime >0
	bonusTime$="Time Left :"+str(bonusTime)
	SetTextString(1,bonusTime$)

	x#=GetSpriteX(frogspr):y#=GetSpriteY(frogSpr)
	if GetRawKeyState (KEY_Up)
		y#=y#-5
	endif
	if GetRawKeyState (KEY_Down)
		y#=y#+5
	endif
	if GetRawKeyState (KEY_Left)
		x#=x#-5
	endif
	if GetRawKeyState (KEY_Right)
		x#=x#+5
	endif
   	SetSpritePosition(frogSpr,x#,y#)
	
	if moveVehicles(frogSpr)=1
		x#=xMax/2:y#=yMax-40
		SetSpritePosition(frogSpr,x#,y#)
	endif 
	
	If GetSpriteCollision(frogSpr,500)=1 and GetSpriteVisible(500)=1 
		changeFrogColor(frogSpr,changeColor)
		score=score+250
		myScore$="Score:"+str(score)
		SetTextString(3,myScore$)
		SetSpriteVisible(500,0)
	endif 
    bonusTime=timePerGame-timer()
	Sync()
endwhile
if bonusTime>0 then score=score+(10*bonusTime)
endfunction score   


function crossRiverLevel(frogSpr as integer,score as integer)
setSpritecolor(900,0,0,140,255)		
for num = 1 to 5
	DeleteSprite(num):deleteSprite(num+5):deleteSprite(num+10)
	DeleteSprite(num+15):DeleteSprite(num+20)
	rem top road moving 
	createSprite(num,0)
	SetSpriteColor(num,139,69,19,255)
	SetSpriteSize(num,128,64)
	SetSpriteDepth(num,20)
	
	createSprite(num+5,0)
	SetSpriteColor(num+5,139,69,19,255)
	SetSpriteSize(num+5,186,64)
	SetSpriteDepth(num+5,20)

	rem bottom river moving left Logs
	CreateSprite(num+10,0)
	SetSpriteColor(num+10,139,69,19,255)
	SetSpriteSize(num+10,186,64)
	SetSpriteDepth(num+10,20)
	
	CreateSprite(num+15,0)
	SetSpriteColor(num+15,139,69,19,255)
	SetSpriteSize(num+15,128,64)
	SetSpriteDepth(num+15,20)
	
	rem 5 crocodiles
	CreateSprite(num+20,0)
	SetSpriteColor(num+20,128,128,128,255)
	SetSpriteSize(num+20,128,64)
	SetSpriteDepth(num+20,20)
	placeLogs(num)
next num	
//change colour of frog if eats fruit
changeColor=placeBonusFruit(500)
SetSpriteDepth(frogSpr,15)

time#=timer()
repeat 
until timer()-time#>1
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)	
bonusTime=timePerGame-timer()
while GetSpriteYByOffset(frogSpr)-35>0 and bonusTime >0
	bonusTime$="Time Left :"+str(bonusTime)
	SetTextString(1,bonusTime$)
	
	x#=GetSpriteX(frogspr):y#=GetSpriteY(frogSpr)
	if GetRawKeyState (KEY_Up)
		y#=y#-5
	endif
	if GetRawKeyState (KEY_Down)
		y#=y#+5
	endif
	if GetRawKeyState (KEY_Left)
		x#=x#-5
	endif
	if GetRawKeyState (KEY_Right)
		x#=x#+5
	endif
   	SetSpritePosition(frogSpr,x#,y#)
	if moveLogs(frogSpr)=0 and GetSpriteY(frogSpr)<yMax-80 
		if y#>40 
			x#=xMax/2:y#=yMax-40
			SetSpritePosition(frogSpr,x#,y#)
		endif	
	endif	
	if x#<-40 or x#>xMax 
		x#=xMax/2:y#=yMax-40
		SetSpritePosition(frogSpr,x#,y#)		
	endif
	
	If GetSpriteCollision(frogSpr,500)=1 and GetSpriteVisible(500)=1 
		changeFrogColor(frogSpr,changeColor)
		score=score+250
		myScore$="Score:"+str(score)
		SetTextString(3,myScore$)
		SetSpriteVisible(500,0)	
	endif 
	bonusTime=timePerGame-timer()
	sync()
endwhile  
if bonusTime>0 then score=score+(10*bonusTime)
endfunction score

function placeVehicles(num as integer)
//randomly place vehicles watching/repeating for collisions
rem y=105:y=210:y=395:y=495
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
SetSpritePositionByOffset(num+10,random2(xMax,xMax*2),395)
SetSpritePositionByOffset(num+15,random2(xMax,xMax*2),495)

for check= 1 to num
	while GetSpriteCollision(num,check)=1 and num <> check
		SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
		check=1
	endwhile
	while GetSpriteCollision(num+5,check+5)=1 and num <> check
		SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
		check=1
	endwhile
	while GetSpriteCollision(num+10,check+10)=1 and num <> check
		SetSpritePositionByOffset(num+10,random2(0,xMax*2),395)
		check=1
	endwhile
	while GetSpriteCollision(num+15,check+15)=1 and num <> check
		SetSpritePositionByOffset(num+15,random2(0,xMax*2),495)
		check=1
	endwhile
next check	
endfunction

function moveVehicles(frogSpr as integer)
collision=0
for num = 1 to 5
	SetSpritePositionByOffset(num,(GetSpriteXByOffset(num)+4),GetSpriteYByOffset(num))
	if GetSpriteXByOffset(num)>xMax*2 then SetSpritePositionByOffset(num,-xMax,GetSpriteYByOffset(num))
	if GetSpriteCollision( frogSpr, num ) then collision=1 
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+5,(GetSpriteXByOffset(num+5)+4),GetSpriteYByOffset(num+5))
	if GetSpriteXByOffset(num+5)>xMax*2 then SetSpritePositionByOffset(num+5,-xMax,GetSpriteYByOffset(num+5))
	if GetSpriteCollision( frogSpr, num+5 ) then collision=1
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+10,(GetSpriteXByOffset(num+10))-4,GetSpriteYByOffset(num+10))
	if GetSpriteXByOffset(num+10)<-xMax then SetSpritePositionByOffset(num+10,xMax*2,GetSpriteYByOffset(num+10))
	if GetSpriteCollision( frogSpr, num+10 ) then collision=1 
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+15,(GetSpriteXByOffset(num+15))-4,GetSpriteYByOffset(num+15))
	if GetSpriteXByOffset(num+15)<-xMax then SetSpritePositionByOffset(num+15,xMax*2,GetSpriteYByOffset(num+15))
	if GetSpriteCollision( frogSpr, num+15 ) then collision=1 
next num
endfunction collision

function moveLogs(frogSpr as integer)
collision=0	
for num = 1 to 5
	SetSpritePositionByOffset(num,(GetSpriteXByOffset(num)+4),GetSpriteYByOffset(num))
	if GetSpriteXByOffset(num)>xMax*2 then SetSpritePositionByOffset(num,-xMax,GetSpriteYByOffset(num))
	if GetSpriteCollision( frogSpr, num ) 
		SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+4,GetSpriteY(frogSpr)) 
		collision=1
	endif
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+5,(GetSpriteXByOffset(num+5)+4),GetSpriteYByOffset(num+5))
	if GetSpriteXByOffset(num+5)>xMax*2 then SetSpritePositionByOffset(num+5,-xMax,GetSpriteYByOffset(num+5))
	if GetSpriteCollision( frogSpr, num+5 ) 
		SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+4,GetSpriteY(frogSpr)) 
		collision=1
	endif
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+10,(GetSpriteXByOffset(num+10))-4,GetSpriteYByOffset(num+10))
	if GetSpriteXByOffset(num+10)<-xMax then SetSpritePositionByOffset(num+10,xMax*2,GetSpriteYByOffset(num+10))
	if GetSpriteCollision( frogSpr, num+10 ) 
		SetSpritePosition(frogSpr,GetSpriteX(frogSpr)-4,GetSpriteY(frogSpr)) 
		collision=1
	endif
next num
for num = 1 to 5
	SetSpritePositionByOffset(num+15,(GetSpriteXByOffset(num+15))-5,GetSpriteYByOffset(num+15))
	if GetSpriteXByOffset(num+15)<-xMax then SetSpritePositionByOffset(num+15,xMax*2,GetSpriteYByOffset(num+15))
	if GetSpriteCollision( frogSpr, num+15 ) 
		SetSpritePosition(frogSpr,GetSpriteX(frogSpr)-4,GetSpriteY(frogSpr)) 
		collision=1
	endif
next num
rem crocodiles
for num = 1 to 5
	SetSpritePositionByOffset(num+20,(GetSpriteXByOffset(num+20)+2),GetSpriteYByOffset(num+20))
	if GetSpriteXByOffset(num+20)>xMax*2 then SetSpritePositionByOffset(num+20,-xMax,GetSpriteYByOffset(num+20))
	if GetSpriteCollision( frogSpr, num+20 ) 
		SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+2,GetSpriteY(frogSpr)) 
		collision=1
	endif
next num
endfunction collision 

function createEllipse()
    Render()
    DrawEllipse(10,10,10,10,MakeColor(255,255,255),MakeColor(255,255,255),1)
    Swap()
    img = getimage(0,0,22,22)
    sync()
endfunction img

function placeBonusFruit(spr as integer)
If getSpriteExists(spr) then DeleteSprite(spr)	
CreateSprite(spr,createEllipse())
SetSpritePositionByOffset(spr,random(10,xMax-10),yMax/2)
SetSpriteDepth (spr,20)
ran=random (1,5)
select ran:
	case 1:
		SetSpriteColor(spr,113,161,25,255):rem green
	endcase
	case 2:
		SetSpriteColor(spr,92,92,255,255):rem blue
	endcase
	case 3:
		SetSpriteColor(spr,190,152,0,255):rem gold
	endcase
	case 4:
		SetSpriteColor(spr,168,35,168,255):rem Purple
	endcase
	case 5:
		SetSpriteColor(spr,246,125,0,255):rem Orange
	endcase
endselect
color=ran	
endfunction color	

function changeFrogColor(spr as integer,num)
select num:
	case 1:
		SetSpriteColor(spr,113,161,25,255):rem green
	endcase
	case 2:
		SetSpriteColor(spr,92,92,255,255):rem blue
	endcase
	case 3:
		SetSpriteColor(spr,190,152,0,255):rem gold
	endcase
	case 4:
		SetSpriteColor(spr,168,35,168,255):rem Purple
	endcase
	case 5:
		SetSpriteColor(spr,246,125,0,255):rem Orange
	endcase
endselect	
endfunction

function placeLogs(num as integer)
//randomly place logs crocs etc repeating for collisions
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
SetSpritePositionByOffset(num+10,random2(xMax,xMax*2),395)
SetSpritePositionByOffset(num+15,random2(xMax,xMax*2),495)
SetSpritePositionByOffset(num+20,random2(-xMax,xMax),302)
for check= 1 to num
	while GetSpriteCollision(num,check)=1 and num <> check
		SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
		check=1
	endwhile
	while GetSpriteCollision(num+5,check+5)=1 and num <> check
		SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
		check=1
	endwhile
	while GetSpriteCollision(num+10,check+10)=1 and num <> check
		SetSpritePositionByOffset(num+10,random2(0,xMax*2),395)
		check=1
	endwhile
	while GetSpriteCollision(num+15,check+15)=1 and num <> check
		SetSpritePositionByOffset(num+15,random2(0,xMax*2),495)
		check=1
	endwhile
	while GetSpriteCollision(num+20,check+20)=1 and num <> check
		SetSpritePositionByOffset(num+20,random2(-xMax,xMax),302)
		check=1
	endwhile
next check	
endfunction

function gameOver()
	SetTextVisible(1,0)
	time#=timer()
	repeat 
	until timer()-time#>1
	ClearScreen()
    repeat
		Print("Game Over click mouse to continue") 
		sync()
    until GetPointerPressed() = 1
    SetTextVisible(1,1)	
endfunction
Posted: 14th Apr 2018 20:33
I made a simple app to create the text file for tiles in a atlas image
simply input image size and tile size and it creates the text file because iam lazy...
https://www.thegamecreators.com/codebase/view/d49d244179286fbfbfa13f17f6f8df0a

the app text says it creates in media folder but is in your documents folder so you know..
Some error on the codebase page so it cant be updated?
Posted: 15th Apr 2018 3:18
Very amazing resource for us newbs!
Posted: 16th Apr 2018 2:03
Thanks Cliff Mellangard for sharing

Thanks Golelorn for your feed back

A Parabolic effect on a terrain mesh no media required
+ Code Snippet
// Project: Parabola
// Created: 2018-04-06

// show all errors
SetErrorMode(2)
#constant screenWidth=1024
#constant screenHeight=768
#constant mapX=1024
#constant mapY=50
#constant mapZ=512

  
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
SetScissor(0,0,0,0)
SetCameraRange( 1, 0.1, 900000 )
SetGlobal3DDepth(10000)


type _heights
	meshposition
	height
    PointX
    PointZ
endtype

rem for sine cosine calculations
#constant centreX=5
#constant yPosition=1
#constant amplitude=150
//#constant speedX#=.1251
#constant WaveWidth=10
#constant frequency#=15



global TerrainImageID
global TerrainObjectID

TerrainImageID=createtexture(32,32, makecolor(0,200,0),155)
Image1=createtexture(512,512, makecolor(200,200,200),5)
//Image1=createtexture(512,512, makecolor(200,200,200),255) //creates like a grass over terrain

saveImage(image1,"height.png")
DeleteImage(image1):rem DeleteObject(mem)
 
// create the terrain object from a height map
TerrainObjectID=CreateObjectFromHeightMap( "height.png", mapX,mapY, mapZ, 0, 0 )
//TerrainObjectID=CreateObjectBox(mapX,1,mapZ)

SetObjectCollisionMode( TerrainObjectID, 1 ) //On needed for object raycasting
SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
SetObjectTransparency(TerrainObjectID,0)
TerrainMemblock= CreateMemblockFromObjectMesh(TerrainObjectID,1)

rem num=mapX*126
maxIndices=GetMemblockInt(terrainMemblock,0)
maxX=(SQRT(maxIndices))
Dim heights[maxIndices] as _heights
meshposition=0:num=0:pointX=0:pointZ=0
for num = 0 to maxIndices //max vertices
        pointX=pointX+1
        if pointX>maxX 
			pointX=1
			pointZ=PointZ+1
		endif
        // add to array
        heights[num].height=1
        heights[num].meshposition=meshposition
		heights[num].PointX=pointX   
        heights[num].PointZ=pointZ    
        
        inc meshposition
next num



//setupArray()  
//SetCameraRange(1,1,2000 ) 
SetCameraPosition(1, 805, 378, -41)
  
steps = -1  
do
    checkCameraMovement()
      
    pointerState=GetRawMouseLeftState() 
	if GetRawMouseRightPressed()
		for i = 0 to maxIndices-1 //max vertices -1
			xWave#=Cos(heights[i].PointX)*(wavewidth/2)+centreX:xWave2#=Cos(heights[i].PointZ)*(wavewidth/2)+centreX
			yWave#=Sin(xWave#*frequency#)*(amplitude)+yposition:yWave2#=Sin(xWave2#*frequency#)*(amplitude)+yposition			
			SetMeshMemblockVertexPosition(TerrainMemblock,heights[i].meshposition,GetMeshMemblockVertexX(TerrainMemblock,i),GetMeshMemblockVertexY(TerrainMemblock,i)+(yWave#+ywave2#),GetMeshMemblockVertexZ(TerrainMemblock,i))
			rem used for the animation
			heights[i].pointX=heights[i].pointX+1
			if heights[i].pointX>maxX 
				heights[i].pointX=1
			endif
		next
		SetObjectMeshFromMemblock(TerrainObjectID,1,TerrainMemblock)         
	endif
    //endif
    // show some information
    Print( "FPS: " + str(ScreenFPS(),1) )
    Print( "Polygons: " + str(GetPolygonsDrawn()))
    print("vertices="+str(GetMemblockInt(terrainMemblock,0)))
    print("Arrows move camera")
    print("Click right mouse to apply sine curve")
    sync()
      
loop


function checkCameraMovement()
  
if GetRawKeyState(37) then MoveCameraLocalX(1,-5) //Left
if GetRawKeyState(39) then MoveCameraLocalX(1,5) //Right
if GetRawKeyState(38) then MoveCameraLocalZ(1,5) //Forward
if GetRawKeyState(40) then MoveCameraLocalZ(1,-5) //Backward
if GetRawKeyState(87) then MoveCameraLocalY(1,-5) //87 W
if GetRawKeyState(83) then MoveCameraLocalY(1,5) //87 S
if GetRawKeyState(65) then RotateCameraLocalY(1,1)
if GetRawKeyState(68) then RotateCameraLocalY(1,-1)
  
// if cameray#<(blocksizey*10) then cameray#=(blocksizey*10)
if GetRawKeyPressed(27) then end

endfunction
  
  

  
function resetTerrain (msblk as integer) 
  
    count = GetMemblockInt( msblk ,0 )
    for i = 0 to count  
        SetMeshMemblockVertexPosition(msblk,i,GetMeshMemblockVertexX(msblk,i),0,GetMeshMemblockVertexZ(msblk,i)) //make it flat
    next
    SetObjectMeshFromMemblock(TerrainObjectID,1,msblk)
Endfunction

// 102, 51, 0
// Function to create a texture
//
// Inputs - Sizex - size of the texture to create - width
//          Sizey - size of the texture to create - height
//          Color - is the main color of the image
//          Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
// 
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100,  makecolor(0,0,255), 100)
//          This could create a DEEP water effect texture?
    
function createtexture(sizex# as float, sizey# as float, color, density as integer)
    swap()
    drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
    render()
    img = getimage(0,0,sizex#, sizey#)
        
    memblockid = CreateMemblockFromImage (img)
    imgwidth = GetMemblockInt(memblockid, 0)
    imgheight = GetMemblockInt(memblockid, 4)
        
    size=GetMemblockSize(memblockid)
    for offset=12 to size-4 step 4
          
        r=GetMemblockByte(memblockid, offset)
        g=GetMemblockByte(memblockid, offset+1)
        b=GetMemblockByte(memblockid, offset+2)
        a=GetMemblockByte(memblockid, offset+3)
                
            
        strength=random(1,density)
    
        SetMemblockByte (memblockid, offset, r-strength)
        SetMemblockByte (memblockid, offset+1, g-strength)
        SetMemblockByte (memblockid, offset+2, b-strength )
        SetMemblockByte (memblockid, offset+3, a-strength)
    next
    deleteimage (img)
    img = CreateImageFromMemblock(memblockid)
    DeleteMemblock(memblockid)
endfunction img

https://forum.thegamecreators.com/thread/222010