Quote: "Cliff ! You Rocks! i was waiting for a simpler usage and now it's cool "
Thanks
I have uplopaded the project in an zipped file and the code is here also!
rem
rem AGK Application
rem
rem Landscape App
//setorientationallowed(1,0,1,0)
setsyncrate(0,0)
REM // original snes mostly used 256x224
#Constant ScrWidth 320
#Constant ScrHeight 240
SetVirtualResolution( ScrWidth, ScrHeight )
global Kart_Sprite,Render_Detail,Debugging
REM // Prepare our kart
Kart_Image = LoadImage("kart.png")
Kart_Speed#=120.0
Kart_Turn_Speed#=120.0
SetImageMagFilter( Kart_Image, 0 )
SetImageMinFilter( Kart_Image, 0 )
Kart_Sprite = CreateSprite(Kart_Image)
fixspritetoscreen(Kart_Sprite,1)
setspritesize(Kart_Sprite,64,64)
SetSpriteAnimation( Kart_Sprite, 32, 32, 4 )
SetSpritePosition(Kart_Sprite, ( ScrWidth/2 )-32, ScrHeight-64)
REM // test
test_Image = LoadImage("sign.png")
SetImageMagFilter( test_Image, 0 )
SetImageMinFilter( test_Image, 0 )
global test_sprite
test_Sprite = CreateSprite(test_Image)
SetSpriteOffset( test_Sprite, 32 , 64 )
global TestX#=0.0
global TestY#=0.0
REM // background
back_Image = LoadImage("back.png")
SetImageMagFilter( back_Image, 0 )
SetImageMinFilter( back_Image, 0 )
global back_sprite
back_Sprite = CreateSprite(back_Image)
setspritesize(back_Sprite,ScrWidth,ScrHeight)
fixspritetoscreen(back_Sprite,1)
setspritedepth(back_Sprite,1000)
` configure for tiling
SetImageWrapU(back_Image,1)
SetImageWrapV(back_Image,1)
type sVRcamera
X As Float
Y As Float
Tilt As Integer
Angle As Float
Ground As integer
endtype
Global VRcamera As sVRcamera
VRcamera.X = ScreenToWorldX( ScrWidth/2 )
VRcamera.Y = ScreenToWorldY( ScrHeight )
REM // This is the default angle and points to the right side of the screen
REM // The same as agks default sprite angle.
VRcamera.Angle = 0.0
REM // Default is 56
VRcamera.Tilt = 52
REM // Prepare the track sprite for the virtual camera
REM // Use an image in the size 1024x1024
img = LoadImage("Mario_Circuit_1.png") : SetImageMagFilter( img, 0 ) : SetImageMinFilter( img, 0 )
VRcamera.Ground = CreateSprite(img) : SetSpritePosition(VRcamera.Ground, 0, 0) : SetSpriteAngle(VRcamera.Ground, -90)
REM // Set transparency off only for final build for best performance
SetSpriteTransparency( VRcamera.Ground , 0 ) : SetSpriteActive ( VRcamera.Ground, 0 ) : setspritedepth(VRcamera.Ground,100)
X#=0
Y#=0
REM // Setup the start screen with the player in the top left corner of the track
Move_VRcamera(X#,Y#)
global GFT#
do
GFT# = GetFrameTime()
//scroll the world
if GetDirectionY() <-0.02
X#=X# + (cos(VRcamera.Angle) * (Kart_Speed#*GFT#))
Y#=Y# + (sin(VRcamera.Angle) * (Kart_Speed#*GFT#))
endif
if GetDirectionY() >0.02
X#=X# - (cos(VRcamera.Angle) * (Kart_Speed#*GFT#))
Y#=Y# - (sin(VRcamera.Angle) * (Kart_Speed#*GFT#))
endif
setspriteframe(Kart_Sprite,1)
//rotate the map
if GetDirectionX() <-0.02
SetSpriteAngle(VRcamera.Ground, GetSpriteAngle(VRcamera.Ground) + (Kart_Turn_Speed#*GFT#))
moveu#=moveu#-((Kart_Turn_Speed#*GFT#)/100)
if moveu#<0.0 then moveu#=moveu#+1.0
SetSpriteUVOffset(back_Sprite,moveu#,movev#)
VRcamera.Angle = VRcamera.Angle - (Kart_Turn_Speed#*GFT#)
setspriteframe(Kart_Sprite,3)
endif
if GetDirectionX() >0.02
SetSpriteAngle(VRcamera.Ground, GetSpriteAngle(VRcamera.Ground) - (Kart_Turn_Speed#*GFT#))
moveu#=moveu#+((Kart_Turn_Speed#*GFT#)/100)
if moveu#>1.0 then moveu#=moveu#-1.0
SetSpriteUVOffset(back_Sprite,moveu#,movev#)
VRcamera.Angle = VRcamera.Angle + (Kart_Turn_Speed#*GFT#)
setspriteframe(Kart_Sprite,2)
endif
Move_VRcamera(X#,Y#)
print(TestX#)
print(TestY#)
if TestX#>1024.0 and TestY#>1024.0 then switch=1
if TestX#<0.0 and TestY#<0.0 then switch=0
if switch=0
TestX#=TestX# + (cos(45) * (60.0*GFT#))
TestY#=TestY# + (sin(45) * (60.0*GFT#))
else
TestX#=TestX# - (cos(45) * (60.0*GFT#))
TestY#=TestY# - (sin(45) * (60.0*GFT#))
endif
REM // Call the track renderer
Setspritevisible(VRcamera.Ground,1)
if Render_Detail =0
High_Render()
else
Low_Render()
endif
if Debugging=0 then Setspritevisible(VRcamera.Ground,0)
//Setspritevisible(test_sprite,0)
print("Detail Track sprite " )
print("Fps = "+str( Screenfps() ) )
//print("screen to world/x = "+str( ScreenToWorldX( ScrWidth/2 ) ) + " y = "+str( ScreenToWorldY( 240 ) ))
//print("view offset/x = "+str( GetViewOffsetX() ) + " y = "+str( GetViewOffsety() ))
REM // Grabb the whole screen so we get the kart and all the text
SetScissor(0, ScrHeight, ScrWidth,0)
// escape on computer and back button on device
if GetRawKeyState(27)=1 then end
REM // various debugging buttons
if GetPointerPressed()
if GetPointerX()<32 and GetPointerY()<32 then inc Render_Detail
if GetPointerX()>ScrWidth-32 and GetPointerY()<32 then inc Debugging
if Render_Detail>1 then Render_Detail=0
if Debugging>1 then Debugging=0
endif
Sync()
loop
REM // Virtual camera functions
Function Move_VRcamera( X# , Y# )
SetViewOffset( X# - ScrWidth/2 , Y# - ScrHeight )
VRcamera.X = ScreenToWorldX( ScrWidth/2 )
VRcamera.Y = ScreenToWorldY( ScrHeight )
SetSpriteOffset( VRcamera.Ground, VRcamera.X , VRcamera.Y )
SetSpritepositionbyOffset( VRcamera.Ground, VRcamera.X , VRcamera.Y )
endfunction
Function High_Render()
scalus=1024*8
itsdone=0
setspritevisible(test_sprite,1)
SetSpritepositionbyOffset( test_sprite, Get_Ground_X(TestX#,TestY#) , Get_Ground_Y(TestX#,TestY#) )
dist=(64.0/GetDistance( 0.0 , VRcamera.Y , 0.0 , getspriteybyoffset(test_sprite) )*32.0)
if dist>64 then dist=64
if dist<6 then setspritevisible(test_sprite,0)
for i = ScrHeight to 90 step -1
setSpritesize(VRcamera.Ground,scalus,scalus)
if itsdone=0
SetSpritepositionbyOffset( test_sprite, Get_Ground_X(TestX#,TestY#) , Get_Ground_Y(TestX#,TestY#) )
ys=worldtoscreeny(getspriteybyoffset(test_sprite))
if ys>i
for t=1 to VRcamera.Tilt
setSpritesize(VRcamera.Ground,scalus+t,scalus+t)
SetSpritepositionbyOffset( test_sprite, Get_Ground_X(TestX#,TestY#) , Get_Ground_Y(TestX#,TestY#) )
ys=worldtoscreeny(getspriteybyoffset(test_sprite))
if ys=i then exit
next t
itsdone=1
setSpritesize(test_sprite,dist,dist)
setSpritesize(VRcamera.Ground,scalus,scalus)
endif
endif
SetScissor(0, i, ScrWidth, i + 1)
DrawSprite(VRcamera.Ground)
scalus=scalus-VRcamera.Tilt
next i
scalus=1024
setSpritesize(VRcamera.Ground,scalus,scalus)
endfunction
Function Low_Render()
scalus=1024*8
SetSpritepositionbyOffset( VRcamera.Ground, ScreenToWorldX( ScrWidth/2 ) , ScreenToWorldY( ScrHeight ) )
for i = ScrHeight to 100 step -2
setSpritesize(VRcamera.Ground,scalus,scalus)
SetScissor(0, i, ScrWidth, i + 2)
DrawSprite(VRcamera.Ground)
scalus=scalus-(VRcamera.Tilt*2)
next i
scalus=1024
setSpritesize(VRcamera.Ground,scalus,scalus)
endfunction
function WrapRotate(a#,v#)
a# = a# + v#
a# = a# - (floor(a#/360) * 360)
endfunction a#
function Point_TO(x#,y#,x2#,y2#)
new_angle# = atanfull(x2#-x#,y2#-y#)
new_angle# = new_angle# - (floor(new_angle#/360) * 360)
endfunction new_angle#
Function GetDistance( x#, y#, x2#, y2#)
d# = sqrt( ((x# - x2#)^2) + ((y# - y2#)^2) )
Endfunction d#
REM // Based on steven holdings (baxslash) spritetoworld functions
function Get_Ground_X(x#,y#)
x#= - VRcamera.X + x#
y#= - VRcamera.Y + y#
rem get sprite data
a# = getSpriteAngle(VRcamera.Ground)
ox# = getSpriteXbyOffset(VRcamera.Ground)
scaleX# = getSpriteWidth(VRcamera.Ground)/1024
scaleY# = getSpriteHeight(VRcamera.Ground)/1024
REM // calculate value
dx# = ( cos(a#)*(x# * scaleX#) ) - ( sin(a#)*(y# * scaleY#) )
wx# = ox# + dx#
endfunction wx#
function Get_Ground_Y(x#,y#)
x#= - VRcamera.X + x#
y#= - VRcamera.Y + y#
rem get sprite data
a# = getSpriteAngle(VRcamera.Ground)
oy# = getSpriteYbyOffset(VRcamera.Ground)
scaleX# = getSpriteWidth(VRcamera.Ground)/1024
scaleY# = getSpriteHeight(VRcamera.Ground)/1024
rem calculate value
dy# = ( sin(a#)*(x# * scaleX#) ) + ( cos(a#)*(y# * scaleY#) )
wy# = oy# + dy#
endfunction wy#
REM *** spriteToWorldX by Steven Holding (baxslash)
REM *** NOTES
REM *** Two functions to get a world co-ordinate based on a point on a sprite
REM *** relative to it's centre of rotation (offset)
REM *** In a percentage based game this is done by percentage of the size of the
REM *** sprite, in a pixel based game this is done in pixels on the original image
function spriteToWorldX(spr,x#,y#)
rem get sprite data
a# = getSpriteAngle(spr)
ox# = getSpriteXbyOffset(spr)
rem get display data
dw# = getVirtualWidth()
dh# = getVirtualHeight()
aspect# = (dw# / dh#)
if aspect# = 1.0
scaleX# = getSpriteWidth(spr)/100.0
aspect# = getDisplayAspect()
scaleY# = scaleX# * aspect#
else
aspect# = 1.0
i = getSpriteImageID(spr)
scaleX# = getSpriteWidth(spr)/getImageWidth(i)
scaleY# = getSpriteHeight(spr)/getImageHeight(i)
endif
rem calculate value
dx# = cos(a#) * (x# * scaleX#) - sin(a#) * (y# * scaleY#)
wx# = ox# + dx#
endfunction wx#
function spriteToWorldY(spr,x#,y#)
rem get sprite data
a# = getSpriteAngle(spr)
oy# = getSpriteYbyOffset(spr)
rem get display data
dw# = getVirtualWidth()
dh# = getVirtualHeight()
aspect# = (dw# / dh#)
if aspect# = 1.0
scaleX# = getSpriteWidth(spr)/100.0
aspect# = getDisplayAspect()
scaleY# = scaleX# * aspect#
else
aspect# = 1.0
i = getSpriteImageID(spr)
scaleX# = getSpriteWidth(spr)/getImageWidth(i)
scaleY# = getSpriteHeight(spr)/getImageHeight(i)
endif
rem calculate value
dy# = sin(a#) * (x# * scaleX#) + cos(a#) * (y# * scaleY#)
wy# = oy# + dy# * aspect#
endfunction wy#
If anyone wants to fool around with it.
I also added scrolling background.
And please only use the track image for testing purposes.
This is a
beta release!