From bf19c6989c16dfa598fb08103be72753030d7e80 Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 11 Nov 2024 18:18:47 +0100 Subject: [PATCH] add burnout particles --- scenes/burnout.tscn | 29 +++++++++++++++++++++++++++++ scenes/car.tscn | 8 +++++++- scripts/car.gd | 38 ++++++++++++++++++++++++++++++-------- scripts/tiretrails.gd | 2 +- 4 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 scenes/burnout.tscn diff --git a/scenes/burnout.tscn b/scenes/burnout.tscn new file mode 100644 index 0000000..a9ce5f9 --- /dev/null +++ b/scenes/burnout.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=3 format=3 uid="uid://dilif5od0ipli"] + +[sub_resource type="Curve" id="Curve_sh5h6"] +_data = [Vector2(0, 0.10989), 0.0, 0.944297, 0, 0, Vector2(1, 1), 0.56508, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="Gradient" id="Gradient_65fx1"] +colors = PackedColorArray(0, 0, 0, 1, 0, 0, 0, 0) + +[node name="CPUParticles2D" type="CPUParticles2D"] +z_index = 9 +position = Vector2(-11, -7) +emitting = false +amount = 100 +lifetime = 2.0 +emission_shape = 1 +emission_sphere_radius = 1.0 +direction = Vector2(-1, 0) +spread = 10.0 +gravity = Vector2(0, 0) +initial_velocity_min = 100.0 +initial_velocity_max = 150.0 +damping_min = 100.0 +damping_max = 500.0 +scale_amount_min = 10.0 +scale_amount_max = 10.0 +scale_amount_curve = SubResource("Curve_sh5h6") +color = Color(0.0901961, 0.0901961, 0.0901961, 0.454902) +color_ramp = SubResource("Gradient_65fx1") diff --git a/scenes/car.tscn b/scenes/car.tscn index eb8ca58..0568a85 100644 --- a/scenes/car.tscn +++ b/scenes/car.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=49 format=3 uid="uid://0g7qqh7naniv"] +[gd_scene load_steps=50 format=3 uid="uid://0g7qqh7naniv"] [ext_resource type="Script" path="res://scripts/car_node.gd" id="1_0tin3"] [ext_resource type="Script" path="res://scripts/car.gd" id="1_i5tet"] @@ -6,6 +6,7 @@ [ext_resource type="Texture2D" uid="uid://e5aeyl47wi8p" path="res://sprites/car_body.png" id="4_lps13"] [ext_resource type="Script" path="res://scripts/tiretrails.gd" id="5_4geqi"] [ext_resource type="Script" path="res://scripts/label_round.gd" id="5_vheit"] +[ext_resource type="PackedScene" uid="uid://dilif5od0ipli" path="res://scenes/burnout.tscn" id="6_nxxrr"] [ext_resource type="PackedScene" uid="uid://dl7r8s5sxyvlw" path="res://scenes/enginesound.tscn" id="6_v21se"] [ext_resource type="AudioStream" uid="uid://dq5rei2w1isu4" path="res://sounds/crash/Car_Crash_01.mp3" id="7_7erwn"] [ext_resource type="AudioStream" uid="uid://c80nrd7syf2do" path="res://sounds/crash/Car_Crash_02.mp3" id="8_v77t5"] @@ -161,6 +162,11 @@ script = ExtResource("5_4geqi") position = Vector2(10, 7) script = ExtResource("5_4geqi") +[node name="Burnout_Left" parent="CharacterBody_Car" instance=ExtResource("6_nxxrr")] + +[node name="Burnout_Right" parent="CharacterBody_Car" instance=ExtResource("6_nxxrr")] +position = Vector2(-11, 7) + [node name="Line2D" type="Line2D" parent="CharacterBody_Car"] width_curve = SubResource("Curve_qs34t") diff --git a/scripts/car.gd b/scripts/car.gd index 7055b7b..0bbf2f7 100644 --- a/scripts/car.gd +++ b/scripts/car.gd @@ -52,6 +52,9 @@ var resetcar_movingspeed=resetcar_stoppedspeed+10 #stop timer when above this sp var resetcar_distance=128 #196 is roughly when car is in the middle of a two wide road var resetcar_steerangle=120 +#Effects +const BURNOUT_KEEP_ON_AFTER_START=1 + #Variables var running=false @@ -63,6 +66,9 @@ var autoreset=false var autosteer_enabled=false + +var burnout:float=0 #at 0 is off + @onready var ray_cast_fl: RayCast2D = $RayCast_FL @onready var ray_cast_fr: RayCast2D = $RayCast_FR @onready var reset_timer: Timer = $resetTimer @@ -93,6 +99,14 @@ func _physics_process(delta: float) -> void: velocity +=acceleration*delta #velocity = transform.x * 200 #vel = move_and_slide() + + if burnout>0: + $Burnout_Left.emitting=true + $Burnout_Right.emitting=true + else: + $Burnout_Left.emitting=false + $Burnout_Right.emitting=false + move_and_slide() for i in get_slide_collision_count(): @@ -117,9 +131,12 @@ func _physics_process(delta: float) -> void: if velocity.length() > resetcar_movingspeed: reset_timer.stop() - - enginesound.setCarSpeed(velocity.length()) - enginesound.setCarAcceleration(applied_engine_power/engine_power,delta) + if running: + enginesound.setCarSpeed(velocity.length()) + enginesound.setCarAcceleration(applied_engine_power/engine_power,delta) + else: #at start or end of round + enginesound.setCarSpeed(burnout*500) + enginesound.setCarAcceleration(1.0,delta) #print("Car Accel="+str(acceleration.length()) +"/"+str(engine_power)) @@ -171,8 +188,10 @@ func get_input(delta:float): applied_engine_power=0 - if running: - if Input.is_action_pressed(Gamestate.userinput_prefix+str(playerid)): + + var key_accelerator_pressed=Input.is_action_pressed(Gamestate.userinput_prefix+str(playerid)) + if key_accelerator_pressed: + if running: #velocity = transform.x * 500 applied_engine_power=engine_power @@ -182,10 +201,13 @@ func get_input(delta:float): collision_enable_timer.start() if autoreset: - print("Cancel autoreset") autoreset=false - #if Input.is_action_pressed("ui_down"): - #acceleration = transform.x * braking + + if not running and finalTime==-1 and key_accelerator_pressed: #at start + burnout=min(1.0,burnout+1.0*delta) + else: + burnout=max(0,burnout-1.0/BURNOUT_KEEP_ON_AFTER_START*delta) + acceleration = transform.x * applied_engine_power diff --git a/scripts/tiretrails.gd b/scripts/tiretrails.gd index 5342805..5dd28fb 100644 --- a/scripts/tiretrails.gd +++ b/scripts/tiretrails.gd @@ -38,6 +38,6 @@ func setSliding(psliding:bool): curve.add_point(Vector2(1,0),-5,0,Curve.TANGENT_FREE,Curve.TANGENT_FREE) currentTrail.width_curve=curve currentTrail.set_as_top_level(true) - currentTrail.z_index=9 #above road, behind car + currentTrail.z_index=8 #above road, behind car isSliding=psliding