| collision help 
 
	 
	
		| Author | Message |   
		| shoobyman 
 
  
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 8:02 am    Post subject: collision help |  |   
				| 
 |  
				| 	  | code: |  	  | setscreen ("offscreenonly")
var x, y, button : int
 var plx, ply, plhealth, explx, exply, expls : int
 var bulx, buly, speed : array 1 .. 10 of int
 var explosion : boolean := false
 plhealth := 600
 bulx (1) := 0
 buly (1) := 100
 bulx (2) := 0
 buly (2) := 200
 bulx (3) := 0
 buly (3) := 300
 bulx (4) := 0
 buly (4) := 400
 bulx (5) := 0
 buly (5) := 500
 bulx (6) := 100
 buly (6) := 0
 bulx (7) := 250
 buly (7) := 0
 bulx (8) := 300
 buly (8) := 0
 bulx (9) := 400
 buly (9) := 0
 bulx (10) := 500
 buly (10) := 0
 speed (1) := 3
 speed (2) := 4
 speed (3) := 5
 speed (4) := 6
 speed (5) := 7
 speed (6) := 4
 speed (7) := 5
 speed (8) := 6
 speed (9) := 7
 speed (10) := 4
 expls := 1
 
 loop
 if bulx (1) > maxx then
 bulx (1) := -50
 randint (buly (1), 20, maxy - 20)
 randint (speed (1), 3, 7)
 end if
 if bulx (2) > maxx then
 bulx (2) := -50
 randint (buly (2), 20, maxy - 20)
 randint (speed (2), 3, 7)
 end if
 if bulx (3) > maxx then
 bulx (3) := -50
 randint (buly (3), 20, maxy - 20)
 randint (speed (3), 3, 7)
 end if
 if bulx (4) > maxx then
 bulx (4) := -50
 randint (buly (4), 20, maxy - 20)
 randint (speed (4), 3, 7)
 end if
 if bulx (5) > maxx then
 bulx (5) := -50
 randint (buly (5), 20, maxy - 20)
 randint (speed (5), 3, 7)
 end if
 if buly (6) > maxy then
 buly (6) := -50
 randint (bulx (6), 20, maxx - 20)
 randint (speed (6), 3, 7)
 end if
 if buly (7) > maxy then
 buly (7) := -50
 randint (bulx (7), 20, maxx - 20)
 randint (speed (7), 3, 7)
 end if
 if buly (8) > maxy then
 buly (8) := -50
 randint (bulx (8), 20, maxx - 20)
 randint (speed (8), 3, 7)
 end if
 if buly (9) > maxy then
 buly (9) := -50
 randint (bulx (9), 20, maxx - 20)
 randint (speed (9), 3, 7)
 end if
 if buly (10) > maxy then
 buly (10) := -50
 randint (bulx (10), 20, maxx - 20)
 randint (speed (10), 3, 7)
 end if
 
 
 mousewhere (x, y, button)
 View.Update
 delay (20)
 cls
 drawfillbox (10, 10, plhealth, 17, 12)
 drawfilloval (x, y, 10, 10, black)
 drawline (bulx (1), buly (1), bulx (1) - 20, buly (1), 7)
 drawline (bulx (2), buly (2), bulx (2) - 20, buly (2), 7)
 drawline (bulx (3), buly (3), bulx (3) - 20, buly (3), 7)
 drawline (bulx (4), buly (4), bulx (4) - 20, buly (4), 7)
 drawline (bulx (5), buly (5), bulx (5) - 20, buly (5), 7)
 drawline (bulx (6), buly (6), bulx (6), buly (6) - 20, 7)
 drawline (bulx (7), buly (7), bulx (7), buly (7) - 20, 7)
 drawline (bulx (8), buly (8), bulx (8), buly (8) - 20, 7)
 drawline (bulx (9), buly (9), bulx (9), buly (9) - 20, 7)
 drawline (bulx (10), buly (10), bulx (10), buly (10) - 20, 7)
 
 bulx (1) += speed (1)
 bulx (2) += speed (2)
 bulx (3) += speed (3)
 bulx (4) += speed (4)
 bulx (5) += speed (5)
 buly (6) += speed (6)
 buly (7) += speed (7)
 buly (8) += speed (8)
 buly (9) += speed (9)
 buly (10) += speed (10)
 if x > bulx (1) - 30 and x < bulx (1) + 10 and y > buly (1) - 10 and y < buly (1) + 10 then
 explosion := true
 plhealth -= 10
 end if
 if x > bulx (2) - 30 and x < bulx (2) + 10 and y > buly (2) - 10 and y < buly (2) + 10 then
 explosion := true
 plhealth -= 10
 end if
 if x > bulx (3) - 30 and x < bulx (3) + 10 and y > buly (3) - 10 and y < buly (3) + 10 then
 explosion := true
 plhealth -= 10
 end if
 if x > bulx (4) - 30 and x < bulx (4) + 10 and y > buly (4) - 10 and y < buly (4) + 10 then
 explosion := true
 plhealth -= 10
 end if
 if x > bulx (5) - 30 and x < bulx (5) + 10 and y > buly (5) - 10 and y < buly (5) + 10 then
 explosion := true
 plhealth -= 10
 end if
 
 if explosion = true then
 explx := x - 7
 exply := y
 drawfilloval (explx, exply, expls, expls, yellow)
 expls += 1
 end if
 if expls >= 13 then
 explosion := false
 expls := 1
 end if
 if plhealth <= 0 then
 quit
 end if
 end loop
 
 | 
 
 
 
 Someone help me make a collision between lines.
 I want it so that if the lines crash into each other, it creates a little explosion, someone help.
 (btw, i just need to know how to do it efficiently)
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| do_pete 
 
  
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 8:33 am    Post subject: (No subject) |  |   
				| 
 |  
				| There is a function in the Math module that will allow you to do this. Sorry I can't tell you what this function is called because I don't have a new version of Turing on hand. By the way, you might also want to look into for loops. This will save you a lot of lines so that instead of: 
 	  | code: |  	  |     if bulx (1) > maxx then 
