Add bullet shooting mechanics and refactor scenes
This commit is contained in:
parent
8501c18dd1
commit
85155b1c7d
6 changed files with 156 additions and 97 deletions
|
|
@ -11,6 +11,7 @@ config_version=5
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="shmup01"
|
config/name="shmup01"
|
||||||
|
run/main_scene="uid://oq85kpt7a853"
|
||||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
extends Area2D
|
extends Area2D
|
||||||
@export var speed = -250
|
@export var speed = -250
|
||||||
|
|
||||||
|
|
||||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
|
||||||
queue_free()
|
|
||||||
|
|
||||||
|
|
||||||
func _on_area_entered(area: Area2D) -> void:
|
|
||||||
if area.is_in_group("enemies"):
|
|
||||||
area.explode()
|
|
||||||
queue_free()
|
|
||||||
|
|
||||||
func start(pos):
|
func start(pos):
|
||||||
position = pos
|
position = pos
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
position.y += speed * delta
|
position.y += speed * delta
|
||||||
|
|
||||||
|
func _on_area_entered(area: Area2D) -> void:
|
||||||
|
if area.is_in_group("enemies"):
|
||||||
|
area.explode()
|
||||||
|
queue_free()
|
||||||
|
|
||||||
|
func _on_visible_on_screen_notifier_2d_screen_exited():
|
||||||
|
queue_free()
|
||||||
|
|
|
||||||
23
scenes/bullet.tscn
Normal file
23
scenes/bullet.tscn
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://bus77xvomweiu"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://byl2w624w0lpb" path="res://scenes/bullet.gd" id="1_y25gk"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bltpqew3le1j" path="res://resources/Mini Pixel Pack 3/Projectiles/Player_charged_beam (16 x 16).png" id="2_l5glv"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_eoqba"]
|
||||||
|
size = Vector2(12, 11)
|
||||||
|
|
||||||
|
[node name="Bullet" type="Area2D"]
|
||||||
|
script = ExtResource("1_y25gk")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
texture = ExtResource("2_l5glv")
|
||||||
|
hframes = 2
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(0, -0.5)
|
||||||
|
shape = SubResource("RectangleShape2D_eoqba")
|
||||||
|
|
||||||
|
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||||
|
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||||
|
|
@ -1,93 +1,12 @@
|
||||||
[gd_scene load_steps=14 format=3 uid="uid://brutkgnx73onj"]
|
[gd_scene load_steps=3 format=3 uid="uid://brutkgnx73onj"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://c7fe5pl54gkem" path="res://scenes/player.gd" id="1_ocj2s"]
|
[ext_resource type="PackedScene" uid="uid://bkuucjejc7p2v" path="res://scenes/player.tscn" id="1_00tan"]
|
||||||
[ext_resource type="Texture2D" uid="uid://di2xhcwcdbhxg" path="res://resources/Mini Pixel Pack 3/Player ship/Player_ship (16 x 16).png" id="2_din8e"]
|
[ext_resource type="PackedScene" uid="uid://bus77xvomweiu" path="res://scenes/bullet.tscn" id="2_l1v76"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ces8fm7lxh574" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters (16 x 16).png" id="3_4bh5q"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://bjdhq42ummgky" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters_left (16 x 16).png" id="4_e124b"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://cjv3xbuj65pav" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters_right (16 x 16).png" id="5_101mb"]
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hbo4f"]
|
|
||||||
atlas = ExtResource("3_4bh5q")
|
|
||||||
region = Rect2(0, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ctvyo"]
|
|
||||||
atlas = ExtResource("3_4bh5q")
|
|
||||||
region = Rect2(16, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qixtg"]
|
|
||||||
atlas = ExtResource("4_e124b")
|
|
||||||
region = Rect2(0, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_nt65e"]
|
|
||||||
atlas = ExtResource("4_e124b")
|
|
||||||
region = Rect2(16, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_bhmdk"]
|
|
||||||
atlas = ExtResource("5_101mb")
|
|
||||||
region = Rect2(0, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_s5y6v"]
|
|
||||||
atlas = ExtResource("5_101mb")
|
|
||||||
region = Rect2(16, 0, 16, 16)
|
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_407ns"]
|
|
||||||
animations = [{
|
|
||||||
"frames": [{
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_hbo4f")
|
|
||||||
}, {
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_ctvyo")
|
|
||||||
}],
|
|
||||||
"loop": true,
|
|
||||||
"name": &"forward",
|
|
||||||
"speed": 10.0
|
|
||||||
}, {
|
|
||||||
"frames": [{
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_qixtg")
|
|
||||||
}, {
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_nt65e")
|
|
||||||
}],
|
|
||||||
"loop": true,
|
|
||||||
"name": &"left",
|
|
||||||
"speed": 10.0
|
|
||||||
}, {
|
|
||||||
"frames": [{
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_bhmdk")
|
|
||||||
}, {
|
|
||||||
"duration": 1.0,
|
|
||||||
"texture": SubResource("AtlasTexture_s5y6v")
|
|
||||||
}],
|
|
||||||
"loop": true,
|
|
||||||
"name": &"right",
|
|
||||||
"speed": 10.0
|
|
||||||
}]
|
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_w3w6i"]
|
|
||||||
size = Vector2(14, 14)
|
|
||||||
|
|
||||||
[node name="Gameplay" type="Node2D"]
|
[node name="Gameplay" type="Node2D"]
|
||||||
|
|
||||||
[node name="Player" type="Area2D" parent="."]
|
[node name="Player" parent="." instance=ExtResource("1_00tan")]
|
||||||
position = Vector2(-10, 0)
|
position = Vector2(-10, 0)
|
||||||
script = ExtResource("1_ocj2s")
|
bullet_scene = ExtResource("2_l1v76")
|
||||||
|
|
||||||
[node name="Ship" type="Sprite2D" parent="Player"]
|
[node name="Bullet" parent="." instance=ExtResource("2_l1v76")]
|
||||||
texture = ExtResource("2_din8e")
|
|
||||||
hframes = 3
|
|
||||||
frame = 1
|
|
||||||
|
|
||||||
[node name="Boosters" type="AnimatedSprite2D" parent="Player/Ship"]
|
|
||||||
position = Vector2(0, 15)
|
|
||||||
sprite_frames = SubResource("SpriteFrames_407ns")
|
|
||||||
animation = &"right"
|
|
||||||
autoplay = "forward"
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
|
|
||||||
shape = SubResource("RectangleShape2D_w3w6i")
|
|
||||||
|
|
||||||
[node name="GunCoolDown" type="Timer" parent="Player"]
|
|
||||||
one_shot = true
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,31 @@
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
@export var speed = 150
|
@export var speed = 150
|
||||||
|
@export var cooldown = 0.25
|
||||||
|
@export var bullet_scene : PackedScene
|
||||||
|
var can_shoot = true
|
||||||
|
|
||||||
@onready var screensize = get_viewport_rect().size
|
@onready var screensize = get_viewport_rect().size
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
start()
|
||||||
|
|
||||||
|
func start():
|
||||||
|
position = Vector2(screensize.x / 2, screensize.y - 64)
|
||||||
|
$GunCooldown.wait_time = cooldown
|
||||||
|
|
||||||
|
func shoot():
|
||||||
|
if not can_shoot:
|
||||||
|
return
|
||||||
|
can_shoot = false
|
||||||
|
$GunCooldown.start()
|
||||||
|
var b = bullet_scene.instantiate()
|
||||||
|
get_tree().root.add_child(b)
|
||||||
|
b.start(position + Vector2(0, -8))
|
||||||
|
|
||||||
|
func _on_gun_cooldown_timeout():
|
||||||
|
can_shoot = true
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var input = Input.get_vector("left", "right", "up", "down")
|
var input = Input.get_vector("left", "right", "up", "down")
|
||||||
if input.x > 0:
|
if input.x > 0:
|
||||||
|
|
@ -17,3 +40,5 @@ func _process(delta):
|
||||||
position += input * speed * delta
|
position += input * speed * delta
|
||||||
position = position.clamp(Vector2(8, 8), screensize-Vector2(8, 8))
|
position = position.clamp(Vector2(8, 8), screensize-Vector2(8, 8))
|
||||||
|
|
||||||
|
if Input.is_action_pressed("shoot"):
|
||||||
|
shoot()
|
||||||
|
|
|
||||||
93
scenes/player.tscn
Normal file
93
scenes/player.tscn
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
[gd_scene load_steps=14 format=3 uid="uid://bkuucjejc7p2v"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://c7fe5pl54gkem" path="res://scenes/player.gd" id="1_qlg0r"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://di2xhcwcdbhxg" path="res://resources/Mini Pixel Pack 3/Player ship/Player_ship (16 x 16).png" id="2_tuyoq"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://ces8fm7lxh574" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters (16 x 16).png" id="3_fjrip"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bjdhq42ummgky" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters_left (16 x 16).png" id="4_smehm"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cjv3xbuj65pav" path="res://resources/Mini Pixel Pack 3/Player ship/Boosters_right (16 x 16).png" id="5_ur7pv"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_hbo4f"]
|
||||||
|
atlas = ExtResource("3_fjrip")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ctvyo"]
|
||||||
|
atlas = ExtResource("3_fjrip")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_qixtg"]
|
||||||
|
atlas = ExtResource("4_smehm")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_nt65e"]
|
||||||
|
atlas = ExtResource("4_smehm")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_bhmdk"]
|
||||||
|
atlas = ExtResource("5_ur7pv")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_s5y6v"]
|
||||||
|
atlas = ExtResource("5_ur7pv")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_407ns"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_hbo4f")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_ctvyo")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"forward",
|
||||||
|
"speed": 10.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_qixtg")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_nt65e")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"left",
|
||||||
|
"speed": 10.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_bhmdk")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_s5y6v")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"right",
|
||||||
|
"speed": 10.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_w3w6i"]
|
||||||
|
size = Vector2(14, 14)
|
||||||
|
|
||||||
|
[node name="Player" type="Area2D"]
|
||||||
|
script = ExtResource("1_qlg0r")
|
||||||
|
|
||||||
|
[node name="Ship" type="Sprite2D" parent="."]
|
||||||
|
texture = ExtResource("2_tuyoq")
|
||||||
|
hframes = 3
|
||||||
|
frame = 1
|
||||||
|
|
||||||
|
[node name="Boosters" type="AnimatedSprite2D" parent="Ship"]
|
||||||
|
position = Vector2(0, 15)
|
||||||
|
sprite_frames = SubResource("SpriteFrames_407ns")
|
||||||
|
animation = &"right"
|
||||||
|
autoplay = "forward"
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_w3w6i")
|
||||||
|
|
||||||
|
[node name="GunCooldown" type="Timer" parent="."]
|
||||||
|
wait_time = 0.001
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
|
[connection signal="timeout" from="GunCooldown" to="." method="_on_gun_cooldown_timeout"]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue