Add new bullet scene

This commit is contained in:
James Skemp 2024-01-06 22:02:54 -06:00
parent 2e93fd8c33
commit 4689798b38
3 changed files with 43 additions and 1 deletions

21
bullet.gd Normal file
View File

@ -0,0 +1,21 @@
extends Area2D
const SPEED = 1000
const RANGE = 1200
var travelled_distance = 0
func _physics_process(delta):
# Current direction the bullet is facing.
var direction = Vector2.RIGHT.rotated(rotation)
position += direction * SPEED * delta
travelled_distance += SPEED * delta
if travelled_distance > RANGE:
queue_free()
func _on_body_entered(body):
queue_free()
if body.has_method("take_damage"):
body.take_damage()

21
bullet.tscn Normal file
View File

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://cav38t37qa74k"]
[ext_resource type="Texture2D" uid="uid://dftkbqwsfd68r" path="res://pistol/projectile.png" id="1_3vtra"]
[ext_resource type="Script" path="res://bullet.gd" id="1_6niae"]
[sub_resource type="CircleShape2D" id="CircleShape2D_d5m6x"]
radius = 16.0
[node name="Bullet" type="Area2D"]
collision_layer = 0
collision_mask = 3
script = ExtResource("1_6niae")
[node name="Projectile" type="Sprite2D" parent="."]
position = Vector2(-11, 0)
texture = ExtResource("1_3vtra")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_d5m6x")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

2
mob.gd
View File

@ -1,5 +1,5 @@
extends CharacterBody2D
# READY
# READY ROTATION
# Path to the player in running game.
@onready var player = get_node("/root/Game/Player")