From 5a9edb7d4c9315be70d26fe9c223964bc2bc8f90 Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 12:49:03 -0400 Subject: [PATCH 01/14] Change capitalization of function arguments --- flixel/addons/weapon/FlxWeapon.hx | 76 +++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 8e2a7099..bb3c4d50 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -12,14 +12,14 @@ import flixel.math.FlxPoint; import flixel.math.FlxRandom; import flixel.math.FlxRect; import flixel.math.FlxVelocity; +import flixel.tile.FlxTilemap; +import flixel.util.helpers.FlxBounds; +import flixel.util.helpers.FlxRange; #if (flixel >= "5.3.0") import flixel.sound.FlxSound; #else import flixel.system.FlxSound; #end -import flixel.tile.FlxTilemap; -import flixel.util.helpers.FlxBounds; -import flixel.util.helpers.FlxRange; /** * A Weapon can only fire 1 type of bullet. But it can fire many of them at once (in different directions if needed) via createBulletPattern @@ -171,10 +171,10 @@ class FlxTypedWeapon /** * Internal function that handles the actual firing of the bullets * - * @param Mode Mode to use for firing the bullet + * @param mode Mode to use for firing the bullet * @return True if a bullet was fired or false if one wasn't available. The bullet last fired is stored in FlxWeapon.prevBullet */ - function runFire(Mode:FlxWeaponFireMode):Bool + function runFire(mode:FlxWeaponFireMode):Bool { if (fireRate > 0 && FlxG.game.ticks < nextFire) { @@ -235,7 +235,7 @@ class FlxTypedWeapon currentBullet.elasticity = bulletElasticity; currentBullet.lifespan = FlxG.random.float(bulletLifeSpan.min, bulletLifeSpan.max); - switch (Mode) + switch (mode) { case FIRE_AT_POSITION(x, y): internalFireAtPoint(currentBullet, FlxPoint.weak(x, y)); @@ -331,12 +331,12 @@ class FlxTypedWeapon /** * Fires a bullet (if one is available) at the FlxTouch coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. * - * @param Touch The FlxTouch object to fire at, if null use the first available one + * @param touch The FlxTouch object to fire at, if null use the first available one * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. */ - public function fireAtTouch(?Touch:FlxTouch):Bool + public function fireAtTouch(?touch:FlxTouch):Bool { - var touch = Touch == null ? FlxG.touches.getFirst() : Touch; + var touch = touch == null ? FlxG.touches.getFirst() : touch; if (touch != null) return runFire(FIRE_AT_TOUCH(touch)); else @@ -347,24 +347,24 @@ class FlxTypedWeapon /** * Fires a bullet (if one is available) at the given x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. * - * @param X The x coordinate (in game world pixels) to fire at - * @param Y The y coordinate (in game world pixels) to fire at + * @param x The x coordinate (in game world pixels) to fire at + * @param y The y coordinate (in game world pixels) to fire at * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. */ - public inline function fireAtPosition(X:Int, Y:Int):Bool + public inline function fireAtPosition(x:Int, y:Int):Bool { - return runFire(FIRE_AT_POSITION(X, Y)); + return runFire(FIRE_AT_POSITION(x, y)); } /** * Fires a bullet (if one is available) at the given targets x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. * - * @param Target The FlxSprite you wish to fire the bullet at + * @param target The FlxSprite you wish to fire the bullet at * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. */ - public inline function fireAtTarget(Target:FlxSprite):Bool + public inline function fireAtTarget(target:FlxSprite):Bool { - return runFire(FIRE_AT_TARGET(Target)); + return runFire(FIRE_AT_TARGET(target)); } /** @@ -391,53 +391,53 @@ class FlxTypedWeapon /** * Sets a pre-fire callback function and sound. These are played immediately before the bullet is fired. * - * @param Callback The function to call - * @param Sound A FlxSound to play + * @param callback The function to call + * @param sound A FlxSound to play */ - public function setPreFireCallback(?Callback:Void->Void, ?Sound:FlxSound):Void + public function setPreFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { - onPreFireCallback = Callback; - onPreFireSound = Sound; + onPreFireCallback = callback; + onPreFireSound = sound; } /** * Sets a post-fire callback function and sound. These are played immediately after the bullet is fired. * - * @param Callback The function to call - * @param Sound An FlxSound to play + * @param callback The function to call + * @param sound An FlxSound to play */ - public function setPostFireCallback(?Callback:Void->Void, ?Sound:FlxSound):Void + public function setPostFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { - onPostFireCallback = Callback; - onPostFireSound = Sound; + onPostFireCallback = callback; + onPostFireSound = sound; } /** * Checks to see if the bullets are overlapping the specified object or group * - * @param ObjectOrGroup The group or object to check if bullets collide - * @param NotifyCallBack A function that will get called if a bullet overlaps an object - * @param SkipParent Don't trigger collision notifies with the parent of this object + * @param objectOrGroup The group or object to check if bullets collide + * @param notifyCallBack A function that will get called if a bullet overlaps an object + * @param skipParent Don't trigger collision notifies with the parent of this object */ - public inline function bulletsOverlap(ObjectOrGroup:FlxBasic, ?NotifyCallBack:FlxObject->FlxObject->Void, SkipParent:Bool = true):Void + public inline function bulletsOverlap(objectOrGroup:FlxBasic, ?notifyCallBack:FlxObject->FlxObject->Void, skipParent:Bool = true):Void { if (group != null && group.length > 0) { - skipParentCollision = SkipParent; - FlxG.overlap(ObjectOrGroup, group, NotifyCallBack != null ? NotifyCallBack : onBulletHit, shouldBulletHit); + skipParentCollision = skipParent; + FlxG.overlap(objectOrGroup, group, notifyCallBack != null ? notifyCallBack : onBulletHit, shouldBulletHit); } } - function shouldBulletHit(Object:FlxObject, Bullet:FlxObject):Bool + function shouldBulletHit(object:FlxObject, bullet:FlxObject):Bool { - if (parent == Object && skipParentCollision) + if (parent == object && skipParentCollision) { return false; } - if ((Object is FlxTilemap)) + if ((object is FlxTilemap)) { - return cast(Object, FlxTilemap).overlapsWithCallback(Bullet); + return cast(object, FlxTilemap).overlapsWithCallback(bullet); } else { @@ -445,9 +445,9 @@ class FlxTypedWeapon } } - function onBulletHit(Object:FlxObject, Bullet:FlxObject):Void + function onBulletHit(object:FlxObject, bullet:FlxObject):Void { - Bullet.kill(); + bullet.kill(); } function internalFireAtPoint(bullet:TBullet, point:FlxPoint):Void From 12310982509ba8faeec2140562871a7f9b0978ac Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 13:36:50 -0400 Subject: [PATCH 02/14] Clarify and update many of FlxWeapon's doc comments --- flixel/addons/weapon/FlxWeapon.hx | 117 +++++++++++++++--------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index bb3c4d50..bdfefe4a 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -22,8 +22,8 @@ import flixel.system.FlxSound; #end /** - * A Weapon can only fire 1 type of bullet. But it can fire many of them at once (in different directions if needed) via createBulletPattern - * A Player could fire multiple Weapons at the same time however, if you need to layer them up + * A Weapon can only fire 1 type of bullet. + * A Player could fire multiple Weapons at the same time, however, if you need to layer them up. * * @version 1.3 - October 9th 2011 * @link http://www.photonstorm.com @@ -55,47 +55,50 @@ class FlxTypedWeapon public static inline var BULLET_SOUTH_WEST:Int = 135; /** - * Internal name for this weapon (i.e. "pulse rifle") + * Internal name for this weapon (e.g. `"pulse rifle"`). */ public var name:String; /** - * The FlxGroup into which all the bullets for this weapon are drawn. This should be added to your display and collision checked against it. + * The `FlxGroup` from which all the bullets for this weapon are drawn. This should be added to your display and collision-checked against it. */ public var group(default, null):FlxTypedGroup; - // Internal variables, use with caution + /** + * The game tick after which the weapon will be able to fire. Only used if `fireRate > 0`. + * Internal variable; use with caution. + */ public var nextFire:Int = 0; /** - * The delay in milliseconds (ms) between which each bullet is fired, set to zero to clear. By default there is no rate, as it can be controlled by FlxControl.setFireButton. - * However if you are firing using the mouse you may wish to set a firing rate. + * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. */ public var fireRate:Int = 0; /** - * When a bullet goes outside of this bounds it will be automatically killed, freeing it up for firing again. + * When a bullet goes outside of these bounds, it will be automatically killed, freeing it up for firing again. * TODO - Needs testing with a scrolling map (when not using single screen display) */ public var bounds:FlxRect; /** - * Only accessible when fireFrom is "PARENT" + * The parent sprite of this weapon. Only accessible when `fireFrom == PARENT`. */ public var parent(default, null):FlxSprite; /** - * If true, when fired the bullet direction is based on parent sprites facing value (up/down/left/right) + * Whether to fire bullets in the direction the `parent` is facing (e.g. `UP`, `DOWN`, `LEFT`, `RIGHT`). Used only when `fireFrom == PARENT`. */ public var useParentDirection:Bool; /** - * If parent is null, the Weapon will fire from a fixed x/y position on the screen, like in the game Missile Command. + * If `parent == null`, the Weapon will fire from a fixed position on the screen, like in the game Missile Command. */ public var firePosition(default, null):FlxBounds; /** - * When the bullet is fired if you need to offset it on the x/y axis, for example to line it up with the "nose" of a space ship, set the amount here (positive or negative) + * A value to use to offset a bullet's position when it is fired. + * Can be used to, for example, line a bullet up with the "nose" of a space ship. */ public var positionOffset(default, null):FlxPoint; @@ -104,23 +107,23 @@ class FlxTypedWeapon /** * The lifespan of the bullet, given in seconds. - * The bullet will be killed once it passes this lifespan, if still alive and in bounds. + * The bullet will be killed once it passes this lifespan, if it is still alive and in bounds. */ public var bulletLifeSpan:FlxBounds; /** * The elasticity of the fired bullet controls how much it rebounds off collision surfaces. - * Between 0 and 1 (0 being no rebound, 1 being 100% force rebound). Set to zero to disable. + * Between 0 and 1 (0 being no rebound, 1 being 100% force rebound). Default is 0. */ public var bulletElasticity:Float = 0; /** - * Auto set the bullet angle when firing, such that it faces towards the target + * Whether to automatically set the bullet's angle when firing, such that it faces towards the target. */ public var rotateBulletTowardsTarget:Bool = false; /** - * A reference to the Bullet that was last fired + * A reference to the bullet that was last fired. */ public var currentBullet:TBullet; @@ -133,7 +136,7 @@ class FlxTypedWeapon public var onPostFireSound:FlxSound; /** - * The factory function to create a bullet + * The factory function used to create new bullets. */ var bulletFactory:FlxTypedWeapon->TBullet; @@ -142,19 +145,19 @@ class FlxTypedWeapon var skipParentCollision:Bool; /** - * When the bullet is fired if you need to offset it's angle from the parent angle, for example if the bullet sprite is angle offsetted, only used when useParentAngle is true + * A value to use to offset a bullet's angle from the parent's angle when it is fired. Used only if `fireFrom == PARENT` and `fireFrom.useParentAngle == true`. */ var angleOffset:Float = 0; /** - * Creates the FlxWeapon class which will fire your bullets. + * Creates an `FlxWeapon` instance which can fire bullets. * You should call one of the makeBullet functions to visually create the bullets. * Then either use setDirection with fire() or one of the fireAt functions to launch them. * - * @param name The name of your weapon (i.e. "laser" or "shotgun"). For your internal reference really, but could be displayed in-game. - * @param bulletFactory FlxWeapon uses this factory function to actually create a bullet - * @param fireFrom enum that describes the weapon firing position, for Example Parent, Position. - * @param speedMode enum that describes the bullets speed mode, for Example Velocity, Acceleration. + * @param name The name of the weapon (e.g. `"laser"`, `"shotgun"`). For your internal reference really, but could be displayed in-game too. + * @param bulletFactory The factory function used to create new bullets. + * @param fireFrom The weapon's firing position (i.e., `PARENT`, `POSITION`). + * @param speedMode The speed mode for the bullets (i.e., `SPEED`, `ACCELERATION`). */ public function new(name:String, bulletFactory:FlxTypedWeapon->TBullet, fireFrom:FlxWeaponFireFrom, speedMode:FlxWeaponSpeedMode) { @@ -169,10 +172,10 @@ class FlxTypedWeapon } /** - * Internal function that handles the actual firing of the bullets + * Internal function that handles the actual firing of the bullets. * - * @param mode Mode to use for firing the bullet - * @return True if a bullet was fired or false if one wasn't available. The bullet last fired is stored in FlxWeapon.prevBullet + * @param mode The mode to use for firing the bullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ function runFire(mode:FlxWeaponFireMode):Bool { @@ -285,12 +288,12 @@ class FlxTypedWeapon } /** - * Calculates the new position for a point rotated around another point + * Calculates the new position for a point rotated around another point. * - * @param point The to be rotated point - * @param origin The to be rotated around point. usually the origin of the parent flxsprite - * @param angle the current angle from of the origin. usually the parent angle. - * @return The new rotated Point + * @param point The point to be rotated. + * @param origin The point around which to be rotated. Usually the origin of the `parent`. + * @param angle The current angle from of the origin, in degrees. Usually the `parent`'s angle. + * @return The new rotated point. */ public function rotatePoints(point:FlxPoint, origin:FlxPoint, angle:Float):FlxPoint { @@ -306,9 +309,9 @@ class FlxTypedWeapon } /** - * Fires a bullet (if one is available) based on the facing (UP/DOWN/LEFT/RIGHT) of the Weapons parent + * Fires a bullet (if one is available) based on the `facing` variable of the weapon's `parent`. * - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromParentFacing(angleNoise:FlxBounds):Bool { @@ -317,9 +320,9 @@ class FlxTypedWeapon #if FLX_MOUSE /** - * Fires a bullet (if one is available) at the mouse coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. + * Fires a bullet (if one is available) at the mouse coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. * - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtMouse():Bool { @@ -329,10 +332,10 @@ class FlxTypedWeapon #if FLX_TOUCH /** - * Fires a bullet (if one is available) at the FlxTouch coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. + * Fires a bullet (if one is available) at the `FlxTouch` coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param touch The FlxTouch object to fire at, if null use the first available one - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @param touch The `FlxTouch` object to fire at. If `null`, uses the first available one. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public function fireAtTouch(?touch:FlxTouch):Bool { @@ -345,11 +348,11 @@ class FlxTypedWeapon #end /** - * Fires a bullet (if one is available) at the given x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. + * Fires a bullet (if one is available) at the given x/y coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param x The x coordinate (in game world pixels) to fire at - * @param y The y coordinate (in game world pixels) to fire at - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @param x The x coordinate (in game world pixels) to fire at. + * @param y The y coordinate (in game world pixels) to fire at. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtPosition(x:Int, y:Int):Bool { @@ -357,10 +360,10 @@ class FlxTypedWeapon } /** - * Fires a bullet (if one is available) at the given targets x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate. + * Fires a bullet (if one is available) at the given target's position, using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param target The FlxSprite you wish to fire the bullet at - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @param target The `FlxSprite` to fire the bullet at. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtTarget(target:FlxSprite):Bool { @@ -368,10 +371,10 @@ class FlxTypedWeapon } /** - * Fires a bullet (if one is available) based on the given angle + * Fires a bullet (if one is available) based on the given angle. * * @param angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromAngle(angle:FlxBounds):Bool { @@ -379,9 +382,9 @@ class FlxTypedWeapon } /** - * Fires a bullet (if one is available) based on the angle of the Weapons parent + * Fires a bullet (if one is available) based on the angle of the weapon's `parent`. * - * @return True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the bullet fired is stored in `currentBullet`. */ public inline function fireFromParentAngle(angle:FlxBounds):Bool { @@ -391,8 +394,8 @@ class FlxTypedWeapon /** * Sets a pre-fire callback function and sound. These are played immediately before the bullet is fired. * - * @param callback The function to call - * @param sound A FlxSound to play + * @param callback The function to call before a bullet is fired. + * @param sound An `FlxSound` to play before a bullet is fired. */ public function setPreFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { @@ -403,8 +406,8 @@ class FlxTypedWeapon /** * Sets a post-fire callback function and sound. These are played immediately after the bullet is fired. * - * @param callback The function to call - * @param sound An FlxSound to play + * @param callback The function to call after a bullet is fired. + * @param sound An `FlxSound` to play after a bullet is fired. */ public function setPostFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { @@ -413,11 +416,11 @@ class FlxTypedWeapon } /** - * Checks to see if the bullets are overlapping the specified object or group + * Checks whether the bullets are overlapping the specified object or group. * - * @param objectOrGroup The group or object to check if bullets collide - * @param notifyCallBack A function that will get called if a bullet overlaps an object - * @param skipParent Don't trigger collision notifies with the parent of this object + * @param objectOrGroup The object or group to check against. + * @param notifyCallBack A function that will get called if a bullet overlaps the object or group. + * @param skipParent Whether to ignore collisions with the parent of this weapon. */ public inline function bulletsOverlap(objectOrGroup:FlxBasic, ?notifyCallBack:FlxObject->FlxObject->Void, skipParent:Bool = true):Void { From 4ddd7858679ebcdb9600f6facca97f38c068bc30 Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 14:14:27 -0400 Subject: [PATCH 03/14] Remove unused fields from FlxWeapon I also moved those unused fields' doc comments to `FlxWeaponFireFrom`. I'm unsure of whether GitHub renders Markdown in commit messages, so I'll find out with this. --- flixel/addons/weapon/FlxWeapon.hx | 64 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index bdfefe4a..dbf17326 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -55,7 +55,7 @@ class FlxTypedWeapon public static inline var BULLET_SOUTH_WEST:Int = 135; /** - * Internal name for this weapon (e.g. `"pulse rifle"`). + * Internal name for this weapon (e.g., `"pulse rifle"`). */ public var name:String; @@ -86,22 +86,6 @@ class FlxTypedWeapon */ public var parent(default, null):FlxSprite; - /** - * Whether to fire bullets in the direction the `parent` is facing (e.g. `UP`, `DOWN`, `LEFT`, `RIGHT`). Used only when `fireFrom == PARENT`. - */ - public var useParentDirection:Bool; - - /** - * If `parent == null`, the Weapon will fire from a fixed position on the screen, like in the game Missile Command. - */ - public var firePosition(default, null):FlxBounds; - - /** - * A value to use to offset a bullet's position when it is fired. - * Can be used to, for example, line a bullet up with the "nose" of a space ship. - */ - public var positionOffset(default, null):FlxPoint; - public var fireFrom(default, set):FlxWeaponFireFrom; public var speedMode:FlxWeaponSpeedMode; @@ -140,21 +124,18 @@ class FlxTypedWeapon */ var bulletFactory:FlxTypedWeapon->TBullet; - var lastFired:Int = 0; - var skipParentCollision:Bool; /** - * A value to use to offset a bullet's angle from the parent's angle when it is fired. Used only if `fireFrom == PARENT` and `fireFrom.useParentAngle == true`. + * A value to use to offset a bullet's angle from the `parent`'s angle when it is fired. Used only if `fireFrom == PARENT` and `fireFrom.useParentAngle == true`. */ var angleOffset:Float = 0; /** * Creates an `FlxWeapon` instance which can fire bullets. - * You should call one of the makeBullet functions to visually create the bullets. - * Then either use setDirection with fire() or one of the fireAt functions to launch them. + * Use one of the `fireFrom...()` or `fireAt...()` functions to fire bullets. * - * @param name The name of the weapon (e.g. `"laser"`, `"shotgun"`). For your internal reference really, but could be displayed in-game too. + * @param name The name of the weapon (e.g., `"laser"`, `"shotgun"`). For your internal reference really, but could be displayed in-game too. * @param bulletFactory The factory function used to create new bullets. * @param fireFrom The weapon's firing position (i.e., `PARENT`, `POSITION`). * @param speedMode The speed mode for the bullets (i.e., `SPEED`, `ACCELERATION`). @@ -196,7 +177,6 @@ class FlxTypedWeapon } #end - lastFired = FlxG.game.ticks; nextFire = FlxG.game.ticks + Std.int(fireRate / FlxG.timeScale); // Get a free bullet from the pool @@ -207,20 +187,19 @@ class FlxTypedWeapon } // Clear any velocity that may have been previously set from the pool - currentBullet.velocity.x = 0; // TODO is this really necessary? - currentBullet.velocity.y = 0; + currentBullet.velocity.zero(); // TODO is this really necessary? switch (fireFrom) { - case PARENT(parent, offset, useParentDirection, angleOffset): + case PARENT(parent, offset, useParentAngle, angleOffset): // store new offset in a new variable - var actualOffset = new FlxPoint(FlxG.random.float(offset.min.x, offset.max.x), FlxG.random.float(offset.min.y, offset.max.y)); - if (useParentDirection) + var actualOffset = FlxPoint.get(FlxG.random.float(offset.min.x, offset.max.x), FlxG.random.float(offset.min.y, offset.max.y)); + if (useParentAngle) { // rotate actual offset around parent origin using the parent angle - actualOffset = rotatePoints(actualOffset, parent.origin, parent.angle); + rotatePoints(actualOffset, parent.origin, parent.angle, actualOffset); - // reposition offset to have it's origin at the new returned point + // reposition offset to have its origin at the new returned point actualOffset.subtract(currentBullet.width / 2, currentBullet.height / 2); actualOffset.subtract(parent.offset.x, parent.offset.y); } @@ -228,6 +207,8 @@ class FlxTypedWeapon currentBullet.last.x = currentBullet.x = parent.x + actualOffset.x; currentBullet.last.y = currentBullet.y = parent.y + actualOffset.y; + actualOffset.put(); + case POSITION(position): currentBullet.last.x = currentBullet.x = FlxG.random.float(position.min.x, position.max.x); currentBullet.last.y = currentBullet.y = FlxG.random.float(position.min.y, position.max.y); @@ -293,11 +274,15 @@ class FlxTypedWeapon * @param point The point to be rotated. * @param origin The point around which to be rotated. Usually the origin of the `parent`. * @param angle The current angle from of the origin, in degrees. Usually the `parent`'s angle. + * @param returnedPoint An optional point to reuse instead of getting another from the pool. * @return The new rotated point. */ - public function rotatePoints(point:FlxPoint, origin:FlxPoint, angle:Float):FlxPoint + public function rotatePoints(point:FlxPoint, origin:FlxPoint, angle:Float, ?returnedPoint:FlxPoint):FlxPoint { - var returnedPoint:FlxPoint = FlxPoint.weak(); + if (returnedPoint == null) + { + returnedPoint = FlxPoint.weak(); + } var inBetweenAngle:Float = origin.degreesTo(point); inBetweenAngle = angle + inBetweenAngle; @@ -384,7 +369,7 @@ class FlxTypedWeapon /** * Fires a bullet (if one is available) based on the angle of the weapon's `parent`. * - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the bullet fired is stored in `currentBullet`. + * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromParentAngle(angle:FlxBounds):Bool { @@ -483,6 +468,7 @@ class FlxTypedWeapon var velocity = FlxVelocity.velocityFromAngle(FlxAngle.asDegrees(radians), FlxG.random.float(speed.min, speed.max)); bullet.velocity.x = velocity.x; bullet.velocity.y = velocity.y; + velocity.put(); case ACCELERATION(acceleration, maxSpeed): FlxVelocity.accelerateFromAngle(bullet, radians, FlxG.random.float(acceleration.min, acceleration.max), @@ -513,7 +499,17 @@ class FlxTypedWeapon enum FlxWeaponFireFrom { + /** + * @param parent The parent sprite of the weapon. + * @param offset A value to use to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. + * @param useParentAngle Whether to fire bullets in the direction of the `parent`'s angle. + * @param angleOffset A value to use to offset a bullet's angle from the `parent`'s angle when it is fired. + */ PARENT(parent:FlxSprite, offset:FlxBounds, ?useParentAngle:Bool, ?angleOffset:Float); + + /** + * @param position A fixed position from which to fire the weapon, like in the game Missile Command. + */ POSITION(position:FlxBounds); } From 16a4531261b801cc714cc0ee799f7f311814f65a Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 14:30:52 -0400 Subject: [PATCH 04/14] Make FlxWeapon destroyable and change fireRate's implementation --- flixel/addons/weapon/FlxWeapon.hx | 71 +++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index dbf17326..e145e87a 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -13,6 +13,7 @@ import flixel.math.FlxRandom; import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.tile.FlxTilemap; +import flixel.util.FlxDestroyUtil; import flixel.util.helpers.FlxBounds; import flixel.util.helpers.FlxRange; #if (flixel >= "5.3.0") @@ -42,7 +43,7 @@ import flixel.system.FlxSound; */ typedef FlxWeapon = FlxTypedWeapon; -class FlxTypedWeapon +class FlxTypedWeapon implements IFlxDestroyable { // Quick firing direction angle constants public static inline var BULLET_UP:Int = -90; @@ -65,15 +66,14 @@ class FlxTypedWeapon public var group(default, null):FlxTypedGroup; /** - * The game tick after which the weapon will be able to fire. Only used if `fireRate > 0`. - * Internal variable; use with caution. + * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. */ - public var nextFire:Int = 0; + public var fireRate:Int = 0; /** - * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. + * A timer used whenever the weapon is fired, with its duration set to `fireRate`. */ - public var fireRate:Int = 0; + public var fireTimer:FlxTimer; /** * When a bullet goes outside of these bounds, it will be automatically killed, freeing it up for firing again. @@ -145,6 +145,8 @@ class FlxTypedWeapon group = new FlxTypedGroup(); bounds = FlxRect.get(0, 0, FlxG.width, FlxG.height); bulletLifeSpan = new FlxBounds(0.0, 0); + fireTimer = new FlxTimer().start(); // start() needs to be called for it to be properly initialized + fireTimer.cancel(); this.name = name; this.bulletFactory = bulletFactory; @@ -160,7 +162,7 @@ class FlxTypedWeapon */ function runFire(mode:FlxWeaponFireMode):Bool { - if (fireRate > 0 && FlxG.game.ticks < nextFire) + if (fireRate > 0 && !fireTimer.finished) { return false; } @@ -177,7 +179,7 @@ class FlxTypedWeapon } #end - nextFire = FlxG.game.ticks + Std.int(fireRate / FlxG.timeScale); + fireTimer.reset(fireRate); // Get a free bullet from the pool currentBullet = group.recycle(null, bulletFactory.bind(this)); @@ -495,6 +497,59 @@ class FlxTypedWeapon } return fireFrom = v; } + + public function destroy():Void + { + name = null; + group = FlxDestroyUtil.destroy(group); + bounds = FlxDestroyUtil.put(bounds); + parent = null; // Don't destroy the parent + if (fireFrom != null) + { + switch (fireFrom) + { + case PARENT(parent, offset, useParentAngle, angleOffset): + parent = null; + if (offset != null) + { + offset.min = FlxDestroyUtil.put(offset.min); + offset.max = FlxDestroyUtil.put(offset.max); + offset = null; + } + angleOffset = null; + case POSITION(position): + if (position != null) + { + position.min = FlxDestroyUtil.put(position.min); + position.max = FlxDestroyUtil.put(position.max); + position = null; + } + } + // fireFrom = null; // Can't do this because sending null to set_fireFrom() causes an NPE + @:bypassAccessor fireFrom = null; + } + if (speedMode != null) + { + switch (speedMode) + { + case SPEED(speed): + speed = null; + case ACCELERATION(acceleration, maxSpeed): + acceleration = null; + maxSpeed = null; + } + speedMode = null; + } + bulletLifeSpan = null; + currentBullet = FlxDestroyUtil.destroy(currentBullet); + onPreFireCallback = null; + onPostFireCallback = null; + onPreFireSound = null; // TODO Should these be destroyed? + onPostFireSound = null; + bulletFactory = null; + + fireTimer = FlxDestroyUtil.destroy(fireTimer); + } } enum FlxWeaponFireFrom From d6b96ef450094d7e9529c6a3c9bd5c35a00c47fd Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 14:31:09 -0400 Subject: [PATCH 05/14] Update FlxBullet.hx --- flixel/addons/weapon/FlxBullet.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flixel/addons/weapon/FlxBullet.hx b/flixel/addons/weapon/FlxBullet.hx index 883f2cbe..85dc3b9b 100644 --- a/flixel/addons/weapon/FlxBullet.hx +++ b/flixel/addons/weapon/FlxBullet.hx @@ -4,6 +4,7 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.math.FlxMath; import flixel.math.FlxRect; +import flixel.util.FlxDestroyUtil; /** * @link http://www.photonstorm.com @@ -47,4 +48,11 @@ class FlxBullet extends FlxSprite super.update(elapsed); } + + override public function destroy():Void + { + super.destroy(); + + bounds = FlxDestroyUtil.put(bounds); + } } From 19b0f1e786f3289fb985550b2a4c240dd770b636 Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Tue, 11 Apr 2023 14:34:47 -0400 Subject: [PATCH 06/14] Add a missing import to FlxWeapon Whoopsie doopsie. --- flixel/addons/weapon/FlxWeapon.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index e145e87a..244c859a 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -14,6 +14,7 @@ import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.tile.FlxTilemap; import flixel.util.FlxDestroyUtil; +import flixel.util.FlxTimer; import flixel.util.helpers.FlxBounds; import flixel.util.helpers.FlxRange; #if (flixel >= "5.3.0") From 3f268c5dcfedf4c7742ba50280bc1975ff10a20f Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Wed, 12 Apr 2023 09:45:59 -0400 Subject: [PATCH 07/14] Update FlxWeapon.hx --- flixel/addons/weapon/FlxWeapon.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 244c859a..39bf6e79 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -180,7 +180,7 @@ class FlxTypedWeapon implements IFlxDestroyable } #end - fireTimer.reset(fireRate); + fireTimer.reset(fireRate / 1000); // Get a free bullet from the pool currentBullet = group.recycle(null, bulletFactory.bind(this)); From dd471d85bce5867e471f9e8a64b57a2e6f016b5b Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Wed, 12 Apr 2023 10:06:25 -0400 Subject: [PATCH 08/14] Clean FlxWeapon and FlxBullet imports --- flixel/addons/weapon/FlxBullet.hx | 1 - flixel/addons/weapon/FlxWeapon.hx | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/flixel/addons/weapon/FlxBullet.hx b/flixel/addons/weapon/FlxBullet.hx index 85dc3b9b..7cb4d2e6 100644 --- a/flixel/addons/weapon/FlxBullet.hx +++ b/flixel/addons/weapon/FlxBullet.hx @@ -1,6 +1,5 @@ package flixel.addons.weapon; -import flixel.FlxG; import flixel.FlxSprite; import flixel.math.FlxMath; import flixel.math.FlxRect; diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 39bf6e79..8713ffbf 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -4,24 +4,23 @@ import flixel.FlxBasic; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; -import flixel.addons.weapon.FlxWeapon.FlxTypedWeapon; import flixel.group.FlxGroup.FlxTypedGroup; -import flixel.input.touch.FlxTouch; import flixel.math.FlxAngle; import flixel.math.FlxPoint; -import flixel.math.FlxRandom; import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.tile.FlxTilemap; import flixel.util.FlxDestroyUtil; import flixel.util.FlxTimer; import flixel.util.helpers.FlxBounds; -import flixel.util.helpers.FlxRange; #if (flixel >= "5.3.0") import flixel.sound.FlxSound; #else import flixel.system.FlxSound; #end +#if FLX_TOUCH +import flixel.input.touch.FlxTouch; +#end /** * A Weapon can only fire 1 type of bullet. From 63b16f525f7d11dbdf7126cd651329bdadc328cd Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Thu, 13 Apr 2023 11:29:36 -0400 Subject: [PATCH 09/14] Reimplement removed FlxWeapon fields, and remove timer --- flixel/addons/weapon/FlxWeapon.hx | 118 ++++++++++++++++++++++-------- 1 file changed, 88 insertions(+), 30 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 8713ffbf..f1772e9b 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -11,7 +11,6 @@ import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.tile.FlxTilemap; import flixel.util.FlxDestroyUtil; -import flixel.util.FlxTimer; import flixel.util.helpers.FlxBounds; #if (flixel >= "5.3.0") import flixel.sound.FlxSound; @@ -66,14 +65,15 @@ class FlxTypedWeapon implements IFlxDestroyable public var group(default, null):FlxTypedGroup; /** - * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. + * The game tick after which the weapon will be able to fire. Only used if `fireRate > 0`. + * Internal variable; use with caution. */ - public var fireRate:Int = 0; + public var nextFire:Int = 0; /** - * A timer used whenever the weapon is fired, with its duration set to `fireRate`. + * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. */ - public var fireTimer:FlxTimer; + public var fireRate:Int = 0; /** * When a bullet goes outside of these bounds, it will be automatically killed, freeing it up for firing again. @@ -86,6 +86,29 @@ class FlxTypedWeapon implements IFlxDestroyable */ public var parent(default, null):FlxSprite; + /** + * Whether to fire bullets in the direction of the `parent`'s angle. Only accessible when `fireFrom == PARENT`. + */ + public var useParentDirection(default, set):Bool; + + /** + * A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. + * Only accessible when `fireFrom == PARENT`. + */ + @:deprecated("Use positionOffsetBounds instead") + public var positionOffset(default, null):FlxPoint; + + /** + * A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. + * Only accessible when `fireFrom == PARENT`. + */ + public var positionOffsetBounds(default, null):FlxBounds; + + /** + * A fixed position from which to fire the weapon, like in the game Missile Command. Only accessible when `fireFrom == POSITION`. + */ + public var firePosition(default, null):FlxBounds; + public var fireFrom(default, set):FlxWeaponFireFrom; public var speedMode:FlxWeaponSpeedMode; @@ -127,7 +150,7 @@ class FlxTypedWeapon implements IFlxDestroyable var skipParentCollision:Bool; /** - * A value to use to offset a bullet's angle from the `parent`'s angle when it is fired. Used only if `fireFrom == PARENT` and `fireFrom.useParentAngle == true`. + * A value used to offset a bullet's initial angle when it is fired. */ var angleOffset:Float = 0; @@ -145,8 +168,6 @@ class FlxTypedWeapon implements IFlxDestroyable group = new FlxTypedGroup(); bounds = FlxRect.get(0, 0, FlxG.width, FlxG.height); bulletLifeSpan = new FlxBounds(0.0, 0); - fireTimer = new FlxTimer().start(); // start() needs to be called for it to be properly initialized - fireTimer.cancel(); this.name = name; this.bulletFactory = bulletFactory; @@ -162,7 +183,7 @@ class FlxTypedWeapon implements IFlxDestroyable */ function runFire(mode:FlxWeaponFireMode):Bool { - if (fireRate > 0 && !fireTimer.finished) + if (fireRate > 0 && FlxG.game.ticks < nextFire) { return false; } @@ -179,7 +200,7 @@ class FlxTypedWeapon implements IFlxDestroyable } #end - fireTimer.reset(fireRate / 1000); + nextFire = FlxG.game.ticks + Std.int(fireRate / FlxG.timeScale); // Get a free bullet from the pool currentBullet = group.recycle(null, bulletFactory.bind(this)); @@ -283,7 +304,7 @@ class FlxTypedWeapon implements IFlxDestroyable { if (returnedPoint == null) { - returnedPoint = FlxPoint.weak(); + returnedPoint = FlxPoint.get(); } var inBetweenAngle:Float = origin.degreesTo(point); @@ -483,27 +504,25 @@ class FlxTypedWeapon implements IFlxDestroyable } } - inline function set_fireFrom(v:FlxWeaponFireFrom):FlxWeaponFireFrom - { - switch (v) - { - case PARENT(parent, _, _, angleOffset): - this.parent = parent; - if (angleOffset != null) - this.angleOffset = angleOffset; - - default: - parent = null; - } - return fireFrom = v; - } - public function destroy():Void { name = null; group = FlxDestroyUtil.destroy(group); bounds = FlxDestroyUtil.put(bounds); parent = null; // Don't destroy the parent + positionOffset = FlxDestroyUtil.put(positionOffset); + if (positionOffsetBounds != null) + { + positionOffsetBounds.min = FlxDestroyUtil.put(positionOffsetBounds.min); + positionOffsetBounds.max = FlxDestroyUtil.put(positionOffsetBounds.max); + positionOffsetBounds = null; + } + if (firePosition != null) + { + firePosition.min = FlxDestroyUtil.put(firePosition.min); + firePosition.max = FlxDestroyUtil.put(firePosition.max); + firePosition = null; + } if (fireFrom != null) { switch (fireFrom) @@ -544,11 +563,50 @@ class FlxTypedWeapon implements IFlxDestroyable currentBullet = FlxDestroyUtil.destroy(currentBullet); onPreFireCallback = null; onPostFireCallback = null; - onPreFireSound = null; // TODO Should these be destroyed? + onPreFireSound = null; onPostFireSound = null; bulletFactory = null; + } + + function set_useParentDirection(v:Bool):Bool + { + switch (fireFrom) + { + case PARENT(parent, offset, useParentAngle, angleOffset): + @:bypassAccessor fireFrom = PARENT(parent, offset, v, angleOffset); + default: + } + return v; + } + + function set_fireFrom(v:FlxWeaponFireFrom):FlxWeaponFireFrom + { + switch (v) + { + case PARENT(parent, offset, useParentAngle, angleOffset): + this.parent = parent; + // this.positionOffset = offset; + this.positionOffsetBounds = offset; + this.useParentDirection = useParentAngle; + if (angleOffset != null) + this.angleOffset = angleOffset; - fireTimer = FlxDestroyUtil.destroy(fireTimer); + this.firePosition = null; + + case POSITION(position): + this.firePosition = position; + + this.parent = null; + this.positionOffset = null; + this.positionOffsetBounds = null; + + default: + this.parent = null; + this.positionOffset = null; + this.positionOffsetBounds = null; + this.firePosition = null; + } + return fireFrom = v; } } @@ -556,9 +614,9 @@ enum FlxWeaponFireFrom { /** * @param parent The parent sprite of the weapon. - * @param offset A value to use to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. + * @param offset A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. * @param useParentAngle Whether to fire bullets in the direction of the `parent`'s angle. - * @param angleOffset A value to use to offset a bullet's angle from the `parent`'s angle when it is fired. + * @param angleOffset A value used to offset a bullet's angle from the `parent`'s angle when it is fired. */ PARENT(parent:FlxSprite, offset:FlxBounds, ?useParentAngle:Bool, ?angleOffset:Float); From f71cd852c0ef27193e6fa4eb24868a18eecfa184 Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Thu, 13 Apr 2023 11:39:10 -0400 Subject: [PATCH 10/14] Add a few doc comments to FlxWeapon and modify some existing ones --- flixel/addons/weapon/FlxWeapon.hx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index f1772e9b..1ef1cb29 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -32,7 +32,7 @@ import flixel.input.touch.FlxTouch; * @author Touch added by Impaler / Beeblerox * * TODO: Angled bullets - * TODO: multishot + * TODO: Multishot * TODO: Baked Rotation support for angled bullets * TODO: Bullet death styles (particle effects) * TODO: Bullet trails - blur FX style and Missile Command "draw lines" style? (could be another FX plugin) @@ -71,7 +71,7 @@ class FlxTypedWeapon implements IFlxDestroyable public var nextFire:Int = 0; /** - * The delay in milliseconds (ms) between which each bullet is fired. Default is 0, which means there is no delay. + * The delay in milliseconds (ms) between which each bullet is fired. Default is `0`, which means there is no delay. */ public var fireRate:Int = 0; @@ -120,7 +120,7 @@ class FlxTypedWeapon implements IFlxDestroyable /** * The elasticity of the fired bullet controls how much it rebounds off collision surfaces. - * Between 0 and 1 (0 being no rebound, 1 being 100% force rebound). Default is 0. + * Between `0` and `1` (`0` being no rebound, and `1` being 100% force rebound). Default is `0`. */ public var bulletElasticity:Float = 0; @@ -134,12 +134,24 @@ class FlxTypedWeapon implements IFlxDestroyable */ public var currentBullet:TBullet; - // Callbacks + /** + * A function that is called immediately before a bullet is fired. + */ public var onPreFireCallback:Void->Void; + + /** + * A function that is called immediately after a bullet is fired. + */ public var onPostFireCallback:Void->Void; - // Sounds + /** + * A sound that is played immediately before a bullet is fired. + */ public var onPreFireSound:FlxSound; + + /** + * A sound that is played immediately after a bullet is fired. + */ public var onPostFireSound:FlxSound; /** From e1b5f529bb96649706442264d58f33fbb1a610cf Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 13 Apr 2023 15:53:03 -0500 Subject: [PATCH 11/14] move re-added field to old position for clearer git diff --- flixel/addons/weapon/FlxWeapon.hx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index d24eb819..cd538794 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -87,6 +87,11 @@ class FlxTypedWeapon implements IFlxDestroyable */ public var useParentDirection(default, set):Bool; + /** + * A fixed position from which to fire the weapon, like in the game Missile Command. Only accessible when `fireFrom == POSITION`. + */ + public var firePosition(default, null):FlxBounds; + /** * A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. * Only accessible when `fireFrom == PARENT`. @@ -100,11 +105,6 @@ class FlxTypedWeapon implements IFlxDestroyable */ public var positionOffsetBounds(default, null):FlxBounds; - /** - * A fixed position from which to fire the weapon, like in the game Missile Command. Only accessible when `fireFrom == POSITION`. - */ - public var firePosition(default, null):FlxBounds; - public var fireFrom(default, set):FlxWeaponFireFrom; public var speedMode:FlxWeaponSpeedMode; From 743b536113c8b78ac91507df2481d510c53ad301 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 13 Apr 2023 16:20:08 -0500 Subject: [PATCH 12/14] doc formatting + rename var --- flixel/addons/weapon/FlxWeapon.hx | 119 +++++++++++++++++------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index cd538794..12a56eec 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -166,10 +166,11 @@ class FlxTypedWeapon implements IFlxDestroyable * Creates an `FlxWeapon` instance which can fire bullets. * Use one of the `fireFrom...()` or `fireAt...()` functions to fire bullets. * - * @param name The name of the weapon (e.g., `"laser"`, `"shotgun"`). For your internal reference really, but could be displayed in-game too. - * @param bulletFactory The factory function used to create new bullets. - * @param fireFrom The weapon's firing position (i.e., `PARENT`, `POSITION`). - * @param speedMode The speed mode for the bullets (i.e., `SPEED`, `ACCELERATION`). + * @param name The name of the weapon (e.g., `"laser"`, `"shotgun"`) + * For your internal reference really, but could be displayed in-game too. + * @param bulletFactory The factory function used to create new bullets. + * @param fireFrom The weapon's firing position (i.e., `PARENT`, `POSITION`). + * @param speedMode The speed mode for the bullets (i.e., `SPEED`, `ACCELERATION`). */ public function new(name:String, bulletFactory:FlxTypedWeapon->TBullet, fireFrom:FlxWeaponFireFrom, speedMode:FlxWeaponSpeedMode) { @@ -186,8 +187,9 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Internal function that handles the actual firing of the bullets. * - * @param mode The mode to use for firing the bullet. - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @param mode The mode to use for firing the bullet. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ function runFire(mode:FlxWeaponFireMode):Bool { @@ -302,32 +304,30 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Calculates the new position for a point rotated around another point. * - * @param point The point to be rotated. - * @param origin The point around which to be rotated. Usually the origin of the `parent`. - * @param angle The current angle from of the origin, in degrees. Usually the `parent`'s angle. - * @param returnedPoint An optional point to reuse instead of getting another from the pool. - * @return The new rotated point. + * @param point The point to be rotated. + * @param origin The point around which to be rotated. Usually the origin of the `parent`. + * @param degrees The current angle from of the origin. Usually the `parent`'s angle. + * @param result An optional point to reuse instead of getting another from the pool. + * @return The new rotated point. */ - public function rotatePoints(point:FlxPoint, origin:FlxPoint, angle:Float, ?returnedPoint:FlxPoint):FlxPoint + public function rotatePoints(point:FlxPoint, origin:FlxPoint, degrees:Float, ?result:FlxPoint):FlxPoint { - if (returnedPoint == null) - { - returnedPoint = FlxPoint.get(); - } - - var inBetweenAngle:Float = origin.degreesTo(point); - inBetweenAngle = angle + inBetweenAngle; - var inBetweenDistance:Float = origin.distanceTo(point); - - returnedPoint.x = Math.cos(inBetweenAngle * Math.PI / 180) * inBetweenDistance; - returnedPoint.y = Math.sin(inBetweenAngle * Math.PI / 180) * inBetweenDistance; - return returnedPoint.add(origin.x, origin.y); + if (result == null) + result = FlxPoint.get(); + + final distanceTo = origin.distanceTo(point); + final degreesTo = degrees + origin.distanceTo(point); + + result.setPolarDegrees(distanceTo, degreesTo); + result.addPoint(origin); + return result; } /** * Fires a bullet (if one is available) based on the `facing` variable of the weapon's `parent`. * - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromParentFacing(angleNoise:FlxBounds):Bool { @@ -336,9 +336,11 @@ class FlxTypedWeapon implements IFlxDestroyable #if FLX_MOUSE /** - * Fires a bullet (if one is available) at the mouse coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. + * Fires a bullet (if one is available) at the mouse coordinates, + * using the speed set in `speedMode` and the rate set in `fireRate`. * - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtMouse():Bool { @@ -348,10 +350,12 @@ class FlxTypedWeapon implements IFlxDestroyable #if FLX_TOUCH /** - * Fires a bullet (if one is available) at the `FlxTouch` coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. + * Fires a bullet (if one is available) at the `FlxTouch` coordinates, + * using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param touch The `FlxTouch` object to fire at. If `null`, uses the first available one. - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @param touch The `FlxTouch` object to fire at. If `null`, uses the first available one. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public function fireAtTouch(?touch:FlxTouch):Bool { @@ -364,11 +368,13 @@ class FlxTypedWeapon implements IFlxDestroyable #end /** - * Fires a bullet (if one is available) at the given x/y coordinates, using the speed set in `speedMode` and the rate set in `fireRate`. + * Fires a bullet (if one is available) at the given x/y coordinates, + * using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param x The x coordinate (in game world pixels) to fire at. - * @param y The y coordinate (in game world pixels) to fire at. - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @param x The x coordinate (in game world pixels) to fire at. + * @param y The y coordinate (in game world pixels) to fire at. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtPosition(x:Int, y:Int):Bool { @@ -376,10 +382,12 @@ class FlxTypedWeapon implements IFlxDestroyable } /** - * Fires a bullet (if one is available) at the given target's position, using the speed set in `speedMode` and the rate set in `fireRate`. + * Fires a bullet (if one is available) at the given target's position, + * using the speed set in `speedMode` and the rate set in `fireRate`. * - * @param target The `FlxSprite` to fire the bullet at. - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @param target The `FlxSprite` to fire the bullet at. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireAtTarget(target:FlxSprite):Bool { @@ -389,8 +397,10 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Fires a bullet (if one is available) based on the given angle. * - * @param angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @param angle The angle (in degrees) calculated in clockwise positive direction + * (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromAngle(angle:FlxBounds):Bool { @@ -400,7 +410,8 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Fires a bullet (if one is available) based on the angle of the weapon's `parent`. * - * @return `true` if a bullet was fired, or `false` if one wasn't available. A reference to the last fired bullet is stored in `currentBullet`. + * @return `true` if a bullet was fired, or `false` if one wasn't available. + * A reference to the last fired bullet is stored in `currentBullet`. */ public inline function fireFromParentAngle(angle:FlxBounds):Bool { @@ -410,8 +421,8 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Sets a pre-fire callback function and sound. These are played immediately before the bullet is fired. * - * @param callback The function to call before a bullet is fired. - * @param sound An `FlxSound` to play before a bullet is fired. + * @param callback The function to call before a bullet is fired. + * @param sound An `FlxSound` to play before a bullet is fired. */ public function setPreFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { @@ -422,8 +433,8 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Sets a post-fire callback function and sound. These are played immediately after the bullet is fired. * - * @param callback The function to call after a bullet is fired. - * @param sound An `FlxSound` to play after a bullet is fired. + * @param callback The function to call after a bullet is fired. + * @param sound An `FlxSound` to play after a bullet is fired. */ public function setPostFireCallback(?callback:Void->Void, ?sound:FlxSound):Void { @@ -434,11 +445,11 @@ class FlxTypedWeapon implements IFlxDestroyable /** * Checks whether the bullets are overlapping the specified object or group. * - * @param objectOrGroup The object or group to check against. - * @param notifyCallBack A function that will get called if a bullet overlaps the object or group. - * @param skipParent Whether to ignore collisions with the parent of this weapon. + * @param objectOrGroup The object or group to check against. + * @param notifyCallBack A function that will get called if a bullet overlaps the object or group. + * @param skipParent Whether to ignore collisions with the parent of this weapon. */ - public inline function bulletsOverlap(objectOrGroup:FlxBasic, ?notifyCallBack:FlxObject->FlxObject->Void, skipParent:Bool = true):Void + public inline function bulletsOverlap(objectOrGroup:FlxBasic, ?notifyCallBack:FlxObject->FlxObject->Void, skipParent = true):Void { if (group != null && group.length > 0) { @@ -621,15 +632,17 @@ class FlxTypedWeapon implements IFlxDestroyable enum FlxWeaponFireFrom { /** - * @param parent The parent sprite of the weapon. - * @param offset A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. - * @param useParentAngle Whether to fire bullets in the direction of the `parent`'s angle. - * @param angleOffset A value used to offset a bullet's angle from the `parent`'s angle when it is fired. + * @param parent The parent sprite of the weapon. + * @param offset A value used to offset a bullet's position when it is fired + * (e.g. to line a bullet up with the "nose" of a space ship). + * @param useParentAngle Whether to fire bullets in the direction of the `parent`'s angle. + * @param angleOffset A value used to offset a bullet's angle from the `parent`'s angle + * when it is fired. */ PARENT(parent:FlxSprite, offset:FlxBounds, ?useParentAngle:Bool, ?angleOffset:Float); /** - * @param position A fixed position from which to fire the weapon, like in the game Missile Command. + * @param position A fixed position from which to fire the weapon, like in the game Missile Command. */ POSITION(position:FlxBounds); } From 1ce83593892377a5f60e987cd31f01e1ec09b300 Mon Sep 17 00:00:00 2001 From: DalekCraft Date: Thu, 13 Apr 2023 17:29:53 -0400 Subject: [PATCH 13/14] Change the wording of the doc for rotatePoint's "degrees" argument --- flixel/addons/weapon/FlxWeapon.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 12a56eec..18785010 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -306,7 +306,7 @@ class FlxTypedWeapon implements IFlxDestroyable * * @param point The point to be rotated. * @param origin The point around which to be rotated. Usually the origin of the `parent`. - * @param degrees The current angle from of the origin. Usually the `parent`'s angle. + * @param degrees The angle by which to rotate `point` around `origin`. Usually the `parent`'s angle. * @param result An optional point to reuse instead of getting another from the pool. * @return The new rotated point. */ @@ -314,10 +314,10 @@ class FlxTypedWeapon implements IFlxDestroyable { if (result == null) result = FlxPoint.get(); - + final distanceTo = origin.distanceTo(point); final degreesTo = degrees + origin.distanceTo(point); - + result.setPolarDegrees(distanceTo, degreesTo); result.addPoint(origin); return result; From b5fbd15aad8153371634dd6bbe873de697d4ddb8 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Mon, 15 May 2023 12:11:19 -0500 Subject: [PATCH 14/14] positionOffsetBounds docs --- flixel/addons/weapon/FlxWeapon.hx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 18785010..c57b83d5 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -100,8 +100,9 @@ class FlxTypedWeapon implements IFlxDestroyable public var positionOffset(default, null):FlxPoint; /** - * A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship. - * Only accessible when `fireFrom == PARENT`. + * A value used to offset a bullet's position when it is fired. Can be used to, for example, + * line a bullet up with the "nose" of a space ship. Only accessible when `fireFrom == PARENT`. + * @since 3.2.0 */ public var positionOffsetBounds(default, null):FlxBounds;