add theme, player simple attack
This commit is contained in:
1549
minimal_theme.tres
Normal file
1549
minimal_theme.tres
Normal file
File diff suppressed because it is too large
Load Diff
40
objects/brick.tscn
Normal file
40
objects/brick.tscn
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bymro4t7angv5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_1c3jb"]
|
||||
[ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_i6t5k"]
|
||||
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="3_8xipx"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"]
|
||||
size = Vector2(16, 10)
|
||||
|
||||
[node name="Brick" type="Area2D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 11
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_ar0xf")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_1c3jb")
|
||||
hframes = 12
|
||||
vframes = 12
|
||||
frame = 80
|
||||
|
||||
[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "visibility_notifier", "timer")]
|
||||
script = ExtResource("2_i6t5k")
|
||||
root = NodePath("..")
|
||||
speed = 120.0
|
||||
area2d = NodePath("..")
|
||||
visibility_notifier = NodePath("../VisibleOnScreenNotifier2D")
|
||||
life_time = 2.0
|
||||
timer = NodePath("../Timer")
|
||||
|
||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
||||
position = Vector2(0, 2.38419e-07)
|
||||
scale = Vector2(0.8, 0.5)
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
|
||||
script = ExtResource("3_8xipx")
|
||||
area2d = NodePath("..")
|
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://bqi5s710xb1ju"]
|
||||
[gd_scene load_steps=13 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"]
|
||||
@@ -9,6 +9,8 @@
|
||||
[ext_resource type="Script" path="res://scripts/components/health.gd" id="7_tqjk8"]
|
||||
[ext_resource type="Script" path="res://scripts/components/player_death.gd" id="8_1v23d"]
|
||||
[ext_resource type="Script" path="res://scripts/components/knockback.gd" id="9_rjyu4"]
|
||||
[ext_resource type="Script" path="res://scripts/components/brick_throw.gd" id="10_u0v3b"]
|
||||
[ext_resource type="PackedScene" uid="uid://bymro4t7angv5" path="res://objects/brick.tscn" id="11_qutq2"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"]
|
||||
size = Vector2(16, 31)
|
||||
@@ -62,5 +64,14 @@ script = ExtResource("9_rjyu4")
|
||||
character_body = NodePath("..")
|
||||
knockback_force = 1500.0
|
||||
|
||||
[node name="BrickThrowComponent" type="Node" parent="." node_paths=PackedStringArray("player_controller", "timer")]
|
||||
script = ExtResource("10_u0v3b")
|
||||
brick_scene = ExtResource("11_qutq2")
|
||||
fire_rate = 0.3
|
||||
player_controller = NodePath("..")
|
||||
timer = NodePath("../ThrowTimer")
|
||||
|
||||
[node name="ThrowTimer" type="Timer" parent="."]
|
||||
|
||||
[connection signal="on_death" from="HealthComponent" to="PlayerDeathComponent" method="_on_health_component_on_death"]
|
||||
[connection signal="on_health_change" from="HealthComponent" to="KnockbackComponent" method="_on_health_component_on_health_change"]
|
||||
|
@@ -9,7 +9,7 @@ radius = 4.0
|
||||
|
||||
[node name="Bullet" type="Area2D"]
|
||||
collision_layer = 8
|
||||
collision_mask = 5
|
||||
collision_mask = 21
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_txsw8")
|
||||
|
@@ -10,7 +10,7 @@ radius = 9.0
|
||||
|
||||
[node name="Coin" type="Area2D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 4
|
||||
collision_mask = 20
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_3ask2")
|
||||
|
@@ -13,7 +13,7 @@ size = Vector2(18, 27)
|
||||
size = Vector2(18, 27)
|
||||
|
||||
[node name="Enemy" type="CharacterBody2D"]
|
||||
collision_layer = 0
|
||||
collision_layer = 8
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 0.5)
|
||||
@@ -45,7 +45,7 @@ root = NodePath("..")
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
collision_mask = 4
|
||||
collision_mask = 20
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
position = Vector2(0, 0.5)
|
||||
|
@@ -32,6 +32,7 @@ GameManager="*res://objects/game_manager.tscn"
|
||||
|
||||
window/size/viewport_width=640
|
||||
window/size/viewport_height=360
|
||||
window/size/initial_position=Vector2i(420, 0)
|
||||
window/size/window_width_override=1280
|
||||
window/size/window_height_override=720
|
||||
window/stretch/mode="viewport"
|
||||
@@ -68,6 +69,12 @@ down={
|
||||
"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)
|
||||
]
|
||||
}
|
||||
attack={
|
||||
"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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
, 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":1,"position":Vector2(416, 6),"global_position":Vector2(425, 50),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
@@ -75,6 +82,7 @@ down={
|
||||
2d_physics/layer_2="Collectible Entities"
|
||||
2d_physics/layer_3="Player"
|
||||
2d_physics/layer_4="Enemy"
|
||||
2d_physics/layer_5="player projectiles"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
39
scripts/components/brick_throw.gd
Normal file
39
scripts/components/brick_throw.gd
Normal file
@@ -0,0 +1,39 @@
|
||||
class_name BrickThrowComponent
|
||||
extends Node
|
||||
|
||||
@export var brick_scene: PackedScene
|
||||
@export var fire_rate: float = 1.0
|
||||
@export var player_controller: PlayerController
|
||||
@export var timer: Timer
|
||||
|
||||
var can_throw: bool = true
|
||||
|
||||
func _ready() -> void:
|
||||
setup_timer()
|
||||
can_throw = true
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("attack") and can_throw:
|
||||
throw_brick()
|
||||
|
||||
func setup_timer() -> void:
|
||||
timer.wait_time = fire_rate
|
||||
timer.one_shot = false
|
||||
timer.autostart = false
|
||||
timer.timeout.connect(on_timer_timeout)
|
||||
|
||||
|
||||
func on_timer_timeout() -> void:
|
||||
can_throw = true
|
||||
|
||||
|
||||
func throw_brick() -> void:
|
||||
var brick_instance: Node2D = brick_scene.instantiate()
|
||||
var brick: BulletComponent = brick_instance.get_node("BulletComponent")
|
||||
brick_instance.position = player_controller.position
|
||||
brick.direction = Vector2.RIGHT if player_controller.velocity.x >= 0.0 else Vector2.LEFT
|
||||
get_tree().current_scene.add_child(brick_instance)
|
||||
|
||||
can_throw = false
|
||||
timer.start()
|
@@ -1,7 +1,6 @@
|
||||
class_name BulletComponent
|
||||
extends Node
|
||||
|
||||
|
||||
@export var root: Node2D
|
||||
@export var direction: Vector2 = Vector2.RIGHT
|
||||
@export var speed: float = 10.0
|
||||
@@ -10,6 +9,7 @@ extends Node
|
||||
@export var life_time: float = 5.0
|
||||
@export var timer: Timer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
root = get_parent()
|
||||
visibility_notifier.screen_exited.connect(_on_screen_exited)
|
||||
@@ -18,12 +18,15 @@ func _ready() -> void:
|
||||
timer.wait_time = life_time
|
||||
timer.timeout.connect(on_timer_timeout)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
root.position += direction * speed * delta
|
||||
|
||||
|
||||
func _on_screen_exited() -> void:
|
||||
root.queue_free()
|
||||
|
||||
|
||||
func on_area2d_body_entered(_body: Node2D) -> void:
|
||||
root.queue_free()
|
||||
|
||||
|
@@ -367,7 +367,7 @@ texture = ExtResource("1")
|
||||
|
||||
[resource]
|
||||
physics_layer_0/collision_layer = 1
|
||||
physics_layer_0/collision_mask = 13
|
||||
physics_layer_0/collision_mask = 29
|
||||
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