add collecting coins
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bqi5s710xb1ju"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://bqi5s710xb1ju"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/player.gd" id="1_8j4h4"]
|
||||
[ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"]
|
||||
[ext_resource type="Texture2D" uid="uid://jl1gwqchhpdc" path="res://sprites/left_eye.png" id="3_2srrh"]
|
||||
[ext_resource type="Texture2D" uid="uid://iiawtnwmeny3" path="res://sprites/right_eye.png" id="4_ccn81"]
|
||||
[ext_resource type="Script" path="res://scripts/components/flip_player.gd" id="5_geu10"]
|
||||
[ext_resource type="Script" path="res://scripts/components/score.gd" id="6_fowa2"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"]
|
||||
size = Vector2(16, 31)
|
||||
|
||||
[node name="Brick Player" type="CharacterBody2D"]
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_8j4h4")
|
||||
|
||||
[node name="Root" type="Node2D" parent="."]
|
||||
@@ -38,3 +41,8 @@ eye_right = NodePath("../Root/Right Eye")
|
||||
player_controller = NodePath("..")
|
||||
|
||||
[node name="CoyoteTimer" type="Timer" parent="."]
|
||||
|
||||
[node name="CanPickUpComponent" type="Node" parent="."]
|
||||
|
||||
[node name="ScoreComponent" type="Node" parent="."]
|
||||
script = ExtResource("6_fowa2")
|
||||
|
26
objects/coin.tscn
Normal file
26
objects/coin.tscn
Normal file
@@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://54w4wisfj8v8"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_epuj5"]
|
||||
[ext_resource type="Script" path="res://scripts/components/collectable.gd" id="2_y0k47"]
|
||||
[ext_resource type="Resource" uid="uid://bc0esas5r2uy8" path="res://resources/collectables/coin.tres" id="3_fm2fq"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3ask2"]
|
||||
radius = 9.0
|
||||
|
||||
[node name="Coin" type="Area2D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_3ask2")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_epuj5")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 51
|
||||
|
||||
[node name="Collectable" type="Node" parent="." node_paths=PackedStringArray("area2d") groups=["coins"]]
|
||||
script = ExtResource("2_y0k47")
|
||||
area2d = NodePath("..")
|
||||
collectable_data = ExtResource("3_fm2fq")
|
19
objects/collapsing_bridge.tscn
Normal file
19
objects/collapsing_bridge.tscn
Normal file
@@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://ct8fim6mduyl3"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_rka1x"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_l44jt"]
|
||||
size = Vector2(16, 4)
|
||||
|
||||
[node name="Collapsing Bridge" type="StaticBody2D"]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -6)
|
||||
shape = SubResource("RectangleShape2D_l44jt")
|
||||
one_way_collision = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_rka1x")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 56
|
6
objects/game_manager.tscn
Normal file
6
objects/game_manager.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b4eifkc31jsun"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/game_manager.gd" id="1_58t7u"]
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource("1_58t7u")
|
@@ -22,6 +22,10 @@ boot_splash/fullsize=false
|
||||
boot_splash/use_filter=false
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
GameManager="*res://objects/game_manager.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=640
|
||||
@@ -32,6 +36,14 @@ window/stretch/mode="viewport"
|
||||
window/stretch/aspect="keep_height"
|
||||
window/stretch/scale_mode="integer"
|
||||
|
||||
[dotnet]
|
||||
|
||||
project/assembly_name="Mr. Brick Adventures"
|
||||
|
||||
[global_group]
|
||||
|
||||
coins=""
|
||||
|
||||
[input]
|
||||
|
||||
left={
|
||||
@@ -49,6 +61,17 @@ jump={
|
||||
"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":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
down={
|
||||
"deadzone": 0.5,
|
||||
"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)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
2d_physics/layer_1="Terrain"
|
||||
2d_physics/layer_2="Collectible Entities"
|
||||
2d_physics/layer_3="Player"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
7
resources/collectables/coin.tres
Normal file
7
resources/collectables/coin.tres
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bc0esas5r2uy8"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/resources/collectable_resource.gd" id="1_nmrta"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_nmrta")
|
||||
amount = 1
|
@@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=15 format=4 uid="uid://h60obxmju6mo"]
|
||||
[gd_scene load_steps=17 format=4 uid="uid://h60obxmju6mo"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_5lb42"]
|
||||
[ext_resource type="TileSet" uid="uid://cl4bn8lofqvky" path="res://tileset/village/tileset_village.tres" id="1_d680t"]
|
||||
[ext_resource type="Texture2D" uid="uid://dxvevrm15uus1" path="res://sprites/flowers_tileset.png" id="3_235u2"]
|
||||
[ext_resource type="PackedScene" uid="uid://54w4wisfj8v8" path="res://objects/coin.tscn" id="3_ygehw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqi5s710xb1ju" path="res://objects/brick_player.tscn" id="4_hetw8"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_anvhr"]
|
||||
@@ -181,9 +182,17 @@ texture = ExtResource("1_5lb42")
|
||||
5:4/0 = 0
|
||||
6:4/0 = 0
|
||||
7:4/0 = 0
|
||||
7:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
7:4/0/physics_layer_0/polygon_0/one_way = true
|
||||
8:4/0 = 0
|
||||
8:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
8:4/0/physics_layer_0/polygon_0/one_way = true
|
||||
9:4/0 = 0
|
||||
9:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
9:4/0/physics_layer_0/polygon_0/one_way = true
|
||||
10:4/0 = 0
|
||||
10:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
10:4/0/physics_layer_0/polygon_0/one_way = true
|
||||
11:4/0 = 0
|
||||
0:5/0 = 0
|
||||
1:5/0 = 0
|
||||
@@ -207,14 +216,22 @@ texture = ExtResource("1_5lb42")
|
||||
7:6/0 = 0
|
||||
8:6/0 = 0
|
||||
9:6/0 = 0
|
||||
9:6/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
9:6/0/physics_layer_0/polygon_0/one_way = true
|
||||
10:6/0 = 0
|
||||
10:6/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
10:6/0/physics_layer_0/polygon_0/one_way = true
|
||||
11:6/0 = 0
|
||||
11:6/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
11:6/0/physics_layer_0/polygon_0/one_way = true
|
||||
0:7/0 = 0
|
||||
1:7/0 = 0
|
||||
2:7/0 = 0
|
||||
3:7/0 = 0
|
||||
5:7/0 = 0
|
||||
7:7/0 = 0
|
||||
7:7/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4)
|
||||
7:7/0/physics_layer_0/polygon_0/one_way = true
|
||||
8:7/0 = 0
|
||||
9:7/0 = 0
|
||||
10:7/0 = 0
|
||||
@@ -231,8 +248,14 @@ texture = ExtResource("1_5lb42")
|
||||
10:8/0 = 0
|
||||
1:9/0 = 0
|
||||
|
||||
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_v3eon"]
|
||||
scenes/1/scene = ExtResource("3_ygehw")
|
||||
|
||||
[sub_resource type="TileSet" id="TileSet_yf4x4"]
|
||||
physics_layer_0/collision_layer = 1
|
||||
physics_layer_0/collision_mask = 5
|
||||
sources/0 = SubResource("TileSetAtlasSource_8idcv")
|
||||
sources/1 = SubResource("TileSetScenesCollectionSource_v3eon")
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8ljy4"]
|
||||
texture = ExtResource("1_5lb42")
|
||||
@@ -373,7 +396,7 @@ tile_map_data = PackedByteArray("AAD8////AAABAAAAAAD9////AAABAAAAAAD+////AAABAAA
|
||||
tile_set = ExtResource("1_d680t")
|
||||
|
||||
[node name="Entities layer" type="TileMapLayer" parent="."]
|
||||
tile_map_data = PackedByteArray("AAAJAPz/AAAHAAMAAAAJAP3/AAAHAAQAAAAKAPz/AAAIAAMAAAAKAP3/AAAIAAQAAAALAP3/AAAIAAQAAAALAPz/AAAIAAMAAAAMAPz/AAAJAAMAAAAMAP3/AAAJAAQAAAANAPz/AAAKAAMAAAANAP3/AAAKAAQAAAAUAPz/AAAGAAMAADAVAPz/AAAGAAMAADAWAPz/AAAGAAMAADAcAAMAAAAGAAMAAGAPAPn/AAADAAYAAAAWAP3/AAALAAQAAAAWAP7/AAALAAQAAAAWAP//AAALAAQAAAAWAAAAAAALAAQAAAAWAAEAAAALAAQAAAAWAAIAAAALAAQAAAAWAAMAAAALAAQAAAAaAAMAAAAGAAQAAAAbAPn/AAADAAQAAAAaAPn/AAADAAQAAAAZAPn/AAADAAQAAAAYAPn/AAADAAQAAAAXAPn/AAADAAQAAAAWAPn/AAADAAQAAAAZAPj/AAADAAQAAAAYAPj/AAADAAQAAAAaAPj/AAADAAQAAAAXAPj/AAADAAQAAAAZAPf/AAADAAQAAAAYAPf/AAADAAQAAAA=")
|
||||
tile_map_data = PackedByteArray("AAAJAPz/AAAHAAMAAAAJAP3/AAAHAAQAAAAKAPz/AAAIAAMAAAAKAP3/AAAIAAQAAAALAP3/AAAIAAQAAAALAPz/AAAIAAMAAAAMAPz/AAAJAAMAAAAMAP3/AAAJAAQAAAANAPz/AAAKAAMAAAANAP3/AAAKAAQAAAAUAPz/AAAGAAMAADAVAPz/AAAGAAMAADAWAPz/AAAGAAMAADAcAAMAAAAGAAMAAGAPAPn/AAADAAYAAAAWAP3/AAALAAQAAAAWAP7/AAALAAQAAAAWAP//AAALAAQAAAAWAAAAAAALAAQAAAAWAAEAAAALAAQAAAAWAAIAAAALAAQAAAAWAAMAAAALAAQAAAAaAAMAAAAGAAQAAAAWAPn/AQAAAAAAAQAXAPn/AQAAAAAAAQAYAPn/AQAAAAAAAQAZAPn/AQAAAAAAAQAaAPn/AQAAAAAAAQAZAPj/AQAAAAAAAQAYAPj/AQAAAAAAAQAXAPj/AQAAAAAAAQAYAPf/AQAAAAAAAQA=")
|
||||
tile_set = SubResource("TileSet_yf4x4")
|
||||
|
||||
[node name="Foreground layer" type="TileMapLayer" parent="."]
|
||||
|
2
scripts/components/can_pickup.gd
Normal file
2
scripts/components/can_pickup.gd
Normal file
@@ -0,0 +1,2 @@
|
||||
class_name CanPickUpComponent
|
||||
extends Node
|
22
scripts/components/collectable.gd
Normal file
22
scripts/components/collectable.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
class_name CollectableComponent
|
||||
extends Node
|
||||
|
||||
var root: Node
|
||||
|
||||
@export var area2d: Area2D
|
||||
@export var collectable_data: Resource
|
||||
|
||||
signal collected(amount: int)
|
||||
|
||||
func _ready() -> void:
|
||||
if area2d:
|
||||
area2d.body_entered.connect(_on_area2d_body_entered)
|
||||
else:
|
||||
print("Collectable node missing Area2D child.")
|
||||
|
||||
root = get_parent()
|
||||
|
||||
func _on_area2d_body_entered(body: Node2D) -> void:
|
||||
if body.has_node("CanPickUpComponent"):
|
||||
collected.emit(collectable_data.amount)
|
||||
root.queue_free()
|
20
scripts/components/score.gd
Normal file
20
scripts/components/score.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
class_name ScoreComponent
|
||||
extends Node
|
||||
|
||||
@onready var game_manager: GM = $"/root/GameManager"
|
||||
|
||||
func _ready():
|
||||
await get_tree().process_frame
|
||||
var coins = get_tree().get_nodes_in_group("coins")
|
||||
|
||||
for coin in coins:
|
||||
coin.connect("collected", on_collected)
|
||||
|
||||
func on_collected(amount: int) -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
game_manager.add_coins(amount)
|
||||
print("Coins: ", game_manager.get_coins())
|
||||
# todo: play sound
|
||||
# todo: update ui
|
18
scripts/game_manager.gd
Normal file
18
scripts/game_manager.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
class_name GM
|
||||
extends Node
|
||||
|
||||
var player_state = {
|
||||
"coins": 0,
|
||||
}
|
||||
|
||||
func add_coins(amount: int) -> void:
|
||||
player_state["coins"] += amount
|
||||
|
||||
func set_coins(amount: int) -> void:
|
||||
player_state["coins"] = amount
|
||||
|
||||
func get_coins() -> int:
|
||||
return player_state["coins"]
|
||||
|
||||
func remove_coins(amount: int) -> void:
|
||||
player_state["coins"] -= amount
|
@@ -48,6 +48,9 @@ func _physics_process(delta):
|
||||
|
||||
if Input.is_action_pressed("jump") and (is_on_floor() or coyote_mode):
|
||||
jump()
|
||||
|
||||
if Input.is_action_just_pressed("down"):
|
||||
position.y += 1
|
||||
|
||||
var direction = Input.get_axis("left", "right")
|
||||
if direction:
|
||||
|
3
scripts/resources/collectable_resource.gd
Normal file
3
scripts/resources/collectable_resource.gd
Normal file
@@ -0,0 +1,3 @@
|
||||
extends Resource
|
||||
|
||||
@export var amount: int = 0
|
@@ -367,6 +367,7 @@ texture = ExtResource("1")
|
||||
|
||||
[resource]
|
||||
physics_layer_0/collision_layer = 1
|
||||
physics_layer_0/collision_mask = 5
|
||||
terrain_set_0/mode = 0
|
||||
terrain_set_0/terrain_0/name = "Village 0"
|
||||
terrain_set_0/terrain_0/color = Color(0.520131, 0.153738, 0.75213, 1)
|
||||
|
Reference in New Issue
Block a user