diff options
author | Victor Andrade de Almeida <vct.a.almeida@gmail.com> | 2022-07-16 18:31:13 -0300 |
---|---|---|
committer | Victor Andrade de Almeida <vct.a.almeida@gmail.com> | 2022-07-16 18:31:27 -0300 |
commit | 5b432198140f06d427079a6c8160b2c525b5eb0f (patch) | |
tree | 2aee9d93c7f2156d6bdc27e9917c458d196ff9dd | |
parent | 3b28b4585b5272a4c72a2c89f02f4441945e03fd (diff) | |
download | gamejam-gmtk-2022-5b432198140f06d427079a6c8160b2c525b5eb0f.tar.gz gamejam-gmtk-2022-5b432198140f06d427079a6c8160b2c525b5eb0f.tar.bz2 gamejam-gmtk-2022-5b432198140f06d427079a6c8160b2c525b5eb0f.zip |
Add damage pressure plates
-rw-r--r-- | Scenes/Dungeon.gd | 13 | ||||
-rw-r--r-- | Scenes/Entity.gd | 18 | ||||
-rw-r--r-- | Scenes/PlateDamage.gd | 19 | ||||
-rw-r--r-- | Scenes/PlateDamage.tscn | 19 | ||||
-rw-r--r-- | Scenes/Player.gd | 5 | ||||
-rw-r--r-- | project.godot | 8 |
6 files changed, 77 insertions, 5 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd index 40dc566..195ddc6 100644 --- a/Scenes/Dungeon.gd +++ b/Scenes/Dungeon.gd @@ -4,6 +4,7 @@ const Player = preload("res://Scenes/Player.tscn") const Obstacle = preload("res://Scenes/Obstacle.tscn") const MonsterScene = preload("res://Scenes/MonsterRandCardinal.tscn") const PlateBounce = preload("res://Scenes/PlateBounce.tscn") +const PlateDamage = preload("res://Scenes/PlateDamage.tscn") const PlateKey = preload("res://Scenes/PlateKey.tscn") const Crystal = preload("res://Scenes/Crystal.tscn") @@ -70,7 +71,7 @@ func build_floor(): add_child(crystal) rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) - while tiles_floor.has(rand_pos): + while tiles_entities.has(rand_pos) or tiles_floor.has(rand_pos): rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) var plate_key = PlateKey.instance() plate_key.set_crystal(crystal) @@ -79,13 +80,21 @@ func build_floor(): for i in range(4): rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) - while tiles_floor.has(rand_pos): + while tiles_entities.has(rand_pos) or tiles_floor.has(rand_pos): rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) var plate_bounce = PlateBounce.instance() plate_bounce.set_cardinal(randi() % 4) tiles_floor[rand_pos] = plate_bounce add_child(plate_bounce) + for i in range(4): + rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) + while tiles_entities.has(rand_pos) or tiles_floor.has(rand_pos): + rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) + var plate_damage = PlateDamage.instance() + tiles_floor[rand_pos] = plate_damage + add_child(plate_damage) + for key in tiles_entities: tiles_entities[key].translation = tile_to_pos(key) diff --git a/Scenes/Entity.gd b/Scenes/Entity.gd index a13c23b..9698189 100644 --- a/Scenes/Entity.gd +++ b/Scenes/Entity.gd @@ -44,3 +44,21 @@ func cor_move(args : Array): # args = [Vector3] func cor_dies(args : Array): yield() + +func cor_shake(args : Array): + var duration = args[0] + var time = 0 + + var zero = Vector3(0, 0.5, 0) + var intensity = 0.02 + + while true: + time = min(time + get_process_delta_time(), duration) + + translation = zero + (2 * Vector3(randf(), randf(), randf()) - Vector3.ONE) * intensity + + if time >= duration: + translation = zero + break + + yield(get_tree(), "idle_frame") diff --git a/Scenes/PlateDamage.gd b/Scenes/PlateDamage.gd new file mode 100644 index 0000000..310ac39 --- /dev/null +++ b/Scenes/PlateDamage.gd @@ -0,0 +1,19 @@ +extends Plate + +export(int) var damage + +func activate(entity : Entity, dungeon): + if entity is Player: + entity.add_action("cor_shake", [0.2]) + Global.turns -= damage + return + + if entity is Monster: + if entity.health - damage <= 0: + entity.alive = false + entity.add_action("cor_dies", []) + dungeon.kill_entity(entity) + else: + entity.health -= damage + entity.add_action("cor_shake", [0.2]) + return diff --git a/Scenes/PlateDamage.tscn b/Scenes/PlateDamage.tscn new file mode 100644 index 0000000..ad83b80 --- /dev/null +++ b/Scenes/PlateDamage.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Scenes/PlateDamage.gd" type="Script" id=1] + +[sub_resource type="CubeMesh" id=1] +size = Vector3( 0.9, 0.05, 1 ) + +[sub_resource type="SpatialMaterial" id=2] +albedo_color = Color( 1, 0.372549, 0.372549, 1 ) + +[node name="PlateDamage" type="Spatial"] +script = ExtResource( 1 ) +valid_symbols = [ "2", "3", "4", "5", "6", "" ] +damage = 1 + +[node name="Mesh" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.025, 0 ) +mesh = SubResource( 1 ) +material/0 = SubResource( 2 ) diff --git a/Scenes/Player.gd b/Scenes/Player.gd index e0ce5ff..5af227b 100644 --- a/Scenes/Player.gd +++ b/Scenes/Player.gd @@ -1,5 +1,7 @@ extends Entity +class_name Player + # Cube Layout: # 0 # 1 @@ -122,7 +124,7 @@ func cor_half_move(args : Array): # args = [Vector3, float] pos_a = translation dir = pos_b - pos_a time = 0 - + while true: time = min(time + get_process_delta_time(), duration) var weight = time / (duration) @@ -134,7 +136,6 @@ func cor_half_move(args : Array): # args = [Vector3, float] yield(get_tree(), "idle_frame") - func cor_shake(args : Array): var duration = args[0] var time = 0 diff --git a/project.godot b/project.godot index 2fc313d..c9a3390 100644 --- a/project.godot +++ b/project.godot @@ -28,12 +28,18 @@ _global_script_classes=[ { "class": "Plate", "language": "GDScript", "path": "res://Scenes/Plate.gd" +}, { +"base": "Entity", +"class": "Player", +"language": "GDScript", +"path": "res://Scenes/Player.gd" } ] _global_script_class_icons={ "Crystal": "", "Entity": "", "Monster": "", -"Plate": "" +"Plate": "", +"Player": "" } [application] |