Skip to content

Commit ac36b49

Browse files
committed
Fixed license comments
1 parent bc6f997 commit ac36b49

29 files changed

Lines changed: 62 additions & 98 deletions

‎Chapter05/Bullet.cpp‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#include "Bullet.h"
@@ -35,10 +35,7 @@ void Bullet::UpdateActor(float deltaTime)
3535
// Check for collision vs enemies
3636
for (Enemy* e : GetGame()->GetEnemies())
3737
{
38-
Vector2 diff = e->GetCircle()->GetCenter() - mCircle->GetCenter();
39-
float rad = e->GetCircle()->GetRadius() + mCircle->GetRadius();
40-
rad *= rad;
41-
if (diff.LengthSq() <= rad)
38+
if (Intersect(*mCircle, *(e->GetCircle())))
4239
{
4340
// We both die on collision
4441
e->SetState(EDead);

‎Chapter05/Bullet.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#pragma once

‎Chapter05/CircleComponent.cpp‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#include "CircleComponent.h"
1010
#include "Actor.h"
1111

1212
CircleComponent::CircleComponent(class Actor* owner)
13-
:CollisionComponent(owner)
13+
:Component(owner)
1414
,mRadius(0.0f)
1515
{
1616

@@ -25,3 +25,16 @@ float CircleComponent::GetRadius() const
2525
{
2626
return mOwner->GetScale() * mRadius;
2727
}
28+
29+
bool Intersect(const CircleComponent& a, const CircleComponent& b)
30+
{
31+
// Calculate distance squared
32+
Vector2 diff = a.GetCenter() - b.GetCenter();
33+
float distSq = diff.LengthSq();
34+
35+
// Calculate sum of radii squared
36+
float radiiSq = a.GetRadius() + b.GetRadius();
37+
radiiSq *= radiiSq;
38+
39+
return distSq <= radiiSq;
40+
}

‎Chapter05/CircleComponent.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#pragma once
10-
#include "CollisionComponent.h"
10+
#include "Component.h"
1111
#include "Math.h"
1212

13-
class CircleComponent : public CollisionComponent
13+
class CircleComponent : public Component
1414
{
1515
public:
1616
CircleComponent(class Actor* owner);
@@ -22,3 +22,5 @@ class CircleComponent : public CollisionComponent
2222
private:
2323
float mRadius;
2424
};
25+
26+
bool Intersect(const CircleComponent& a, const CircleComponent& b);

‎Chapter05/CollisionComponent.cpp‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎Chapter05/CollisionComponent.h‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎Chapter05/Enemy.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#include "Enemy.h"

‎Chapter05/Enemy.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ----------------------------------------------------------------
22
// From Game Programming in C++ by Sanjay Madhav
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
4-
//
4+
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#pragma once

‎Chapter05/Game.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
44
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#include "Game.h"

‎Chapter05/Game.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
44
//
55
// Released under the BSD License
6-
// See LICENSE.txt for full details.
6+
// See LICENSE in root directory for full details.
77
// ----------------------------------------------------------------
88

99
#pragma once

0 commit comments

Comments
 (0)