Implement fire repeat rate
This commit is contained in:
parent
07e9aefbaa
commit
23add4aba3
|
@ -8,6 +8,7 @@ var Bullet = preload("res://World/bullet.tscn")
|
|||
|
||||
var thrust = 6.0
|
||||
var gravity := Vector2.ZERO
|
||||
var last_shot_utime := 0
|
||||
|
||||
# Set by the authority, synchronized on spawn.
|
||||
@export var player := 1 :
|
||||
|
@ -30,11 +31,17 @@ func _ready():
|
|||
|
||||
gravity = 1000*MapConfig.gravity * Vector2.LEFT.rotated(deg_to_rad(MapConfig.gravityangle))
|
||||
|
||||
|
||||
func shoot():
|
||||
if Time.get_ticks_usec() < last_shot_utime + 1000000 * MapConfig.firerepeatrate / MapConfig.framespersecond:
|
||||
return
|
||||
|
||||
# "Muzzle" is a Marker2D placed at the barrel of the gun.
|
||||
var b = Bullet.instantiate()
|
||||
b.start($"Muzzle main".global_position, rotation)
|
||||
b.start($"Muzzle main".global_position, velocity, rotation)
|
||||
get_tree().root.add_child(b)
|
||||
last_shot_utime = Time.get_ticks_usec()
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
rotation += input.rotate
|
||||
|
|
|
@ -5,10 +5,10 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|||
var speed = 750
|
||||
@onready var life_time: float = MapConfig.shotlife
|
||||
|
||||
func start(_position, _direction):
|
||||
func start(_position, _velocity, _direction):
|
||||
rotation = _direction
|
||||
position = _position
|
||||
velocity = Vector2(speed, 0).rotated(rotation)
|
||||
velocity = _velocity + Vector2(speed, 0).rotated(rotation)
|
||||
|
||||
func _physics_process(delta):
|
||||
var collision = move_and_collide(velocity * delta)
|
||||
|
|
Loading…
Reference in New Issue