Wands will autoshoot when button is held

This commit is contained in:
Logan 2020-07-17 16:24:04 -05:00
parent 26828da27b
commit f64ace3402
4 changed files with 45 additions and 28 deletions

View file

@ -3,8 +3,8 @@
[ext_resource path="res://script/player.gd" type="Script" id=1]
[ext_resource path="res://meta/BoundedCamera.tscn" type="PackedScene" id=2]
[ext_resource path="res://script/PlayerStateMachine.gd" type="Script" id=3]
[ext_resource path="res://art/Wand.png" type="Texture" id=4]
[ext_resource path="res://art/WizardM.png" type="Texture" id=5]
[ext_resource path="res://art/WizardM.png" type="Texture" id=4]
[ext_resource path="res://magic/Wands/BasicWand.tscn" type="PackedScene" id=5]
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( -7, 0, -7, -2, -6, -2, -6, -3, -5, -3, -5, -5, -6, -5, -6, -10, -7, -10, -7, -12, -6, -12, -6, -19, -4, -19, -4, -18, -3, -18, -3, -17, 1, -17, 1, -16, 3, -16, 3, -15, 4, -15, 4, -14, 5, -14, 5, -13, 6, -13, 6, -12, 7, -12, 7, -10, 6, -10, 6, -9, 5, -9, 5, -8, 6, -8, 6, -4, 5, -4, 5, 0, -7, 0 )
@ -77,22 +77,9 @@ drag_margin_bottom = 0.0
[node name="PlayerStateMachine" type="Node" parent="."]
script = ExtResource( 3 )
[node name="HoldPosition" type="Position2D" parent="."]
position = Vector2( 0, -6 )
rotation = 1.5708
[node name="Wand" type="Sprite" parent="HoldPosition"]
position = Vector2( 9, -4.76837e-007 )
rotation = 1.5708
texture = ExtResource( 4 )
[node name="ProjectileSpawn" type="Position2D" parent="HoldPosition"]
position = Vector2( 17, -9.53674e-007 )
rotation = 1.5708
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -12 )
texture = ExtResource( 5 )
texture = ExtResource( 4 )
vframes = 3
hframes = 4
@ -126,4 +113,10 @@ position = Vector2( 0, -7 )
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hitbox"]
visible = false
polygon = PoolVector2Array( -6, -12, -6, -5, -7, -5, -7, -3, -6, -3, -6, 2, -5, 2, -5, 4, -6, 4, -6, 5, -7, 5, -7, 7, 5, 7, 5, 3, 6, 3, 6, -1, 5, -1, 5, -2, 6, -2, 6, -3, 7, -3, 7, -5, 6, -5, 6, -6, 5, -6, 5, -7, 4, -7, 4, -8, 3, -8, 3, -9, 1, -9, 1, -10, -3, -10, -3, -11, -4, -11, -4, -12, -6, -12 )
[node name="HoldPosition" type="Position2D" parent="."]
position = Vector2( 0, -7 )
[node name="Wand" parent="HoldPosition" instance=ExtResource( 5 )]
position = Vector2( 14, 0 )
[connection signal="grounded_updated" from="." to="Node2D" method="_on_grounded_updated"]

View file

@ -0,0 +1,17 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://art/Wand.png" type="Texture" id=1]
[ext_resource path="res://script/BasicWand.gd" type="Script" id=2]
[node name="Wand" type="Sprite"]
position = Vector2( 7, 0 )
rotation = 1.5708
texture = ExtResource( 1 )
script = ExtResource( 2 )
[node name="ProjectileSpawn" type="Position2D" parent="."]
position = Vector2( -6.11959e-007, -7 )
[node name="ShootDelay" type="Timer" parent="."]
wait_time = 0.4
one_shot = true

15
script/BasicWand.gd Normal file
View file

@ -0,0 +1,15 @@
extends Sprite
onready var ShootDelay : Timer = $ShootDelay
onready var ProjectileSpawn : Timer = $ProjectileSpawn
export var projectile_ps = globals.WHITE_PROJECTILE_PS
func fire_projectile(rot):
if ShootDelay.is_stopped():
var temp = projectile_ps.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.rotation_degrees = rot
temp.launch()
ShootDelay.start()

View file

@ -15,7 +15,6 @@ var walljump_height = 2.25 * 16
var jump_duration = 0.35
var is_grounded
var touching_wall = 0
var projectile_ps = globals.WHITE_PROJECTILE_PS
onready var Spr: Sprite = $Sprite
onready var Occluder: LightOccluder2D = $Sprite/LightOccluder2D
@ -25,6 +24,7 @@ onready var ShootDelay: Timer = $ShootDelay
onready var StateMachine: Node = $PlayerStateMachine
onready var HoldPosition: Node2D = $HoldPosition
onready var ProjectileSpawn: Node2D = $HoldPosition/ProjectileSpawn
onready var Wand: Sprite = $HoldPosition/Wand
@ -43,10 +43,9 @@ func handle_move_input():
input_direction = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
velocity.x = lerp(velocity.x, speed * input_direction, get_movement_weight())
HoldPosition.look_at(get_global_mouse_position())
HoldPosition.rotation_degrees
if Input.is_action_just_pressed("shoot"):
fire_projectile()
if Input.is_action_pressed("shoot"):
Wand.fire_projectile(HoldPosition.rotation_degrees)
if input_direction > 0:
Spr.flip_h = false
@ -60,14 +59,7 @@ func jump():
velocity.y = max_jump_velocity
CoyoteTimer.stop()
func fire_projectile():
if ShootDelay.is_stopped():
var temp = projectile_ps.instance()
get_tree().current_scene.add_child(temp)
temp.global_position = ProjectileSpawn.global_position
temp.rotation_degrees = HoldPosition.rotation_degrees
temp.launch()
ShootDelay.start()
func apply_gravity(delta, modifier = 1):
velocity.y += gravity * delta * modifier