Skip to content

Commit

Permalink
Mining now fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
PonderSlime committed Jul 19, 2024
1 parent 27289ed commit 40a3dc2
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 217 deletions.
45 changes: 45 additions & 0 deletions project/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ var prev_power_up : int = 0
var player_default_movement_speed : float = 120
var player_current_movement_speed : float = 0


func _ready():
player_health = start_health
var root = get_tree().root
current_scene = root.get_child(root.get_child_count() - 1)

func _process(delta):
var save_nodes = get_tree().get_nodes_in_group("Persist")
for node in save_nodes:
# Now, we can call our save function on each node.
pass
save()
save_game()
if carrots < 0:
carrots = 0
GlobalVariableLoader.prev_carrots = GlobalVariableLoader.carrots
Expand Down Expand Up @@ -60,3 +67,41 @@ func _deferred_goto_scene(path):

# Optionally, to make it compatible with the SceneTree.change_scene_to_file() API.
get_tree().current_scene = current_scene

func save():
var save_dict = {

"filename" : get_scene_file_path(),
"parent" : get_parent().get_path(),
"player_health" : player_health,
"carrots" : carrots,
"current_scene" : current_scene,
}
return save_dict

# Note: This can be called from anywhere inside the tree. This function is
# path independent.
# Go through everything in the persist category and ask them to return a
# dict of relevant variables.
func save_game():
var save_game = FileAccess.open("user://savegame.save", FileAccess.WRITE)
var save_nodes = get_tree().get_nodes_in_group("Persist")
for node in save_nodes:
# Check the node is an instanced scene so it can be instanced again during load.
if node.scene_file_path.is_empty():
print("persistent node '%s' is not an instanced scene, skipped" % node.name)
continue

# Check the node has a save function.
if !node.has_method("save"):
print("persistent node '%s' is missing a save() function, skipped" % node.name)
continue

# Call the node's save function.
var node_data = node.call("save")

# JSON provides a static method to serialized JSON string.
var json_string = JSON.stringify(node_data)

# Store the save dictionary as a new line in the save file.
save_game.store_line(json_string)
103 changes: 23 additions & 80 deletions project/Prepped Assets/Characters/PlayerRPG/RayCast2D.gd
Original file line number Diff line number Diff line change
@@ -1,86 +1,29 @@
extends Node
@export var ray_01 : RayCast2D
@export var ray_02 : RayCast2D
@export var ray_03 : RayCast2D
var active
signal ray1
signal ray2
signal ray3
signal noray1
signal noray2
signal noray3
extends RayCast2D


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("left"):
ray_02.enabled = false
ray_02.force_raycast_update()
#ray_02.visible = false
ray_03.enabled = false
ray_03.force_raycast_update()
#ray_03.visible = false
ray_01.enabled = true
ray_01.force_raycast_update()
#ray_01.visible = true
ray_01.rotation_degrees = 90
active = ray_01
rotation_degrees = 90
position.y = -10
elif Input.is_action_pressed("right"):
ray_02.enabled = false
ray_02.force_raycast_update()
#ray_02.visible = false
ray_03.enabled = false
ray_03.force_raycast_update()
#ray_03.visible = false
ray_01.enabled = true
ray_01.force_raycast_update()
#ray_01.visible = true
ray_01.rotation_degrees = -90
active = ray_01
rotation_degrees = -90
position.y = -10
elif Input.is_action_pressed("up"):
ray_01.enabled = false
ray_01.force_raycast_update()
#ray_01.visible = false
ray_03.enabled = false
ray_03.force_raycast_update()
#ray_03.visible = false
ray_02.enabled = true
ray_02.force_raycast_update()
#ray_02.visible = true
active = ray_02
rotation_degrees = 180
position.y = -22
elif Input.is_action_pressed("down"):
ray_01.enabled = false
ray_01.force_raycast_update()
#ray_01.visible = false
ray_02.enabled = false
ray_02.force_raycast_update()
#ray_02.visible = false
ray_03.enabled = true
ray_03.force_raycast_update()
#ray_03.visible = true
active=ray_03
#print("colliding at: ", cellPosition)
if active == ray_01:
ray1.emit()
noray2.emit()
noray3.emit()
#var collider = ray_01.get_collider()
#if collider is TileMap:
#var colliderPosition = ray_01.get_collision_point()
#var cellPosition: Vector2 = collider.local_to_map(colliderPosition)
#GlobalVariableLoader.cellPosition = cellPosition
elif active == ray_02:
ray2.emit()
noray1.emit()
noray3.emit()
#var collider = ray_02.get_collider()
#if collider is TileMap:
#var colliderPosition = ray_02.get_collision_point()
#var cellPosition: Vector2 = collider.local_to_map(colliderPosition)
#GlobalVariableLoader.cellPosition = cellPosition
elif active == ray_03:
ray3.emit()
noray1.emit()
noray2.emit()
#var collider = ray_03.get_collider()
#if collider is TileMap:
#var colliderPosition = ray_03.get_collision_point()
#var cellPosition: Vector2 = collider.local_to_map(colliderPosition)
rotation_degrees = 0
position.y = 1
var collider = get_collider()
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if collider is TileMap:
var colliderPosition = get_collision_point()
var cellPosition: Vector2 = collider.local_to_map(colliderPosition)
GlobalVariableLoader.cellPosition = cellPosition

