123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|453|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Block Breaker Block Collisions

Thu, 13 Sep 2007, 13:38
mole
Yo yo yo!

Mmkay, I have my lil block breaker game coming along relatively nicely.

It is currently at a very basic stage, it supports the following fun features:
- A mouse controlled paddle!
- A ball!
- Some blocks in a grid-like pattern!
- A few collision things!

OK, the the collisions between the ball and the blocks is my problem. If the ball hits the TOP or the BOTTOM of a block, it works fine, bouncing off in that well known, happy fashion. The ball simply goes ploughing straight through the sides of the blocks, though! Can you believe it? Well I could.

Anyways, this is the code I currently have that works great for the TOP and BOTTOM of the blocks:



Pretty simple, basic stuff

So basically, I need someone to tell me just how I can get it to register hits to the side.

Cheers

Thu, 13 Sep 2007, 14:06
Forklift_Fred
Oooh, that's interesting!

I don't understand the second If statement though.

The first one checks for a collision and if the ball is 'inside' the block, it reverses the y direction.

In the second one, The b\y checks don't seem to match up. If one if true then the other one can't be so the If is always going top be false. You are asking if the ball is below the block and above the block

I think you need to specify where the ball was last cycle to determine which way it has hit the block.

-=-=-
Come rain or shine...
Thu, 13 Sep 2007, 14:35
mole
That second If was sumint random i put in in a vain attemp to solve my problems. In retrospect I find it useless xD.

I have never got block breaker collisions working properly; i suck at it, so a bit of real/psuedo/theory code stuffz would help me lol..

Anyone remember "gimme da codez"? xD
Thu, 13 Sep 2007, 14:50
magicman
i would recommend using a imagescollide command instead of using a math function. takes less space, is easier, and will work.

-=-=-
Stuff... Yeah...
Thu, 13 Sep 2007, 15:00
Jayenkai
But at the same time, If you've got a big Multiball thing going, and you're checking 10+ balls against 100+ blocks, the maths would most certainly be quicker than imagecollides.

I'll be honest and say that I've never quite got it right, either. I can get basic brick bouncing working, but as soon as the ball starts hopping around inside clumps of bricks it all starts to go heywire!!

-=-=-
''Load, Next List!''
Thu, 13 Sep 2007, 15:21
Forklift_Fred
That's a very good point. One thing you could try is breaking down the block into segments or zones. If a collision is detected then, before deleting the block check where the collision is. You could do this with images easier if you have one for each zone of the block, divided something like this:

