0 votes

script: ship

extends Area2D

var armor = 4 setget setarmor
const scn
laser = preload("res://scenes/lasership.tscn")
const scn
explosion = preload("res://scenes/explosion.tscn")
const scn_flash = preload("res://scenes/flash.tscn")

signal armor_changed

func ready():
set
process(true)
addtogroup("ship")

yield(utils.create_timer(0.5), "timeout")






shoot()

pass

func process(delta):
# tracking mouse
var motion = (utils.mouse
pos.x - get_pos().x) * 0.2
translate(Vector2(motion, 0))

# clamping to view
var pos = get_pos()
pos.x   = clamp(pos.x, 0+16, utils.view_size.width-16)
set_pos(pos)


pass

func shoot():
while true:

    var pos_left  = get_node("cannons/left" ).get_global_pos()
    var pos_right = get_node("cannons/right").get_global_pos()
    create_laser(pos_left )
    create_laser(pos_right)

    yield(utils.create_timer(0.25), "timeout")
pass

func setarmor(newvalue):
if newvalue < armor:
utils.main
node.addchild(scnflash.instance())

armor = new_value
emit_signal("armor_changed", armor)

if armor <= 0:
    create_explosion()
    queue_free()
pass

func createlaser(pos):
var laser = scn
laser.instance()
laser.setpos(pos)
utils.main
node.add_child(laser)
pass

func createexplosion():
var explosion = scn
explosion.instance()
explosion.setpos(getpos())
utils.mainnode.addchild(explosion)
pass

in Engine by (12 points)

2 Answers

0 votes

Don't panic Iam really new to godot but i suppose this is easy just try to put your shooting function inside a pressed button

by (28 points)

Thank You Your Comment Was Helpful

0 votes

this play list teach us how to make simple space shoot game.
https://www.youtube.com/watch?v=qZOOruWMRT8&list=PL6bQeQE-ybqAzXZlZCiRKCtu6RbkXLgmh

try use input function or use

func _input(event: InputEvent) -> void:
    pass

something like :

if Input.is_action_pressed("Lclick") : # if you use Input.is_action_pressed it keep shoot until you release press, if you use Input.is_action_just_pressed it will shot once each click.
shoot() #shoot function

by (419 points)

Thank You Your Comment Was Helpful .But I am Facing An Issue It Is Not Working I Hope it is Because the older version 2.1.6. When I Use the Input Function It Gets Stopped

i hope so, i use 3.2

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.