65 changes: 15 additions & 50 deletions project/Prepped Assets/Characters/PlayerRPG/player_rpg.tscn
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
[gd_scene load_steps=47 format=3 uid="uid://bvse5e73c1cs7"]
[gd_scene load_steps=45 format=3 uid="uid://bvse5e73c1cs7"]

[ext_resource type="Script" path="res://Prepped Assets/Characters/PlayerRPG/player_rpg.gd" id="1_ojupd"]
[ext_resource type="Texture2D" uid="uid://ch7orknpbswpb" path="res://Sprites/Player/SpriteSheet.png" id="2_co24h"]
[ext_resource type="Script" path="res://Prepped Assets/Characters/PlayerRPG/RayCast2D.gd" id="3_yfcjo"]
[ext_resource type="PackedScene" uid="uid://bd8v4t8j3r4us" path="res://Prepped Assets/UI/hud.tscn" id="4_37dv5"]
[ext_resource type="Texture2D" uid="uid://covaadkcirfii" path="res://Sprites/Items/Carrot.png" id="4_arn5n"]
[ext_resource type="Script" path="res://Prepped Assets/Characters/PlayerRPG/ray_lr.gd" id="4_h6eq0"]
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd" id="5_qby07"]
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="6_l767b"]
[ext_resource type="Script" path="res://Prepped Assets/Characters/PlayerRPG/ray_up.gd" id="6_x6mn6"]
[ext_resource type="Script" path="res://Prepped Assets/Characters/PlayerRPG/ray_down.gd" id="7_7kikl"]
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera_host/phantom_camera_host.gd" id="7_n1ssx"]
[ext_resource type="Script" path="res://Prepped Assets/Characters/audio_controller.gd" id="8_2uimf"]
[ext_resource type="Texture2D" uid="uid://ddpwk6ygmcuxx" path="res://Sprites/Easter Eggs/flag-orpheus-left_pixelated.png" id="8_5ac3y"]

[sub_resource type="GDScript" id="GDScript_0qspb"]
script/source = "extends Node2D



"

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_sqedp"]
radius = 7.0
height = 20.0
height = 22.0

[sub_resource type="Animation" id="Animation_8jdja"]
length = 0.001
Expand Down Expand Up @@ -269,6 +273,7 @@ _data = {
}

[node name="PlayerRPG" type="Node2D"]
script = SubResource("GDScript_0qspb")

