Finish Line end on intersection
Blitz3D Forums/Blitz3D Beginners Area/Finish Line end on intersection
| ||
If you look at my example code (no media) it will be clearer what i'm trying to do. I have a ball bounce around the screen, if i left-click a wall (or line) will start to expand outwards from the place where a clicked on the x axis. Same thing goes for right-clicking except it will expand on the y axis. Once the lines collide with the edge of the screen, they're set. If the lines aren't set the ball can break through them. Now what i need is a way to determine if a wall collided with another wall, and then to set that side but continue the expansion of the other side until another collision if detect on that point. Here's what ive got so far. Thanks for helping: |
| ||
maybe if you create a ton of variables (within a type) holding the x values of each vertical line, and y value of each horizontal line, and say that if this line is complete then put it in the run for inter-line collisions. All inter-line collision runners will have their x and y (depending if they're vertical or horizontal) checked with the incomplete lines. It's kind of hard to explain. If the x of a vertical line is equal to the x of a horizontal line, then they are touching eachother. If the y of a horizontal line is equal to the y of a vertical line, then they are touching, and growth should stop. I didn't take time to look at your code, so this is all theoretical. |
| ||
but how would you compare two of the same type against each other? You can't do: for w.wall=each wall for w.wall=each wall ;check collisions next next wait... or can you? |
| ||
what's the problem with this? I get a memory access in debug mode. |
| ||
I'm guessing your problem is re-using the 'w' variable in the nested loop. In your second loop use for v.wall = each wall and check that v <> w before proceeding. p.s. A bit of indentation wouldn't go a miss!!! |
| ||
ok, great! its kinda working now. But both sides stop once a collision is registered... updated (and somewhat indented) code: Function CheckWallCollisions() Local x,y,axis,x2,y2 For v.wall=Each wall x=v\x y=v\y axis=v\axis x2=v\x2 y2=v\y2 For w.wall=Each wall If w<>v If w\axis<>axis If w\axis=1 Then If axis=2 Then If w\x=x Or w\x=x-1 Or w\x=x+1 Then w\placed1=1 If w\x2=x2 Or w\x2=x2-1 Or w\x2=x2+1 Then w\placed2=1 EndIf EndIf EndIf Else If w\axis=2 Then If w\y=y Or w\y=y-1 Or w\y=y+1 Then w\placed1=1 If w\y2=y2 Or w\y2=y2-1 Or w\y2=y2+1 Then w\placed2=1 EndIf EndIf EndIf EndIf EndIf Next Next End Function |
| ||
It seems like the collision data isn't cleared once the line is destroyed by the ball, seeing that growing lines will stop dead without colliding into anything. |
| ||
i deleted the type instance. What more can i do? |
| ||
Is there something i'm not getting about 2d collisions? |
| ||
fuller wrote:but how would you compare two of the same type against each other? its really simple to compare a type against another u just simply upload it to a regular variable: for bullet.bullet = each bullet drawimage(bullet_image,bullet\x,bullet\y) if imagescollide(bullet_image,bullet\x,bullet\y,bullet_image,bulletx,bullety) print "collision!" endif bullet\x=bulletx bullet\y=bullety next |
| ||
ok, i got that now. But the lines are still colliding with the other already gone lines. |
| ||
for bullet.bullet = each bullet drawimage(bullet_image,bullet\x,bullet\y) if imagescollide(bullet_image,bullet\x,bullet\y,bullet_image,bulletx,bullety) print "collision!" endif bullet\x=bulletx bullet\y=bullety next That's a pretty bad example as your only comparing the previous bullet coords to the current. For b.bullet = Each bullet c.bullet = b While c <> Last bullet c = After c If ImagesCollide( bullet_image, b\x, b\y, Frame, bullet_image, c\x, c\y, Frame ) ;Handle collision EndIf Wend Next This method ensures that you only check each pair once. @ Fuller, If you want help with your routines - post what code you have. Stevie |
| ||
ok, thank you: And here's a diagram of what i'm trying to achieve: ![]() |