small racing game im working on
Diffstat (limited to 'classes/human_car.gd')
| -rw-r--r-- | classes/human_car.gd | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/classes/human_car.gd b/classes/human_car.gd index 335b604..f70c06d 100644 --- a/classes/human_car.gd +++ b/classes/human_car.gd @@ -1,19 +1,40 @@ class_name HumanCar extends Car -static func attach(to: PackedScene) -> HumanCar: +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: - throttle = Input.get_action_strength("accel") - brake = Input.get_action_strength("brake") * MAX_BRAKE_FORCE - steer(Input.get_axis("left", "right")) + steer(steer_left - steer_right) super(delta) + shup = false + shown = false -func shift_up(): - return Input.is_action_just_pressed("shift_up") - -func shift_down(): - return Input.is_action_just_pressed("shift_down") +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 |