(I know I didn't need to label them but... meh!)

You may want to change the order in which the zones are checked depending on which way the ball is moving. If it's going up-left then check bottom, right, top, left. I can't quite explain why but it makes sense to me to prevent false readings.

You may be able to use some maths to determine whether the line between the ball's last position and current position crosses each of the lines around the block similar to HERE. Ultimately, given Jay's thinking, this could be your best bet.

-=-=-
Come rain or shine...
Fri, 14 Sep 2007, 05:21
JL235
I'm busy over the next few days, but a per-pixel collision detection function I wrote in Java could be used for this. In this case I wouldn't actually be checking any pixels. Rather then simply going along each horizontal line of pixels in turn, it went around edge working inward.

In this case you could check if the ball and rectangle's position overlaps somewhere and return if it was checking on the top, left, right or bottom edge. It could also return a no collision value too.
Fri, 14 Sep 2007, 07:13
Jayenkai
I think that this is one of those "Over-thinking it" issues.
All of this stuff seems insanely complex.

Megaball on the Amiga had it down perfectly, in fact most of the original Breakout's worked just as well.. And I'm pretty sure that those versions weren't doing this much work!

There must be a really easy solution to doing this. It's just a case of figuring out what that solution is!

-=-=-
''Load, Next List!''
Fri, 14 Sep 2007, 12:44
Forklift_Fred
Genius! We need more people like you Jay, that last sentence really nailed the problem

That is a very valid point though. I can't image a great deal of work going into "Thro' The Wall" on the original Spectrum 48K introduction tape!

-=-=-
Come rain or shine...
Fri, 14 Sep 2007, 14:17
Teasy
Yeah, Arkanoid's a real killer (of the brain )
There are zillions of ways of doing it (most are complex),
but I've outlined 2 'easier' implementations below.

First, a solution using diagonals,
basically like Forklift_Fred's pic,
where you divide each block into 4 triangles:



You can do this, for example,
using the following function,
which checks which side of a line a point is on:



Then you just check the ball (point) with 2 lines
to know which zone/triangle it is in.
Here's an example program to demonstrate how it works:



And, I've taken the liberty to mess with your original code
and take it a little further,
which now also includes the above algorithm,
and a bunch of other things:



The next problem is being able to affect the ball angle,
using the paddle, depending on:
- where the ball hits
- and at what speed you move the paddle

Btw I also found one of my old BlitzCoder tutorials called The way of Pong,
which uses a tilemap (faster), rather than a set of tile objects,
and only images without (too) (many) complicated maths or algorithms.



Well I hope you (or anyone) will find something useful in there
Lemme know if something is unclear.

|edit| Oops, almost forgot! |edit|

Here's a remake of a game I played when I was very young on a computer from the good'ol days
Basically; Capture The Balls.
(nowadays I play Capture The Flag )



Mon, 17 Sep 2007, 11:33
mole
Thanks for all this info, guys.

"The Way of Pong" source posted by Teasy is particularly helpful, I find. So helpful, in fact, that I am shoe-horning my game into it. Muahaha!

In all seriousness, who is the author? Much thanks to them indeed!
Thu, 20 Sep 2007, 09:43
Teasy
Hihihi
Actually, that would be me
I'm very happy that you find the code useful,
and expand on it to make something cool out of it
That's the great thing about teamwork!
Fri, 21 Sep 2007, 05:17
mole
Well thank you very much Teasy ^^

Now.... I have another problem. Almost completely unrelated to the specifics of block breaker, but as I'm here, I'l shove it here.

I am trying to make power ups, and I want to load them from a text file (so I can make a power-up editor hopefully).

Basically, the power ups are going to be 16*16, in a text file with (currently) the numbers 1-4 representing a different colour. I did a bit of coding and thought "wow, theis must work!". Lo, it didn't.



It is called like so:


The file format looks like this:


When it runs, it throws the runtime error in my face. I'm sure it is not a wrong directory issue. I have B+ V1.35, V1.10, V1.36, so is it a version issue? Or is it simply that I have completely forgotten how to do this stuff ?

Cheers for all help ^^
Fri, 21 Sep 2007, 14:38
Forklift_Fred
There is a lot wrong with that, mole.

I'm trying to get my head around the bits that I think should work but in the mean time...

You need to put Dim in front of ImageArray(16,16)

ReadByte is not what you want.
If you add the line Text a*20,b*20,ImageArray(a,b)
after it to write what it has just read, you'll see that rather than the numbers 1 to 4, it is trying to use the values like 49, 13, 51 etc.

You also need to have your For...Next loops the other way around so it's b then a because you are stepping through the rows and then, within each row, stepping through the columns. Otherwise your image will come out sideways.

You could get away with ReadByte if you first use WriteByte to write your 1,2,3,4 data to the file. But that would make life more complicated.

My option would be to use a string as it works with the dat file you already have. Read the file line by line and then step through it...



You also need to end your function with a Return command otherwise nothing is put into the InvinciballPwr variable and you'll get an "Image does not exist" error.

Finally, you can do away with the whole ImageArray(a,b) array and draw straight from the data to the image. There's no point in looping through the data twice.

Et Voila:



You need to use a+1 because strings start at 1 not 0 (don't you just love Blitz!) You could change the For loop to For a = 1 To x and then use Mid$(RowData$,a,1) but that just confuses things when you look at the co-ordinates!

That should do the trick

-=-=-
Come rain or shine...
Sat, 22 Sep 2007, 01:43
mole
I am so glad you are here :x

Thanks a lot!


Sat, 22 Sep 2007, 14:02
Forklift_Fred
I amaze myself sometime

It helps that I already had a similar bit of code on my Think Pink! Workshop entry to make a pink mouse-pointer. I'd done it with Data statements so that the whole game worked straight from source but I've also done some work with extracting employee details from data reports so that helped as well.

The important thing to remember is that you were heading in the right direction I like this kind of puzzle!

-=-=-
Come rain or shine...