Arkanoid

BlitzPlus Forums/BlitzPlus Beginners Area/Arkanoid

blicek(Posted 2016) [#1]
Hello

I am in the process of creating games such as arkanoid, but unfortunately I can not cope with the function detects the collision of blocks which bounces the ball. Calculation of collision the ball with your paddle is no problem. Please help how to properly detect the collision was between blocks and ball.

Blicek


Matty(Posted 2016) [#2]
Lots of ways of doing it but I'd imagine either having a type list of each block with an x,y,w,h value for it or having an array that points to a type object for each block.

The simply check if the ball x,y (plus radius) is inside the x,y,w,h boundaries and if so the block is hit.

Next...if you calculate the angle of incidence that the ball hits the block you can then reflect that angle about the normal of the block's collision side and that will give you the new direction of the ball.

Hope that helps.


RustyKristi(Posted 2016) [#3]
Just a note: Blitzanoid game by Tracer is already under blitzplus games folder. It's a complete game with source just check it out.

https://github.com/blitz-research/blitzplus/tree/master/_release/games/Blitzanoid/




xlsior(Posted 2016) [#4]
One way of doing it is dividing the entire playfield into blocks, and match them to an array that stores the contents of each cell.

e.g. a playingfield that's 1000x700 pixels, each block is 20x10 pixels, which means an array with [100,70]. Associate a value with each different block, and leave at zero if there is no block.

If the ball is at pixel position 300,300, that means you're in cell 300/20=15 by 300/10=30, which is array cell [10,30] Consider your movement, and do the same math for your next position. If it looks like you're hitting [10,29], see what's inside that array slot: If it's zero just keep moving, if it's a different value you know you're about to hit something and you can figure out what to do from there.