Initial reorganization of shmup prroject; temp player sprites added.
This commit is contained in:
parent
02d14e913c
commit
accc463791
116 changed files with 298 additions and 177 deletions
18
scenes/bullet.gd
Normal file
18
scenes/bullet.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends Area2D
|
||||
|
||||
@export var speed = -250
|
||||
|
||||
func start(pos):
|
||||
position = pos
|
||||
|
||||
func _process(delta):
|
||||
position.y += speed * delta
|
||||
|
||||
# Signal checks to see if the bullet leaves the viewport then removes bullet.
|
||||
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()
|
||||
1
scenes/bullet.gd.uid
Normal file
1
scenes/bullet.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c6oorp45vpqpc
|
||||
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://bwxxdrdvo3le0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c6oorp45vpqpc" path="res://scenes/bullet.gd" id="1_v8qja"]
|
||||
[ext_resource type="Texture2D" uid="uid://bltpqew3le1j" path="res://_graphics/Mini Pixel Pack 3/Projectiles/Player_charged_beam (16 x 16).png" id="2_t4vbm"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2b2rl"]
|
||||
size = Vector2(12, 10)
|
||||
|
||||
[node name="Bullet" type="Area2D"]
|
||||
script = ExtResource("1_v8qja")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_t4vbm")
|
||||
hframes = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -1)
|
||||
shape = SubResource("RectangleShape2D_2b2rl")
|
||||
|
||||
[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"]
|
||||
56
scenes/enemy.gd
Normal file
56
scenes/enemy.gd
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
extends Area2D
|
||||
|
||||
var bullet_scene = preload("res://scenes/enemy_bullet.tscn")
|
||||
var start_pos = Vector2.ZERO
|
||||
var speed = 0
|
||||
var tween_speed: float = 1.4
|
||||
|
||||
var exploding = false
|
||||
|
||||
var enemy_move_aggression = randf_range(5, 20)
|
||||
var enemy_shoot_aggression = randf_range(4, 20)
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
|
||||
|
||||
func start(pos):
|
||||
speed = 0
|
||||
position = Vector2(pos.x, -pos.y)
|
||||
start_pos = pos
|
||||
await get_tree().create_timer(randf_range(0.25, 0.55)).timeout
|
||||
var tween = create_tween().set_trans(Tween.TRANS_BACK)
|
||||
tween.tween_property(self, "position:y", start_pos.y, tween_speed)
|
||||
await tween.finished
|
||||
$MoveTimer.wait_time = enemy_move_aggression
|
||||
$MoveTimer.start()
|
||||
$ShootTimer.wait_time = enemy_shoot_aggression
|
||||
$ShootTimer.start()
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
speed = randf_range(75, 100)
|
||||
|
||||
func _on_shoot_timer_timeout():
|
||||
var b = bullet_scene.instantiate()
|
||||
get_tree().root.add_child(b)
|
||||
b.start(position)
|
||||
$ShootTimer.wait_time = randf_range(4, 20)
|
||||
$ShootTimer.start()
|
||||
|
||||
func _process(delta):
|
||||
position.y += speed * delta
|
||||
if position.y > screensize.y + 32:
|
||||
start(start_pos)
|
||||
|
||||
|
||||
func explode():
|
||||
if exploding: return
|
||||
exploding = true
|
||||
print_debug("Enemy explode!")
|
||||
EventBus.enemy_hit.emit(5)
|
||||
speed = 0
|
||||
$AnimationPlayer.play("explode")
|
||||
set_deferred("monitoring", false)
|
||||
await $AnimationPlayer.animation_finished
|
||||
queue_free()
|
||||
EventBus.enemy_died.emit()
|
||||
1
scenes/enemy.gd.uid
Normal file
1
scenes/enemy.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://xoihsrr4hw4k
|
||||
161
scenes/enemy.tscn
Normal file
161
scenes/enemy.tscn
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://mp72cjiuquik"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://xoihsrr4hw4k" path="res://scenes/enemy.gd" id="1_4gyqm"]
|
||||
[ext_resource type="Texture2D" uid="uid://deyu1prtitqcp" path="res://_graphics/Mini Pixel Pack 3/Enemies/Bon_Bon (16 x 16).png" id="1_7k104"]
|
||||
[ext_resource type="Texture2D" uid="uid://h04wm5a27u0" path="res://_graphics/Mini Pixel Pack 3/Effects/Explosion (16 x 16).png" id="3_qi2p4"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4gyqm"]
|
||||
size = Vector2(14, 8)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_iifgy"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:texture")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [ExtResource("1_7k104")]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprite2D:hframes")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [4]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite2D:frame")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [2]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_qi2p4"]
|
||||
resource_name = "bounce"
|
||||
loop_mode = 1
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:texture")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [ExtResource("1_7k104")]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprite2D:hframes")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [4]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite2D:frame")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1023555, 0.2, 0.3, 0.35),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [2, 1, 0, 3, 0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_epg4t"]
|
||||
resource_name = "explode"
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1, 2, 4, 5]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprite2D:texture")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [ExtResource("3_qi2p4")]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite2D:hframes")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [6]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_3yqyl"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_iifgy"),
|
||||
&"bounce": SubResource("Animation_qi2p4"),
|
||||
&"explode": SubResource("Animation_epg4t")
|
||||
}
|
||||
|
||||
[node name="Enemy" type="Area2D" groups=["enemies"]]
|
||||
script = ExtResource("1_4gyqm")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_7k104")
|
||||
hframes = 4
|
||||
frame = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_4gyqm")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_3yqyl")
|
||||
}
|
||||
autoplay = "bounce"
|
||||
|
||||
[node name="MoveTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="ShootTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="MoveTimer" to="." method="_on_timer_timeout"]
|
||||
[connection signal="timeout" from="ShootTimer" to="." method="_on_shoot_timer_timeout"]
|
||||
20
scenes/enemy_bullet.gd
Normal file
20
scenes/enemy_bullet.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
extends Area2D
|
||||
|
||||
|
||||
|
||||
|
||||
@export var speed = 150
|
||||
|
||||
func start(pos):
|
||||
position = pos
|
||||
|
||||
func _process(delta):
|
||||
position.y += speed * delta
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited():
|
||||
queue_free()
|
||||
|
||||
func _on_area_entered(area):
|
||||
if area.name == "Player":
|
||||
queue_free()
|
||||
area.shield -= 1
|
||||
1
scenes/enemy_bullet.gd.uid
Normal file
1
scenes/enemy_bullet.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dusi2flaqer4b
|
||||
22
scenes/enemy_bullet.tscn
Normal file
22
scenes/enemy_bullet.tscn
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://3xbr5bnuk04u"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dubjbfdp6ep34" path="res://_graphics/Mini Pixel Pack 3/Projectiles/Enemy_projectile (16 x 16).png" id="1_1xapl"]
|
||||
[ext_resource type="Script" uid="uid://dusi2flaqer4b" path="res://scenes/enemy_bullet.gd" id="1_gl7bs"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gl7bs"]
|
||||
size = Vector2(6, 6)
|
||||
|
||||
[node name="EnemyBullet" type="Area2D" groups=["enemy_bullets"]]
|
||||
script = ExtResource("1_gl7bs")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_1xapl")
|
||||
hframes = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_gl7bs")
|
||||
|
||||
[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"]
|
||||
12
scenes/event_bus.gd
Normal file
12
scenes/event_bus.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
extends Node
|
||||
|
||||
@warning_ignore_start("unused_signal") # since otherwise Godot will throw a warning that the signal is unused in current scope
|
||||
|
||||
signal shield_changed(max_value: int, old_value: int, new_value: int)
|
||||
signal player_died()
|
||||
signal enemy_died()
|
||||
signal enemy_hit(value: int)
|
||||
signal initialize_shieldbar()
|
||||
signal start_game()
|
||||
|
||||
@warning_ignore_restore("unused_signal") # put any future signals you add between the two ignore annotations
|
||||
1
scenes/event_bus.gd.uid
Normal file
1
scenes/event_bus.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://jibpipn2p1c7
|
||||
51
scenes/explosion.tscn
Normal file
51
scenes/explosion.tscn
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://4jvu41vu2557"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://h04wm5a27u0" path="res://_graphics/Mini Pixel Pack 3/Effects/Explosion (16 x 16).png" id="1_q7epf"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_j4sxf"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_vxas0"]
|
||||
resource_name = "explosion-one-shot"
|
||||
length = 0.5
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2, 0.3, 0.4, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1, 3, 4, 5]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_m5xho"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_j4sxf"),
|
||||
&"explosion-one-shot": SubResource("Animation_vxas0")
|
||||
}
|
||||
|
||||
[node name="Explosion" type="Sprite2D"]
|
||||
texture = ExtResource("1_q7epf")
|
||||
hframes = 6
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_m5xho")
|
||||
}
|
||||
autoplay = "RESET"
|
||||
6
scenes/global.gd
Normal file
6
scenes/global.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Node
|
||||
|
||||
# Global Game variables
|
||||
var score: int = 0
|
||||
var new_game = true
|
||||
var playing = false
|
||||
1
scenes/global.gd.uid
Normal file
1
scenes/global.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dhfukspc2nyu0
|
||||
135
scenes/main.gd
Normal file
135
scenes/main.gd
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
extends Node2D
|
||||
|
||||
var enemy = preload("res://scenes/enemy.tscn")
|
||||
var player = preload("res://scenes/player.tscn")
|
||||
var instance = null
|
||||
var playing = false
|
||||
var enemy_count: int = 0:
|
||||
set(value):
|
||||
if value < 0:
|
||||
print_debug("Enemy value set to below zero: ", get_stack())
|
||||
if value > 27:
|
||||
print_debug("Enemy value set to above 27!: ", get_stack())
|
||||
enemy_count = value
|
||||
|
||||
const COLS: int = 9
|
||||
const ROWS: int = 3
|
||||
|
||||
@onready var start_button = $CanvasLayer/CenterContainer/Start
|
||||
@onready var game_over = $CanvasLayer/CenterContainer/GameOver
|
||||
|
||||
func _ready():
|
||||
game_over.hide()
|
||||
start_button.show()
|
||||
EventBus.player_died.connect(_on_player_died)
|
||||
EventBus.enemy_died.connect(_on_enemy_died)
|
||||
EventBus.enemy_hit.connect(_on_enemy_hit)
|
||||
|
||||
|
||||
func spawn_enemies():
|
||||
# print("Remaining enemies: ", enemy_count)
|
||||
# await get_tree().process_frame
|
||||
for x in range(COLS):
|
||||
for y in range(ROWS):
|
||||
var e = enemy.instantiate()
|
||||
var pos = Vector2(x * (16 + 8) + 24, 16 * 4 + y * 16)
|
||||
add_child(e)
|
||||
e.start(pos)
|
||||
enemy_count = ROWS * COLS
|
||||
await get_tree().process_frame
|
||||
print_debug("Remaining enemies: ", enemy_count, ", ", get_tree().get_nodes_in_group("enemies").size())
|
||||
|
||||
|
||||
|
||||
func _on_enemy_died():
|
||||
enemy_count -= 1
|
||||
print_debug(enemy_count)
|
||||
if enemy_count == 0:
|
||||
print_debug("Remaining enemies: ", enemy_count, ", ", get_tree().get_nodes_in_group("enemies").size())
|
||||
win_game()
|
||||
if enemy_count == ROWS * COLS / 2:
|
||||
print_debug("Enemy count is 50%")
|
||||
update_enemy_aggression(2,10)
|
||||
if enemy_count == ROWS * COLS / 4:
|
||||
print_debug("Enemy count is 25%")
|
||||
update_enemy_aggression(1,1)
|
||||
|
||||
func update_enemy_aggression(low,high):
|
||||
var nodes = get_tree().get_nodes_in_group("enemies")
|
||||
|
||||
for node in nodes:
|
||||
if node is Area2D:
|
||||
node.enemy_move_aggression = randf_range(low,high)
|
||||
node.enemy_shoot_aggression = randf_range(low,high)
|
||||
node.tween_speed = min(low,high) - .75
|
||||
|
||||
func _on_enemy_hit(value: int):
|
||||
Global.score += value
|
||||
$CanvasLayer/UI.update_score(Global.score)
|
||||
|
||||
func _on_player_died():
|
||||
# get_tree().call_group("enemies", "queue_free")
|
||||
# $Player.set_process(false)
|
||||
# get_tree().call_group("enemies", "set_process", false)
|
||||
enemy_win()
|
||||
instance.queue_free()
|
||||
game_over.show()
|
||||
await get_tree().create_timer(2).timeout
|
||||
game_over.hide()
|
||||
$CanvasLayer/Title.show()
|
||||
start_button.show()
|
||||
playing = false
|
||||
|
||||
func new_game():
|
||||
$CanvasLayer/Title.hide()
|
||||
# Ensure enemies are cleared.
|
||||
get_tree().call_group("enemies", "queue_free")
|
||||
get_tree().call_group("enemy_bullets", "queue_free")
|
||||
# print("Number of enemies at new_game: ",enemy_count)
|
||||
enemy_count = 0
|
||||
await get_tree().process_frame
|
||||
|
||||
# Reset score.
|
||||
Global.score = 0
|
||||
$CanvasLayer/UI.update_score(Global.score)
|
||||
|
||||
# Tell the shield to recharge.
|
||||
# EventBus.initialize_shieldbar.emit()
|
||||
# await EventBus.initialize_shieldbar
|
||||
|
||||
# instantiate the Player
|
||||
# await get_tree().create_timer(1).timeout
|
||||
instance = player.instantiate()
|
||||
add_child(instance)
|
||||
$Player.start()
|
||||
|
||||
# Tell the enemies to spawn!
|
||||
#await get_tree().create_timer(.5).timeout
|
||||
spawn_enemies()
|
||||
|
||||
# Tell the game we're playing.
|
||||
playing = true
|
||||
print("New game started!")
|
||||
|
||||
|
||||
func _input(EventInput):
|
||||
if EventInput.is_action_pressed("shoot") and playing == false:
|
||||
print("Input detected!")
|
||||
start_button.hide()
|
||||
new_game()
|
||||
|
||||
func _on_start_pressed():
|
||||
start_button.hide()
|
||||
new_game()
|
||||
|
||||
func win_game():
|
||||
playing = false
|
||||
game_over.show()
|
||||
$Player._on_player_victory()
|
||||
await get_tree().create_timer(2).timeout
|
||||
game_over.hide()
|
||||
$CanvasLayer/Title.show()
|
||||
start_button.show()
|
||||
|
||||
func enemy_win() -> void:
|
||||
print("Enemy win!")
|
||||
1
scenes/main.gd.uid
Normal file
1
scenes/main.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c51huloycn5as
|
||||
111
scenes/main.tscn
Normal file
111
scenes/main.tscn
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://cc2dnhuv4qx7m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c51huloycn5as" path="res://scenes/main.gd" id="1_h2yge"]
|
||||
[ext_resource type="PackedScene" uid="uid://tlcdxoupi2lb" path="res://scenes/parallax_starfield.tscn" id="2_5vw27"]
|
||||
[ext_resource type="Texture2D" uid="uid://b25w6ms7bxlhu" path="res://sprites/third space bgrnd.png" id="3_tipki"]
|
||||
[ext_resource type="PackedScene" uid="uid://s6wf3egdqtmh" path="res://scenes/ui.tscn" id="4_1bvp3"]
|
||||
[ext_resource type="Shader" uid="uid://x02irwg8ynvp" path="res://shaders/pixel_highlight.gdshader" id="4_272bh"]
|
||||
[ext_resource type="Texture2D" uid="uid://bonoqs5pisflo" path="res://_graphics/Mini Pixel Pack 3/UI objects/START (48 x 8).png" id="5_lquwl"]
|
||||
[ext_resource type="Texture2D" uid="uid://0mcbtnidp5kn" path="res://sprites/third space title.png" id="5_tipki"]
|
||||
[ext_resource type="Texture2D" uid="uid://bubqwoum50gf8" path="res://_graphics/Mini Pixel Pack 3/UI objects/GAME_OVER (72 x 8).png" id="6_7mycd"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_1bvp3"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("background:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Rect2(0, 0, 240, 320)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_h2yge"]
|
||||
resource_name = "scroll"
|
||||
length = 2.0
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("background:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Rect2(0, 0, 240, 320), Rect2(0, -64, 240, 320)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_lquwl"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_1bvp3"),
|
||||
&"scroll": SubResource("Animation_h2yge")
|
||||
}
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_kek77"]
|
||||
shader = ExtResource("4_272bh")
|
||||
shader_parameter/speed = 2.250000106875
|
||||
shader_parameter/line_width = 0.1450000068875
|
||||
shader_parameter/line_color = Color(1, 1, 1, 1)
|
||||
shader_parameter/pause_duration = 6.0
|
||||
shader_parameter/offset = 10.0
|
||||
shader_parameter/pixelate_line = 0
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5vw27"]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource("1_h2yge")
|
||||
|
||||
[node name="Parallax Starfield" parent="." instance=ExtResource("2_5vw27")]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_lquwl")
|
||||
}
|
||||
autoplay = "scroll"
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="UI" parent="CanvasLayer" instance=ExtResource("4_1bvp3")]
|
||||
offset_right = 196.0
|
||||
offset_bottom = 36.0
|
||||
|
||||
[node name="Title" type="TextureRect" parent="CanvasLayer"]
|
||||
self_modulate = Color(0.015236704, 0.015236706, 0.0152367065, 1)
|
||||
material = SubResource("ShaderMaterial_kek77")
|
||||
offset_left = 50.0
|
||||
offset_top = 50.0
|
||||
offset_right = 146.0
|
||||
offset_bottom = 117.0
|
||||
texture = ExtResource("5_tipki")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Start" type="TextureButton" parent="CanvasLayer/CenterContainer"]
|
||||
layout_mode = 2
|
||||
texture_normal = ExtResource("5_lquwl")
|
||||
|
||||
[node name="GameOver" type="TextureRect" parent="CanvasLayer/CenterContainer"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("6_7mycd")
|
||||
|
||||
[node name="background" type="Sprite2D" parent="."]
|
||||
z_index = -4
|
||||
texture_repeat = 2
|
||||
material = SubResource("ShaderMaterial_5vw27")
|
||||
scale = Vector2(1.1064814, 1.0557377)
|
||||
texture = ExtResource("3_tipki")
|
||||
centered = false
|
||||
region_rect = Rect2(0, 0, 240, 320)
|
||||
|
||||
[connection signal="pressed" from="CanvasLayer/CenterContainer/Start" to="." method="_on_start_pressed"]
|
||||
66
scenes/parallax_starfield.tscn
Normal file
66
scenes/parallax_starfield.tscn
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://tlcdxoupi2lb"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dpkeiihfos28m" path="res://_graphics/parallax/foreground stars.png" id="1_1f8kc"]
|
||||
[ext_resource type="Texture2D" uid="uid://4n7q1wsq13ub" path="res://_graphics/parallax/foreground stars_b.png" id="2_mewf1"]
|
||||
[ext_resource type="Texture2D" uid="uid://c855276xbf7g6" path="res://_graphics/parallax/midground stars.png" id="2_xwl8n"]
|
||||
[ext_resource type="Texture2D" uid="uid://bn5iw6fm88p2i" path="res://_graphics/parallax/background stars.png" id="3_mewf1"]
|
||||
|
||||
[node name="Parallax Starfield" type="Node2D"]
|
||||
|
||||
[node name="Foreground Stars" type="Parallax2D" parent="."]
|
||||
scroll_scale = Vector2(1.5, 1)
|
||||
scroll_offset = Vector2(52, 11)
|
||||
repeat_size = Vector2(0, 128)
|
||||
autoscroll = Vector2(0, 9)
|
||||
repeat_times = 5
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Foreground Stars"]
|
||||
modulate = Color(0.6524728, 0.65247285, 0.6524728, 1)
|
||||
texture_repeat = 2
|
||||
position = Vector2(89, 133)
|
||||
texture = ExtResource("1_1f8kc")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 0, 128, 32)
|
||||
|
||||
[node name="Foreground Stars_b" type="Parallax2D" parent="."]
|
||||
repeat_size = Vector2(0, 320)
|
||||
autoscroll = Vector2(0, 7)
|
||||
repeat_times = 5
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Foreground Stars_b"]
|
||||
modulate = Color(0.71867925, 0.71867925, 0.71867925, 1)
|
||||
texture_repeat = 2
|
||||
position = Vector2(151, 59)
|
||||
texture = ExtResource("2_mewf1")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 0, 128, 32)
|
||||
|
||||
[node name="Midground Stars" type="Parallax2D" parent="."]
|
||||
scroll_scale = Vector2(0.75, 1)
|
||||
repeat_size = Vector2(0, 320)
|
||||
autoscroll = Vector2(0, 5)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Midground Stars"]
|
||||
texture_repeat = 2
|
||||
position = Vector2(120, 160)
|
||||
texture = ExtResource("2_xwl8n")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 0, 240, 320)
|
||||
|
||||
[node name="Background Stars" type="Parallax2D" parent="."]
|
||||
scroll_scale = Vector2(-1, 1)
|
||||
repeat_size = Vector2(0, 320)
|
||||
autoscroll = Vector2(0, 2)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Background Stars"]
|
||||
texture_repeat = 2
|
||||
position = Vector2(120, 160)
|
||||
texture = ExtResource("3_mewf1")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 0, 240, 320)
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
z_index = -5
|
||||
offset_right = 239.0
|
||||
offset_bottom = 323.0
|
||||
color = Color(0, 0, 0, 1)
|
||||
135
scenes/player.gd
Normal file
135
scenes/player.gd
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
extends Area2D
|
||||
|
||||
|
||||
signal damage_taken
|
||||
# signal shield_damage
|
||||
# signal shield_ui
|
||||
|
||||
@export var speed: int = 150
|
||||
@export var cooldown: float = 0.25
|
||||
@export var bullet_scene : PackedScene
|
||||
@export var max_shield: int = 10
|
||||
var shield: int = 0:
|
||||
set = set_shield
|
||||
|
||||
|
||||
var can_shoot = false
|
||||
var shader_active: bool = false:
|
||||
set(value):
|
||||
if value == true:
|
||||
print_debug("Shader active!", get_stack())
|
||||
else:
|
||||
print_debug("Shader inactive!", get_stack())
|
||||
|
||||
var clamp_shield = clamp(shield, 0, max_shield)
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
@onready var explosion = $Explosion
|
||||
@onready var wait_time = $GunCooldown
|
||||
@onready var ship = $Ship
|
||||
|
||||
func _ready():
|
||||
set_process(false)
|
||||
print(shield)
|
||||
# start()
|
||||
|
||||
func start():
|
||||
print(shield)
|
||||
shader_active = false
|
||||
$Ship.frame = 1
|
||||
# $Ship/Boosters/BoosterBurst.hide()
|
||||
# $Ship/Boosters.hide()
|
||||
$Ship.show()
|
||||
position = Vector2(screensize.x / 2, screensize.y)
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "position:y", 48 * -1, .75).as_relative()
|
||||
await tween.finished
|
||||
$GunCooldown.wait_time = cooldown
|
||||
set_shield(max_shield)
|
||||
print(shield)
|
||||
await get_tree().create_timer(1).timeout
|
||||
set_process(true)
|
||||
# $Ship/Boosters.show()
|
||||
can_shoot = true
|
||||
# EventBus.shield_changed.emit(max_shield, old_value, shield)
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up", "down")
|
||||
if input.x > 0:
|
||||
$Ship.frame = 2
|
||||
# $Ship/Boosters.animation = "right"
|
||||
elif input.x < 0:
|
||||
$Ship.frame = 0
|
||||
# $Ship/Boosters.animation = "left"
|
||||
else:
|
||||
$Ship.frame = 1
|
||||
$Ship/Boosters.animation = "forward"
|
||||
position += input * speed * delta
|
||||
position = position.clamp(Vector2(8, 8), screensize - Vector2(8, 8))
|
||||
if Input.is_action_pressed("shoot"):
|
||||
shoot()
|
||||
|
||||
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 + ship.position + Vector2(0, -10))
|
||||
var tween = create_tween().set_parallel(false)
|
||||
tween.tween_property(ship, "position:y", 1, 0.1)
|
||||
tween.tween_property(ship, "position:y", 0, 0.05)
|
||||
|
||||
func set_shield(value: int):
|
||||
var old_value = shield
|
||||
# shield = clamp(value, 0, max_shield)
|
||||
shield = min(max_shield, value)
|
||||
EventBus.shield_changed.emit(max_shield, old_value, shield)
|
||||
print("Shield set to:", shield)
|
||||
if shield <= 0:
|
||||
set_process(false)
|
||||
$Ship.hide()
|
||||
shader_active = false
|
||||
$Explosion.show()
|
||||
$Explosion/AnimationPlayer.play("explosion-one-shot")
|
||||
await $Explosion/AnimationPlayer.animation_finished
|
||||
EventBus.player_died.emit()
|
||||
|
||||
|
||||
func _on_gun_cooldown_timeout() -> void:
|
||||
can_shoot = true
|
||||
|
||||
func _on_area_entered(area):
|
||||
if area.is_in_group("enemies"):
|
||||
shield -= int(max_shield / 2)
|
||||
# damage_taken.emit()
|
||||
area.explode()
|
||||
if area.is_in_group("enemy_bullets") and self.monitoring == true:
|
||||
damage_taken.emit()
|
||||
|
||||
|
||||
func _on_damage_taken():
|
||||
|
||||
if shield == 0:
|
||||
shader_active = false
|
||||
return
|
||||
|
||||
else:
|
||||
shader_active = true
|
||||
$Ship.material.set_shader_parameter("toggle", 1.0)
|
||||
await get_tree().create_timer(1).timeout
|
||||
$Ship.material.set_shader_parameter("toggle", 0.0)
|
||||
shader_active = false
|
||||
|
||||
func _on_player_victory() -> void:
|
||||
print("Victory!")
|
||||
# get_node("EnemyBullet").monitoring = false #TODO make sure bullets stop monitoring!
|
||||
set_process(false)
|
||||
$Ship.frame = 1
|
||||
await get_tree().create_timer(1).timeout
|
||||
# $Ship/Boosters/BoosterBurst.show()
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "position:y", 60 * -1, .25).set_ease(tween.EASE_IN)
|
||||
await tween.finished
|
||||
queue_free()
|
||||
1
scenes/player.gd.uid
Normal file
1
scenes/player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dcrnf4r6c5qaw
|
||||
133
scenes/player.tscn
Normal file
133
scenes/player.tscn
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
[gd_scene load_steps=20 format=3 uid="uid://pyuorpwb7lpe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dcrnf4r6c5qaw" path="res://scenes/player.gd" id="1_sweqy"]
|
||||
[ext_resource type="PackedScene" uid="uid://bwxxdrdvo3le0" path="res://scenes/bullet.tscn" id="2_1jxqw"]
|
||||
[ext_resource type="Texture2D" uid="uid://ces8fm7lxh574" path="res://_graphics/Mini Pixel Pack 3/Player ship/Boosters (16 x 16).png" id="3_1jxqw"]
|
||||
[ext_resource type="Shader" uid="uid://dfywtah53il1m" path="res://shaders/player_hit.gdshader" id="3_dw050"]
|
||||
[ext_resource type="Texture2D" uid="uid://bjdhq42ummgky" path="res://_graphics/Mini Pixel Pack 3/Player ship/Boosters_left (16 x 16).png" id="4_dw050"]
|
||||
[ext_resource type="Texture2D" uid="uid://42nppsb4mtv8" path="res://sprites/coop.png" id="4_smehm"]
|
||||
[ext_resource type="Texture2D" uid="uid://cjv3xbuj65pav" path="res://_graphics/Mini Pixel Pack 3/Player ship/Boosters_right (16 x 16).png" id="5_b26j0"]
|
||||
[ext_resource type="PackedScene" uid="uid://4jvu41vu2557" path="res://scenes/explosion.tscn" id="8_dw050"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b26j0"]
|
||||
shader = ExtResource("3_dw050")
|
||||
shader_parameter/toggle = 0.0
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_n7ghd"]
|
||||
atlas = ExtResource("3_1jxqw")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_nvl01"]
|
||||
atlas = ExtResource("3_1jxqw")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ivps1"]
|
||||
atlas = ExtResource("4_dw050")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_urp6f"]
|
||||
atlas = ExtResource("4_dw050")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_bwjto"]
|
||||
atlas = ExtResource("5_b26j0")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_606se"]
|
||||
atlas = ExtResource("5_b26j0")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_u1c27"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_n7ghd")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_nvl01")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"forward",
|
||||
"speed": 10.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ivps1")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_urp6f")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"left",
|
||||
"speed": 10.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_bwjto")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_606se")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"right",
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_dw050"]
|
||||
particles_animation = true
|
||||
particles_anim_h_frames = 2
|
||||
particles_anim_v_frames = 1
|
||||
particles_anim_loop = false
|
||||
|
||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_b26j0"]
|
||||
particle_flag_disable_z = true
|
||||
gravity = Vector3(0, 98, 0)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_op7ga"]
|
||||
size = Vector2(14, 14)
|
||||
|
||||
[node name="Player" type="Area2D"]
|
||||
script = ExtResource("1_sweqy")
|
||||
bullet_scene = ExtResource("2_1jxqw")
|
||||
|
||||
[node name="Ship" type="Sprite2D" parent="." groups=["ship"]]
|
||||
unique_name_in_owner = true
|
||||
material = SubResource("ShaderMaterial_b26j0")
|
||||
texture = ExtResource("4_smehm")
|
||||
hframes = 3
|
||||
frame = 1
|
||||
|
||||
[node name="Boosters" type="AnimatedSprite2D" parent="Ship"]
|
||||
visible = false
|
||||
position = Vector2(0, 15)
|
||||
sprite_frames = SubResource("SpriteFrames_u1c27")
|
||||
animation = &"forward"
|
||||
autoplay = "forward"
|
||||
|
||||
[node name="BoosterBurst" type="GPUParticles2D" parent="Ship/Boosters"]
|
||||
texture_repeat = 2
|
||||
material = SubResource("CanvasItemMaterial_dw050")
|
||||
amount = 10
|
||||
texture = ExtResource("3_1jxqw")
|
||||
lifetime = 0.75
|
||||
interp_to_end = 1.0
|
||||
preprocess = 1.83
|
||||
speed_scale = 15.69
|
||||
draw_order = 2
|
||||
trail_lifetime = 1.85
|
||||
trail_sections = 2
|
||||
process_material = SubResource("ParticleProcessMaterial_b26j0")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(2.0054688, 2.0054688)
|
||||
shape = SubResource("RectangleShape2D_op7ga")
|
||||
|
||||
[node name="GunCooldown" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="Explosion" parent="." instance=ExtResource("8_dw050")]
|
||||
visible = false
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="damage_taken" from="." to="." method="_on_damage_taken"]
|
||||
[connection signal="timeout" from="GunCooldown" to="." method="_on_gun_cooldown_timeout"]
|
||||
6
scenes/progress_bar.gd
Normal file
6
scenes/progress_bar.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends TextureProgressBar
|
||||
|
||||
func _ready():
|
||||
self.value = 0
|
||||
var shield_tween = get_tree().create_tween()
|
||||
shield_tween.tween_property(self, "value", 100, 3).set_trans(Tween.TRANS_LINEAR)
|
||||
1
scenes/progress_bar.gd.uid
Normal file
1
scenes/progress_bar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b85ktxeoj4b2n
|
||||
19
scenes/progress_bar.tscn
Normal file
19
scenes/progress_bar.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://c8s7htpdg4v4i"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://d11molrkdjjh5" path="res://_graphics/bar_background.png" id="1_q0tf5"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsl3pxvxiuoqg" path="res://_graphics/bar_foreground.png" id="2_5xu4y"]
|
||||
[ext_resource type="Script" uid="uid://b85ktxeoj4b2n" path="res://scenes/progress_bar.gd" id="3_5xu4y"]
|
||||
|
||||
[node name="ProgressBar" type="TextureProgressBar"]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
nine_patch_stretch = true
|
||||
stretch_margin_left = 8
|
||||
stretch_margin_top = 8
|
||||
stretch_margin_right = 8
|
||||
stretch_margin_bottom = 8
|
||||
texture_under = ExtResource("1_q0tf5")
|
||||
texture_progress = ExtResource("2_5xu4y")
|
||||
script = ExtResource("3_5xu4y")
|
||||
36
scenes/score_counter.gd
Normal file
36
scenes/score_counter.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
extends HBoxContainer
|
||||
|
||||
var last_score: String = "00000000"
|
||||
|
||||
var digit_coords = {
|
||||
1: Vector2(0, 0),
|
||||
2: Vector2(8, 0),
|
||||
3: Vector2(16, 0),
|
||||
4: Vector2(24, 0),
|
||||
5: Vector2(32, 0),
|
||||
6: Vector2(0, 8),
|
||||
7: Vector2(8, 8),
|
||||
8: Vector2(16, 8),
|
||||
9: Vector2(24, 8),
|
||||
0: Vector2(32, 8)
|
||||
}
|
||||
|
||||
func display_digits(n):
|
||||
|
||||
var s = "%08d" % n
|
||||
var start = 8 - str(n).length() # Finds the starting position of the counter by converting the score to a string, minus the leading zeros.
|
||||
var changed = false
|
||||
|
||||
for i in 8:
|
||||
get_child(i).texture.region = Rect2(digit_coords[int(s[i])], Vector2(8, 8))
|
||||
if i >= start and s[i] != last_score[i]:
|
||||
changed = true
|
||||
if changed:
|
||||
for i in 8:
|
||||
if i >= start:
|
||||
var tween = create_tween()
|
||||
tween.tween_property(get_child(i), "scale", Vector2(2,2), .15).set_trans(Tween.TRANS_BOUNCE)
|
||||
# tween.tween_property(get_child(i), "position:y", +5, .15).set_ease(tween.TRANS_QUART)
|
||||
tween.tween_property(get_child(i), "scale", Vector2(1,1), .15).set_trans(Tween.TRANS_BOUNCE)
|
||||
# tween.tween_property(get_child(i), "position:y", -5, .15).set_ease(tween.TRANS_QUART)
|
||||
last_score = s
|
||||
1
scenes/score_counter.gd.uid
Normal file
1
scenes/score_counter.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://val4c82n4krk
|
||||
83
scenes/score_counter.tscn
Normal file
83
scenes/score_counter.tscn
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://5qkcf1cpre32"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://val4c82n4krk" path="res://scenes/score_counter.gd" id="1_t7i3n"]
|
||||
[ext_resource type="Texture2D" uid="uid://ddh7mk2ekhq3u" path="res://_graphics/Mini Pixel Pack 3/UI objects/Number_font (8 x 8).png" id="1_terno"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_t7i3n"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_knege"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qa8aw"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pd82r"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_j44f5"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_emiqc"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_inuy1"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ke503"]
|
||||
atlas = ExtResource("1_terno")
|
||||
region = Rect2(32, 8, 8, 8)
|
||||
|
||||
[node name="ScoreCounter" type="HBoxContainer"]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
size_flags_horizontal = 8
|
||||
script = ExtResource("1_t7i3n")
|
||||
|
||||
[node name="Digit0" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_t7i3n")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit1" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_knege")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit2" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_qa8aw")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit3" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_pd82r")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit4" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_j44f5")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit5" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_emiqc")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit6" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_inuy1")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Digit7" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = SubResource("AtlasTexture_ke503")
|
||||
stretch_mode = 5
|
||||
41
scenes/ui.gd
Normal file
41
scenes/ui.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
extends MarginContainer
|
||||
|
||||
@onready var shield_bar = $HBoxContainer/ShieldBar
|
||||
@onready var score_counter = $HBoxContainer/ScoreCounter
|
||||
|
||||
var shader_active = false
|
||||
|
||||
func _ready():
|
||||
# get_node("Player.Ship").node_ready.connect("shield_ui", self, "_on_shield_ui")
|
||||
EventBus.shield_changed.connect(_on_shield_changed)
|
||||
EventBus.initialize_shieldbar.connect(_on_initialize_shieldbar)
|
||||
|
||||
func update_score(value):
|
||||
score_counter.display_digits(value)
|
||||
# var digits = score_counter.get_children()
|
||||
# var tween = create_tween()
|
||||
# tween.tween_property(digits,"scale",2,.15)
|
||||
|
||||
|
||||
func _on_shield_changed(max_value: int, old_value: int, new_value: int) -> void:
|
||||
shield_bar.max_value = max_value
|
||||
shield_bar.value = old_value
|
||||
var tween = create_tween()
|
||||
print_debug("Tweening shield bar")
|
||||
tween.tween_property(shield_bar, "value", new_value, .25).set_trans(Tween.TRANS_LINEAR)
|
||||
_on_fx_shield_ui()
|
||||
|
||||
|
||||
func _on_fx_shield_ui():
|
||||
shader_active = true
|
||||
shield_bar.material.set_shader_parameter("toggle", 1.0)
|
||||
await get_tree().create_timer(1).timeout
|
||||
shader_active = false
|
||||
shield_bar.material.set_shader_parameter("toggle", 0.0)
|
||||
|
||||
func _on_initialize_shieldbar():
|
||||
print("Shieldbar Initializing!")
|
||||
var tween = create_tween()
|
||||
tween.tween_property(shield_bar, "value", 100, .25).set_trans(Tween.TRANS_LINEAR)
|
||||
await tween.finished
|
||||
print_debug("Tweens played!")
|
||||
1
scenes/ui.gd.uid
Normal file
1
scenes/ui.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b544c65halgk4
|
||||
43
scenes/ui.tscn
Normal file
43
scenes/ui.tscn
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://s6wf3egdqtmh"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://d11molrkdjjh5" path="res://_graphics/bar_background.png" id="1_m6e0p"]
|
||||
[ext_resource type="Script" uid="uid://b544c65halgk4" path="res://scenes/ui.gd" id="1_nltto"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsl3pxvxiuoqg" path="res://_graphics/bar_foreground.png" id="2_27fn8"]
|
||||
[ext_resource type="Shader" uid="uid://dfywtah53il1m" path="res://shaders/player_hit.gdshader" id="2_ibotj"]
|
||||
[ext_resource type="PackedScene" uid="uid://5qkcf1cpre32" path="res://scenes/score_counter.tscn" id="4_ibotj"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_n5ude"]
|
||||
shader = ExtResource("2_ibotj")
|
||||
shader_parameter/toggle = 0.0
|
||||
|
||||
[node name="UI" type="MarginContainer"]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
script = ExtResource("1_nltto")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ShieldBar" type="TextureProgressBar" parent="HBoxContainer"]
|
||||
material = SubResource("ShaderMaterial_n5ude")
|
||||
custom_minimum_size = Vector2(80, 16)
|
||||
layout_mode = 2
|
||||
step = 0.0
|
||||
nine_patch_stretch = true
|
||||
stretch_margin_left = 3
|
||||
stretch_margin_top = 3
|
||||
stretch_margin_right = 3
|
||||
stretch_margin_bottom = 3
|
||||
texture_under = ExtResource("1_m6e0p")
|
||||
texture_progress = ExtResource("2_27fn8")
|
||||
|
||||
[node name="ScoreCounter" parent="HBoxContainer" instance=ExtResource("4_ibotj")]
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="value_changed" from="HBoxContainer/ShieldBar" to="." method="_on_shield_bar_value_changed"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue