Player shoots at mouse

This commit is contained in:
Logan 2020-07-17 15:21:22 -05:00
parent 175f64b738
commit 25f984c213
5 changed files with 33 additions and 11 deletions

View file

@ -9,7 +9,7 @@
[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 )
[sub_resource type="CapsuleShape2D" id=6]
[sub_resource type="CapsuleShape2D" id=2]
radius = 6.0
height = 2.0
@ -79,14 +79,16 @@ script = ExtResource( 3 )
[node name="HoldPosition" type="Position2D" parent="."]
position = Vector2( 0, -6 )
rotation = 1.57079
rotation = 1.5708
[node name="Wand" type="Sprite" parent="HoldPosition"]
position = Vector2( 2.86102e-005, -13 )
position = Vector2( 10, 0 )
rotation = 1.5708
texture = ExtResource( 4 )
[node name="ProjectileSpawn" type="Position2D" parent="HoldPosition/Wand"]
position = Vector2( 1.52588e-005, -7 )
[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 )
@ -102,7 +104,7 @@ occluder = SubResource( 1 )
[node name="WorldCollision" type="CollisionShape2D" parent="."]
visible = false
position = Vector2( 0, -7 )
shape = SubResource( 6 )
shape = SubResource( 2 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/Idle = SubResource( 3 )

View file

@ -10,3 +10,5 @@ position = Vector2( 152, 157 )
[node name="TileMap" parent="." instance=ExtResource( 2 )]
tile_data = PoolIntArray( 0, 0, 8, 1, 0, 10, 2, 0, 10, 3, 0, 10, 4, 0, 10, 5, 0, 10, 6, 0, 10, 7, 0, 10, 8, 0, 10, 9, 0, 10, 10, 0, 10, 11, 0, 10, 12, 0, 10, 13, 0, 10, 14, 0, 10, 15, 0, 10, 16, 0, 10, 17, 0, 10, 18, 0, 10, 19, 0, 10, 20, 0, 10, 21, 0, 11, 65536, 0, 65544, 65537, 0, 131078, 65538, 0, 196617, 65539, 0, 196617, 65540, 0, 196617, 65541, 0, 196617, 65542, 0, 196617, 65543, 0, 196617, 65544, 0, 196617, 65545, 0, 196617, 65546, 0, 196617, 65547, 0, 196617, 65548, 0, 196617, 65549, 0, 196617, 65550, 0, 196617, 65551, 0, 196617, 65552, 0, 196617, 65553, 0, 196617, 65554, 0, 196617, 65555, 0, 196617, 65556, 0, 131077, 65557, 0, 131083, 131072, 0, 65544, 131073, 0, 131083, 131092, 0, 65544, 131093, 0, 131083, 196608, 0, 65544, 196609, 0, 131083, 196628, 0, 65544, 196629, 0, 131083, 262144, 0, 65544, 262145, 0, 131083, 262164, 0, 65544, 262165, 0, 131083, 327680, 0, 65544, 327681, 0, 131083, 327700, 0, 65544, 327701, 0, 131083, 393216, 0, 65544, 393217, 0, 131083, 393236, 0, 65544, 393237, 0, 131083, 458752, 0, 65544, 458753, 0, 131083, 458772, 0, 65544, 458773, 0, 131083, 524288, 0, 65544, 524289, 0, 131083, 524308, 0, 65544, 524309, 0, 131083, 589824, 0, 65544, 589825, 0, 131083, 589844, 0, 65544, 589845, 0, 131083, 655360, 0, 65544, 655361, 0, 131083, 655380, 0, 65544, 655381, 0, 131083, 720896, 0, 65544, 720897, 0, 65542, 720898, 0, 10, 720899, 0, 10, 720900, 0, 10, 720901, 0, 10, 720902, 0, 10, 720903, 0, 10, 720904, 0, 10, 720905, 0, 10, 720906, 0, 10, 720907, 0, 10, 720908, 0, 10, 720909, 0, 10, 720910, 0, 10, 720911, 0, 10, 720912, 0, 10, 720913, 0, 10, 720914, 0, 10, 720915, 0, 10, 720916, 0, 65541, 720917, 0, 131083, 786432, 0, 196616, 786433, 0, 196617, 786434, 0, 196617, 786435, 0, 196617, 786436, 0, 196617, 786437, 0, 196617, 786438, 0, 196617, 786439, 0, 196617, 786440, 0, 196617, 786441, 0, 196617, 786442, 0, 196617, 786443, 0, 196617, 786444, 0, 196617, 786445, 0, 196617, 786446, 0, 196617, 786447, 0, 196617, 786448, 0, 196617, 786449, 0, 196617, 786450, 0, 196617, 786451, 0, 196617, 786452, 0, 196617, 786453, 0, 196619 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]

View file

@ -9,8 +9,9 @@ func _physics_process(delta):
if collision != null:
on_impact()
func launch(direction: Vector2):
velocity = direction * speed
func launch():
velocity = (Vector2(speed, 0)).rotated(rotation)
print(velocity)
func on_impact():
queue_free()

4
script/globals.gd Normal file
View file

@ -0,0 +1,4 @@
extends Node
const TILE_SIZE = 16
const WHITE_PROJECTILE_PS = preload("res://magic/projectiles/WhiteProjectile.tscn")

View file

@ -15,6 +15,7 @@ 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
@ -22,7 +23,7 @@ onready var Anim: AnimationPlayer = $AnimationPlayer
onready var CoyoteTimer: Timer = $CoyoteTimer
onready var StateMachine: Node = $PlayerStateMachine
onready var HoldPosition: Node2D = $HoldPosition
onready var ProjectileSpawn: Node2D = $HoldPosition/Wand/ProjectileSpawn
onready var ProjectileSpawn: Node2D = $HoldPosition/ProjectileSpawn
func _ready():
@ -39,21 +40,33 @@ func _physics_process(delta):
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()
print("fire")
if input_direction > 0:
Spr.flip_h = false
Occluder.scale.x = 1
HoldPosition.rotation_degrees = 90
if input_direction < 0:
Spr.flip_h = true
Occluder.scale.x = -1
HoldPosition.rotation_degrees = -90
func jump():
velocity.y = max_jump_velocity
CoyoteTimer.stop()
func fire_projectile():
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()
func apply_gravity(delta, modifier = 1):
velocity.y += gravity * delta * modifier