The Partridge Family were neither partridges nor a family. Discuss.
-
Anarkus
- Posts: 7
- Joined: February 27th, 2020, 4:03 am
Post
by Anarkus » February 27th, 2020, 4:17 am
I'm having an issue with this function in tutorial 20. It's returning true and the ball is rebounding but for some reason destroyed isn't being set to true in the brick.h.
Code: Select all
bool Brick::DoBallCollision(Ball & ball)
{
if (!destroyed && rect.IsOverlappingWith(ball.GetRect())) {
destroyed = true;
ball.ReboundY();
return true;
}
return false;
}
[/code
-
Anarkus
- Posts: 7
- Joined: February 27th, 2020, 4:03 am
Post
by Anarkus » February 27th, 2020, 4:19 am
Here's brick.h let me know if you need the rest of the code to check it out.
Code: Select all
#pragma once
#include "rectf.h"
#include "Colors.h"
#include "Graphics.h"
#include "Ball.h"
class Brick
{
private:
RectF rect;
Color color;
bool destroyed = false;
float offset = -2.0f;
public:
Brick() = default;
Brick(const RectF& rect_in, Color color_in);
void Draw(Graphics& gfx)const;
bool DoBallCollision(Ball& ball);
};
-
Anarkus
- Posts: 7
- Joined: February 27th, 2020, 4:03 am
Post
by Anarkus » February 27th, 2020, 5:37 am
Okay so I figured it out but I'm not sure why it worked. I was using a for(Brick brick: bricks) instead of for(i= 0 ;i < brickcount; i ++).
Why can I usee the former to draw but not to check collision?
-
Anarkus
- Posts: 7
- Joined: February 27th, 2020, 4:03 am
Post
by Anarkus » February 27th, 2020, 6:58 am
JFC ignore me. I had to pass Brick brick&.
-
chili
- Site Admin
- Posts: 3948
- Joined: December 31st, 2011, 4:53 pm
- Location: Japan
-
Contact:
Post
by chili » February 28th, 2020, 6:01 am
Well my work here is done.
Chili