Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placeable miner #12

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bullet.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name Bullet
extends Area2D

@export var speed: float = 700.0
Expand Down
12 changes: 7 additions & 5 deletions bullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ radius = 3.0
height = 16.0

[node name="Area2D" type="Area2D"]
scale = Vector2(2, 2)
collision_layer = 8
collision_mask = 6
collision_mask = 22
script = ExtResource("1_falbk")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_wy01o")
autoplay = "default"

[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["Bullet"]]
rotation = 1.5708
shape = SubResource("CapsuleShape2D_4udxs")

[node name="Timer" type="Timer" parent="."]
unique_name_in_owner = true
one_shot = true
autostart = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["Bullet"]]
rotation = 1.5708
shape = SubResource("CapsuleShape2D_4udxs")

[connection signal="body_entered" from="." to="." method="_on_area_2d_body_entered"]
10 changes: 10 additions & 0 deletions miner.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class_name Miner
extends Area2D


func _ready():
pass


func _physics_process(_delta):
pass
56 changes: 56 additions & 0 deletions miner.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[gd_scene load_steps=9 format=3 uid="uid://co87fcy7nhm03"]

[ext_resource type="Script" path="res://miner.gd" id="1_kvdlu"]
[ext_resource type="Texture2D" uid="uid://njtf4kfmkots" path="res://assets/All_Fire_Bullet_Pixel_16x16_03.png" id="1_ri74v"]

[sub_resource type="AtlasTexture" id="AtlasTexture_1oyvy"]
atlas = ExtResource("1_ri74v")
region = Rect2(96, 96, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_thacm"]
atlas = ExtResource("1_ri74v")
region = Rect2(112, 96, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_ylwx2"]
atlas = ExtResource("1_ri74v")
region = Rect2(128, 96, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_glhx6"]
atlas = ExtResource("1_ri74v")
region = Rect2(144, 96, 16, 16)

[sub_resource type="SpriteFrames" id="SpriteFrames_5kvba"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_1oyvy")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_thacm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ylwx2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_glhx6")
}],
"loop": true,
"name": &"default",
"speed": 10.0
}]

[sub_resource type="CircleShape2D" id="CircleShape2D_pqnky"]
radius = 256.0

[node name="Miner" type="Area2D"]
collision_layer = 32
script = ExtResource("1_kvdlu")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(2, 2)
sprite_frames = SubResource("SpriteFrames_5kvba")
autoplay = "default"

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_pqnky")
debug_color = Color(0.282353, 0.501961, 1, 0.0431373)
21 changes: 21 additions & 0 deletions ore.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class_name Ore
extends StaticBody2D

@export var miner_scene: PackedScene

var _miner: Miner = null
var _player_is_near: bool = false


func _physics_process(_delta):
if _player_is_near and not _miner and Input.is_action_just_pressed("place_miner"):
_miner = miner_scene.instantiate()
add_child(_miner)


func _on_player_nearby_detector_body_entered(_body):
_player_is_near = true


func _on_player_nearby_detector_body_exited(_body):
_player_is_near = false
39 changes: 39 additions & 0 deletions ore.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[gd_scene load_steps=6 format=3 uid="uid://5lcr3pww35f2"]

[ext_resource type="Script" path="res://ore.gd" id="1_cqjta"]
[ext_resource type="Texture2D" uid="uid://0mo6y3vutc8a" path="res://autotile_tileset.png" id="1_g58vr"]
[ext_resource type="PackedScene" uid="uid://co87fcy7nhm03" path="res://miner.tscn" id="2_anw00"]

[sub_resource type="CircleShape2D" id="CircleShape2D_47xg5"]
radius = 32.0

[sub_resource type="CircleShape2D" id="CircleShape2D_3ye4y"]
radius = 128.0

[node name="Ore" type="StaticBody2D"]
collision_layer = 16
collision_mask = 0
script = ExtResource("1_cqjta")
miner_scene = ExtResource("2_anw00")

[node name="Polygon2D" type="Polygon2D" parent="."]
color = Color(1, 1, 1, 0.0392157)
polygon = PackedVector2Array(-64, -64, 0, -96, 64, -64, 96, 0, 64, 64, 0, 96, -64, 64, -96, 0)

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_g58vr")
region_enabled = true
region_rect = Rect2(518, 222, 64, 64)

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_47xg5")

[node name="PlayerNearbyDetector" type="Area2D" parent="."]
collision_layer = 0

[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerNearbyDetector"]
shape = SubResource("CircleShape2D_3ye4y")
debug_color = Color(0, 0.643137, 0.301961, 0.0352941)

[connection signal="body_entered" from="PlayerNearbyDetector" to="." method="_on_player_nearby_detector_body_entered"]
[connection signal="body_exited" from="PlayerNearbyDetector" to="." method="_on_player_nearby_detector_body_exited"]
1 change: 1 addition & 0 deletions player.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name Player
extends CharacterBody2D

@export var speed: float = 300.0
Expand Down
2 changes: 1 addition & 1 deletion player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
size = Vector2(64, 64)

[node name="Player" type="CharacterBody2D"]
collision_mask = 6
collision_mask = 86
script = ExtResource("1_x82fp")
bullet_scene = ExtResource("2_17bio")

Expand Down
11 changes: 10 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ config/icon="res://icon.svg"
window/size/viewport_width=1920
window/size/viewport_height=1080
window/size/resizable=false
window/stretch/mode="viewport"

[input]

Expand Down Expand Up @@ -48,13 +49,21 @@ shoot={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
place_miner={
"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":70,"key_label":0,"unicode":102,"echo":false,"script":null)
]
}

[layer_names]

2d_physics/layer_1="Player"
2d_physics/layer_2="Enemy"
2d_physics/layer_3="Wall"
2d_physics/layer_3="Environment"
2d_physics/layer_4="Projectile"
2d_physics/layer_5="Ore"
2d_physics/layer_6="Miner"
2d_physics/layer_7="NPC"

[rendering]

Expand Down
6 changes: 5 additions & 1 deletion world.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=15 format=3 uid="uid://brr557s2lfy5s"]
[gd_scene load_steps=16 format=3 uid="uid://brr557s2lfy5s"]

[ext_resource type="PackedScene" uid="uid://ceys4vrcavapp" path="res://player.tscn" id="1_gtarq"]
[ext_resource type="Texture2D" uid="uid://0mo6y3vutc8a" path="res://autotile_tileset.png" id="3_6yl3h"]
[ext_resource type="PackedScene" uid="uid://qi2widkoej4c" path="res://enemy.tscn" id="3_60omp"]
[ext_resource type="PackedScene" uid="uid://5lcr3pww35f2" path="res://ore.tscn" id="4_sonye"]

[sub_resource type="NavigationPolygon" id="NavigationPolygon_h6v47"]
vertices = PackedVector2Array(-16, -32, 32, -32, 32, 32, -16, 32)
Expand Down Expand Up @@ -263,3 +264,6 @@ position = Vector2(777, 341)

[node name="Enemy3" parent="." instance=ExtResource("3_60omp")]
position = Vector2(1044, 691)

[node name="Ore1" parent="." instance=ExtResource("4_sonye")]
position = Vector2(324, 206)