|
|
@ -58,30 +58,20 @@ class SpriteMeeple : SKNode {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
var x: CGFloat = 0
|
|
|
|
if let parent = parent, let position = touches.first?.location(in: parent) {
|
|
|
|
var y: CGFloat = 0
|
|
|
|
// Arrondir à la case la plus proche pour x et y
|
|
|
|
let position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
|
|
|
|
let x = round(position.x / 100) * 100
|
|
|
|
if (position.x < -400){
|
|
|
|
let y = round(position.y / 100) * 100
|
|
|
|
x = -400
|
|
|
|
|
|
|
|
}
|
|
|
|
// Assurer que les coordonnées sont dans les limites
|
|
|
|
else if (position.x > 500){
|
|
|
|
let clampedX = min(max(x, -300), 300)
|
|
|
|
x = 500
|
|
|
|
let clampedY = min(max(y, -400), 400)
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
self.position = CGPoint(x: clampedX, y: clampedY)
|
|
|
|
x = (abs(x.truncatingRemainder(dividingBy: 100)) < 50) ? floor(position.x/100) * 100 : ceil(position.x/100) * 100
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (position.y < -300){
|
|
|
|
|
|
|
|
y = -300
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (position.y > 400){
|
|
|
|
|
|
|
|
y = 400
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
y = (abs(y.truncatingRemainder(dividingBy: 100)) < 50) ? floor(position.y/100) * 100 : ceil(position.y/100) * 100
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.position = CGPoint(x: x, y: y)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
|
|
|
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
|
|
|
|
self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
|
|
|
|
self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|