Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Shockwave on May 11, 2006
-
Original post by Shockwave, taken from the old board.
Fast Deforming landscape;
;
; Coded by Shockwave /DBF 2004.
;
;-------------------------------------------------------------------------------------------------------
Global xres = 640
Global yres = 480
Global masterfade = 100
Global effecttimer = 0
Graphics xres,yres,0,1
SetBuffer BackBuffer()
;
; Set up Land grid;
;
Dim land_grid_x (990)
Dim land_grid_y (990)
Dim land_grid_z#(990)
Global land_scale_x = 40
Global land_scrolling_offset#=0
Global land_height_sine_offset=0
Global deformation_offset=0
Global land_chequers
setlandgrid()
Global land_image_buffer = CreateImage(xres,100,1)
While Not KeyDown(1)
landscape()
Flip
Cls
Wend
Function landscape()
effecttimer=effecttimer+1
If effecttimer>100 And effecttimer<355 Then
masterfade = masterfade+1
End If
If effecttimer>1000 Then
masterfade = masterfade-1
End If
If effecttimer>=1250 Then
effect=effect+1
effecttimer=0
End If
LockBuffer BackBuffer()
deformation_offset=deformation_offset+3
Local loopx
Local loopy
Local land_tralansform_x1
Local land_tralansform_y1
Local land_drawing_offset=1
;-------------------------------------------------------------------------------------------------------
; Flex the grid;
;-------------------------------------------------------------------------------------------------------
cvv=22*Sin(deformation_offset)
For loopy = 1 To 30
For loopx = 1 To 30
cv1= (cvv*Sin(loopx+(loopy*40)+land_height_sine_offset))
syv1 = -40-(cv1*Sin(loopx*30))
land_grid_y(land_drawing_offset) = syv1
land_drawing_offset=land_drawing_offset+1
Next
Next
land_drawing_offset=899
land_chequerss=land_chequers
For loopy = 1 To 29
For loopx = 1 To 29
;-------------------------------------------------------------------------------------------------------
; Retrieve poly co-ordilanates from grid.
;-------------------------------------------------------------------------------------------------------
land_tralansform_x1 = (xres/2) + (land_grid_x(land_drawing_offset) / (land_grid_z#(land_drawing_offset)+land_scrolling_offset#))
land_tralansform_y1 = (180+(yres/2) + (land_grid_y(land_drawing_offset) / (land_grid_z#(land_drawing_offset)+land_scrolling_offset#)))
land_tralansform_x2 = (xres/2) + (land_grid_x(land_drawing_offset+1) / (land_grid_z#(land_drawing_offset+1)+land_scrolling_offset#))
land_tralansform_y2 = (180+(yres/2) + (land_grid_y(land_drawing_offset+1) / (land_grid_z#(land_drawing_offset+1)+land_scrolling_offset#)))
land_tralansform_x3 = (xres/2) + (land_grid_x(land_drawing_offset+30) / (land_grid_z#(land_drawing_offset+30)+land_scrolling_offset#))
land_tralansform_y3 = (180+(yres/2) + (land_grid_y(land_drawing_offset+30) / (land_grid_z#(land_drawing_offset+30)+land_scrolling_offset#)))
land_tralansform_x4 = (xres/2) + (land_grid_x(land_drawing_offset+31) / (land_grid_z#(land_drawing_offset+31)+land_scrolling_offset#))
land_tralansform_y4 = (180+(yres/2) + (land_grid_y(land_drawing_offset+31) / (land_grid_z#(land_drawing_offset+31)+land_scrolling_offset#)))
If land_chequerss = 1 colv= Abs(land_grid_z#(land_drawing_offset)+2+landscroll)*20
If land_chequerss = 2 colv= Abs(land_grid_z#(land_drawing_offset)+2+landscroll)*40
If colv>masterfade colv=masterfade
land_colour=(((colv Shl 8)+0) Shl 8) + 0
If land_tralansform_y3=land_tralansform_y4 land_tralansform_y4 = land_tralansform_y4+1
If land_tralansform_y1=land_tralansform_y2 land_tralansform_y2 = land_tralansform_y2+1
;-------------------------------------------------------------------------------------------------------
; Draw polygolans (elimilanatilang backfacilang ones to boost speed)
;-------------------------------------------------------------------------------------------------------
If (loopx>4 And loopx<25) And (loopy<29 And loopy>19) Then
land_vx1= land_tralansform_x1-land_tralansform_x2
land_vy1= land_tralansform_y1-land_tralansform_y2
land_vx2= land_tralansform_x3-land_tralansform_x2
land_vy2= land_tralansform_y3-land_tralansform_y2
lan= land_vx1*land_vy2-land_vx2*land_vy1
If lan<0 Then
;
;-------------------------------------------------------------------------------------------------------
; poly # 1 =
;-------------------------------------------------------------------------------------------------------
If (land_tralansform_x1>0 And land_tralansform_x1<xres-1) Or (land_tralansform_x2>0 And land_tralansform_x2<xres-1) Or (land_tralansform_x3>0 And land_tralansform_x3<xres-1) Then
If (land_tralansform_y1>0 And land_tralansform_y1<yres-1) Or (land_tralansform_y2>0 And land_tralansform_y2<yres-1) Or (land_tralansform_y3>0 And land_tralansform_y3<yres-1) Then
flat_shaded_trialangle(land_tralansform_x1,land_tralansform_y1,land_tralansform_x2,land_tralansform_y2,land_tralansform_x3,land_tralansform_y3,land_colour)
End If
End If
End If
land_vx1= land_tralansform_x3-land_tralansform_x2
land_vy1= land_tralansform_y3-land_tralansform_y2
land_vx2= land_tralansform_x3-land_tralansform_x4
land_vy2= land_tralansform_y3-land_tralansform_y4
lan= land_vx1*land_vy2-land_vx2*land_vy1
If lan>0 Then
;-------------------------------------------------------------------------------------------------------
; poly 2
;-------------------------------------------------------------------------------------------------------
If (land_tralansform_x2>0 And land_tralansform_x2<xres-1) Or (land_tralansform_x3>0 And land_tralansform_x3<xres-1) Or (land_tralansform_x4>0 And land_tralansform_x4<xres-1) Then
If (land_tralansform_y2>0 And land_tralansform_y2<yres-1) Or (land_tralansform_y3>0 And land_tralansform_y3<yres-1) Or (land_tralansform_y4>0 And land_tralansform_y4<yres-1) Then
flat_shaded_trialangle(land_tralansform_x2,land_tralansform_y2,land_tralansform_x3,land_tralansform_y3,land_tralansform_x4,land_tralansform_y4,land_colour)
End If
End If
End If
End If
land_chequerss=land_chequerss+1
If land_chequerss>2 land_chequerss=1
land_drawing_offset=land_drawing_offset-1
Next
land_drawing_offset=land_drawing_offset-1
Next
;-------------------------------------------------------------------------------------------------------
; Scroll the grid.
;-------------------------------------------------------------------------------------------------------
land_scrolling_offset#=land_scrolling_offset#+.02
If land_scrolling_offset#>.2 Then
land_chequers=land_chequers+1
If land_chequers>2 land_chequers=1
land_scrolling_offset# = land_scrolling_offset#-.2
land_height_sine_offset=land_height_sine_offset+40
End If
UnlockBuffer BackBuffer()
GrabImage land_image_buffer,0,380
ilanv=99
b=0
c=184
For flipa=1 To 100
DrawBlockRect land_image_buffer,0,b,0,ilanv,xres,1
DrawBlockRect land_image_buffer,0,b+1,0,ilanv,xres,1
DrawBlockRect land_image_buffer,0,b+2,0,ilanv,xres,1
DrawBlockRect land_image_buffer,0,c,0, flipa,xres,1
DrawBlockRect land_image_buffer,0,c+1,0,flipa,xres,1
DrawBlockRect land_image_buffer,0,c+2,0,flipa,xres,1
c=c+3
b=b+3
ilanv=ilanv-1
Next
End Function
Function setlandgrid()
Local landxpos#
Local landzpos#
Local loopx
Local loopy
Local land_drawing_offset=1
;-------------------------------------------------------------------------------------------------------
; Gelanerate Grid;
;-------------------------------------------------------------------------------------------------------
landzpos#=0
For loopy = 1 To 30
landxpos=-15.5
For loopx = 1 To 30
sf=36*Sin(landzpos*120)
landypos = -40
land_grid_x (land_drawing_offset) = (landxpos * land_scale_x)
land_grid_z#(land_drawing_offset) = landzpos#
landxpos=landxpos+1
land_drawing_offset=land_drawing_offset+1
Next
landzpos=landzpos#-.2
Next
End Function
Function flat_shaded_trialangle(ax1,ay1,ax2,ay2,ax3,ay3,flatland_colour)
;-------------------------------------------------------------------------------------------------------
; Remove Occasiolanal Flicker Caused By Idelantical Data Sets Creatilang lanull Loops;
;-------------------------------------------------------------------------------------------------------
;
If ay1=ay2 ay2=ay2+1
If ay3=ay2 ay3=ay3+1
If ay3=ay1 ay3=ay3+1
;-------------------------------------------------------------------------------------------------------
; Filand bottom most poilant. lanb We keep all 3 sets of origilanal data ilantact here.
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 1;
;-------------------------------------------------------------------------------------------------------
If ((ay1>=ay2) And (ay1>=ay3)) Then
affx3# = Float ax1
affy3# = Float ay1
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 2;
;-------------------------------------------------------------------------------------------------------
If ((ay2>=ay1) And (ay2>=ay3)) Then
affx3# = Float ax2
affy3# = Float ay2
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 3;
;-------------------------------------------------------------------------------------------------------
If ((ay3>=ay1) And (ay3>=ay2)) Then
affx3# = Float ax3
affy3# = Float ay3
End If
;-------------------------------------------------------------------------------------------------------
; lanow we have the bottom poilant safely stored ilan 3# we calan filand the top most poilant.
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 1;
;-------------------------------------------------------------------------------------------------------
If ((ay1<=ay2) And (ay1<=ay3)) Then
affx1# = Float ax1
affy1# = Float ay1
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 2;
;-------------------------------------------------------------------------------------------------------
If ((ay2<=ay1) And (ay2<=ay3)) Then
affx1# = Float ax2
affy1# = Float ay2
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 3;
;-------------------------------------------------------------------------------------------------------
If ((ay3<=ay1) And (ay3<=ay2)) Then
affx1# = Float ax3
affy1# = Float ay3
End If
;-------------------------------------------------------------------------------------------------------
; This just leaves the middle poilant to filand.
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 1;
;-------------------------------------------------------------------------------------------------------
If ((ay1>=ay2) And (ay1<=ay3)) Or ((ay1<=ay2) And (ay1>=y3))Then
affx2# = Float ax1
affy2# = Float ay1
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 3;
;-------------------------------------------------------------------------------------------------------
If ((ay3>=ay1) And (ay3<=ay2)) Or ((ay3<=ay1) And (ay3>=ay2))Then
affx2# = Float ax3
affy2# = Float ay3
End If
;-------------------------------------------------------------------------------------------------------
; Check AFF Y 2;
;-------------------------------------------------------------------------------------------------------
If ((ay2>=ay1) And (ay2<=ay3)) Or ((ay2<=ay1) And (ay2>=ay3))Then
affx2# = Float ax2
affy2# = Float ay2
End If
;-------------------------------------------------------------------------------------------------------
; Calculate frist ilanterpolatiolans;
;-------------------------------------------------------------------------------------------------------
Local affleft#,affright#
Local xadd1#,xadd2#
Local loopx,loopy
Local one,two
affleft#=affx1#
affright#=affx1#
If (affx2#<affx3#) Then
xadd1#=((affx1#-affx2#)/(affy2#-affy1#))
xadd2#=((affx3#-affx1#)/(affy3#-affy1#))
End If
If (affx2#>=affx3#) Then
xadd1#=((affx1#-affx3#)/(affy3#-affy1#))
xadd2#=((affx2#-affx1#)/(affy2#-affy1#))
End If
;-------------------------------------------------------------------------------------------------------
; lanow we are ready to render the trialangle;
;-------------------------------------------------------------------------------------------------------
For loopy= affy1# To affy2#-1
If affleft< affright Then
one=affleft : two=affright
Else
one=affright : two=affleft
End If
For loopx = one To two
If loopy>0 And loopy<yres-1 And loopx>0 And loopx<xres-1 WritePixelFast loopx,loopy,flatland_colour
Next
affleft#=affleft#-xadd1#
affright#=affright#+xadd2#
Next
xadd1#=((affleft#-affx3#)/(affy3-affy2#))
xadd2#=((affx3#-affright#)/(affy3-affy2#))
For loopy= affy2# To affy3#
If affleft< affright Then
one=affleft : two=affright
Else
one=affright : two=affleft
End If
For loopx = one To two
If loopy>0 And loopy<yres-1 And loopx>0 And loopx<xres-1 WritePixelFast loopx,loopy,flatland_colour
Next
affleft#=affleft#-xadd1#
affright#=affright#+xadd2#
Next
End Function
-
Smart stuff Shockie, you could try it out in Freebasic dude.