Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Shockwave on May 11, 2006
-
Taken from the old board, original post by Shockwave.
A snippet of the beginning of an effect for you to abuse :)
;
; Landscape Fly-Over part.
;
; This cheats like hell but who gives a shit?
;
; Coded by Shockwave /DBF 2004.
;
;-------------------------------------------------------------------------------------------------------
Global xres = 640
Global yres = 480
Graphics xres,yres,0,1
SetBuffer BackBuffer()
Dim landgridx (900)
Dim landgridy (900)
Dim landgridz#(900)
Global landscalex = 45
Global landscaley = 2
Global landscroll#=0
Global heightoff=0
Global cccc=0
setlandgrid()
While Not KeyDown(1)
landscape()
Flip
Cls
Wend
Function landscape()
cccc=cccc+2
Local loopx
Local loopy
Local ltx1
Local lty1
Local mmm=1
;-------------------------------------------------------------------------------------------------------
; Flex the grid;
;-------------------------------------------------------------------------------------------------------
cvv=120*Sin(cccc)
For loopy = 1 To 30
For loopx = 1 To 30
cv1= (cvv*Sin(loopx+(loopy*40)+heightoff))
syv1 = -(180+cv1*Sin(loopx*30))
landgridy(mmm) = syv1
mmm=mmm+1
Next
Next
mmm=899
For loopy = 1 To 29
For loopx = 1 To 29
;-------------------------------------------------------------------------------------------------------
; Retrieve poly co-ordinates from grid.
;-------------------------------------------------------------------------------------------------------
ltx1 = (xres/2) + (landgridx(mmm) / (landgridz#(mmm)+landscroll#))
lty1 = (yres/2) + (landgridy(mmm) / (landgridz#(mmm)+landscroll#))
ltx2 = (xres/2) + (landgridx(mmm+1) / (landgridz#(mmm+1)+landscroll#))
lty2 = (yres/2) + (landgridy(mmm+1) / (landgridz#(mmm+1)+landscroll#))
ltx3 = (xres/2) + (landgridx(mmm+30) / (landgridz#(mmm+30)+landscroll#))
lty3 = (yres/2) + (landgridy(mmm+30) / (landgridz#(mmm+30)+landscroll#))
ltx4 = (xres/2) + (landgridx(mmm+31) / (landgridz#(mmm+31)+landscroll#))
lty4 = (yres/2) + (landgridy(mmm+31) / (landgridz#(mmm+31)+landscroll#))
colv= Abs(landgridz#(mmm)+2+landscroll)*40
Color colv,colv Shr 1,0
;-------------------------------------------------------------------------------------------------------
; Draw polygons (eliminating backfacing ones to boost speed)
;-------------------------------------------------------------------------------------------------------
If loopy<30 And loopy>20 Then
vx1= ltx1-ltx2
vy1= lty1-lty2
vx2= ltx3-ltx2
vy2= lty3-lty2
n= vx1*vy2-vx2*vy1
If n<0 Then
;-------------------------------------------------------------------------------------------------------
; poly # 1 =
;-------------------------------------------------------------------------------------------------------
Line ltx1,lty1,ltx2,lty2
Line ltx2,lty2,ltx3,lty3
Line ltx3,lty3,ltx1,lty1
End If
vx1= ltx3-ltx2
vy1= lty3-lty2
vx2= ltx3-ltx4
vy2= lty3-lty4
n= vx1*vy2-vx2*vy1
If n>0 Then
;-------------------------------------------------------------------------------------------------------
; poly 2
;-------------------------------------------------------------------------------------------------------
Line ltx2,lty2,ltx3,lty3
Line ltx3,lty3,ltx4,lty4
Line ltx4,lty4,ltx2,lty2
End If
End If
mmm=mmm-1
Next
mmm=mmm-1
Next
;-------------------------------------------------------------------------------------------------------
; Scroll the grid.
;-------------------------------------------------------------------------------------------------------
landscroll#=landscroll#+.01
If landscroll#>.2 Then
landscroll = landscroll-.2
heightoff=heightoff+40
End If
End Function
Function setlandgrid()
Local landxpos#
Local landzpos#
Local loopx
Local loopy
Local mmm=1
;-------------------------------------------------------------------------------------------------------
; Generate Grid;
;-------------------------------------------------------------------------------------------------------
landzpos#=0
For loopy = 1 To 30
landxpos=-15.5
For loopx = 1 To 30
sf=36*Sin(landzpos*120)
landypos = -40
landgridx (mmm) = (landxpos * landscalex)
landgridz#(mmm) = landzpos#
landxpos=landxpos+1
mmm=mmm+1
Next
landzpos=landzpos#-.2
Next
End Function