game saving like for real, bad guy movement, player damage, player death, ui with controls labels
This commit is contained in:
parent
b40f2baaa7
commit
f772a9e736
BIN
assets/graphics/player/death/Player Death 64x64.png
Normal file
BIN
assets/graphics/player/death/Player Death 64x64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
40
assets/graphics/player/death/Player Death 64x64.png.import
Normal file
40
assets/graphics/player/death/Player Death 64x64.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c4pynj40whop7"
|
||||
path="res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/death/Player Death 64x64.png"
|
||||
dest_files=["res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
BIN
assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
40
assets/graphics/player/hurt/Player Hurt 48x48.png.import
Normal file
40
assets/graphics/player/hurt/Player Hurt 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://n60s2ffy25hc"
|
||||
path="res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/hurt/Player Hurt 48x48.png"
|
||||
dest_files=["res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@ -66,3 +66,13 @@ chuck={
|
||||
"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":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
save={
|
||||
"deadzone": 0.2,
|
||||
"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":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
load={
|
||||
"deadzone": 0.2,
|
||||
"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":76,"key_label":0,"unicode":108,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=21 format=4 uid="uid://cy1i6ucex6m0d"]
|
||||
[gd_scene load_steps=22 format=4 uid="uid://cy1i6ucex6m0d"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://qv8blu8wkqvq" path="res://scenes/crate.tscn" id="1_uwrxv"]
|
||||
[ext_resource type="Script" uid="uid://barmq4qhp5cvl" path="res://scripts/scene_manager.gd" id="2_p57ef"]
|
||||
@ -12,6 +12,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://ds2j76cg1r8y2" path="res://assets/graphics/objects/plane.png" id="5_kvpfn"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxocmoeuu32ex" path="res://scenes/coin.tscn" id="12_dinhu"]
|
||||
[ext_resource type="PackedScene" uid="uid://ccx1uakpj5143" path="res://scenes/slime.tscn" id="13_kvuet"]
|
||||
[ext_resource type="PackedScene" uid="uid://ck553kksdq0ku" path="res://scenes/ui.tscn" id="13_trtic"]
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_p57ef"]
|
||||
tile_data = PackedInt32Array(0, 0, 4, 1, 65536, 4, 2, 65536, 4, 3, 65536, 4, 4, 131072, 4)
|
||||
@ -337,11 +338,13 @@ metadata/_edit_group_ = true
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D3"]
|
||||
shape = SubResource("RectangleShape2D_8cj0n")
|
||||
|
||||
[node name="Crate" parent="." groups=["explodable", "pushable"] instance=ExtResource("1_uwrxv")]
|
||||
[node name="Crates" type="Node2D" parent="."]
|
||||
position = Vector2(114, 175)
|
||||
|
||||
[node name="Crate2" parent="." groups=["explodable", "pushable"] instance=ExtResource("1_uwrxv")]
|
||||
position = Vector2(155.00002, 199)
|
||||
[node name="Crate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("1_uwrxv")]
|
||||
|
||||
[node name="Crate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("1_uwrxv")]
|
||||
position = Vector2(41.000015, 24)
|
||||
rotation = 0.8783198
|
||||
|
||||
[node name="Boundary" type="StaticBody2D" parent="."]
|
||||
@ -358,7 +361,7 @@ position = Vector2(201, 376)
|
||||
position = Vector2(62.000015, 278)
|
||||
intent = "powerup"
|
||||
|
||||
[node name="CharacterBody2D" parent="." instance=ExtResource("3_lnu2h")]
|
||||
[node name="Player" parent="." instance=ExtResource("3_lnu2h")]
|
||||
position = Vector2(96, 206)
|
||||
|
||||
[node name="TimerLabel" type="Label" parent="."]
|
||||
@ -376,5 +379,9 @@ position = Vector2(-34, 284)
|
||||
[node name="Slime" parent="Enemies" instance=ExtResource("13_kvuet")]
|
||||
position = Vector2(71, 213)
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="UI" parent="CanvasLayer" instance=ExtResource("13_trtic")]
|
||||
|
||||
[connection signal="triggerFiredSignal" from="Trigger" to="." method="_on_trigger_fired"]
|
||||
[connection signal="triggerFiredSignal" from="Trigger2" to="." method="_on_trigger_fired"]
|
||||
|
||||
@ -1,17 +1,75 @@
|
||||
[gd_scene load_steps=37 format=3 uid="uid://b1yy0sybg66hh"]
|
||||
[gd_scene load_steps=53 format=3 uid="uid://b1yy0sybg66hh"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bpcy1rfota5tu" path="res://scripts/player.gd" id="1_3vyb7"]
|
||||
[ext_resource type="Texture2D" uid="uid://c4pynj40whop7" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_fjrip"]
|
||||
[ext_resource type="Texture2D" uid="uid://bb6uc2alre1qu" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"]
|
||||
[ext_resource type="Texture2D" uid="uid://dr8leuj7yjpmo" path="res://assets/graphics/player/jumpandfall/player jump 48x48.png" id="2_qhqgy"]
|
||||
[ext_resource type="Texture2D" uid="uid://n60s2ffy25hc" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_tuyoq"]
|
||||
[ext_resource type="Texture2D" uid="uid://gat5giebysdj" path="res://assets/graphics/player/run/player run 48x48.png" id="4_dqkch"]
|
||||
[ext_resource type="Texture2D" uid="uid://csmss00eyd21r" path="res://assets/graphics/player/shove/Player Punch 64x64.png" id="5_qlg0r"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3vyb7"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_t4otl"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_j2b1d"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cs1tg"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(192, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(240, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_giy8y"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(288, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fdfoy"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(336, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hhpqf"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(384, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_g5jhy"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(432, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
|
||||
atlas = ExtResource("2_qhqgy")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"]
|
||||
atlas = ExtResource("3_tuyoq")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"]
|
||||
atlas = ExtResource("3_tuyoq")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"]
|
||||
atlas = ExtResource("3_tuyoq")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"]
|
||||
atlas = ExtResource("3_tuyoq")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"]
|
||||
atlas = ExtResource("2_g2els")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
@ -128,6 +186,41 @@ region = Rect2(448, 0, 64, 64)
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_jc3p3")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hax0n")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_t4otl")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_j2b1d")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_cs1tg")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_2dvfe")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_giy8y")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fdfoy")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hhpqf")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_g5jhy")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"death",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_jej6c")
|
||||
}],
|
||||
"loop": false,
|
||||
@ -136,6 +229,23 @@ animations = [{
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_gl8cc")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_487ah")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_md1ol")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_bj30b")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qhqgy")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@ -268,9 +378,9 @@ one_shot = true
|
||||
position = Vector2(1, -3)
|
||||
scale = Vector2(1, 0.8064177)
|
||||
sprite_frames = SubResource("SpriteFrames_jej6c")
|
||||
animation = &"shove"
|
||||
animation = &"death"
|
||||
autoplay = "idle"
|
||||
frame = 7
|
||||
frame = 9
|
||||
frame_progress = 1.0
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
@ -46,7 +46,7 @@ size = Vector2(14, 14)
|
||||
texture_filter = 1
|
||||
script = ExtResource("1_p2gj0")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
[node name="SlimeGraphic" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = SubResource("SpriteFrames_fd6lc")
|
||||
animation = &"idle"
|
||||
autoplay = "idle"
|
||||
|
||||
47
scenes/ui.tscn
Normal file
47
scenes/ui.tscn
Normal file
@ -0,0 +1,47 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://ck553kksdq0ku"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://nc5d7xcrrsgu" path="res://scripts/ui.gd" id="1_nt7q6"]
|
||||
|
||||
[node name="UI" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_nt7q6")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Health"
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Timer" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
text = "Timer"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Coins" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
text = "Coins"
|
||||
horizontal_alignment = 2
|
||||
@ -20,12 +20,18 @@ signal levelChangeSignal(level)
|
||||
signal destroySignal(body)
|
||||
signal playerDamagedSignal(health, maxHealth)
|
||||
signal playerDeathSignal
|
||||
signal gameSaveSignal(level, timeRemaining, playerHealth, enemiesDictionary)
|
||||
signal gameLoadSignal(stashData)
|
||||
signal countDownSignal(time)
|
||||
signal coinUpdateSignal(remainingCoins)
|
||||
|
||||
var enemy:CharacterStats
|
||||
var player:CharacterStats
|
||||
var enemiesDict = {}
|
||||
var playerCurrentHealth:int = 0
|
||||
|
||||
var stashData = {}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
# load in characters
|
||||
@ -40,6 +46,14 @@ func _ready():
|
||||
timer.start()
|
||||
#$TimerLabel.text = str(timeLimit)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("save"):
|
||||
print("save")
|
||||
saveGame()
|
||||
if Input.is_action_just_pressed("load"):
|
||||
print("load")
|
||||
loadGame()
|
||||
|
||||
func secondCounter() -> void:
|
||||
#timeLimit -= 1
|
||||
#$TimerLabel.text = str(timeLimit)
|
||||
@ -49,6 +63,7 @@ func secondCounter() -> void:
|
||||
|
||||
#class
|
||||
timeAvailable -= 1
|
||||
countDownSignal.emit(timeAvailable)
|
||||
if timeAvailable <= 0:
|
||||
print("You lose baby!")
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
@ -78,6 +93,7 @@ func _on_coin_collected(body, coin):
|
||||
destroySignal.emit(coin)
|
||||
|
||||
func totalCoins(value):
|
||||
coinUpdateSignal.emit(value)
|
||||
if value == 0:
|
||||
# you won
|
||||
print("you won")
|
||||
@ -97,17 +113,25 @@ func _on_slime_damage(body, slime):
|
||||
print("Player Health " + str(playerCurrentHealth) + " of " + str(player.starting_health))
|
||||
playerDamagedSignal.emit(playerCurrentHealth, player.starting_health)
|
||||
|
||||
func deathComplete() -> void:
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
|
||||
func totalEnemies(value):
|
||||
print("GC knows total enemies " + str(value))
|
||||
#totalEnemies = value
|
||||
|
||||
func addEnemyToLevel(slime) -> void:
|
||||
func addEnemyToLevel(slime, _stat=null) -> void:
|
||||
print("GC adding enemy")
|
||||
var randDamage:int = randi() % 10
|
||||
var enemyStat = {
|
||||
"health": enemy.health,
|
||||
"damage": enemy.meleeDamage + randDamage
|
||||
}
|
||||
if _stat:
|
||||
enemyStat = {
|
||||
"health": _stat.health,
|
||||
"damage": _stat.damage
|
||||
}
|
||||
enemiesDict[slime] = enemyStat
|
||||
|
||||
func bulletDamage(area, bullet) -> void:
|
||||
@ -124,4 +148,27 @@ func bulletDamage(area, bullet) -> void:
|
||||
|
||||
func removeEnemyFromLevel(slime) -> void:
|
||||
enemiesDict.erase(slime)
|
||||
|
||||
func saveGame() -> void:
|
||||
print("saving...")
|
||||
gameSaveSignal.emit(currentLevel, timeAvailable, playerCurrentHealth, enemiesDict)
|
||||
|
||||
func loadGame() -> void:
|
||||
if not ResourceLoader.exists("res://scripts/rscs/level"+str(currentLevel)+"_gameSaveStats.tres"):
|
||||
return
|
||||
var saved_game:SaveObject = load("res://scripts/rscs/level"+str(currentLevel)+"_gameSaveStats.tres")
|
||||
print("loading...")
|
||||
enemiesDict.clear()
|
||||
stashData = saved_game.gameSave
|
||||
gameLoadSignal.emit(stashData)
|
||||
|
||||
func stashGame(stash) -> void:
|
||||
print("stashing...")
|
||||
stashData = stash
|
||||
var stashObject = SaveObject.new()
|
||||
stashObject.gameSave = stashData
|
||||
ResourceSaver.save(stashObject, "res://scripts/rscs/level"+str(currentLevel)+"_gameSaveStats.tres")
|
||||
|
||||
func playerHealth(value) -> void:
|
||||
playerCurrentHealth = value
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ var direction:float = 0
|
||||
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
enum State{IDLE, JUMP, FALLING, RUNNING, SHOVE}
|
||||
enum State{IDLE, JUMP, FALLING, RUNNING, SHOVE, HURT, DEATH}
|
||||
var current_state:State = State.IDLE
|
||||
|
||||
@onready var right_cast: RayCast2D = $RightCast
|
||||
@ -28,14 +28,25 @@ var upJump:bool = false
|
||||
|
||||
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||
|
||||
signal playerDeathCompleteSignal
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_state == State.HURT:
|
||||
return
|
||||
|
||||
handle_input()
|
||||
handle_movement(delta)
|
||||
update_states()
|
||||
update_animation()
|
||||
move_and_slide()
|
||||
move_and_slide()
|
||||
handle_collision()
|
||||
|
||||
func handleDamage(_health, _maxHealth):
|
||||
current_state = State.HURT
|
||||
|
||||
func handleDeath()->void:
|
||||
current_state = State.DEATH
|
||||
|
||||
func update_states()->void:
|
||||
# create a state machine
|
||||
match current_state:
|
||||
@ -65,6 +76,10 @@ func update_animation()->void:
|
||||
player_graphic.play("run")
|
||||
State.SHOVE:
|
||||
player_graphic.play("shove")
|
||||
State.HURT:
|
||||
player_graphic.play("hurt")
|
||||
State.DEATH:
|
||||
player_graphic.play("death")
|
||||
|
||||
func handle_input()->void:
|
||||
# Handle jump.
|
||||
@ -158,3 +173,7 @@ func _on_animation_finished() -> void:
|
||||
current_state = State.IDLE
|
||||
else:
|
||||
current_state = State.RUNNING
|
||||
State.HURT:
|
||||
current_state = State.IDLE
|
||||
State.DEATH:
|
||||
playerDeathCompleteSignal.emit()
|
||||
|
||||
19
scripts/rscs/level0_gameSaveStats.tres
Normal file
19
scripts/rscs/level0_gameSaveStats.tres
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_resource type="Resource" script_class="SaveObject" load_steps=2 format=3 uid="uid://352f5gde8dxp"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddp6q3gi13sw1" path="res://scripts/rscs/save_object.gd" id="1_a13pi"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_a13pi")
|
||||
gameSave = {
|
||||
"coinsData": [Transform2D(1, 0, 0, 1, -34, 284)],
|
||||
"cratesData": [Transform2D(-0.8802142, -0.47457656, 0.47457656, -0.8802142, -161.41519, 400.55682), Transform2D(0.9999821, -0.0059799734, 0.0059799734, 0.9999821, 8.116272, 38.237946)],
|
||||
"enemiesData": [{
|
||||
"damage": 13,
|
||||
"health": 10,
|
||||
"position": Transform2D(1, 0, 0, 1, 119.30582, 213)
|
||||
}],
|
||||
"playerData": {
|
||||
"health": 61.0,
|
||||
"position": Transform2D(1, 0, 0, 1, 94.80647, 212.99904)
|
||||
}
|
||||
}
|
||||
3
scripts/rscs/save_object.gd
Normal file
3
scripts/rscs/save_object.gd
Normal file
@ -0,0 +1,3 @@
|
||||
class_name SaveObject extends Resource
|
||||
|
||||
@export var gameSave:Dictionary = {}
|
||||
1
scripts/rscs/save_object.gd.uid
Normal file
1
scripts/rscs/save_object.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://ddp6q3gi13sw1
|
||||
@ -1,14 +1,20 @@
|
||||
class_name SceneManager extends Node2D
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
|
||||
@onready var coins: Node2D = $"../Coins"
|
||||
@onready var enemies: Node2D = $"../Enemies"
|
||||
@onready var player: Player = $"../Player"
|
||||
@onready var crates: Node2D = $"../Crates"
|
||||
@onready var ui: UI = $"../CanvasLayer/UI"
|
||||
|
||||
var bulletArray = []
|
||||
var totalAllowedBullets = 7
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var grenade = preload("res://scenes/grenade.tscn")
|
||||
var coinScene = preload("res://scenes/coin.tscn")
|
||||
var crateScene = preload("res://scenes/crate.tscn")
|
||||
var enemyScene = preload("res://scenes/slime.tscn")
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@ -26,6 +32,14 @@ func buildLevel() -> void:
|
||||
# wire up signals from GameController
|
||||
Gamecontroller.levelChangeSignal.connect(changeScene)
|
||||
Gamecontroller.destroySignal.connect(destroy)
|
||||
Gamecontroller.gameSaveSignal.connect(saveGameByLevel)
|
||||
Gamecontroller.gameLoadSignal.connect(loadGameByLevel)
|
||||
Gamecontroller.playerDamagedSignal.connect(player.handleDamage)
|
||||
Gamecontroller.playerDamagedSignal.connect(ui.healthUpdate)
|
||||
Gamecontroller.playerDeathSignal.connect(player.handleDeath)
|
||||
player.playerDeathCompleteSignal.connect(Gamecontroller.deathComplete)
|
||||
Gamecontroller.countDownSignal.connect(ui.timerUpdate)
|
||||
Gamecontroller.coinUpdateSignal.connect(ui.coinUpdate)
|
||||
|
||||
func updateEnemies() -> void:
|
||||
var totalEnemies = 0
|
||||
@ -86,3 +100,87 @@ func changeScene(level) -> void:
|
||||
|
||||
func destroy(body) -> void:
|
||||
body.queue_free()
|
||||
|
||||
func loadGameByLevel(stash) -> void:
|
||||
print("load")
|
||||
# get the player data from the stash
|
||||
var playerData = stash.playerData
|
||||
var coinsData = stash.coinsData
|
||||
var cratesData = stash.cratesData
|
||||
var enemiesData = stash.enemiesData
|
||||
|
||||
player.transform = playerData.position
|
||||
# tell the game controller the players health
|
||||
Gamecontroller.playerHealth(playerData.health)
|
||||
|
||||
if coins:
|
||||
for coin in coins.get_children():
|
||||
#remove the listeners
|
||||
coin.tree_exited.disconnect(updateCoins)
|
||||
coins.remove_child(coin)
|
||||
coin.queue_free()
|
||||
for trans in coinsData:
|
||||
var coinObj:Coin = coinScene.instantiate()
|
||||
coins.add_child(coinObj)
|
||||
coinObj.transform = trans
|
||||
updateCoins()
|
||||
|
||||
if crates:
|
||||
for crate in crates.get_children():
|
||||
crate.remove_child(crate)
|
||||
crate.queue_free()
|
||||
for crate in cratesData:
|
||||
var crateObj:RigidBody2D = crateScene.instantiate()
|
||||
crates.add_child(crateObj)
|
||||
crateObj.transform = crate
|
||||
|
||||
if enemies:
|
||||
for enemy in enemies.get_children():
|
||||
enemies.remove_child(enemy)
|
||||
enemy.queue_free()
|
||||
for enemy in enemiesData:
|
||||
var enemyObj:Slime = enemyScene.instantiate()
|
||||
enemies.add_child(enemyObj)
|
||||
enemyObj.transform = enemy.position
|
||||
Gamecontroller.addEnemyToLevel(enemyObj, enemy)
|
||||
|
||||
func saveGameByLevel(currentLevel:int, timeAvailable:int, playerCurrentHealth:float, enemiesDict:Dictionary) -> void:
|
||||
print("saving game...")
|
||||
print(playerCurrentHealth)
|
||||
print(player.transform)
|
||||
var playerData = {
|
||||
"health": playerCurrentHealth,
|
||||
"position": player.transform
|
||||
}
|
||||
|
||||
var coinDataArray:Array
|
||||
if coins:
|
||||
for coin in coins.get_children():
|
||||
print(coin.transform)
|
||||
coinDataArray.push_front(coin.transform)
|
||||
|
||||
var crateDataArray:Array
|
||||
if crates:
|
||||
for crate in crates.get_children():
|
||||
crateDataArray.push_front(crate.transform)
|
||||
|
||||
var enemyDataArray:Array
|
||||
for enemyKey in enemiesDict:
|
||||
print("ENEMY FOUND")
|
||||
print(enemyKey.transform)
|
||||
print(enemiesDict[enemyKey].health)
|
||||
print(enemiesDict[enemyKey].damage)
|
||||
var enemy = {
|
||||
"position": enemyKey.transform,
|
||||
"health": enemiesDict[enemyKey].health,
|
||||
"damage": enemiesDict[enemyKey].damage
|
||||
}
|
||||
enemyDataArray.push_front(enemy)
|
||||
|
||||
var stash = {
|
||||
"playerData": playerData,
|
||||
"coinsData": coinDataArray,
|
||||
"cratesData": crateDataArray,
|
||||
"enemiesData": enemyDataArray
|
||||
}
|
||||
Gamecontroller.stashGame(stash)
|
||||
|
||||
@ -4,6 +4,7 @@ class_name Slime extends Area2D
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var right_down_cast: RayCast2D = $RightDownCast
|
||||
@onready var left_down_cast: RayCast2D = $LeftDownCast
|
||||
@onready var slime_graphic: AnimatedSprite2D = $SlimeGraphic
|
||||
|
||||
var speed:int = 100
|
||||
var direction = 1
|
||||
@ -17,6 +18,19 @@ func _ready() -> void:
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
# raycast detection
|
||||
if not right_down_cast.is_colliding():
|
||||
direction = -1
|
||||
slime_graphic.flip_h = true
|
||||
elif not left_down_cast.is_colliding():
|
||||
direction = 1
|
||||
slime_graphic.flip_h = false
|
||||
elif right_cast.is_colliding() and not right_cast.get_collider() is Player:
|
||||
direction = -1
|
||||
slime_graphic.flip_h = true
|
||||
elif left_cast.is_colliding() and not left_cast.get_collider() is Player:
|
||||
direction = 1
|
||||
slime_graphic.flip_h = false
|
||||
position.x += direction * speed * delta
|
||||
|
||||
|
||||
|
||||
24
scripts/ui.gd
Normal file
24
scripts/ui.gd
Normal file
@ -0,0 +1,24 @@
|
||||
class_name UI extends Control
|
||||
|
||||
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/Health
|
||||
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer2/Timer
|
||||
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer3/Coins
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func healthUpdate(currentHealth, maxHealth):
|
||||
health.text = "Health: " + str(currentHealth)
|
||||
|
||||
func timerUpdate(timeRemaining):
|
||||
timer.text = str(timeRemaining)
|
||||
|
||||
func coinUpdate(remainingCoins):
|
||||
coins.text = "Coins: " + str(remainingCoins)
|
||||
1
scripts/ui.gd.uid
Normal file
1
scripts/ui.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://nc5d7xcrrsgu
|
||||
Loading…
Reference in New Issue
Block a user