Player Missile
This commit is contained in:
parent
b7b4d03fda
commit
853eb28d33
6 changed files with 80 additions and 9 deletions
|
@ -3,6 +3,7 @@ extends KinematicBody2D
|
|||
const DustEffect = preload("res://Scenes/Effects/DustEffect.tscn")
|
||||
const WallDustEffect = preload("res://Scenes/Effects/WallDustEffect.tscn")
|
||||
const PlayerBullet = preload("res://Scenes/Player/PlayerBullet.tscn")
|
||||
const PlayerMissile = preload("res://Scenes/Player/PlayerMissile.tscn")
|
||||
const JumpEffect = preload("res://Scenes/Effects/JumpEffect.tscn")
|
||||
|
||||
var PlayerStats = ResourceLoader.PlayerStats
|
||||
|
@ -17,6 +18,7 @@ export (int) var wall_slide_speed = 42
|
|||
export (int) var max_wall_slide_speed = 128
|
||||
export (int) var max_slope = 46
|
||||
export (int) var bullet_speed = 250
|
||||
export (int) var missile_speed = 250
|
||||
|
||||
enum {
|
||||
MOVE,
|
||||
|
@ -79,6 +81,9 @@ func _physics_process(delta):
|
|||
|
||||
if Input.is_action_pressed("fire") and fireBulletTimer.time_left == 0:
|
||||
fire_bullet()
|
||||
|
||||
if Input.is_action_pressed("fire_missile") and fireBulletTimer.time_left == 0:
|
||||
fire_missile()
|
||||
|
||||
func fire_bullet():
|
||||
var bullet = Utils.instance_scene_on_main(PlayerBullet, muzzle.global_position)
|
||||
|
@ -87,6 +92,14 @@ func fire_bullet():
|
|||
bullet.rotation = bullet.velocity.angle()
|
||||
fireBulletTimer.start()
|
||||
|
||||
func fire_missile():
|
||||
var missile = Utils.instance_scene_on_main(PlayerMissile, muzzle.global_position)
|
||||
missile.velocity = Vector2.RIGHT.rotated(playerGun.rotation) * missile_speed
|
||||
missile.velocity.x *= sprite.scale.x # Flip left/right depending on players direction
|
||||
motion -= missile.velocity * 0.25
|
||||
missile.rotation = missile.velocity.angle()
|
||||
fireBulletTimer.start()
|
||||
|
||||
func create_dust_effect():
|
||||
var dust_position = global_position
|
||||
dust_position.x += rand_range(-4, 4)
|
||||
|
@ -134,7 +147,9 @@ func apply_gravity(delta):
|
|||
motion.y = min(motion.y, jump_force)
|
||||
|
||||
func update_animations(input_vector):
|
||||
sprite.scale.x = sign(get_local_mouse_position().x)
|
||||
var facing = sign(get_local_mouse_position().x)
|
||||
if facing != 0:
|
||||
sprite.scale.x = facing
|
||||
animation.playback_speed = 1
|
||||
|
||||
if input_vector.x != 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue