BULLET!
Added bullet template created a scene for the player character to move around in added the ability for the player character to shoot
This commit is contained in:
parent
7e60a3948c
commit
8fce988954
17
tutorial---basic-player-traits/bullet.gd
Normal file
17
tutorial---basic-player-traits/bullet.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends Area2D
|
||||
|
||||
var speed = 1500
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
position = calculateTrajectory(delta, transform)
|
||||
|
||||
func _on_Bullet_body_entered(body):
|
||||
if body.is_in_group("mobs"):
|
||||
body.queue_free()
|
||||
queue_free()
|
||||
|
||||
func calculateTrajectory(delta, the_transform):
|
||||
var new_position = position
|
||||
new_position += the_transform.y * -speed * delta
|
||||
return new_position
|
34
tutorial---basic-player-traits/bullet.tscn
Normal file
34
tutorial---basic-player-traits/bullet.tscn
Normal file
@ -0,0 +1,34 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dphnf0cjfrcu7"]
|
||||
|
||||
[ext_resource type="Script" path="res://bullet.gd" id="1_cpge0"]
|
||||
[ext_resource type="Texture2D" uid="uid://bixef7um6g62c" path="res://assets/helenknives.png" id="2_cxno8"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_8byar"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_cxno8")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_sehhp"]
|
||||
radius = 10.9589
|
||||
height = 43.5616
|
||||
|
||||
[node name="bullet" type="Area2D"]
|
||||
script = ExtResource("1_cpge0")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
modulate = Color(1, 1, 1, 0.509804)
|
||||
sprite_frames = SubResource("SpriteFrames_8byar")
|
||||
offset = Vector2(3.465, 0)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -10)
|
||||
scale = Vector2(1.095, 1.095)
|
||||
shape = SubResource("CapsuleShape2D_sehhp")
|
||||
one_way_collision_margin = 0.0
|
||||
debug_color = Color(0, 0.641316, 0.336247, 0.42)
|
@ -3,13 +3,17 @@ signal hit
|
||||
@export var speed = 600
|
||||
var spriteRotateAngle = 0
|
||||
var screen_size
|
||||
@export var bullet : PackedScene
|
||||
@export var firespeed = 10
|
||||
var timeBetweenBullets = 1.00000 / firespeed
|
||||
var deltaSum = 0
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
screen_size = get_viewport_rect().size
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
func _physics_process(delta: float) -> void:
|
||||
var velocity = Vector2.ZERO
|
||||
var currentSpeed = speed
|
||||
if Input.is_action_pressed("move_up"):
|
||||
@ -40,4 +44,17 @@ func _process(delta: float) -> void:
|
||||
position = position.clamp(Vector2.ZERO, screen_size)
|
||||
rotation_degrees = spriteRotateAngle
|
||||
|
||||
|
||||
if Input.is_action_pressed("shoot"):
|
||||
deltaSum += delta
|
||||
if deltaSum > timeBetweenBullets :
|
||||
var remainder = fmod(deltaSum, timeBetweenBullets)
|
||||
var numBullets = round ((deltaSum - remainder) / timeBetweenBullets)
|
||||
deltaSum = remainder
|
||||
for n in numBullets :
|
||||
shoot()
|
||||
|
||||
|
||||
func shoot():
|
||||
var b = bullet.instantiate()
|
||||
owner.add_child(b)
|
||||
b.transform = $FrontBulletSource.global_transform
|
||||
|
@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dn6vstynf4qyu"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://dn6vstynf4qyu"]
|
||||
|
||||
[ext_resource type="Script" path="res://player.gd" id="1_ro1ml"]
|
||||
[ext_resource type="PackedScene" uid="uid://dphnf0cjfrcu7" path="res://bullet.tscn" id="2_5m6h0"]
|
||||
[ext_resource type="Texture2D" uid="uid://c01t7u0aoeir7" path="res://assets/HelenMidQuality.png" id="2_k2fmb"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_77x2a"]
|
||||
@ -21,7 +22,9 @@ radius = 67.42
|
||||
radius = 9.06
|
||||
|
||||
[node name="Player" type="Area2D"]
|
||||
z_index = 1
|
||||
script = ExtResource("1_ro1ml")
|
||||
bullet = ExtResource("2_5m6h0")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
@ -35,3 +38,6 @@ shape = SubResource("CircleShape2D_emqsv")
|
||||
[node name="KillBox" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_tnmln")
|
||||
debug_color = Color(0.966315, 0, 0.481295, 0.42)
|
||||
|
||||
[node name="FrontBulletSource" type="Marker2D" parent="."]
|
||||
position = Vector2(0, -50)
|
||||
|
@ -47,3 +47,8 @@ focus={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
shoot={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
7
tutorial---basic-player-traits/testinggrounds.tscn
Normal file
7
tutorial---basic-player-traits/testinggrounds.tscn
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dgjpt6r8lqtp5"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dn6vstynf4qyu" path="res://player.tscn" id="1_oa02w"]
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_oa02w")]
|
Loading…
Reference in New Issue
Block a user