Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | System_Error |
Hi all, I have a question. In my game, I have a gun that fires as fast as the player can hit a button, which leads to some testers pressing very quickly to rid the screen of incoming enemies. But I don’t want that to be as effective as it feels.
What I’d like is to limit the number of LazerShots instanced into my Level. I might have to re-write the fire() function in my LazerGun script. Any suggestions on how to do that?
LazerGun.gd
extends KinematicBody2D
const LAZER = preload("res://player-side/EnergyShot.tscn")
const ROTATION_SPEED = 0.5
signal fire
var playing = false
var rotation_Direction
func _ready():
pass
func get_input():
rotation_Direction = 0.0
if playing == true:
if Input.is_action_pressed('test_up'):
rotation_Direction -= 1.25
elif Input.is_action_pressed('test_down'):
rotation_Direction += 1.25
if Input.is_action_just_pressed('test_fire'):
fire()
func fire():
var lazershot = LAZER.instance()
lazershot.start($LazerSpawn.global_position, rotation)
get_parent().add_child(lazershot)
func _physics_process(delta):
get_input()
rotation += rotation_Direction * ROTATION_SPEED * delta
rotation = clamp(rotation, deg2rad(-60), deg2rad(60))
func _on_game_over():
playing = false
func _on_HUD_play_game():
playing = true
Level.gd
extends Node2D
const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010
signal game_over
var timescore
var kills
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')
var SpawnWaitTime = 5
var highscore = 0.0
func _ready():
randomize()
func _on_SpawnTimer_timeout():
var enemy = eyeworm.instance()
enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
enemy.connect("kill", self, "_on_kill")
add_child(enemy)
SpawnWaitTime -= 0.15
if (SpawnWaitTime < 0.4):
SpawnWaitTime += 4.85
$Node/SpawnTimer.set_wait_time(SpawnWaitTime)
func _on_SurvivalTimer_timeout():
timescore += 1
$HUD.score_count(timescore)
func _on_kill():
kills += 1
$HUD.kill_count(kills)
func _on_BaseArea_area_entered(area):
$Node/SpawnTimer.stop()
$Node/SurvivalTimer.stop()
finalscore = timescore + kills*5
if highscore < finalscore:
highscore = finalscore
$HUD.player_loss(finalscore, highscore)
emit_signal('game_over')
$BaseArea/CollisionShape2D.disabled = true
get_tree().call_group("EyeWorms", "queue_free")
func _on_HUD_play_game():
timescore = 0
kills = 0
SpawnWaitTime = 5
finalscore = 0
$Node/SurvivalTimer.start()
$Node/SpawnTimer.start()
$HUD.show_message("Survive!")
$BaseArea/CollisionShape2D.disabled = false