Player Missile

This commit is contained in:
Felipe M 2021-05-18 20:33:18 +02:00
parent b7b4d03fda
commit 853eb28d33
Signed by: fmartingr
GPG key ID: 716BC147715E716F
6 changed files with 80 additions and 9 deletions

View file

@ -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: