Skip to content

Commit 5729295

Browse files
committed
Fix triangle overlap with peg for level designer
1 parent 4a38bb4 commit 5729295

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

‎ps4/peggleclone/Models/TriangleBlock.swift‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ class TriangleBlock: PeggleObject {
1919
self.base = base
2020
self.height = height
2121
self.vertexOne = Point(xCoordinate: center.xCoordinate,
22-
yCoordinate: center.yCoordinate + 2 * height / 3)
23-
self.vertexTwo = Point(xCoordinate: center.xCoordinate + base / 2,
24-
yCoordinate: center.yCoordinate - height / 3)
25-
self.vertexThree = Point(xCoordinate: center.xCoordinate - base / 2,
26-
yCoordinate: center.yCoordinate - height / 3)
22+
yCoordinate: center.yCoordinate - height / 2)
23+
self.vertexTwo = Point(xCoordinate: center.xCoordinate - base / 2,
24+
yCoordinate: center.yCoordinate + height / 2)
25+
self.vertexThree = Point(xCoordinate: center.xCoordinate + base / 2,
26+
yCoordinate: center.yCoordinate + height / 2)
2727
super.init(center: center)
2828
}
2929

3030
init(id: UUID, center: Point, base: Double = 50, height: Double = 50) {
3131
self.base = base
3232
self.height = height
3333
self.vertexOne = Point(xCoordinate: center.xCoordinate,
34-
yCoordinate: center.yCoordinate + 2 * height / 3)
35-
self.vertexTwo = Point(xCoordinate: center.xCoordinate + base / 2,
36-
yCoordinate: center.yCoordinate - height / 3)
37-
self.vertexThree = Point(xCoordinate: center.xCoordinate - base / 2,
38-
yCoordinate: center.yCoordinate - height / 3)
34+
yCoordinate: center.yCoordinate - height / 2)
35+
self.vertexTwo = Point(xCoordinate: center.xCoordinate - base / 2,
36+
yCoordinate: center.yCoordinate + height / 2)
37+
self.vertexThree = Point(xCoordinate: center.xCoordinate + base / 2,
38+
yCoordinate: center.yCoordinate + height / 2)
3939
super.init(id: id, center: center)
4040
}
4141

@@ -66,7 +66,6 @@ class TriangleBlock: PeggleObject {
6666
let c3x = peg.center.xCoordinate - vertexThree.xCoordinate
6767
let c3y = peg.center.yCoordinate - vertexThree.yCoordinate
6868

69-
// &c3sqr = radiusSqr // ; reference to radiusSqr
7069
let c3sqr = c3x * c3x + c3y * c3y - radiusSqr
7170

7271
if c3sqr <= 0 {
@@ -142,17 +141,17 @@ class TriangleBlock: PeggleObject {
142141
return false
143142
} else {
144143
// TODO: implemenation of trinagle triangle intersect
145-
return false
144+
return false
146145
}
147146
}
148147

149148
override func shiftTo(location: Point) {
150149
self.center = location
151150
self.vertexOne = Point(xCoordinate: center.xCoordinate,
152-
yCoordinate: center.yCoordinate + 2 * height / 3)
153-
self.vertexTwo = Point(xCoordinate: center.xCoordinate + base / 2,
154-
yCoordinate: center.yCoordinate - height / 3)
155-
self.vertexThree = Point(xCoordinate: center.xCoordinate - base / 2,
156-
yCoordinate: center.yCoordinate - height / 3)
151+
yCoordinate: center.yCoordinate - height / 2)
152+
self.vertexTwo = Point(xCoordinate: center.xCoordinate - base / 2,
153+
yCoordinate: center.yCoordinate + height / 2)
154+
self.vertexThree = Point(xCoordinate: center.xCoordinate + base / 2,
155+
yCoordinate: center.yCoordinate + height / 2)
157156
}
158157
}

‎ps4/peggleclone/Views/LevelDesigner/LevelDesignerCanvasView.swift‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct LevelDesignerCanvasView: View {
3939
})))
4040
} else if let triangle = peggleObject as? TriangleBlock {
4141
return AnyView(
42+
// ZStack() {
4243
TriangleView(location: .constant(CGPoint(x: triangle.center.xCoordinate,
4344
y: triangle.center.yCoordinate)),
4445
triangleBase: triangle.base,
@@ -60,7 +61,21 @@ struct LevelDesignerCanvasView: View {
6061
newLocation: locationOfTriangle,
6162
canvasDimensions: canvasDimensions)
6263
}
63-
})))
64+
}))
65+
// Circle()
66+
// .fill(Color.black)
67+
// .frame(width: 15, height: 15)
68+
// .position(x: triangle.vertexOne.xCoordinate, y: triangle.vertexOne.yCoordinate)
69+
// Circle()
70+
// .fill(Color.black)
71+
// .frame(width: 15, height: 15)
72+
// .position(x: triangle.vertexTwo.xCoordinate, y: triangle.vertexTwo.yCoordinate)
73+
// Circle()
74+
// .fill(Color.black)
75+
// .frame(width: 15, height: 15)
76+
// .position(x: triangle.vertexThree.xCoordinate, y: triangle.vertexThree.yCoordinate)
77+
// }
78+
)
6479
} else {
6580
return AnyView(EmptyView())
6681
}

0 commit comments

Comments
 (0)