Added some TODO lines and implemented very bad dash system

This commit is contained in:
2ndbeam 2024-04-25 23:21:54 +03:00
commit 828f4c52c7
12 changed files with 70 additions and 14 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -1,5 +1,4 @@
extends Node
class_name Game
enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION}

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,5 @@
extends Button
# TODO: rewrite to use resource as button info
var texts = {
"NewGame" : "New Game",
"CreateProfile" : "Create Profile",

View file

@ -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")

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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