Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- # Default thrust speed.
- var thrust_speed : int = 20000
- # Default angular speed.
- var angular_speed : float = PI
- # Drag.
- var drag : int = 100
- # Velocity.
- var velocity : Vector2 = Vector2.ZERO
- # Read user input & apply.
- func get_input(delta):
- # Check for brake & adjust drag.
- if Input.is_action_pressed("brake"):
- drag = 1000
- else:
- drag = 100
- # Apply drag.
- if velocity.x > 0:
- if velocity.x >= drag: velocity.x -= drag
- else: velocity.x = 0
- elif velocity.x < 0:
- if velocity.x <= drag: velocity.x += drag
- else: velocity.x = 0
- if velocity.y > 0:
- if velocity.y >= drag: velocity.y -= drag
- else: velocity.y = 0
- elif velocity.y < 0:
- if velocity.y <= drag: velocity.y += drag
- else: velocity.y = 0
- # Check for guns.
- if Input.is_action_pressed("left_gun"):
- $LeftGun.fire()
- if Input.is_action_pressed("right_gun"):
- $RightGun.fire()
- # Reset direction.
- var direction = 0
- # Check for turns & adjust rotation.
- if Input.is_action_pressed("turn_left"):
- direction = -1
- if Input.is_action_pressed("turn_right"):
- direction = 1
- rotation += angular_speed * direction * delta
- # Check for thrust & adjust velocity.
- if Input.is_action_pressed("thrust"):
- velocity = Vector2.UP.rotated(rotation) * thrust_speed
- $ThrustSprite.play()
- $ThrustSprite.show()
- else:
- $ThrustSprite.hide()
- $ThrustSprite.stop()
- # Apply movement.
- move_and_slide(velocity * delta)
- # Physics process.
- func _physics_process(delta):
- # Receive user input.
- get_input(delta)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement