Skip to content

Ammo and reloading #28

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

Closed
wants to merge 16 commits into from
Closed

Ammo and reloading #28

wants to merge 16 commits into from

Conversation

Ryan-Mirch
Copy link
Contributor

Please check if the PR fulfills these requirements:

  • The commit message follows our guidelines.
  • For bug fixes and features:
    • You tested the changes.

Related issue (if applicable): #

What kind of change does this PR introduce?
Added the ammo and reloading demo to the ranged attacks folder

Does this PR introduce a breaking change?

New feature or change

What is the current behavior?

What is the new behavior?
A demo with basic bullet shooting with an ammo and reload system.

Other information

Copy link
Contributor

@NathanLovato NathanLovato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really want to avoid adding boolean variables. This is the most important feedback I have in this PR.

Every bit of state and code that you add increases the surface area for bugs. Especially the state because it's so easy to forget to switch a boolean.

Here's the code changes I made to remove the booleans, but also group the input into a single function. I recommend you to study it, you'll see it removes over 20% of the code size, meaning once you get used to doing this, it will save you time coding on top of preventing more bugs (thus saving you maintenance work): b3fc5b2#diff-91075a352ce78af7185f36825fafb6413e9c884a31de05e23b114cd5f75bf2d0

Comment on lines 20 to 22
var is_reloading := false
var left_click_held := false
var shoot_ready := true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main sources of bugs in computer programs is the addition of unnecessary state. Try to use existing state over adding new variables whenever you can. Here, you can use the timers and the Input object in _process() to replace these 3 extra variables.

Copy link
Contributor

@NathanLovato NathanLovato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last tasks:

  • Move the code that gets and connects sliders from Player.gd to AmmoReloadingDemo.gd (because this UI isn't part of the Player scene, the corresponding code shouldn't be in the Player scene)
  • Move the player-specific UI (the reloading bar and ammo display) into the player scene. You can add a CanvasLayer in the Player scene to ensure the UI always displays in front

Copy link
Contributor

@NathanLovato NathanLovato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code and features are good, good job on that. there are two small issues left:

  1. The interface covers the player's weapon.
  2. This pull request changes the demos' main scene. Wouldn't this affect the ranged attack video tutorial, where viewers can assume the demo opens on the scene where you can shoot arrows?

You can see issue 1. here:

image

@NathanLovato
Copy link
Contributor

Merged manually as a02951f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants