-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the Player and gun to fit our code guidelines
- Loading branch information
1 parent
55d8e1d
commit c7de3b4
Showing
4 changed files
with
104 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extends Position2D | ||
class_name Gun | ||
|
||
|
||
onready var sound_shoot: AudioStreamPlayer2D = $Shoot | ||
onready var timer: Timer = $Cooldown | ||
|
||
const Bullet = preload("res://src/Objects/Bullet.tscn") | ||
const BULLET_VELOCITY := 1000.0 | ||
|
||
|
||
func shoot(direction: int = 1) -> bool: | ||
if not timer.is_stopped(): | ||
return false | ||
var bullet = Bullet.instance() | ||
bullet.global_position = global_position | ||
bullet.linear_velocity = Vector2(direction * BULLET_VELOCITY, 0) | ||
|
||
bullet.set_as_toplevel(true) | ||
add_child(bullet) | ||
sound_shoot.play() | ||
return true |
This file contains 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
This file contains 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