bulx (1) := -50
 randint (buly (1), 20, maxy - 20)
 randint (speed (1), 3, 7)
 end if
 if bulx (2) > maxx then
 bulx (2) := -50
 randint (buly (2), 20, maxy - 20)
 randint (speed (2), 3, 7)
 end if
 if bulx (3) > maxx then
 bulx (3) := -50
 randint (buly (3), 20, maxy - 20)
 randint (speed (3), 3, 7)
 end if
 if bulx (4) > maxx then
 bulx (4) := -50
 randint (buly (4), 20, maxy - 20)
 randint (speed (4), 3, 7)
 end if
 if bulx (5) > maxx then
 bulx (5) := -50
 randint (buly (5), 20, maxy - 20)
 randint (speed (5), 3, 7)
 end if
 if buly (6) > maxy then
 buly (6) := -50
 randint (bulx (6), 20, maxx - 20)
 randint (speed (6), 3, 7)
 end if
 if buly (7) > maxy then
 buly (7) := -50
 randint (bulx (7), 20, maxx - 20)
 randint (speed (7), 3, 7)
 end if
 if buly (8) > maxy then
 buly (8) := -50
 randint (bulx (8), 20, maxx - 20)
 randint (speed (8), 3, 7)
 end if
 if buly (9) > maxy then
 buly (9) := -50
 randint (bulx (9), 20, maxx - 20)
 randint (speed (9), 3, 7)
 end if
 if buly (10) > maxy then
 buly (10) := -50
 randint (bulx (10), 20, maxx - 20)
 randint (speed (10), 3, 7)
 end if
 
 | 
 You can have:
 
 	  | code: |  	  | for bulletNumber: 1..10
if buly (bulletNumber) > maxy then
 buly (bulletNumber) := -50
 randint (bulx (bulletNumber), 20, maxx - 20)
 randint (speed (bulletNumber), 3, 7)
 end if
 end for
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| shoobyman 
 
  
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 9:46 am    Post subject: (No subject) |  |   
				| 
 |  
				| thanx, the for makes the code much better, but i still need to make collision between lines, some1 help? |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Clayton 
 
  
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 12:37 pm    Post subject: (No subject) |  |   
				| 
 |  
				| check into collision detection in the Turing Walkthrough |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| do_pete 
 
  
 
 
 | 
			
				|  Posted: Thu Oct 05, 2006 9:52 am    Post subject: (No subject) |  |   
				| 
 |  
				| You can try and use for loops for htis or you can use Math.DistancePointLine. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |