fuzzyworld

godot-shooter / commit

Added a constant, so the speed of all objects can be defined in terms of a common speed factor: player is 1, enemies are 1.05, bullets are 5, and rockets are 3. Meaning that the enemies are slightly faster than the player, bullets move 5 times faster, etc.

ee6296b3acc6a546c76245cd26a6c69e3054b5c3 · Pavel Safronov · 2023-11-17 14:37:36 -0800 · parents 0386b89dab87

Added a constant, so the speed of all objects can be defined in terms of a common speed factor: player is 1, enemies are 1.05, bullets are 5, and rockets are 3. Meaning that the enemies are slightly faster than the player, bullets move 5 times faster, etc.
 actors/Enemy.gd     | 3 ++-
 actors/Player.gd    | 3 ++-
 utils/Constants.gd  | 1 +
 weapons/Bullet.gd   | 4 +++-
 weapons/Rocket.gd   | 4 +++-
 weapons/Rocket.tscn | 1 -
 6 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/actors/Enemy.gd b/actors/Enemy.gd
index ea87389..404f10c 100644
--- a/actors/Enemy.gd
+++ b/actors/Enemy.gd
@@ -6,8 +6,9 @@ onready var damage_points = $DamagePoints
 const Utils = preload("res://utils/Utils.gd")
 const Explosion = preload("res://effects/Explosion.tscn")
 const Smoke = preload("res://effects/Smoke.tscn")
+const Constants = preload("res://utils/Constants.gd")
 
-export var move_speed = 40
+export var move_speed = Constants.SPEED * 1.05
 export var turn_rate = 0.01
 export var health = -1
 export var max_health = 100
diff --git a/actors/Player.gd b/actors/Player.gd
index f55e7e8..9762e21 100644
--- a/actors/Player.gd
+++ b/actors/Player.gd
@@ -2,9 +2,10 @@ extends KinematicBody2D
 class_name Player
 
 const Weapons = preload("res://weapons/Weapons.gd")
+const Constants = preload("res://utils/Constants.gd")
 
 export var score = 0
-export var move_speed = 60
+export var move_speed = Constants.SPEED
 export var health = 50
 export var max_health = 100
 export var is_invincible = false
diff --git a/utils/Constants.gd b/utils/Constants.gd
new file mode 100644
index 0000000..ff14641
--- /dev/null
+++ b/utils/Constants.gd
@@ -0,0 +1 @@
+const SPEED = 100
diff --git a/weapons/Bullet.gd b/weapons/Bullet.gd
index aaada15..e14f34e 100644
--- a/weapons/Bullet.gd
+++ b/weapons/Bullet.gd
@@ -3,8 +3,10 @@ class_name Bullet
 
 const Utils = preload("res://utils/Utils.gd")
 const SmallExplosion = preload("res://effects/SmallExplosion.tscn")
+const Constants = preload("res://utils/Constants.gd")
+
 export var lifetime_seconds = 1.5
-export var speed = 300
+export var speed = Constants.SPEED * 5
 export var damage_amount = 1
 
 func _ready() -> void:
diff --git a/weapons/Rocket.gd b/weapons/Rocket.gd
index 59aab70..e564ce4 100644
--- a/weapons/Rocket.gd
+++ b/weapons/Rocket.gd
@@ -3,8 +3,10 @@ class_name Rocket
 
 const Utils = preload("res://utils/Utils.gd")
 const SmallExplosion = preload("res://effects/SmallExplosion.tscn")
+const Constants = preload("res://utils/Constants.gd")
+
 export var lifetime_seconds = 5
-export var speed = 100
+export var speed = Constants.SPEED * 3
 export var arm_secs = 1
 export var damage_amount = 2
 var is_dead = false
diff --git a/weapons/Rocket.tscn b/weapons/Rocket.tscn
index dc7523c..a073759 100644
--- a/weapons/Rocket.tscn
+++ b/weapons/Rocket.tscn
@@ -125,7 +125,6 @@ position = Vector2( 0, -1 )
 collision_layer = 8
 collision_mask = 2
 script = ExtResource( 2 )
-speed = 200
 
 [node name="Sprite" type="Sprite" parent="."]
 modulate = Color( 0, 1, 0.0627451, 1 )