Scene manager limits how many grenades can be used
Player keyboard map:
if Input.is_action_just_pressed("chuck"):
print("ima chuck a grenade")
match facing:
FaceDirection.RIGHT:
%SceneManager.makeGrenade(right_spawn.global_transform, 1)
FaceDirection.LEFT:
%SceneManager.makeGrenade(left_spawn.global_transform, -1)
In Scenemanager, grenade preload: var grenade = preload("res://scenes/grenade.tscn")
Make a grenade and propel it:
func makeGrenade(_grenadePosition, _grenadeDirection)->void:
print("SM make a grenade")
var myGrenade:Grenade = grenade.instantiate()
owner.add_child(myGrenade)
myGrenade.apply_central_impulse(Vector2(_grenadeDirection, -1)*200)
myGrenade.transform = _grenadePosition
To add grenades, we will need the following:
- Create a scene manager
- Create a grenade
- Scene manager limits how many grenades can be used
Player keyboard map:
```
if Input.is_action_just_pressed("chuck"):
print("ima chuck a grenade")
match facing:
FaceDirection.RIGHT:
%SceneManager.makeGrenade(right_spawn.global_transform, 1)
FaceDirection.LEFT:
%SceneManager.makeGrenade(left_spawn.global_transform, -1)
```
In Scenemanager, grenade preload:
`var grenade = preload("res://scenes/grenade.tscn")`
Make a grenade and propel it:
```
func makeGrenade(_grenadePosition, _grenadeDirection)->void:
print("SM make a grenade")
var myGrenade:Grenade = grenade.instantiate()
owner.add_child(myGrenade)
myGrenade.apply_central_impulse(Vector2(_grenadeDirection, -1)*200)
myGrenade.transform = _grenadePosition
```
class_name Grenade extends RigidBody2D
var timer = Timer.new()
# Called when the node enters the scene tree for the first time.
func _ready():
add_child(timer)
timer.wait_time = 2
timer.one_shot = true
timer.connect("timeout", explode)
timer.start()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func explode()->void:
print("ima splode")
self.queue_free()
func _on_body_entered(body):
print("grenade hit something")
if body.is_in_group("splodable"):
body.queue_free()
explode()
Grenade code:
```
class_name Grenade extends RigidBody2D
var timer = Timer.new()
# Called when the node enters the scene tree for the first time.
func _ready():
add_child(timer)
timer.wait_time = 2
timer.one_shot = true
timer.connect("timeout", explode)
timer.start()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func explode()->void:
print("ima splode")
self.queue_free()
func _on_body_entered(body):
print("grenade hit something")
if body.is_in_group("splodable"):
body.queue_free()
explode()
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
To add grenades, we will need the following:
Player keyboard map:
In Scenemanager, grenade preload:
var grenade = preload("res://scenes/grenade.tscn")Make a grenade and propel it:
Grenade code: