New Project

The Partridge Family were neither partridges nor a family. Discuss.
Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

New Project

Post by Lorth » July 27th, 2012, 2:00 pm

Hey Guys!

Now i am back again with a new small project :D

Last night i watched my girlfriend playing an online game, Bubble Shooter.

she said she loves that game just to relax, and as i watched i wondered if i am able to make it myself.

so i started out today, and so far it have gone well...

but now comes the collisions... and a start of new problems
It seems like that if i use the
if(ball[index].x > ball[index].x &&
ball[index].x < ball[index].x) and so on, you all know the drill....
when i use this version it seems like it somehow collide with itself and stop at the start of it's initial...

if i remove this i am able to shoot balls to the end of the top.

Question is how do i get the balls with different index to collide with eachother?

i thought this was going to be easy, and my girlfriend said i would never make it...
but with the game as it is now, it is not impossible for me, maby a month or so :P

//Lorth
Attachments
Chili DirectX Framework Bubble Shotter - Kopia.zip
(179.87 KiB) Downloaded 327 times

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: New Project

Post by chili » July 27th, 2012, 2:17 pm

if(ball[index].x > ball[index].x &&

You're comparing each ball to itself only. You need to compare each ball to each other ball. To do this you need two loops--one inside of the other.
Chili

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: New Project

Post by Lorth » July 27th, 2012, 4:14 pm

I made a new void CollideBall() and added like this:

void Game::CollideBall()
{
for(int index = 0; index < NBALLS; index++)
{
if(nBalls[index].BallExist)
{
for(int indexx = 0; indexx < NBALLS; indexx++)
{
if(nBalls[indexx].BallExist)
{
if(nBalls[index].BallX + 10 > nBalls[indexx].BallX - 10 &&
nBalls[index].BallX - 10 < nBalls[indexx].BallX + 10 &&
nBalls[index].BallY + 10 > nBalls[indexx].BallY - 10 &&
nBalls[index].BallY - 10 < nBalls[indexx].BallY + 10)
{
nBalls[index].BallIsStuck = true;
shooting = false;
}
}
}
}
}
}

i added a new for loop to look between the to balls but it still dosn't work :/

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: New Project

Post by viruskiller » July 27th, 2012, 10:15 pm

looking at the game code is hard to understand where did u put this function,if u put it right it should work,better post an updated solution and someone might tell u why is not working:P

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: New Project

Post by Lorth » July 28th, 2012, 12:28 pm

Here is the new project with the collide code added
Attachments
Chili DirectX Framework Bubble Shotter - Kopia.rar
(141.47 KiB) Downloaded 290 times

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: New Project

Post by LuX » July 28th, 2012, 1:36 pm

Too bored to put this to the test, but I think the problem is your update ball function. There you loop through all balls and if at least one is at the top "shoot" becomes false. So if one ball is at the top, shoot will be false again.

This means, that now when you shoot, it will actually spawn multiple balls, that will then collide at the bottom and get stuck there.

This would explain the behaviour of the program. Fist ball works and rest get stuck at the bottom and if you hold down the shoot button the frame rate goes up.

What you may want to do is keep track on the ball of the index you just shot and make shoot only false if this particular ball has stopped moving.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: New Project

Post by chili » July 28th, 2012, 1:42 pm

Hey LuX, how's it hangin?
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: New Project

Post by LuX » July 28th, 2012, 1:50 pm

Cool, haven't been coding much lately (doing other stuff as well, you know).

When is the next tutorial coming? I'm waiting for the framework explanation stuff.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: New Project

Post by chili » July 28th, 2012, 1:55 pm

The last preparatory lesson should be finished this weekend. Then I can finally explain the framwork.

Wanted to get it done earlier, but the Chili has been busy too.
Chili

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: New Project

Post by Lorth » July 28th, 2012, 2:53 pm

Hey!

Now it feels like a great start, but the problem is now the collision, and it feels like i might tought i could do more than i actually know, becouse i have tryed alot of varitys on the collision but it still messes up, so far i have tryed just with two with the same color as i get random colors all the time, but it removes all different colors all the time, what am i doing wrong?
Attachments
Chili DirectX Framework Bubble Shotter - Kopia.zip
(179.96 KiB) Downloaded 281 times

Post Reply