[node name="PlayerRPG" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_anim_player")]
z_index = 2
Expand All @@ -285,7 +290,7 @@ hframes = 16
vframes = 6

[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerRPG"]
position = Vector2(0, -10)
position = Vector2(0, -11)
shape = SubResource("CapsuleShape2D_sqedp")

[node name="AnimationPlayer" type="AnimationPlayer" parent="PlayerRPG"]
Expand All @@ -298,46 +303,12 @@ autoplay = "idle"
tree_root = SubResource("AnimationNodeStateMachine_5ltp2")
anim_player = NodePath("../AnimationPlayer")

[node name="RayCasts" type="Node2D" parent="PlayerRPG" node_paths=PackedStringArray("ray_01", "ray_02", "ray_03")]
position = Vector2(0, -10)
script = ExtResource("3_yfcjo")
ray_01 = NodePath("RayCast2D")
ray_02 = NodePath("RayCast2D2")
ray_03 = NodePath("RayCast2D3")

[node name="RayCast2D" type="RayCast2D" parent="PlayerRPG/RayCasts"]
[node name="RayCasts" type="RayCast2D" parent="PlayerRPG"]
position = Vector2(0, -20)
target_position = Vector2(0, 25)
collide_with_areas = true
script = ExtResource("4_h6eq0")

[node name="Sprite2D" type="Sprite2D" parent="PlayerRPG/RayCasts/RayCast2D"]
texture_filter = 1
position = Vector2(0, 22)
scale = Vector2(0.25, 0.25)
texture = ExtResource("4_arn5n")
hframes = 25

[node name="RayCast2D2" type="RayCast2D" parent="PlayerRPG/RayCasts"]
position = Vector2(0, -10)
target_position = Vector2(0, -25)
collide_with_areas = true
script = ExtResource("6_x6mn6")

[node name="Sprite2D" type="Sprite2D" parent="PlayerRPG/RayCasts/RayCast2D2"]
texture_filter = 1
position = Vector2(0, -22)
rotation = 3.14159
scale = Vector2(0.25, 0.25)
texture = ExtResource("4_arn5n")
hframes = 25

[node name="RayCast2D3" type="RayCast2D" parent="PlayerRPG/RayCasts"]
position = Vector2(0, 10)
target_position = Vector2(0, 25)
collide_with_areas = true
script = ExtResource("7_7kikl")
script = ExtResource("3_yfcjo")

[node name="Sprite2D" type="Sprite2D" parent="PlayerRPG/RayCasts/RayCast2D3"]
[node name="Sprite2D" type="Sprite2D" parent="PlayerRPG/RayCasts"]
texture_filter = 1
position = Vector2(0, 22)
scale = Vector2(0.25, 0.25)
Expand Down Expand Up @@ -414,9 +385,3 @@ autoplay = "dissolve_out"
[connection signal="hurt" from="PlayerRPG" to="Sound/AudioController" method="_hurt"]
[connection signal="jump" from="PlayerRPG" to="Sound/AudioController" method="_jump"]
[connection signal="no_walk" from="PlayerRPG" to="Sound/AudioController" method="_no_walk"]
[connection signal="noray1" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D" method="_on_ray_casts_noray_1"]
[connection signal="noray2" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D2" method="_on_ray_casts_noray_2"]
[connection signal="noray3" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D3" method="_on_ray_casts_noray_3"]
[connection signal="ray1" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D" method="_on_ray_casts_ray_1"]
[connection signal="ray2" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D2" method="_on_ray_casts_ray_2"]
[connection signal="ray3" from="PlayerRPG/RayCasts" to="PlayerRPG/RayCasts/RayCast2D3" method="_on_ray_casts_ray_3"]
24 changes: 0 additions & 24 deletions project/Prepped Assets/Characters/PlayerRPG/ray_down.gd

This file was deleted.

24 changes: 0 additions & 24 deletions project/Prepped Assets/Characters/PlayerRPG/ray_lr.gd

This file was deleted.

24 changes: 0 additions & 24 deletions project/Prepped Assets/Characters/PlayerRPG/ray_up.gd

This file was deleted.

11 changes: 10 additions & 1 deletion project/Scenes/Test/TileMap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ func _remove_cell(tile_position):
Vector2i(tile_position.x+1,tile_position.y+1),Vector2i(tile_position.x-1,tile_position.y+1),
Vector2i(tile_position.x,tile_position.y-1),Vector2i(tile_position.x+1,tile_position.y-1),
Vector2i(tile_position.x-1,tile_position.y-1)]
set_cells_terrain_connect(0, list_of_tiles, 0, 1, true)
for i in list_of_tiles:
set_cells_terrain_connect(0, list_of_tiles, 0, 1, true)

func save():
var save_dict = {

"filename" : get_scene_file_path(),
"parent" : get_parent().get_path(),
}
return save_dict

4 changes: 1 addition & 3 deletions project/Scenes/Test/test_scene_1.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[gd_scene load_steps=18 format=3 uid="uid://dg88qd2iyrbgb"]
[gd_scene load_steps=17 format=3 uid="uid://dg88qd2iyrbgb"]

[ext_resource type="PackedScene" uid="uid://q01o7rogtouc" path="res://Prepped Assets/Characters/player.tscn" id="1_60xql"]
[ext_resource type="Script" path="res://Scenes/Test/test_scene_1.gd" id="1_lcnp5"]
[ext_resource type="Texture2D" uid="uid://bmqmu2cagdk1t" path="res://Sprites/Environment/Tilemap.png" id="1_usa6h"]
[ext_resource type="PackedScene" uid="uid://opewwobgojc1" path="res://Prepped Assets/Environment/spikes.tscn" id="3_v0wrf"]
[ext_resource type="Texture2D" uid="uid://l00yjfnvepmv" path="res://Sprites/Environment/Cloud1.png" id="6_55r36"]
Expand Down Expand Up @@ -220,7 +219,6 @@ point_count = 2

[node name="Node2D" type="Node2D"]
texture_filter = 1
script = ExtResource("1_lcnp5")

[node name="Player" parent="." instance=ExtResource("1_60xql")]

Expand Down
Loading

0 comments on commit 40a3dc2

Please sign in to comment.