Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / need help with brick game

Author
Message
jjeff
13
Years of Service
User Offline
Joined: 11th Mar 2011
Location:
Posted: 11th Mar 2011 20:09
I am trying to make a brick game like this one http://www.youtube.com/watch?v=K1Ih5IyoydQ&feature=related

I have created all the bricks with this code



The problem, however, is with my collision function. It checks one brick at a time to see if a brick is being hit by the ball. it only works if you hit the brick it happens to be checking. this is my function, i haven't finished it. how can i make it check all bricks at all times or should i be doing this completely differently?

jjeff
13
Years of Service
User Offline
Joined: 11th Mar 2011
Location:
Posted: 11th Mar 2011 23:48
Sorry, my collision function was really sloppy. i cleaned it up a bit

DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 12th Mar 2011 04:40 Edited at: 12th Mar 2011 04:40
You seem to be making this harder than it needs to be.

I would suggest making it change the x then check collision.
If there is a collision then you know it was on a side. By looking at the sign of the velocity in the x component you can know which side it was, but you don't even need to know this.
You could just reverse the velocity by multiplying it by -1 and not pay attention to which side it hit.

Then do the same thing for the y component.

Also, that break could be causing a problem. I don't see a need for it.

Btw, Have a look at this demo code (11th post) which uses this process of analyzing the x and y movement separately.

http://forum.thegamecreators.com/?m=forum_view&t=182549&b=22

I'll get a new signature someday.
jjeff
13
Years of Service
User Offline
Joined: 11th Mar 2011
Location:
Posted: 15th Mar 2011 07:07
Okay, I rewrote my ball movement function to change the ball's vertical displacement, check for collision, change horizontal displacement, and then check for collision again. this works great for the bricks, but when the ball hits the user's bar, it just bounces up and down on the bar, rather than moving back towards the bricks. also, i have it set to spawn the ball when the user hits space bar and although that works for initially spawning the ball, the user is unable to respawn the ball.

Login to post a reply

Server time is: 2024-09-28 12:37:34
Your offset time is: 2024-09-28 12:37:34