]> Untitled Git - star-foxy.git/blobdiff - player/player.gd
Updated with keyboard controls
[star-foxy.git] / player / player.gd
index 53bd3ed500259114a93cd216d6d67f71cb75e0cb..018f6694bc23ba003487e072c61e66c6bfc4d694 100644 (file)
@@ -1,11 +1,13 @@
 extends KinematicBody
 
 extends KinematicBody
 
-const SPEED_FORWARD = 5
-const SPEED_TURN = 60
-const SPEED_AIM = PI / 4
-const FRICTION = 0.99
+const SPEED_FORWARD = 20
+const SPEED_MAX = 20
+const SPEED_TURN = 120
+const SPEED_AIM = PI / 2
 
 
+var bullet_alterating = 0
 var velocity = Vector3()
 var velocity = Vector3()
+var scene_bullet = preload("res://player/bullet.tscn")
 
 # Called when the node enters the scene tree for the first time.
 func _ready():
 
 # Called when the node enters the scene tree for the first time.
 func _ready():
@@ -27,25 +29,42 @@ func get_player_input(delta):
                velocity += SPEED_TURN * -vec_vertical * delta
        
        if Input.is_action_pressed("player_aim_up"):
                velocity += SPEED_TURN * -vec_vertical * delta
        
        if Input.is_action_pressed("player_aim_up"):
-               rotate_x(SPEED_AIM * delta)
+               rotate_object_local(Vector3.RIGHT, SPEED_AIM * delta)
        elif Input.is_action_pressed("player_aim_down"):
        elif Input.is_action_pressed("player_aim_down"):
-               rotate_x(-SPEED_AIM * delta)    
+               rotate_object_local(Vector3.RIGHT, -SPEED_AIM * delta)  
                
        if Input.is_action_pressed("player_aim_left"):
                
        if Input.is_action_pressed("player_aim_left"):
-               rotate_y(SPEED_AIM * delta)
+               rotate(Vector3.UP, SPEED_AIM * delta)
        elif Input.is_action_pressed("player_aim_right"):
        elif Input.is_action_pressed("player_aim_right"):
-               rotate_y(-SPEED_AIM * delta)    
+               rotate(Vector3.UP, -SPEED_AIM * delta)  
                
                
+       # offense
+       if Input.is_action_pressed("player_fire"):
+               if $bullet_timer.time_left == 0:
+                       fire_bullet()
+               
+func fire_bullet():
+       var bullet = scene_bullet.instance()
+       $"..".add_child(bullet)
+       
+       bullet_alterating = (bullet_alterating + 1) % 2
+       bullet.translation = translation - transform.basis.x * (4 * bullet_alterating - 2)
+       bullet.rotation = rotation
+       bullet.direction = -transform.basis.z
+       
+       $bullet_timer.start()
        
 func _process(delta):
        # get velocity changes player asks for
        get_player_input(delta)
        
 func _process(delta):
        # get velocity changes player asks for
        get_player_input(delta)
-       velocity.x *= FRICTION
-       velocity.y *= FRICTION
        
        # move foward according to the camera's POV
        var vec_forward = transform.basis.z
        velocity += SPEED_FORWARD * -vec_forward * delta
        
        # move foward according to the camera's POV
        var vec_forward = transform.basis.z
        velocity += SPEED_FORWARD * -vec_forward * delta
+       
+       # air friction
+       var friction = SPEED_MAX / velocity.length()
+       velocity *= friction
 
 
-func _physics_process(delta):
+func _physics_process(_delta):
        velocity = move_and_slide(velocity, Vector3.UP)
        velocity = move_and_slide(velocity, Vector3.UP)