rotating pieces that mostly work

This commit is contained in:
2022-08-12 22:49:29 +00:00
parent 3909d5ad6e
commit ceee9a1284
2 changed files with 28 additions and 5 deletions

View File

@@ -77,6 +77,9 @@
// TODO provide a saner/configurable set of bindings to trigger these ui action functions
{
(when FlxG.keys.justPressed.Q
(when draggingSprite
(draggingSprite.rotate 90)))
(when (and FlxG.keys.justPressed.SPACE !entryNameText)
(defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
@@ -402,10 +405,12 @@
minY (/ (apply min pointsY) ros)
maxX (/ (apply max pointsX) ros)
maxY (/ (apply max pointsY) ros)
rect (.fromTwoPoints (new FlxRect) (new FlxPoint minX minY) (new FlxPoint maxX maxY))]
(+= rect.x s.x)
(+= rect.y s.y)
rect)))
rect (.fromTwoPoints (new FlxRect) (new FlxPoint minX minY) (new FlxPoint maxX maxY))
originOffset (new FlxPoint (- s.origin.x minX) (- s.origin.y minY))
rotated (rect.getRotatedBounds s.angle originOffset)]
(+= rotated.x s.x)
(+= rotated.y s.y)
rotated)))
(method :FlxRect matchZoneLeft [:KissExtendedSprite s]
(matchZone s WEST))
@@ -456,7 +461,7 @@
`(whenLet [,to (dictGet ,mp id)
mz1 (,mz1 s)
mz2 (,mz2 ,to)]
(unless .isEmpty (mz1.intersection mz2)
(unless (or !(= s.angle .angle ,to) .isEmpty (mz1.intersection mz2))
(connectPiece id s ,to mz1 mz2)))))
(method :Bool checkMatches [id]

View File

@@ -25,6 +25,24 @@ class KissExtendedSprite extends flixel.addons.display.FlxExtendedSprite {
mouseStartPos = FlxG.mouse.getWorldPosition();
}
// Sleazy method just for Habit Puzzles
public function rotate(deg:Float) {
if (deg < 0) {
deg += 360 * Math.ceil(Math.abs(deg / 360));
}
angle = angle + deg % 360;
for (c in connectedSprites) {
if (c != this) {
c.angle = c.angle + deg % 360;
var thisCenter = new FlxPoint(x + origin.x, y + origin.y);
var cCenter = new FlxPoint(c.x + c.origin.x, c.y + c.origin.y);
var offset = cCenter.subtractPoint(thisCenter);
c.origin.subtractPoint(offset);
}
}
}
override function updateDrag() {
var mouseTotalMovement = FlxG.mouse.getWorldPosition().subtractPoint(mouseStartPos);
var nextPos = dragStartPos.copyTo().addPoint(mouseTotalMovement);