From df9d413d1a80acfa0d8998089a58ad02ae0986cc Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 10 Sep 2021 14:51:40 -0500 Subject: [PATCH 1/8] messing around with pixel perfect check --- .../GamepadTest/.vscode copy/extensions.json | 5 + Input/GamepadTest/.vscode copy/launch.json | 28 ++++ Input/GamepadTest/.vscode copy/settings.json | 5 + Input/GamepadTest/.vscode copy/tasks.json | 35 ++++ .../PixelPerfectCollision/source/Main.hx | 1 + .../PixelPerfectCollision/source/TestState.hx | 154 ++++++++++++++++++ 6 files changed, 228 insertions(+) create mode 100644 Input/GamepadTest/.vscode copy/extensions.json create mode 100644 Input/GamepadTest/.vscode copy/launch.json create mode 100644 Input/GamepadTest/.vscode copy/settings.json create mode 100644 Input/GamepadTest/.vscode copy/tasks.json create mode 100644 Performance/PixelPerfectCollision/source/TestState.hx diff --git a/Input/GamepadTest/.vscode copy/extensions.json b/Input/GamepadTest/.vscode copy/extensions.json new file mode 100644 index 000000000..419972a49 --- /dev/null +++ b/Input/GamepadTest/.vscode copy/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "openfl.lime-vscode-extension" + ] +} diff --git a/Input/GamepadTest/.vscode copy/launch.json b/Input/GamepadTest/.vscode copy/launch.json new file mode 100644 index 000000000..4552f8861 --- /dev/null +++ b/Input/GamepadTest/.vscode copy/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "HTML5", + "type": "chrome", + "request": "launch", + "url": "http://127.0.0.1:3001", + "sourceMaps": true, + "webRoot": "${workspaceFolder}", + "preLaunchTask": "debug: html5" + }, + { + "name": "Flash", + "type": "fdb", + "request": "launch", + "preLaunchTask": "debug: flash", + "program": "${workspaceRoot}/export/flash/bin/GamepadTest.swf" + }, + { + "name": "Neko", + "type": "fdb", + "request": "launch", + "preLaunchTask": "debug: neko", + "program": "${workspaceRoot}/export/neko/bin/GamepadTest.app" + } + ] +} diff --git a/Input/GamepadTest/.vscode copy/settings.json b/Input/GamepadTest/.vscode copy/settings.json new file mode 100644 index 000000000..1dd75b373 --- /dev/null +++ b/Input/GamepadTest/.vscode copy/settings.json @@ -0,0 +1,5 @@ +{ + "search.exclude": { + "export/**/*.hx": true + } +} diff --git a/Input/GamepadTest/.vscode copy/tasks.json b/Input/GamepadTest/.vscode copy/tasks.json new file mode 100644 index 000000000..e87cb1916 --- /dev/null +++ b/Input/GamepadTest/.vscode copy/tasks.json @@ -0,0 +1,35 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "debug: html5", + "command": "haxelib", + "args": [ "run", "lime", "build", "html5", "-debug" ], + "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "debug: flash", + "command": "haxelib", + "args": [ "run", "lime", "build", "flash", "-debug", "-D fdb" ], + "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "debug: neko", + "command": "haxelib", + "args": [ "run", "lime", "build", "neko" ], + "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/Performance/PixelPerfectCollision/source/Main.hx b/Performance/PixelPerfectCollision/source/Main.hx index e6ccdaa62..c728fdfef 100644 --- a/Performance/PixelPerfectCollision/source/Main.hx +++ b/Performance/PixelPerfectCollision/source/Main.hx @@ -9,5 +9,6 @@ class Main extends Sprite { super(); addChild(new FlxGame(320, 200, PlayState)); + // addChild(new FlxGame(320, 200, TestState)); } } diff --git a/Performance/PixelPerfectCollision/source/TestState.hx b/Performance/PixelPerfectCollision/source/TestState.hx new file mode 100644 index 000000000..00813d5d2 --- /dev/null +++ b/Performance/PixelPerfectCollision/source/TestState.hx @@ -0,0 +1,154 @@ +package; + +import flixel.math.FlxMath; +import flixel.text.FlxText; +import flixel.FlxG; +import flixel.FlxObject; +import flixel.FlxSprite; +import flixel.FlxState; +import flixel.math.FlxAngle; +import flixel.math.FlxRect; + +using flixel.util.FlxSpriteUtil; + +class TestState extends FlxState +{ + var player:Player; + + override public function create():Void + { + super.create(); + + // create the player + add(player = new Player()); + + // don't need the cursor + FlxG.mouse.visible = false; + + var field = new FlxText(); + field.text + = "Mouse: move\n" + + "Click: toggle auto rotate\n" + + "Arrows: move offset\n" + + "SHIFT + Arrows: change scale\n" + + "ALT + Arrows: move origin\n" + + "Q/E: rotate\n" + + "Enter: reset"; + field.y = FlxG.height - field.height; + field.setBorderStyle(OUTLINE); + #if debug field.ignoreDrawDebug = true; #end + add(field); + + #if debug FlxG.debugger.drawDebug = true; #end + } +} + +private class Player extends FlxSprite +{ + var rotatedRect = new FlxObject(); + var offsetRect = new FlxObject(); + var pivot = new FlxObject(0, 0, 2, 2); + var rect = new FlxRect(); + + public function new() + { + super(); + makeGraphic(50, 50, 0xFFffffff); + screenCenter(); + rotatedRect.immovable = true; + offsetRect.immovable = true; + pivot.immovable = true; + + #if debug + // ignoreDrawDebug = true; + #end + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + x = FlxG.mouse.x; + y = FlxG.mouse.y; + + var left = FlxG.keys.anyPressed([LEFT , A]); + var right = FlxG.keys.anyPressed([RIGHT, D]); + var up = FlxG.keys.anyPressed([UP , W]); + var down = FlxG.keys.anyPressed([DOWN , S]); + + if (FlxG.keys.pressed.SHIFT) + { + if (left ) scale.x -= 0.05; + if (right) scale.x += 0.05; + if (up ) scale.y += 0.05; + if (down ) scale.y -= 0.05; + + width = frameWidth * scale.x; + height = frameHeight * scale.y; + } + else if (FlxG.keys.pressed.ALT) + { + if (left ) origin.x--; + if (right) origin.x++; + if (up ) origin.y--; + if (down ) origin.y++; + } + else + { + // move opposite for offset + if (left ) offset.x++; + if (right) offset.x--; + if (up ) offset.y++; + if (down ) offset.y--; + } + + if (FlxG.keys.pressed.Q) angle -= 2; + if (FlxG.keys.pressed.E) angle += 2; + if (FlxG.keys.pressed.ENTER) + { + scale.set(1, 1); + offset.set(0, 0); + updateHitbox(); + centerOrigin(); + angle = 0; + angularVelocity = 0; + } + + var wheel = FlxG.mouse.wheel; + if (wheel != 0) + { + var scroll = FlxMath.bound(scrollFactor.x + wheel / 50, 1/50, 2.0); + scrollFactor.set(scroll, scroll); + trace(wheel, scroll); + } + + if (FlxG.mouse.justPressed) + angularVelocity = angularVelocity == 0 ? 50 : 0; + + offsetRect.update(elapsed); + offsetRect.width = scale.x * frameWidth; + offsetRect.height = scale.y * frameHeight; + offsetRect.x = x - offset.x + origin.x - origin.x * scale.x; + offsetRect.y = y - offset.y + origin.y - origin.y * scale.y; + + pivot.update(elapsed); + pivot.x = x + origin.x - offset.x - pivot.width / 2; + pivot.y = y + origin.y - offset.y - pivot.height / 2; + + rotatedRect.update(elapsed); + rect = calcRotatedGraphicBounds(rect); + rotatedRect.x = rect.x; + rotatedRect.y = rect.y; + rotatedRect.width = rect.width; + rotatedRect.height = rect.height; + } + + override function draw() + { + super.draw(); + + rotatedRect.draw(); + offsetRect.draw(); + pivot.draw(); + } +} From 75ca3d3300d39ca320060c80ce2ae6003e9daf04 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Tue, 5 Oct 2021 10:25:35 -0500 Subject: [PATCH 2/8] beauty changes --- Performance/PixelPerfectCollision/Project.xml | 2 +- .../PixelPerfectCollision/assets/alien.png | Bin 246 -> 419 bytes .../PixelPerfectCollision/source/Alien.hx | 73 +++++ .../source/DemoSprite.hx | 43 +++ .../PixelPerfectCollision/source/PlayState.hx | 288 +++++++++--------- .../PixelPerfectCollision/source/Player.hx | 33 ++ 6 files changed, 291 insertions(+), 148 deletions(-) create mode 100644 Performance/PixelPerfectCollision/source/Alien.hx create mode 100644 Performance/PixelPerfectCollision/source/DemoSprite.hx create mode 100644 Performance/PixelPerfectCollision/source/Player.hx diff --git a/Performance/PixelPerfectCollision/Project.xml b/Performance/PixelPerfectCollision/Project.xml index ddb1fcd3e..faa24f06b 100644 --- a/Performance/PixelPerfectCollision/Project.xml +++ b/Performance/PixelPerfectCollision/Project.xml @@ -16,7 +16,7 @@ - + diff --git a/Performance/PixelPerfectCollision/assets/alien.png b/Performance/PixelPerfectCollision/assets/alien.png index 514d1d081dcc45883f82c46ddd0b00c7c0b98e0e..b0f2b9b38abb868cbef26943c6b2756d8cbdbf24 100644 GIT binary patch literal 419 zcmV;U0bKrxP)AHIP00001b5ch_0Itp) z=>Px$T}ebiR9J=8R@)K7APmF3PLx?PW@lj~`cvl!XJZ*dY4w%ZNCxqwvMGVxq9t}xHjyROA~r_s=A-5@S|fJxA1V0<-{a5+XnaO}@8El! zGiQ=kxE7Drf7HRANl1P-dL|+H9eBl2XMPzIs#L|cL2BJ9dMffbcL=MJfdl}L09OC^B>W4)s>EbQ4XqADtK}d zq$6OIgKF_ZKx)&=-C!92jN@uAeXoXPfJaCA{tIXmxT7y4&?az2tvAwly>zJe3m5BpW*3t11})2!qdeuq~g|; zNsN346gZgs|JPTgaWOG(mt3rw>ngZJrstx;Qidq@sSKNvm1Xz?^ZEEc{^61}WHc6j zC93e!o#FA^N6Q^Q^)kipd3d#8-KozP%U4EpU)yzDo@YUX@f(N9iFM&`R0~b=vbb)q m5m1_; + var aliens:FlxTypedGroup; // the player ship var player:Player; @@ -40,6 +53,9 @@ class PlayState extends FlxState // number of collisions at any given time var numCollisions:Int = 0; + // number of collisions at any given time + var numChecks:Int = 0; + // setting this to 255 means two object will collide only if totally opaque var alphaTolerance:Int = 1; @@ -49,27 +65,40 @@ class PlayState extends FlxState // to track fps var fps:FPS; - // wether the objects should rotate - var rotate(default, set):Bool = true; + // whether the objects should rotate + var rotate:Bool = false; + // whether the objects should be scaled + var scale:Bool = false; + // whether the key instructions will show + var showFullInfo = true; override public function create():Void { super.create(); + FlxG.camera.bgColor = FlxG.stage.color; // the group containing all the objects - add(aliens = new FlxTypedGroup()); + add(aliens = new FlxTypedGroup()); // create the player add(player = new Player()); + FlxG.camera.follow(player); + FlxG.camera.setScrollBounds(0, FlxG.width * 10, 0, FlxG.height); + FlxG.worldBounds.set(-10, -10, FlxG.camera.maxScrollX + 20, FlxG.camera.maxScrollY + 20); + + updateSpriteAngles(); + updateSpriteScales(); // add objects for more interstellar fun! for (i in 1...NUM_ALIENS) addAlien(); + // add in some text so we know what's happening - infoText = new FlxText(2, 0, 400, INFO); + infoText = new FlxText(2, 0, 400, INFO_FULL); infoText.y = FlxG.height - infoText.height; - infoText.setBorderStyle(OUTLINE); + infoText.setBorderStyle(OUTLINE, FlxColor.BLACK); + infoText.scrollFactor.x = 0; add(infoText); // just need this to get the fps, so we display it outside view range @@ -77,9 +106,6 @@ class PlayState extends FlxState // makes low fps less noticable FlxG.fixedTimestep = false; - - // don't need the cursor - FlxG.mouse.visible = false; } /** @@ -87,35 +113,20 @@ class PlayState extends FlxState */ function addAlien():FlxSprite { - var alien = aliens.recycle(FlxSprite); - alien.loadGraphic("assets/alien.png", true); // load graphics from asset - alien.animation.add("dance", [0, 1, 0, 2], FlxG.random.int(6, 10)); // set dance dance interstellar animation - alien.animation.play("dance"); // dance! - randomize(alien); // set position, angle and alpha to random values - return alien; - } - - /** - * Randomize position, angle and alpha of `obj`. - */ - function randomize(obj:FlxSprite):FlxSprite - { - // The start position of the alien is offscreen on a circle - var point = getRandomCirclePos(); - obj.setPosition(point.x, point.y); - point.put(); // recycle point - - var destX = FlxG.random.int(0, Std.int(FlxG.width - obj.width)); - var destY = FlxG.random.int(0, Std.int(FlxG.height - obj.height)); - obj.alpha = FlxG.random.float(0.3, 1.0); - - // Neat tweening effect for new aliens appearing - FlxTween.tween(obj, {x: destX, y: destY}, 2, {ease: FlxEase.expoOut}); - + var alien = aliens.recycle(Alien); + alien.randomize(); + if (rotate) - randomizeRotation(obj); - - return obj; + alien.randomAngle(); + else + alien.resetAngle(); + + if (scale) + alien.randomScale(); + else + alien.resetScale(); + + return alien; } /** @@ -124,47 +135,33 @@ class PlayState extends FlxState override public function update(elapsed:Float):Void { super.update(elapsed); - + handleInput(); checkCollisions(); updateInfo(); - - player.screenWrap(); // make sure the player can't go offscreen } function handleInput():Void { - // Reset velocity to (0,0) - player.velocity.set(); - - // player movement - if (FlxG.keys.pressed.LEFT) - player.velocity.x = -PLAYER_SPEED; - if (FlxG.keys.pressed.RIGHT) - player.velocity.x = PLAYER_SPEED; - if (FlxG.keys.pressed.UP) - player.velocity.y = -PLAYER_SPEED; - if (FlxG.keys.pressed.DOWN) - player.velocity.y = PLAYER_SPEED; - // toggle rotation if (FlxG.keys.justReleased.SPACE) { rotate = !rotate; - rotate ? randomizeRotation(player) : resetRotation(player); + updateSpriteAngles(); + } + + // toggle scale + if (FlxG.keys.justReleased.T) + { + scale = !scale; + updateSpriteScales(); } // randomize if (FlxG.keys.justReleased.R) { - for (obj in aliens) - { - // Don't randomize the player's position - if (obj != player) - { - randomize(obj); - } - } + for (a in aliens) + a.randomize(); } // increment/decrement number of objects @@ -173,6 +170,7 @@ class PlayState extends FlxState for (i in 0...3) addAlien(); } + if (FlxG.keys.justReleased.S) { for (i in 0...3) @@ -182,6 +180,13 @@ class PlayState extends FlxState alien.kill(); } } + + if (FlxG.keys.justReleased.H) + { + showFullInfo = !showFullInfo; + updateInfo(); + infoText.y = FlxG.height - infoText.height; + } // increment/decrement alpha tolerance if (FlxG.keys.pressed.D) @@ -205,105 +210,94 @@ class PlayState extends FlxState */ function checkCollisions():Void { + numChecks = 0; numCollisions = 0; - player.color = FlxColor.GREEN; + player.color = 0xFF6abe30; - for (i in 0...aliens.length) + for (alien in aliens) + alien.cameraWrap(WALL); + + for (alien1 in aliens) { - var obj1 = aliens.members[i]; var collides = false; // Only collide alive members - if (!obj1.alive) + if (!alien1.alive) continue; - - for (j in 0...aliens.length) - { - var obj2 = aliens.members[j]; - - // Only collide alive members and don't collide an object with itself - if (!obj2.alive || (i == j)) - continue; - - // this is how we check if obj1 and obj2 are colliding - if (FlxCollision.pixelPerfectCheck(obj1, obj2, alphaTolerance)) - { - collides = true; - numCollisions++; - break; - } - } - + + numChecks++; // We check collisions with the player seperately, since he's not in the group - if (FlxCollision.pixelPerfectCheck(obj1, player, alphaTolerance)) + if (FlxCollision.pixelPerfectCheck(alien1, player, alphaTolerance)) { collides = true; numCollisions++; - player.color = FlxColor.RED; + player.color = 0xFFac3232; } - - obj1.color = collides ? FlxColor.RED : FlxColor.WHITE; + else + { + for (alien2 in aliens) + { + // Only collide alive members and don't collide an object with itself + if (!alien2.alive || alien1 == alien2) + continue; + + numChecks++; + // this is how we check if obj1 and obj2 are colliding + if (FlxCollision.pixelPerfectCheck(alien1, alien2, alphaTolerance)) + { + collides = true; + numCollisions++; + break; + } + } + } + + alien1.setCollides(collides); } } - - function updateInfo():Void - { - infoText.text = INFO // + 1 for the player that is not in the group - .replace("|objects|", Std.string(aliens.countLiving() + 1)) - .replace("|alpha|", Std.string(alphaTolerance)) - .replace("|hits|", Std.string(numCollisions)) - .replace("|fps|", Std.string(fps.currentFPS)); - } - - function set_rotate(Value:Bool):Bool + + function updateSpriteAngles() { - if (Value) - aliens.forEach(randomizeRotation); + if (rotate) + { + for (alien in aliens) + alien.randomAngle(); + + player.randomAngle(); + } else - aliens.forEach(resetRotation); - - return rotate = Value; - } - - function randomizeRotation(obj:FlxSprite):Void - { - obj.angle = FlxG.random.float() * 360; - obj.angularVelocity = 100; - } - - function resetRotation(obj:FlxSprite):Void - { - obj.angle = 0; - obj.angularVelocity = 0; + { + for (alien in aliens) + alien.resetAngle(); + + player.resetAngle(); + } } - - /** - * Returns a random position on an offscreen circle to tween the aliens from / to - */ - function getRandomCirclePos():FlxPoint + + function updateSpriteScales() { - // choose a random position on our circle, from 1° to 360° - var startAngle = FlxG.random.int(1, 360); - - // make sure the radius of our circle is 200 px bigger than the game's width / height (whichever is bigger) - var startRadius = (FlxG.width > FlxG.height) ? (FlxG.height + 200) : (FlxG.width + 200); - - var coords:FlxPoint = FlxAngle.getCartesianCoords(startRadius, startAngle); - // Currently, the coords represent a circle with its center at (0,0) - let's move them! - coords.x += FlxG.width / 2; - coords.y += FlxG.height / 2; - - return coords; + if (scale) + { + for (alien in aliens) + alien.randomScale(); + } + else + { + for (alien in aliens) + alien.resetScale(); + } } -} -class Player extends FlxSprite -{ - public function new() + function updateInfo():Void { - super(); - loadGraphic("assets/ship.png"); - screenCenter(); - angularVelocity = 50; + infoText.text = (showFullInfo ? INFO_FULL : INFO_MIN) + .replace("|checks|", Std.string(numChecks)) + .replace("|hits|", Std.string(numCollisions)) + .replace("|fps|", Std.string(fps.currentFPS)) + .replace("|objects|", Std.string(aliens.countLiving() + 1))// + 1 for the player + .replace("|alpha|", Std.string(alphaTolerance)) + .replace("|rotate|", rotate ? "Disable" : "Enable") + .replace("|scale|", scale ? "Disable" : "Enable"); + } } diff --git a/Performance/PixelPerfectCollision/source/Player.hx b/Performance/PixelPerfectCollision/source/Player.hx new file mode 100644 index 000000000..c3323358d --- /dev/null +++ b/Performance/PixelPerfectCollision/source/Player.hx @@ -0,0 +1,33 @@ +import flixel.FlxG; +import flixel.FlxSprite; + +class Player extends DemoSprite +{ + // How fast the player moves + inline static var PLAYER_SPEED:Int = 75; + + public function new() + { + super(); + loadGraphic("assets/ship.png"); + screenCenter(); + x += FlxG.width; + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + // player movement + velocity.set(0, 0); + + if (FlxG.keys.pressed.LEFT) + velocity.x = -PLAYER_SPEED; + if (FlxG.keys.pressed.RIGHT) + velocity.x = PLAYER_SPEED; + if (FlxG.keys.pressed.UP) + velocity.y = -PLAYER_SPEED; + if (FlxG.keys.pressed.DOWN) + velocity.y = PLAYER_SPEED; + } +} \ No newline at end of file From 398877e085a90a734efb341cb10cb3e6701ea07d Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 19:29:07 -0600 Subject: [PATCH 3/8] debug drawing --- .../source/DemoSprite.hx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Performance/PixelPerfectCollision/source/DemoSprite.hx b/Performance/PixelPerfectCollision/source/DemoSprite.hx index 84cec8fcb..b68d63325 100644 --- a/Performance/PixelPerfectCollision/source/DemoSprite.hx +++ b/Performance/PixelPerfectCollision/source/DemoSprite.hx @@ -40,4 +40,27 @@ class DemoSprite extends FlxSprite scale.x = FlxG.random.float(0.5, 2.0); scale.y = scale.x; } + + #if debug + override function draw() + { + // For debugging + // drawDebugScreenBounds(); + + super.draw(); + } + + function drawDebugScreenBounds() + { + for (camera in cameras) + { + var rect = getScreenBounds(camera); + var gfx = beginDrawDebug(camera); + // fill static graphics object with square shape + gfx.lineStyle(1, 0x0000ff, 0.5); + gfx.drawRect(rect.x, rect.y, rect.width, rect.height); + endDrawDebug(camera); + } + } + #end } \ No newline at end of file From 6f81383ffd1dc4a9e3e723f2452bfcce1dd83406 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 19:29:19 -0600 Subject: [PATCH 4/8] disable origin --- Performance/PixelPerfectCollision/source/Alien.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Performance/PixelPerfectCollision/source/Alien.hx b/Performance/PixelPerfectCollision/source/Alien.hx index 5c80035ad..7aa34e959 100644 --- a/Performance/PixelPerfectCollision/source/Alien.hx +++ b/Performance/PixelPerfectCollision/source/Alien.hx @@ -48,7 +48,7 @@ class Alien extends DemoSprite super.randomAngle(); var ran = FlxG.random; offset.set(ran.float(0, width), ran.float(0, height)); - origin.set(ran.float(0, width), ran.float(0, height)); + // origin.set(ran.float(0, width), ran.float(0, height)); } override function resetAngle() From bda9472829b80413f9744affdce5b788f03f7d75 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 19:29:37 -0600 Subject: [PATCH 5/8] delete TestState --- .../PixelPerfectCollision/source/TestState.hx | 154 ------------------ 1 file changed, 154 deletions(-) delete mode 100644 Performance/PixelPerfectCollision/source/TestState.hx diff --git a/Performance/PixelPerfectCollision/source/TestState.hx b/Performance/PixelPerfectCollision/source/TestState.hx deleted file mode 100644 index 00813d5d2..000000000 --- a/Performance/PixelPerfectCollision/source/TestState.hx +++ /dev/null @@ -1,154 +0,0 @@ -package; - -import flixel.math.FlxMath; -import flixel.text.FlxText; -import flixel.FlxG; -import flixel.FlxObject; -import flixel.FlxSprite; -import flixel.FlxState; -import flixel.math.FlxAngle; -import flixel.math.FlxRect; - -using flixel.util.FlxSpriteUtil; - -class TestState extends FlxState -{ - var player:Player; - - override public function create():Void - { - super.create(); - - // create the player - add(player = new Player()); - - // don't need the cursor - FlxG.mouse.visible = false; - - var field = new FlxText(); - field.text - = "Mouse: move\n" - + "Click: toggle auto rotate\n" - + "Arrows: move offset\n" - + "SHIFT + Arrows: change scale\n" - + "ALT + Arrows: move origin\n" - + "Q/E: rotate\n" - + "Enter: reset"; - field.y = FlxG.height - field.height; - field.setBorderStyle(OUTLINE); - #if debug field.ignoreDrawDebug = true; #end - add(field); - - #if debug FlxG.debugger.drawDebug = true; #end - } -} - -private class Player extends FlxSprite -{ - var rotatedRect = new FlxObject(); - var offsetRect = new FlxObject(); - var pivot = new FlxObject(0, 0, 2, 2); - var rect = new FlxRect(); - - public function new() - { - super(); - makeGraphic(50, 50, 0xFFffffff); - screenCenter(); - rotatedRect.immovable = true; - offsetRect.immovable = true; - pivot.immovable = true; - - #if debug - // ignoreDrawDebug = true; - #end - } - - override function update(elapsed:Float) - { - super.update(elapsed); - - x = FlxG.mouse.x; - y = FlxG.mouse.y; - - var left = FlxG.keys.anyPressed([LEFT , A]); - var right = FlxG.keys.anyPressed([RIGHT, D]); - var up = FlxG.keys.anyPressed([UP , W]); - var down = FlxG.keys.anyPressed([DOWN , S]); - - if (FlxG.keys.pressed.SHIFT) - { - if (left ) scale.x -= 0.05; - if (right) scale.x += 0.05; - if (up ) scale.y += 0.05; - if (down ) scale.y -= 0.05; - - width = frameWidth * scale.x; - height = frameHeight * scale.y; - } - else if (FlxG.keys.pressed.ALT) - { - if (left ) origin.x--; - if (right) origin.x++; - if (up ) origin.y--; - if (down ) origin.y++; - } - else - { - // move opposite for offset - if (left ) offset.x++; - if (right) offset.x--; - if (up ) offset.y++; - if (down ) offset.y--; - } - - if (FlxG.keys.pressed.Q) angle -= 2; - if (FlxG.keys.pressed.E) angle += 2; - if (FlxG.keys.pressed.ENTER) - { - scale.set(1, 1); - offset.set(0, 0); - updateHitbox(); - centerOrigin(); - angle = 0; - angularVelocity = 0; - } - - var wheel = FlxG.mouse.wheel; - if (wheel != 0) - { - var scroll = FlxMath.bound(scrollFactor.x + wheel / 50, 1/50, 2.0); - scrollFactor.set(scroll, scroll); - trace(wheel, scroll); - } - - if (FlxG.mouse.justPressed) - angularVelocity = angularVelocity == 0 ? 50 : 0; - - offsetRect.update(elapsed); - offsetRect.width = scale.x * frameWidth; - offsetRect.height = scale.y * frameHeight; - offsetRect.x = x - offset.x + origin.x - origin.x * scale.x; - offsetRect.y = y - offset.y + origin.y - origin.y * scale.y; - - pivot.update(elapsed); - pivot.x = x + origin.x - offset.x - pivot.width / 2; - pivot.y = y + origin.y - offset.y - pivot.height / 2; - - rotatedRect.update(elapsed); - rect = calcRotatedGraphicBounds(rect); - rotatedRect.x = rect.x; - rotatedRect.y = rect.y; - rotatedRect.width = rect.width; - rotatedRect.height = rect.height; - } - - override function draw() - { - super.draw(); - - rotatedRect.draw(); - offsetRect.draw(); - pivot.draw(); - } -} From 497f014ebbbd27d7db940e201d3a3fad9ba3bb02 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 19:33:32 -0600 Subject: [PATCH 6/8] remove whoopsies --- .../GamepadTest/.vscode copy/extensions.json | 5 --- Input/GamepadTest/.vscode copy/launch.json | 28 --------------- Input/GamepadTest/.vscode copy/settings.json | 5 --- Input/GamepadTest/.vscode copy/tasks.json | 35 ------------------- .../PixelPerfectCollision/source/Main.hx | 1 - 5 files changed, 74 deletions(-) delete mode 100644 Input/GamepadTest/.vscode copy/extensions.json delete mode 100644 Input/GamepadTest/.vscode copy/launch.json delete mode 100644 Input/GamepadTest/.vscode copy/settings.json delete mode 100644 Input/GamepadTest/.vscode copy/tasks.json diff --git a/Input/GamepadTest/.vscode copy/extensions.json b/Input/GamepadTest/.vscode copy/extensions.json deleted file mode 100644 index 419972a49..000000000 --- a/Input/GamepadTest/.vscode copy/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "openfl.lime-vscode-extension" - ] -} diff --git a/Input/GamepadTest/.vscode copy/launch.json b/Input/GamepadTest/.vscode copy/launch.json deleted file mode 100644 index 4552f8861..000000000 --- a/Input/GamepadTest/.vscode copy/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "HTML5", - "type": "chrome", - "request": "launch", - "url": "http://127.0.0.1:3001", - "sourceMaps": true, - "webRoot": "${workspaceFolder}", - "preLaunchTask": "debug: html5" - }, - { - "name": "Flash", - "type": "fdb", - "request": "launch", - "preLaunchTask": "debug: flash", - "program": "${workspaceRoot}/export/flash/bin/GamepadTest.swf" - }, - { - "name": "Neko", - "type": "fdb", - "request": "launch", - "preLaunchTask": "debug: neko", - "program": "${workspaceRoot}/export/neko/bin/GamepadTest.app" - } - ] -} diff --git a/Input/GamepadTest/.vscode copy/settings.json b/Input/GamepadTest/.vscode copy/settings.json deleted file mode 100644 index 1dd75b373..000000000 --- a/Input/GamepadTest/.vscode copy/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "search.exclude": { - "export/**/*.hx": true - } -} diff --git a/Input/GamepadTest/.vscode copy/tasks.json b/Input/GamepadTest/.vscode copy/tasks.json deleted file mode 100644 index e87cb1916..000000000 --- a/Input/GamepadTest/.vscode copy/tasks.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "debug: html5", - "command": "haxelib", - "args": [ "run", "lime", "build", "html5", "-debug" ], - "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "label": "debug: flash", - "command": "haxelib", - "args": [ "run", "lime", "build", "flash", "-debug", "-D fdb" ], - "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "label": "debug: neko", - "command": "haxelib", - "args": [ "run", "lime", "build", "neko" ], - "problemMatcher": [ "$haxe-absolute", "$haxe", "$haxe-error", "$haxe-trace" ], - "group": { - "kind": "build", - "isDefault": true - } - } - ] -} \ No newline at end of file diff --git a/Performance/PixelPerfectCollision/source/Main.hx b/Performance/PixelPerfectCollision/source/Main.hx index c728fdfef..e6ccdaa62 100644 --- a/Performance/PixelPerfectCollision/source/Main.hx +++ b/Performance/PixelPerfectCollision/source/Main.hx @@ -9,6 +9,5 @@ class Main extends Sprite { super(); addChild(new FlxGame(320, 200, PlayState)); - // addChild(new FlxGame(320, 200, TestState)); } } From 7ca63b415b2d74f9f77c1be338b2e85b0f67cff8 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 22:00:56 -0600 Subject: [PATCH 7/8] remove offset/origin stuff --- .../PixelPerfectCollision/source/Alien.hx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Performance/PixelPerfectCollision/source/Alien.hx b/Performance/PixelPerfectCollision/source/Alien.hx index 7aa34e959..0cab584dc 100644 --- a/Performance/PixelPerfectCollision/source/Alien.hx +++ b/Performance/PixelPerfectCollision/source/Alien.hx @@ -42,21 +42,7 @@ class Alien extends DemoSprite y = (y < FlxG.height / 2) ? -20 : FlxG.height + 20; FlxTween.tween(this, {y: toY}, 1.0, { ease: FlxEase.expoOut, startDelay: ran.float() * 0.5 }); } - - override function randomAngle() - { - super.randomAngle(); - var ran = FlxG.random; - offset.set(ran.float(0, width), ran.float(0, height)); - // origin.set(ran.float(0, width), ran.float(0, height)); - } - - override function resetAngle() - { - super.resetAngle(); - offset.set(); - centerOrigin(); - } + /** * Switches the between the red/white color to show whether an overlap is occurring. * @param value From 1b47d0018be66737ba5137f4376766f4f352080e Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 20 Jan 2022 22:01:51 -0600 Subject: [PATCH 8/8] remove debug info --- Performance/PixelPerfectCollision/source/PlayState.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Performance/PixelPerfectCollision/source/PlayState.hx b/Performance/PixelPerfectCollision/source/PlayState.hx index 12b4d8d52..2b2ab1d46 100644 --- a/Performance/PixelPerfectCollision/source/PlayState.hx +++ b/Performance/PixelPerfectCollision/source/PlayState.hx @@ -27,8 +27,8 @@ class PlayState extends FlxState inline static var NUM_ALIENS:Int = 50; inline static var INFO_FULL:String - = "Checks: |checks|\n" - + "Collisions: |hits|\n" + = "Collisions: |hits|\n" + #if debug + "Checks: |checks|\n" #end + "FPS: |fps|\n\n" + "[W/S] Objects: |objects|\n" + "[A/D] Alpha tolerance: |alpha|\n" @@ -40,7 +40,7 @@ class PlayState extends FlxState inline static var INFO_MIN:String = "Objects: |objects|\n" - + "Checks: |checks|\n" + #if debug + "Checks: |checks|\n" #end + "Collisions: |hits|\n" + "FPS: |fps|";