diff --git a/scenes/engines/starterengine.tscn b/scenes/engines/starterengine.tscn index 9b75fc4..75758d0 100644 --- a/scenes/engines/starterengine.tscn +++ b/scenes/engines/starterengine.tscn @@ -47,10 +47,12 @@ scale_min = 1.5 scale_max = 1.5 scale_curve = SubResource("CurveTexture_ot3qw") -[node name="Engine" type="Node2D"] +[node name="Engine" type="Node2D" node_paths=PackedStringArray("dash_recharge_timer")] use_parent_material = true script = ExtResource("1_jvcps") rotation_speed = 120 +dash_recharge_timer = NodePath("Timer") +dashes_count = 1 [node name="EngineSprite" type="Sprite2D" parent="."] use_parent_material = true @@ -76,3 +78,7 @@ fixed_fps = 50 local_coords = true trail_enabled = true script = ExtResource("4_f11x7") + +[node name="Timer" type="Timer" parent="."] +wait_time = 5.0 +one_shot = true diff --git a/scenes/npcships/NPCShipDefault.tscn b/scenes/npcships/NPCShipDefault.tscn index 138b779..21b76fb 100644 --- a/scenes/npcships/NPCShipDefault.tscn +++ b/scenes/npcships/NPCShipDefault.tscn @@ -34,13 +34,11 @@ destination_timer = NodePath("DestinationTimer") bounty = ExtResource("2_6fdps") [node name="Shield" parent="." instance=ExtResource("3_47apr")] -use_parent_material = true [node name="Hull" parent="." instance=ExtResource("4_1ne0s")] use_parent_material = true [node name="Engine" parent="." instance=ExtResource("4_tguk3")] -use_parent_material = true [node name="Collision" type="CollisionPolygon2D" parent="."] polygon = PackedVector2Array(0, -16, 32, 0, 0, 16, 0, 4, -4, 4, -8, 8, -8, -8, -4, -4, 0, -4) diff --git a/scripts/Space.gd b/scripts/Space.gd index 62195d9..d345648 100644 --- a/scripts/Space.gd +++ b/scripts/Space.gd @@ -1,5 +1,5 @@ extends Node2D - +# TODO: move colors to profile settings var can_target = [] var color_player var color_base @@ -59,10 +59,12 @@ func _ready(): scene_ready.emit() func addtargetlist(body : Node2D): + #print("ГОЙДА") if !can_target.has(body): can_target.append(body) func removetargetlist(body : Node2D): + #print("ГОЙДАN'T") if can_target.has(body): can_target.erase(body) diff --git a/scripts/game.gd b/scripts/game.gd index 492b9dd..03bafa0 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -1,5 +1,4 @@ extends Node - class_name Game enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION} diff --git a/scripts/menu/BaseMenu.gd b/scripts/menu/BaseMenu.gd index ccd81bc..70aefa3 100644 --- a/scripts/menu/BaseMenu.gd +++ b/scripts/menu/BaseMenu.gd @@ -1,5 +1,5 @@ extends Control - +# TODO: split this code into different scripts var base @onready var ship = get_tree().current_scene.ship @onready var sell_list = $TradingMenu/SellList diff --git a/scripts/menu/MainMenu.gd b/scripts/menu/MainMenu.gd index eabbe72..1472cb9 100644 --- a/scripts/menu/MainMenu.gd +++ b/scripts/menu/MainMenu.gd @@ -1,5 +1,5 @@ extends Node2D - +# TODO: rewrite to use resource as button info var map_width = 1280 var map_height = 720 var menu_id = 0 diff --git a/scripts/menu/MainMenuButton.gd b/scripts/menu/MainMenuButton.gd index 1488848..af15d0e 100644 --- a/scripts/menu/MainMenuButton.gd +++ b/scripts/menu/MainMenuButton.gd @@ -1,5 +1,5 @@ extends Button - +# TODO: rewrite to use resource as button info var texts = { "NewGame" : "New Game", "CreateProfile" : "Create Profile", diff --git a/scripts/objects/Base.gd b/scripts/objects/Base.gd index 25c41cc..ceb3be8 100644 --- a/scripts/objects/Base.gd +++ b/scripts/objects/Base.gd @@ -1,5 +1,4 @@ extends Node2D - @export var type : Game.BASE_TYPE @onready var menu : Area2D = $MenuCollider @onready var ship : MainShip = get_tree().current_scene.get_node("MainShip") diff --git a/scripts/objects/MainShip.gd b/scripts/objects/MainShip.gd index e284a39..b15af47 100644 --- a/scripts/objects/MainShip.gd +++ b/scripts/objects/MainShip.gd @@ -1,5 +1,5 @@ extends CharacterBody2D - +# TODO: create class_name which is used to inherit common attributes to mainship and npc ship class_name MainShip @onready var engine = $Engine diff --git a/scripts/objects/Rocket.gd b/scripts/objects/Rocket.gd index 6c062b5..ae60d43 100644 --- a/scripts/objects/Rocket.gd +++ b/scripts/objects/Rocket.gd @@ -2,6 +2,7 @@ extends Projectile func areyouready(): target = Node2D.new() + print(get_tree().current_scene.can_target) if len(get_tree().current_scene.can_target) > 0: get_tree().current_scene.can_target[0].add_child(target) else: diff --git a/scripts/objects/ShipEngine.gd b/scripts/objects/ShipEngine.gd index f2036d8..a4f9b47 100644 --- a/scripts/objects/ShipEngine.gd +++ b/scripts/objects/ShipEngine.gd @@ -1,5 +1,7 @@ extends Node2D +# TODO: rewrite movement system to be impulse based + class_name ShipEngine @export var max_speed : float = 200 @@ -8,7 +10,13 @@ class_name ShipEngine @export var fuel_consumption : float = 100 @export var rotation_speed : int = 90 @export var id : String = "starterengine" +@export var dash_recharge_timer : Timer +@export_range(1, 10, 1) var dashes_count : int = 3 + @onready var ship = get_parent() +@onready var double_tap_timer = Timer.new() +@onready var dash_timer = Timer.new() + var hull var speed = 0 var min_speed = max_speed / -4 @@ -16,13 +24,41 @@ var turbo_enabled = false var alternative_movement = false var destination_angle : float var destination_difference : float +var dash_direction_left = true +var is_double_tapping = false +var is_dashing = false + +func _ready(): + dash_recharge_timer.timeout.connect(dash_recharge) + add_child(double_tap_timer) + add_child(dash_timer) + double_tap_timer.one_shot = true + double_tap_timer.timeout.connect(not_double_tapping) + dash_timer.one_shot = true + dash_timer.timeout.connect(not_dashing) func _physics_process(delta): hull = ship.hull modulate = ship.material.get_shader_parameter('color') var turbo_input = Input.get_action_raw_strength("turbo") var acceleration_input = Input.get_axis("deccelerate", "accelerate") if ship is MainShip else 1.0 - var rotation_input = Input.get_axis("rotateleft","rotateright") + var rotation_input = Input.get_axis("rotateleft", "rotateright") + # проверка на рывок + var left_released = Input.is_action_just_released("rotateleft") + var right_released = Input.is_action_just_released("rotateright") + if (left_released or right_released): + if !is_double_tapping and !is_dashing: + double_tap_timer.start(0.25) + is_double_tapping = true + print("first tap") + else: + dash_direction_left = left_released + is_dashing = true + is_double_tapping = false + dash_timer.start(0.1) + double_tap_timer.stop() + print("second tap") + if destination_angle - ship.rotation_degrees == clamp(destination_angle - ship.rotation_degrees, -180, 180): destination_difference = destination_angle - ship.rotation_degrees else: @@ -51,9 +87,23 @@ func _physics_process(delta): hull.fuel -= fuel_consumption * delta if hull.fuel < 0: hull.fuel = 0 - - ship.velocity = Vector2.from_angle(ship.rotation) * speed + var additional_rotation = 0 + var additional_speed = 0 + if is_dashing and ship is MainShip: + print("wanna dash") + additional_speed = 500 + additional_rotation = deg_to_rad(-90) if dash_direction_left else deg_to_rad(90) + ship.velocity = Vector2.from_angle(ship.rotation + additional_rotation) * (speed + additional_speed) ship.move_and_slide() if Input.is_action_just_released("alternatemovement") and ship is MainShip: alternative_movement = !alternative_movement + +func dash_recharge(): + pass + +func not_double_tapping(): + is_double_tapping = false + +func not_dashing(): + is_dashing = false diff --git a/scripts/objects/npcship.gd b/scripts/objects/npcship.gd index 3291251..53714d2 100644 --- a/scripts/objects/npcship.gd +++ b/scripts/objects/npcship.gd @@ -1,5 +1,6 @@ extends CharacterBody2D - +# TODO: rewrite NPC to use state machine +# TODO: create class_name which is used to inherit common attributes to mainship and npc ship class_name NPCShip @export var destination_timer : Timer