Rem ***** Main Source File *****
REM F08, mindesign entertainment

Rem ***** Includes *****
#Include "Includes/builder.dba"
Rem ********************

Rem ***** ***** Inicializls ***** *****
Rem Autocam off
Hide Mouse
Sync On : Sync Rate 60
Rem ***** ***** ***** ***** ***** *****

Rem ///// ///// Globlis vltozk

  Rem TPS Sugr
  Global TPS_R As Float : TPS_R=30

  Rem Karakter
  Global Karakter As Integer : Karakter=FreeObject()

  Rem Alapok
  Global Alap As Integer : Alap=FreeObject()+100

  Rem Ugrs vltozk
  Global MaxY# as Float : MaxY#=5.0
  Global SzintY# as Float : SzintY#=MaxY#-0.3
  Global DeltaY# as Float : DeltaY#=0.1
  Global Jump as Boolean : Jump=0
  Global yPuffer# as Float
  Global Mozgas$ : Mozgas$="elore"

  Rem Builder
  DIM map(1000,1000) as byte
  Global done as boolean


Rem Globlis vltozk \\\\\ \\\\\


Rem Debug Matrix
Make matrix 1,100,100,25,25

Rem TPS Kamera
Global Self As Integer : Self=1
Make object cube Self,10 : Hide object Self

Rem Karakter Betltse
Make object box Karakter, 5,10,5

Rem Alapok betlse
Make object box Alap,15,5,15
Hide object Alap

Rem Plya betltse
Build_Map(20)


Rem Main Loop
Do

 Rem Alprogramok meghvsa
 Gosub Control_Karakter
 Gosub Control_Camera
 Gosub Debug

 Rem Kperny frissts
 Sync
Loop

Rem Kamera kezel alprogram
Control_Camera:

 Rem Egr
 Rotate object Self, Object Angle X(Self)+MouseMoveY(),Object Angle Y(Self)+MouseMoveX(),0

 Rem Debug
 If Object Angle X(Self)<10 then xRotate Object Self,10
 If Object Angle X(Self)>50 then xRotate Object Self,50
 If Object Angle Y(Self)>360 then yRotate Object Self,0
 If Object Angle Y(Self)<0 then yRotate Object Self,360

 Rem Asszimillds
 Position camera Object Position X(Self),Object Position Y(Self)+yPuffer#,Object Position z(Self)
 Rotate camera Object Angle X(Self),Object Angle Y(Self),Object Angle Z(Self)

 Rem Sugr
 Move camera TPS_R*(-1)

Return

Rem Karakter kezel alprogram
Control_Karakter:

Rem Karakter mozgatsa
If not jump

 Mozgas$=""

 If keystate(17)
  Move object Karakter,0.5
  Position Object Self, Object Position X(Karakter),Object Position Y(Self),Object Position Z(Karakter)
  If not jump then Mozgas$="elore"
 Endif

 If keystate(31)
  Move object Karakter,-0.5
  Position Object Self, Object Position X(Karakter),Object Position Y(Self),Object Position Z(Karakter)
  If not jump then Mozgas$="hatra"
 Endif

 If keystate(32)
  yRotate object Karakter,Object Angle Y(Karakter)+90
  Move object Karakter,0.5
  yRotate object Karakter,Object Angle Y(Karakter)-90
  Position Object Self, Object Position X(Karakter),Object Position Y(Self),Object Position Z(Karakter)
  If not jump then Mozgas$="jobbra"
 Endif

 If keystate(30)
  yRotate object Karakter,Object Angle Y(Karakter)-90
  Move object Karakter,0.5
  yRotate object Karakter,Object Angle Y(Karakter)+90
  Position Object Self, Object Position X(Karakter),Object Position Y(Self),Object Position Z(Karakter)
  If not jump then Mozgas$="balra"
 Endif

 Rem Srg
 If keystate(17) and keystate(32) then Mozgas$="jobbfel"
  If keystate(17) and keystate(30) then Mozgas$="balfel"

 If keystate(31)
  If keystate(32) then Mozgas$="jobble"
  If keystate(30) then Mozgas$="balle"
 Endif

 Rem Mozgs vge
 Endif

 Rem Ugrs
 If spacekey() then Jump=1
 If Jump
 If Mozgas$="elore" then Move object Self,0.5
 If Mozgas$="hatra" then Move object Self,-0.5

 If Mozgas$="balra"
  yRotate object Self,Object Angle Y(Self)-90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)+90
 Endif

 If Mozgas$="jobbra"
  yRotate object Self,Object Angle Y(Self)+90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)-90
 Endif

 If mozgas$="balfel"
  Rem Fel
  Move object Self,0.5

  Rem Balra
  yRotate object Self,Object Angle Y(Self)-90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)+90
 Endif


 If mozgas$="jobbfel"
  Rem Fel
  Move object Self,0.5

  Rem Jobbra
  yRotate object Self,Object Angle Y(Self)+90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)-90
 Endif

  If mozgas$="jobble"
  Rem Fel
  Move object Self,-0.5

  Rem Jobbra
  yRotate object Self,Object Angle Y(Self)+90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)-90
 Endif

  If mozgas$="balle"
  Rem Fel
  Move object Self,-0.5

  Rem Balra
  yRotate object Self,Object Angle Y(Self)-90
  Move object Self,0.5
  yRotate object Self,Object Angle Y(Self)+90
 Endif

   yPuffer#=(yPuffer#+(MaxY#-yPuffer#)*DeltaY#)
   If yPuffer#>=SzintY# and DeltaY#>0 then DeltaY#=(-1)*DeltaY#
   If yPuffer#<=0.005 and DeltaY#<0
     Jump=0
     DeltaY#=DeltaY#*(-1)
     yPuffer#=0
   Endif

 Endif


 Rem Karakter szink
 Position Object Karakter, Object Position X(Self),yPuffer#,Object Position Z(Self)
 Position Object Self, Object Position X(Self),0,Object Position Z(Self)
 yRotate Object Karakter, Object Angle Y(Self)

Return


Rem Debug
Debug:
 Set Cursor 1,1
 Print "xAngle: ",Object Angle X(Self)
 Print "yAngle: ",Object Angle Y(Self)
 Print "FPS: ",Screen FPS()
 Print Jump
 Print "Y ",yPuffer#
 Print "DeltaY ",DeltaY#
 Print Object Position Y(Self)
 Print Mozgas$
Return



Rem ********** Fggvnyek **********

Rem BuildMap
Function Build_Map(elemszam as integer)
  Randomize timer()
  done=0
  map(50,50)=1
  map(49,50)=1
  kirak(49,50,2,elemszam)

  For n=1 to 1000
   For m=1 to 1000
    If map(n,m)>0
     temp=FreeObject()
     Clone object temp,Alap
     Position object temp,m*17,0,n*17
    Endif
   Next m
  Next n
Endfunction

Rem FreeObject
Function FreeObject()
 I=1
 Repeat
 I=I+1
 Until Object Exist(I)=0
Endfunction I

Rem ********************************