-
Notifications
You must be signed in to change notification settings - Fork 154
FlxWeapon rework #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DalekCraft2
wants to merge
16
commits into
HaxeFlixel:dev
Choose a base branch
from
DalekCraft2:weapon-rework
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
FlxWeapon rework #383
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5a9edb7
Change capitalization of function arguments
DalekCraft2 1231098
Clarify and update many of FlxWeapon's doc comments
DalekCraft2 4ddd785
Remove unused fields from FlxWeapon
DalekCraft2 16a4531
Make FlxWeapon destroyable and change fireRate's implementation
DalekCraft2 d6b96ef
Update FlxBullet.hx
DalekCraft2 19b0f1e
Add a missing import to FlxWeapon
DalekCraft2 3f268c5
Update FlxWeapon.hx
DalekCraft2 dd471d8
Clean FlxWeapon and FlxBullet imports
DalekCraft2 63b16f5
Reimplement removed FlxWeapon fields, and remove timer
DalekCraft2 f71cd85
Add a few doc comments to FlxWeapon and modify some existing ones
DalekCraft2 59a042d
Merge branch 'dev' into weapon-rework
DalekCraft2 e1b5f52
move re-added field to old position for clearer git diff
Geokureli 743b536
doc formatting + rename var
Geokureli 1ce8359
Change the wording of the doc for rotatePoint's "degrees" argument
DalekCraft2 0b499db
Merge branch 'dev' into weapon-rework
Geokureli b5fbd15
positionOffsetBounds docs
Geokureli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ class FlxTypedWeapon<TBullet:FlxBullet> | |
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<TBullet:FlxBullet> | |
*/ | ||
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<FlxPoint>; | ||
|
||
/** | ||
* 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; | ||
DalekCraft2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public var fireFrom(default, set):FlxWeaponFireFrom; | ||
public var speedMode:FlxWeaponSpeedMode; | ||
|
||
|
@@ -140,21 +124,18 @@ class FlxTypedWeapon<TBullet:FlxBullet> | |
*/ | ||
var bulletFactory:FlxTypedWeapon<TBullet>->TBullet; | ||
|
||
var lastFired:Int = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing this is technically a breaking change but i'll allow it. In all likelyhood no real person will have a compile error unless they use this field in an extending class, and highly unlikely and easy to fix. In the future, when in doubt, just deprecate it |
||
|
||
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<TBullet:FlxBullet> | |
} | ||
#end | ||
|
||
lastFired = FlxG.game.ticks; | ||
nextFire = FlxG.game.ticks + Std.int(fireRate / FlxG.timeScale); | ||
|
||
// Get a free bullet from the pool | ||
|
@@ -207,27 +187,28 @@ class FlxTypedWeapon<TBullet:FlxBullet> | |
} | ||
|
||
// 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); | ||
} | ||
|
||
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<TBullet:FlxBullet> | |
* @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(); | ||
DalekCraft2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
var inBetweenAngle:Float = origin.degreesTo(point); | ||
inBetweenAngle = angle + inBetweenAngle; | ||
|
@@ -384,7 +369,7 @@ class FlxTypedWeapon<TBullet:FlxBullet> | |
/** | ||
* 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<Float>):Bool | ||
{ | ||
|
@@ -483,6 +468,7 @@ class FlxTypedWeapon<TBullet:FlxBullet> | |
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<TBullet:FlxBullet> | |
|
||
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<FlxPoint>, ?useParentAngle:Bool, ?angleOffset:Float); | ||
|
||
/** | ||
* @param position A fixed position from which to fire the weapon, like in the game Missile Command. | ||
*/ | ||
POSITION(position:FlxBounds<FlxPoint>); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.