Added some TODO lines and implemented very bad dash system
This commit is contained in:
parent
255a47f6da
commit
828f4c52c7
12 changed files with 70 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue