Destructable Landscapes

Blitz3D Forums/Blitz3D Beginners Area/Destructable Landscapes

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hey man, change your function TestShotsGround() to :


Function TestShotsGround()
For s.shot = Each shot
If ImagesCollide(s\Image,s\x,s\y,0,TestForg,512,350,0)
SetBuffer ImageBuffer(TestForg)
Color 0,0,0
Oval s\x-50,s\y-50,100,100,1 ; 
SetBuffer BackBuffer()
Delete s
End If 
Next 
End Function 


I would also encourage you to tab your code. It helps alot when debuging and following th program flow. So you code looks like:

;Initialize Graphics Mode
Graphics 1024,700
SetBuffer BackBuffer()
AutoMidHandle True
SeedRnd MilliSecs()


;Load Graphics
Global Silo1 = LoadImage("p1silo.bmp")
MaskImage Silo1,255,255,255

Global Turret1 = LoadImage("p1turret.bmp")

Global shot = LoadImage("shot.bmp")
MaskImage shot,0,0,0

Global TestForg = LoadImage("Testforg.bmp")
MaskImage TestForg,0,0,0

;Arrays
Dim tur1(45)
RotateImage Turret1,-45
tur1(0) = Turret1

For i = 1 To 45
	tur1(i) = CopyImage(Turret1)
	RotateImage tur1(i),2 * i
Next 

;Turret direction Array
Dim dir(45)
dir(0) = 135

For i = 1 To 45
	dir(i) = dir(i-1) + 2
Next 




;Variables
Global x = 400
Global y = -10
Global rot = 0
Global velocity
Global gravity# = 0.2

;Types
Type shot
	Field x,y
	Field vx#,vy#
	Field id$
	Field Image
	Field radius
End Type 

While Not ImagesCollide(Silo1,x,y,0,TestForg,512,350,0)
	y = y + 1
Wend 

;Main Loop
While Not KeyHit(1)
	TestInput()
	DrawGrounds()
	DrawPlayers()
	UpdateShots()
	TestShotsGround()
	
	Flip
	Cls
Wend 
End 


Function TestInput()
	rot = rot + MouseXSpeed()

	If rot < 0
		rot = 0
	Else If rot > 45
		rot = 45
	End If 

	If MouseHit(1)
		s.shot = New shot
		s\x = x
		s\y = y
		s\vx# = -Sin(dir(rot)) * 9
		s\vy# = Cos(dir(rot)) * 9
		s\id$ = "ICBM"
		s\Image = CopyImage(shot)
		s\radius = 5
	End If 

End Function 

Function DrawGrounds()
	DrawImage TestForg,512,350
End Function 

Function DrawPlayers()
	DrawImage tur1(rot),x,y -6
	DrawImage Silo1,x,y
End Function 

Function UpdateShots()
	For s.shot = Each shot
		DrawImage s\Image,s\x,s\y
		s\x = s\x + s\vx#
		s\y = s\y + s\vy#
		
		s\vy# = s\vy# + gravity#
		
	Next
End Function 

Function TestShotsGround()
	For s.shot = Each shot
		If ImagesCollide(s\Image,s\x,s\y,0,TestForg,512,350,0)
			SetBuffer ImageBuffer(TestForg)
			Color 0,0,0
			Oval s\x-50,s\y-50,100,100,1 ; 
			SetBuffer BackBuffer()
			Delete s
		End If 
	Next 
End Function