Advertisement
NeshZul

111

May 1st, 2024
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 2.66 KB | Gaming | 0 0
  1. extends KinematicBody2D
  2.  
  3.  
  4. var bullet = load("res://bullet_laser.tscn")
  5.  
  6. var score = 0
  7. var dir
  8. var turn_speed = 0.02
  9.  
  10. var speed = 1800
  11. var friction = 0.008
  12. var acceleration = 0.004
  13. var velocity = Vector2.ZERO
  14.  
  15.  
  16. onready var damp_effect = $Thrust_patricles.get_process_material()
  17. onready var gun_laser = $gun_laser
  18. onready var tween = $Tween
  19. onready var camera =$Camera2D
  20.  
  21. var zoom_1 = Vector2(1,1)
  22. var zoom_5 = Vector2(5,5)
  23. var zoom_max = Vector2(30,30)
  24.  
  25. func _ready():
  26.     GameState.player = self
  27. func _process(delta):
  28.     var gun_laser_pos = gun_laser.position
  29.     damp_effect.damping = 100 - (velocity.length())
  30. #   print(velocity.length())
  31.     _rotate()
  32.     var input_velocity = Vector2.ZERO
  33.     # Check input for "desired" velocity
  34.     if Input.is_action_pressed("lean_right"):
  35.         input_velocity.x += 1
  36.     if Input.is_action_pressed("lean_left"):
  37.         input_velocity.x -= 1
  38.     if Input.is_action_pressed("back"):
  39.         input_velocity.y += 1
  40.     if Input.is_action_pressed("forward"):
  41.         input_velocity.y -= 1
  42.  
  43.  
  44.     input_velocity = input_velocity.normalized() * speed
  45.  
  46.     if Input.is_action_just_pressed("friction_off"):
  47.         friction = 0.000000000000001
  48.     if Input.is_action_just_released("friction_off"):
  49.         friction = 0.008
  50.     if Input.is_action_just_released("click_right"):
  51.         var dir_bullet = (get_global_mouse_position() - position).normalized()
  52.         var instance_bullet= bullet.instance()
  53.         instance_bullet.position = gun_laser.get_global_transform().origin
  54.         instance_bullet.rotation = gun_laser.rotation
  55.         if velocity.length() > 300:
  56.             instance_bullet.dir = dir_bullet * velocity.length()/100
  57.         else:
  58.             instance_bullet.dir = dir_bullet *2
  59.         get_parent().add_child(instance_bullet)
  60.  
  61.     # If there's input, accelerate to the input velocity
  62.     if input_velocity.length() > 0:
  63.         velocity = velocity.linear_interpolate(input_velocity, acceleration)
  64.     else:
  65.         # If there's no input, slow down to (0, 0)
  66.         velocity = velocity.linear_interpolate(Vector2.ZERO, friction)
  67.     velocity = move_and_slide(velocity)
  68.  
  69. func _rotate():
  70.     dir = get_angle_to(get_global_mouse_position())
  71.     if abs(dir) < turn_speed:
  72.         rotation += dir
  73.     else:
  74.         if dir > 0: rotation += turn_speed #clockwise
  75.         if dir < 0: rotation -= turn_speed #anit - clockwise
  76.  
  77. func _input(event):
  78.     if event is InputEventMouseButton:
  79.         if camera.zoom == zoom_1 and event.button_index == BUTTON_WHEEL_DOWN:
  80.             ## smooth
  81.             tween.stop_all()
  82.             tween.interpolate_property(camera, "zoom" , zoom_1,  zoom_5, 0.25,Tween.TRANS_CUBIC )
  83.             tween.start()
  84.         if camera.zoom == zoom_5 and event.button_index == BUTTON_WHEEL_UP:
  85.             tween.stop_all()
  86.             tween.interpolate_property(camera, "zoom" , zoom_5,  zoom_1, 0.25,Tween.TRANS_CUBIC )
  87.             tween.start()
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement