set display mode 1280, 1024, 32
sync on
sync rate 0
hide mouse
backdrop on
color backdrop 0
randomize timer()
autocam off
`predefined colors
white as DWORD: white = rgb(255,255,255)
black as DWORD: black = rgb(0,0,0)
border as DWORD: border = rgba(255,255,255,96)
jump  as DWORD: jump  = rgba(255,0,0, 96)
`shadow as DWORD: shadow = rgba(0,0,0,96)
 
 
#constant GridSize 5
Type GridCell
   rate#
   col as DWORD
   r
   g
   b
   a#
EndType
 
Dim Grid(GridSize, GridSize) as GridCell
 
make memblock 1, 12 + (GridSize * GridSize * 4)
write memblock dword 1, 0, GridSize
write memblock dword 1, 4, GridSize
write memblock dword 1, 8, 32
 
for y=0 to GridSize-1
   for x=0 to GridSize-1
      InitializeCell(x,y)
   next x
next y
generateTexture()
 
make object plain 1, GridSize, GridSize
position object 1, 0, 0, 0
point object 1, 0, 1, 0
texture object 1, 1
set object transparency 1, 3
set object filter 1, 0
scale object 1, (15.0/GridSize)*100.0, (15.0/GridSize)*100.0, 100.0
TileSize# = object size x(1) / GridSize
 
 
 
`Underlayer
make object cube 2, TileSize#
make mesh from object 1, 2
n=1
for y = 0 to GridSize-1
   for x = 0 to GridSize-1
      if x > 0 OR y > 0
         add limb 2, n, 1
         offset limb 2, n, x*TileSize#, 0.0, y*TileSize#
         inc n
      endif
   next x
next y
position object 2, -TileSize#*2, -TileSize#, -TileSize#*2
set object transparency 2, 3
make memblock 2, 16
write memblock dword 2, 0, 1
write memblock dword 2, 4, 1
write memblock dword 2, 8, 32
write memblock dword 2, 12, rgba(255,255,255,8)
make image from memblock 2,2
delete memblock 2
texture object 2, 2
 
 
 
 
 
`player stuff
type PlayerData
   x#
   y#
   z#
   sX#
   sY#
   sZ#
   jumpPower#
endtype
make object sphere 3, TileSize#*0.25, 24, 24
 
P as PlayerData
P.x# = 0.0
P.y# = TileSize#*0.125
P.z# = 0.0
P.x# = 0.0
P.y# = 0.0
P.sZ# = 0.0
P.jumpPower# = 0.0
#constant maxJump 40
make memblock 2, 12 + (4 * (maxJump+3) * 6)
write memblock dword 2, 0, 6
write memblock dword 2, 4, maxJump+3
write memblock dword 2, 8, 32
 
 
`Make shadow
#constant shadowRes 63
make memblock 3, 12 + (shadowRes * shadowRes * 4)
write memblock dword 3, 0, shadowRes
write memblock dword 3, 4, shadowRes
write memblock dword 3, 8, 32
center# = (shadowRes*0.50)
a as dword
for y=0 to shadowRes-1
   for x = 0 to shadowRes-1
      a# = sqrt(((center#-y)*(center#-y)) + ((center#-x)*(center#-x)))
      a# = a# / sqrt((shadowRes*shadowRes)* 0.25)
      a = 192-(a#*192)
      if a < 0 then a = 0 else if a > 255 then a = 255
      write memblock dword 3, 12 + ((x + (y*shadowRes))*4), rgba(0,0,0,a)
   next x
next y
 
make image from memblock 4, 3
delete memblock 3
make object plain 4, TileSize#*0.25, TileSize#*0.25
position object 4, 0.0, 0.000, 0.0
xrotate object 4, 90
texture object 4, 4
set object transparency 4,3
set object light 4,0
 
 
 
 
 
 
 
 
 
 
position camera 0, 20, 0
point camera 0,0,0
global frameTime# = 1.0
startTime = timer()
do
   frameTime# = (frameTime# * 0.8) + ((timer() - startTime) * 0.2)
   startTime = timer()
 
   text 10, 10, "FPS: " + str$(screen fps())
   text 10, 30, "ts = " + str$(TileSize#)
 
   `Controls
   if P.y# > TileSize#*0.125
      if keystate(200)
         `up
         inc P.sZ#, frameTime# * 0.01
      endif
      if keystate(208)
         `down
         dec P.sZ#, frameTime# * 0.01
      endif
      if keystate(205)
         `right
         inc P.sX#, frameTime# * 0.01
      endif
      if keystate(203)
         `left
         dec P.sX#, frameTime# * 0.01
      endif
   endif
 
   P.sX# = curvevalue(0.0, P.sX#, 500.0/ frameTime#)
   inc P.sY#, frameTime# * -0.05
   P.sZ# = curvevalue(0.0, P.sZ#, 500.0/ frameTime#)
 
 
   inc P.x#, P.sX# * frameTime# * 0.001
   inc P.y#, P.sY# * frameTime# * 0.001
   inc P.z#, P.sZ# * frameTime# * 0.001
   position object 3, P.x#, P.y#, P.z#
   position object 4, P.x#, 0.1, P.z#
 
   if P.y# <= TileSize#*0.125 AND P.sY# < 0.0 then P.sY# = 0.0
 
   if P.y# <= TileSize#*0.125 AND keystate(57)
      gosub MakeJumpBar
   else
      if P.jumpPower# > 0.0
         P.sY# = P.jumpPower#+20.0
         P.jumpPower# = 0.0
      endif
   endif
 
 
 
   `Underlayer
   for i = 0 to n-1
      if i mod 2 = 0
         rotate limb 2, i, limb angle x(2,i) + frameTime#*0.090, 0, 0
      else
         rotate limb 2, i, 0, 0, limb angle z(2,i) + frameTime#*0.090
      endif
   next i
 
   `Upper layer
   generateTexture()
   sync
loop
end
 
 
 
 
MakeJumpBar:
   inc P.jumpPower#, frameTime# * 0.02
   if P.jumpPower# > maxJump then P.jumpPower# = maxJump
   jX# = object screen x(3) + 20.0
   jY# = object screen y(3) - maxJump
 
   c as dword
   for x = 0 to 5
      write memblock dword 2, 12 + (x*4), border
   next x
   for y = 0 to maxJump
      if y <= P.jumpPower# then c = jump else c = 0
      y2 = maxJump-y+1
      write memblock dword 2, 12 + (0 + ((maxJump-y)*6))*4, border
      for x = 1 to 4
         write memblock dword 2, 12 + (x + (y2*6))*4, c
      next x
      write memblock dword 2, 12 + (5 + ((maxJump-y)*6))*4, border
   next y
   for x = 0 to 5
      write memblock dword 2, 12 + (x + ((maxJump+1)*6))*4, border
   next x
   make image from memblock 3, 2
   paste image 3, jX#, jY#, 1
return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
function generateTexture()
   for y=0 to GridSize-1
      for x=0 to GridSize-1
         inc Grid(x,y).a#, frameTime# * 0.01 * Grid(x,y).rate#
         if Grid(x,y).a# > 255.0 then InitializeCell(x, y)
         if Grid(x,y).a# < 32.0 then a# = 0.0 else a# = Grid(x,y).a#
         write memblock dword 1, 12 + (x + (y*GridSize))*4, rgba(Grid(x,y).r, Grid(x,y).g, Grid(x,y).b, a#)
      next x
   next y
   make image from memblock 1, 1
endfunction
 
 
 
 
 
 
 
 
function InitializeCell(x, y)
   Grid(x,y).rate# = 0.5 + (rnd(100) * 0.001) :`Gives range of 0.5-1.5
   Grid(x,y).a# = 0.0
   Grid(x,y).r = 191 + rnd(64)
   Grid(x,y).g = 191 + rnd(64)
   Grid(x,y).b = 191 + rnd(64)
endfunction
 
 
 
 
 
 
 
function rgba(r as integer,g as integer,b as integer,a as integer)
  colour as dword
  colour = (b)+(g*256)+(r*65536)+(a*16777216)
endfunction colour