small racing game im working on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class_name HumanCar
extends Car

var device := -2 # -2 for any


var steer_left := 0.0
var steer_right := 0.0

func _ready():
	super()
	$Engine.volume = 0.3

static func attach(to: PackedScene, device: int = -2) -> HumanCar:
	var car := to.instantiate()
	car.set_script(load("res://classes/human_car.gd"))
	car.device = device
	return car

func _physics_process(delta: float) -> void:
	steer(steer_left - steer_right)
	super(delta)
	shup = false
	shown = false

func _input(event: InputEvent) -> void:
	if device != -2 and event.device != device:
		return
	if event.is_action("accel"):
		throttle = event.get_action_strength("accel")
	if event.is_action("brake"):
		brake = event.get_action_strength("brake") * MAX_BRAKE_FORCE
	if event.is_action("left"):
		steer_left = event.get_action_strength("left")
	if event.is_action("right"):
		steer_right = event.get_action_strength("right")
	if event.get_action_strength("shift_up") > .5:
		shup = true # process changes it to false after use because of a wierd bug i found
	if event.get_action_strength("shift_down") > .5:
		shown = true