Reworked weapons and projectiles
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class_name Background
|
||||
extends Node2D
|
||||
|
||||
|
||||
@onready var paralax_1 : Parallax2D = $Parallax1
|
||||
@onready var paralax_2 : Parallax2D = $Parallax2
|
||||
@onready var paralax_3 : Parallax2D = $Parallax3
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
paralax_1.scroll_offset.x = randf_range(1, paralax_1.repeat_size.x)
|
||||
paralax_2.scroll_offset.x = randf_range(1, paralax_2.repeat_size.x)
|
||||
paralax_3.scroll_offset.x = randf_range(1, paralax_3.repeat_size.x)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddp4unooscflj
|
||||
@@ -0,0 +1,50 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://chdrjc7c6bdpb"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddp4unooscflj" path="res://game/entities/world/background.gd" id="1_fypbl"]
|
||||
[ext_resource type="Texture2D" uid="uid://mvcnpsfsyiq6" path="res://images/passage/background.png" id="1_hvye4"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_yetnv"]
|
||||
atlas = ExtResource("1_hvye4")
|
||||
region = Rect2(0, 0, 3200, 360)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cuj01"]
|
||||
atlas = ExtResource("1_hvye4")
|
||||
region = Rect2(0, 360, 3200, 360)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_u0ams"]
|
||||
atlas = ExtResource("1_hvye4")
|
||||
region = Rect2(0, 720, 3200, 360)
|
||||
|
||||
[node name="Background" type="Node2D"]
|
||||
z_index = -100
|
||||
script = ExtResource("1_fypbl")
|
||||
|
||||
[node name="Parallax1" type="Parallax2D" parent="."]
|
||||
scroll_offset = Vector2(0, 180)
|
||||
repeat_size = Vector2(3200, 0)
|
||||
autoscroll = Vector2(-1, 0)
|
||||
follow_viewport = false
|
||||
ignore_camera_scroll = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Parallax1"]
|
||||
texture = SubResource("AtlasTexture_yetnv")
|
||||
|
||||
[node name="Parallax2" type="Parallax2D" parent="."]
|
||||
scroll_offset = Vector2(0, 180)
|
||||
repeat_size = Vector2(3200, 0)
|
||||
autoscroll = Vector2(-5, 0)
|
||||
follow_viewport = false
|
||||
ignore_camera_scroll = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Parallax2"]
|
||||
texture = SubResource("AtlasTexture_cuj01")
|
||||
|
||||
[node name="Parallax3" type="Parallax2D" parent="."]
|
||||
scroll_offset = Vector2(0, 180)
|
||||
repeat_size = Vector2(3200, 0)
|
||||
autoscroll = Vector2(-10, 0)
|
||||
follow_viewport = false
|
||||
ignore_camera_scroll = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Parallax3"]
|
||||
texture = SubResource("AtlasTexture_u0ams")
|
||||
@@ -0,0 +1,184 @@
|
||||
class_name Game
|
||||
extends Node
|
||||
|
||||
|
||||
const PASSAGE = preload("res://game/entities/world/passage.tscn")
|
||||
const AREA_MAP = preload("res://game/area_map/area_map.tscn")
|
||||
const WEAPON_SELECTION_SCREEN = preload("res://game/menu/ingame/weapon_selection_screen.tscn")
|
||||
|
||||
|
||||
var world_data : WorldData
|
||||
var current_area : AreaData
|
||||
var current_stage : StageData
|
||||
var current_sector : SectorData
|
||||
var current_passage : PassageData
|
||||
|
||||
var _current_passage_scene : Passage
|
||||
var _current_area_map_scene : AreaMap
|
||||
var _weapon_selection_screen : WeaponSelectionScreen
|
||||
|
||||
|
||||
@onready var pause_screen : Control = $PauseScreen
|
||||
@onready var game_over_screen : Control = $GameOverScreen
|
||||
@onready var victory_screen : Control = $VictoryScreen
|
||||
@onready var world_generator : WorldGenerator = $WorldGenerator
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pause_screen.hide()
|
||||
victory_screen.hide()
|
||||
game_over_screen.hide()
|
||||
|
||||
start_game(SaveManager.game_data)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var is_game_starded := _weapon_selection_screen == null
|
||||
var is_game_over := victory_screen.visible or game_over_screen.visible
|
||||
var use_pause := is_game_starded and not is_game_over
|
||||
if event.is_action_pressed("pause") and use_pause:
|
||||
pause_screen.show()
|
||||
get_tree().paused = true
|
||||
|
||||
|
||||
func start_game(game_data: GameData) -> void:
|
||||
if not _fill_data(game_data):
|
||||
print("Can't process game data")
|
||||
_show_main_menu()
|
||||
return
|
||||
|
||||
if SaveManager.player_data.is_new_game:
|
||||
_show_weapon_selection_screen()
|
||||
else:
|
||||
_create_game_map()
|
||||
|
||||
|
||||
func _show_weapon_selection_screen() -> void:
|
||||
if _weapon_selection_screen != null: _weapon_selection_screen.queue_free()
|
||||
_weapon_selection_screen = WEAPON_SELECTION_SCREEN.instantiate()
|
||||
add_child(_weapon_selection_screen)
|
||||
_weapon_selection_screen.world_data = world_data
|
||||
_weapon_selection_screen.weapon_selected.connect(_on_weapon_selected)
|
||||
|
||||
|
||||
func _fill_data(game_data: GameData) -> bool:
|
||||
world_data = world_generator.generate(game_data.game_seed.hash())
|
||||
|
||||
return _set_currents(game_data)
|
||||
|
||||
|
||||
func _set_currents(game_data: GameData) -> bool:
|
||||
if game_data.current_area_index >= world_data.areas.size(): return false
|
||||
current_area = world_data.areas[game_data.current_area_index]
|
||||
|
||||
if game_data.current_stage_index >= current_area.stages.size(): return false
|
||||
current_stage = current_area.stages[game_data.current_stage_index]
|
||||
|
||||
if game_data.current_sector_index >= current_stage.sectors.size(): return false
|
||||
current_sector = current_stage.sectors[game_data.current_sector_index]
|
||||
|
||||
return true
|
||||
|
||||
|
||||
func _process_to_next_area() -> void:
|
||||
SaveManager.game_data.current_area_index += 1
|
||||
SaveManager.game_data.current_stage_index = 0
|
||||
SaveManager.game_data.current_sector_index = 0
|
||||
|
||||
print(SaveManager.game_data.current_area_index)
|
||||
|
||||
if SaveManager.game_data.current_area_index >= world_data.areas.size():
|
||||
SaveManager.delete_game_data()
|
||||
victory_screen.show()
|
||||
else:
|
||||
SaveManager.save()
|
||||
_set_currents(SaveManager.game_data)
|
||||
_create_game_map()
|
||||
|
||||
|
||||
func _create_game_map() -> void:
|
||||
if _current_area_map_scene != null: _current_area_map_scene.queue_free()
|
||||
|
||||
_current_area_map_scene = AREA_MAP.instantiate()
|
||||
add_child(_current_area_map_scene)
|
||||
_current_area_map_scene.area_data = current_area
|
||||
_current_area_map_scene.current_sector = current_sector
|
||||
_current_area_map_scene.selected_sector = current_sector
|
||||
_current_area_map_scene.passage_selected.connect(_create_passage)
|
||||
|
||||
|
||||
func _show_map() -> void:
|
||||
if _current_passage_scene != null: _current_passage_scene.queue_free()
|
||||
_current_area_map_scene.current_sector = current_sector
|
||||
_current_area_map_scene.selected_sector = current_sector
|
||||
_current_area_map_scene.show()
|
||||
|
||||
|
||||
func _create_passage(passage_data: PassageData) -> void:
|
||||
if _current_passage_scene != null: _current_passage_scene.queue_free()
|
||||
_current_area_map_scene.hide()
|
||||
|
||||
current_passage = passage_data
|
||||
|
||||
_current_passage_scene = PASSAGE.instantiate()
|
||||
add_child(_current_passage_scene)
|
||||
|
||||
_current_passage_scene.passage_data = passage_data
|
||||
_current_passage_scene.player_data = SaveManager.player_data
|
||||
_current_passage_scene.completed.connect(_on_passage_completion, CONNECT_ONE_SHOT)
|
||||
_current_passage_scene.player_died.connect(_on_passage_player_died)
|
||||
|
||||
|
||||
func _on_weapon_selected(weapon_data: WeaponData) -> void:
|
||||
if _weapon_selection_screen != null: _weapon_selection_screen.queue_free()
|
||||
|
||||
SaveManager.player_data.weapons.append(weapon_data)
|
||||
SaveManager.player_data.is_new_game = false
|
||||
SaveManager.save()
|
||||
_create_game_map()
|
||||
|
||||
|
||||
func _on_pause_screen_continue_game() -> void:
|
||||
pause_screen.hide()
|
||||
|
||||
|
||||
func _show_main_menu() -> void:
|
||||
if _current_passage_scene: _current_passage_scene.queue_free()
|
||||
if _current_area_map_scene: _current_area_map_scene.queue_free()
|
||||
|
||||
SaveManager.save()
|
||||
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_file("res://game/menu/main/title_screen.tscn")
|
||||
|
||||
|
||||
func _on_passage_player_died() -> void:
|
||||
SaveManager.delete_game_data()
|
||||
game_over_screen.show()
|
||||
|
||||
|
||||
func _on_passage_completion() -> void:
|
||||
_current_passage_scene.queue_free()
|
||||
var projectiles := get_tree().get_nodes_in_group("projectiles")
|
||||
for projectile in projectiles:
|
||||
projectile.queue_free()
|
||||
|
||||
current_sector = current_passage.next_sector
|
||||
if current_sector.next_passages.size() == 0:
|
||||
_process_to_next_area()
|
||||
else:
|
||||
_update_data_indexes()
|
||||
_show_map()
|
||||
|
||||
|
||||
func _update_data_indexes() -> void:
|
||||
for area_index in range(world_data.areas.size()):
|
||||
var area := world_data.areas[area_index]
|
||||
for stage_index in range(area.stages.size()):
|
||||
var stage := area.stages[stage_index]
|
||||
for sector_index in range(stage.sectors.size()):
|
||||
if stage.sectors[sector_index] == current_sector:
|
||||
SaveManager.game_data.current_area_index = area_index
|
||||
SaveManager.game_data.current_stage_index = stage_index
|
||||
SaveManager.game_data.current_sector_index = sector_index
|
||||
SaveManager.save()
|
||||
@@ -0,0 +1 @@
|
||||
uid://1wfu4iuddo25
|
||||
@@ -0,0 +1,39 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dl7m4rqyj8mck"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://1wfu4iuddo25" path="res://game/entities/world/game.gd" id="1_l1rk1"]
|
||||
[ext_resource type="PackedScene" uid="uid://d34nh3lc1gpb" path="res://game/menu/ingame/pause_screen.tscn" id="2_h7iqs"]
|
||||
[ext_resource type="PackedScene" uid="uid://duxm8n62j2qt6" path="res://game/menu/ingame/game_over_screen.tscn" id="4_4fuuu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bdcs2ff85qjs4" path="res://game/menu/ingame/victory_screen.tscn" id="4_dxrkv"]
|
||||
[ext_resource type="PackedScene" uid="uid://ggf76ayl53bb" path="res://game/generators/world_generator.tscn" id="5_dxrkv"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_l1rk1")
|
||||
|
||||
[node name="PauseScreen" parent="." instance=ExtResource("2_h7iqs")]
|
||||
process_mode = 2
|
||||
z_index = 100
|
||||
|
||||
[node name="VictoryScreen" parent="." instance=ExtResource("4_dxrkv")]
|
||||
offset_left = 320.0
|
||||
offset_top = 172.0
|
||||
offset_right = 320.0
|
||||
offset_bottom = 172.0
|
||||
|
||||
[node name="GameOverScreen" parent="." instance=ExtResource("4_4fuuu")]
|
||||
z_index = 100
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = 320.0
|
||||
offset_top = 172.0
|
||||
offset_right = 320.0
|
||||
offset_bottom = 172.0
|
||||
|
||||
[node name="WorldGenerator" parent="." instance=ExtResource("5_dxrkv")]
|
||||
|
||||
[connection signal="continue_game" from="PauseScreen" to="." method="_on_pause_screen_continue_game"]
|
||||
[connection signal="show_main_menu" from="PauseScreen" to="." method="_show_main_menu"]
|
||||
[connection signal="show_main_menu" from="VictoryScreen" to="." method="_show_main_menu"]
|
||||
[connection signal="show_main_menu" from="GameOverScreen" to="." method="_show_main_menu"]
|
||||
@@ -0,0 +1,73 @@
|
||||
class_name Passage
|
||||
extends Node2D
|
||||
|
||||
|
||||
signal player_died
|
||||
signal completed
|
||||
|
||||
|
||||
@export var passage_data : PassageData:
|
||||
set = _set_passage_data
|
||||
|
||||
@export var player_data : PlayerData:
|
||||
set = _set_player_data
|
||||
|
||||
|
||||
var _current_progress := 0.0
|
||||
var _timer_time_elapsed := 0.0
|
||||
var _current_enemy_index := 0
|
||||
|
||||
|
||||
@onready var player : PlayerShip = $PlayerShip
|
||||
@onready var enemy_swamp_controller : EnemySwampController = $EnemySwampController
|
||||
@onready var enemy_timer : Timer = $EnemyTimer
|
||||
@onready var progress_bar : TextureProgressBar = $ProgressBar
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_current_progress += delta
|
||||
_update_progress_indicator()
|
||||
if _current_progress >= passage_data.length:
|
||||
completed.emit()
|
||||
|
||||
|
||||
func _set_passage_data(new_data: PassageData) -> void:
|
||||
passage_data = new_data
|
||||
if passage_data and progress_bar:
|
||||
_update_progress_indicator()
|
||||
_current_enemy_index = 0
|
||||
_timer_time_elapsed = 0
|
||||
|
||||
_start_timer_for_current_enemy()
|
||||
|
||||
|
||||
func _set_player_data(new_data: PlayerData) -> void:
|
||||
player_data = new_data
|
||||
if passage_data and player:
|
||||
player.player_data = player_data
|
||||
|
||||
|
||||
func _update_progress_indicator() -> void:
|
||||
progress_bar.value = _current_progress
|
||||
progress_bar.max_value = passage_data.length
|
||||
|
||||
|
||||
func _start_timer_for_current_enemy() -> void:
|
||||
if passage_data == null: return
|
||||
if _current_enemy_index >= passage_data.enemies.size(): return
|
||||
|
||||
var enemy := passage_data.enemies[_current_enemy_index]
|
||||
var time := enemy.spawn_time - _timer_time_elapsed
|
||||
enemy_timer.start(time)
|
||||
_timer_time_elapsed += time
|
||||
|
||||
|
||||
func _on_enemy_timer_timeout() -> void:
|
||||
var enemy := passage_data.enemies[_current_enemy_index]
|
||||
enemy_swamp_controller.create_enemy(enemy)
|
||||
_current_enemy_index += 1
|
||||
_start_timer_for_current_enemy()
|
||||
|
||||
|
||||
func _on_player_ship_destroyed() -> void:
|
||||
player_died.emit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://c6gpm3edyr4nu
|
||||
@@ -0,0 +1,73 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dgc0087kvarx6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c6gpm3edyr4nu" path="res://game/entities/world/passage.gd" id="1_ltkyg"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpn5x0ijgl7ei" path="res://game/controllers/enemy_swamp_controller.tscn" id="2_72vqi"]
|
||||
[ext_resource type="PackedScene" uid="uid://br074cqcnul3d" path="res://game/entities/ships/player/player_ship.tscn" id="3_r3x05"]
|
||||
[ext_resource type="PackedScene" uid="uid://chdrjc7c6bdpb" path="res://game/entities/world/background.tscn" id="4_cuj01"]
|
||||
[ext_resource type="Texture2D" uid="uid://d1n7qejdcrpkf" path="res://images/passage_process.png" id="5_yetnv"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ltkyg"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_u0ams"]
|
||||
atlas = ExtResource("5_yetnv")
|
||||
region = Rect2(0, 0, 640, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_heelu"]
|
||||
atlas = ExtResource("5_yetnv")
|
||||
region = Rect2(0, 8, 640, 8)
|
||||
|
||||
[node name="Passage" type="Node2D"]
|
||||
script = ExtResource("1_ltkyg")
|
||||
|
||||
[node name="World" type="StaticBody2D" parent="."]
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionTop" type="CollisionShape2D" parent="World"]
|
||||
position = Vector2(320, 0)
|
||||
rotation = 3.1415927
|
||||
shape = SubResource("WorldBoundaryShape2D_ltkyg")
|
||||
one_way_collision = true
|
||||
|
||||
[node name="CollisionBottom" type="CollisionShape2D" parent="World"]
|
||||
position = Vector2(320, 352)
|
||||
shape = SubResource("WorldBoundaryShape2D_ltkyg")
|
||||
one_way_collision = true
|
||||
|
||||
[node name="CollisionLeft" type="CollisionShape2D" parent="World"]
|
||||
position = Vector2(0, 180)
|
||||
rotation = 1.5707964
|
||||
shape = SubResource("WorldBoundaryShape2D_ltkyg")
|
||||
one_way_collision = true
|
||||
|
||||
[node name="CollisionRight" type="CollisionShape2D" parent="World"]
|
||||
position = Vector2(640, 180)
|
||||
rotation = -1.5707964
|
||||
shape = SubResource("WorldBoundaryShape2D_ltkyg")
|
||||
one_way_collision = true
|
||||
|
||||
[node name="PlayerShip" parent="." instance=ExtResource("3_r3x05")]
|
||||
position = Vector2(100, 100)
|
||||
|
||||
[node name="EnemySwampController" parent="." node_paths=PackedStringArray("passage") instance=ExtResource("2_72vqi")]
|
||||
passage = NodePath("..")
|
||||
|
||||
[node name="EnemyTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="Background" parent="." instance=ExtResource("4_cuj01")]
|
||||
|
||||
[node name="ProgressBar" type="TextureProgressBar" parent="."]
|
||||
z_index = 50
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 352.0
|
||||
offset_right = 640.0
|
||||
offset_bottom = 360.0
|
||||
grow_vertical = 0
|
||||
step = 0.5
|
||||
texture_under = SubResource("AtlasTexture_u0ams")
|
||||
texture_progress = SubResource("AtlasTexture_heelu")
|
||||
|
||||
[connection signal="destroyed" from="PlayerShip" to="." method="_on_player_ship_destroyed"]
|
||||
[connection signal="timeout" from="EnemyTimer" to="." method="_on_enemy_timer_timeout"]
|
||||
Reference in New Issue
Block a user