extends Area2D signal shooting_speed_upgrade export (PackedScene) var Laser #Constants const BULLET_DELAY_DEFAULT = 0.9 const SHOOTING_SPEED_UPGRADE_DEFAULT = 50 const SHIP_SPEED_DEFAULT = 400 var ship_value = 0 var ship_speed = SHIP_SPEED_DEFAULT var bullet_delay = BULLET_DELAY_DEFAULT var screensize var money = 100 var shooting_speed_upgrade = 50 var double_laser = true # class member variables go here, for example: # var a = 2 # var b = "textvar" func _ready(): timer = Timer.new() timer.set_one_shot(true) timer.set_wait_time(bullet_delay) timer.connect("timeout", self, "on_timeout_complete") add_child(timer) position.x = 100 position.y = 250 screensize = get_viewport_rect().size $AnimatedSprite.play() # Initialization here pass func refund(): bullet_delay = BULLET_DELAY_DEFAULT ship_speed = SHIP_SPEED_DEFAULT money += ship_value ship_value = 0 var timer = null var can_shoot = true func on_timeout_complete(): can_shoot = true var going_up = false var going_down = false var shoot_down = false func _process(delta): var velocity = Vector2() # the player's movement vector if (Input.is_action_pressed("ui_right")): velocity.x += 1 if (Input.is_action_pressed("ui_left")): velocity.x -= 1 if (Input.is_action_pressed("ui_down") || going_down == true): velocity.y += 1 if (Input.is_action_pressed("ui_up") || going_up == true): velocity.y -= 1 if (velocity.length() > 0): velocity = velocity.normalized() * ship_speed position += velocity * delta position.x = clamp(position.x, 0, screensize.x) position.y = clamp(position.y, 0, screensize.y) if (Input.is_action_pressed("ui_select") && can_shoot == true && money >= shooting_speed_upgrade ): emit_signal("shooting_speed_upgrade") money -= shooting_speed_upgrade ship_value += shooting_speed_upgrade shooting_speed_upgrade *= 1.02 bullet_delay = bullet_delay * 0.95 can_shoot = false timer.set_wait_time(bullet_delay) timer.start() if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true): var laser = Laser.instance() get_node("../").add_child(laser) laser.position.y = position.y - 27 laser.position.x = position.x + 46 #MAYBE THE SECOND LASER SHOULD BE IT'S OWN NODE if double_laser == true: var laser2 = Laser.instance() get_node("../").add_child(laser2) laser2.position.y = position.y + 28 laser2.position.x = position.x + 46 can_shoot = false timer.start() func _on_Player_body_entered(body): prints("hit") pass # replace with function body func upPressed(): going_up = true func upDepressed(): going_up = false func downPressed(): going_down = true func downDepressed(): going_down = false func shootDown(): shoot_down = true # replace with function body func shootUp(): shoot_down = false # replace with function body