diff options
author | Henrique Alves <henriquelalves@gmail.com> | 2022-07-16 01:50:37 -0300 |
---|---|---|
committer | Henrique Alves <henriquelalves@gmail.com> | 2022-07-16 01:50:37 -0300 |
commit | 8d121400b0fac6f61328cb055b91ea5636c7db3c (patch) | |
tree | e7f4153cfbf2156869e3ff9e49a1b2e1b66f8684 | |
parent | 476d62772d5f29129ef8e563d3dd0f1c75539b15 (diff) | |
download | gamejam-gmtk-2022-8d121400b0fac6f61328cb055b91ea5636c7db3c.tar.gz gamejam-gmtk-2022-8d121400b0fac6f61328cb055b91ea5636c7db3c.tar.bz2 gamejam-gmtk-2022-8d121400b0fac6f61328cb055b91ea5636c7db3c.zip |
Add monster attack logic
-rw-r--r-- | Scenes/Dungeon.gd | 38 | ||||
-rw-r--r-- | Scenes/Entity.gd | 3 | ||||
-rw-r--r-- | Scenes/Monster.gd | 9 | ||||
-rw-r--r-- | Scenes/Monster.tscn | 61 | ||||
-rw-r--r-- | Scenes/MonsterRandCardinal.gd | 21 | ||||
-rw-r--r-- | Scenes/MonsterRandCardinal.tscn | 25 |
6 files changed, 120 insertions, 37 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd index 0f409b3..2483032 100644 --- a/Scenes/Dungeon.gd +++ b/Scenes/Dungeon.gd @@ -28,21 +28,26 @@ func set_tile(entity, tile): tiles_entities[tile] = entity entities_tiles[entity] = tile +func kill_entity(entity): + var tile = entities_tiles[entity] + tiles_entities.erase(tile) + entities_tiles.erase(entity) + func build_floor(): player = Player.instance() add_child(player) - var rand_pos = Vector2(-5, 0) + var rand_pos = Vector2(-6, 0) set_tile(player, rand_pos) for i in range(4): - rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3) + rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) var obstacle = Obstacle.instance() set_tile(obstacle, rand_pos) add_child(obstacle) - for i in range(2): - rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3) + for i in range(4): + rand_pos = Vector2(randi()%8 - 4, randi()%8 - 4) var monster = MonsterScene.instance() set_tile(monster, rand_pos) add_child(monster) @@ -68,8 +73,22 @@ func _process(delta): process_turn_logic() + func process_turn_logic(): # player attack + var cur_tile = entities_tiles[player] + var new_tile = cur_tile + input + + # simulate roll to attack + player.roll(input) + if tiles_entities.has(new_tile): + var monster = tiles_entities[new_tile] + if monster.has_method("get_weakness"): + if tiles_entities[new_tile].get_weakness().has(player.get_upper_face()): + monster.alive = false + monster.add_action("cor_dies", []) + kill_entity(monster) + player.roll(-input) # player move if move_entity(player, input): @@ -81,22 +100,21 @@ func process_turn_logic(): # monsters move+attack var monsters = get_tree().get_nodes_in_group("monsters") for monster in monsters: + if not monster.alive: continue monster = monster as Monster var monster_action = monster.try_moving(entities_tiles[player], entities_tiles[monster]) match monster_action.type: Monster.MonsterActionType.IDLE: pass Monster.MonsterActionType.ATTACK: - pass + player.add_action("cor_shake", [0.2]) Monster.MonsterActionType.MOVE: - print(monster_action.dir) move_entity(monster, monster_action.dir) # check tile monsters # start actions var actionables = get_tree().get_nodes_in_group("actionables") - print(actionables) for actionable in actionables: actionable.play_actions() @@ -124,13 +142,13 @@ func move_entity(entity : Entity, dir : Vector2): var new_tile = cur_tile + dir if tiles_entities.has(new_tile): - entity.add_action("cor_shake", [0.2]) + if entity.has_method("cor_shake"): + entity.add_action("cor_shake", [0.2]) return false set_tile(entity, new_tile) - #player_check_attack(new_tile) - print("foi") + entity.add_action("cor_move", [tile_to_pos(new_tile), 0.2]) return true diff --git a/Scenes/Entity.gd b/Scenes/Entity.gd index 49aa823..26b5b3f 100644 --- a/Scenes/Entity.gd +++ b/Scenes/Entity.gd @@ -35,3 +35,6 @@ func cor_move(args : Array): # args = [Vector3] break yield(get_tree(), "idle_frame") + +func cor_dies(args : Array): + yield() diff --git a/Scenes/Monster.gd b/Scenes/Monster.gd index 3e82d5d..38ea3ef 100644 --- a/Scenes/Monster.gd +++ b/Scenes/Monster.gd @@ -6,6 +6,7 @@ enum MonsterActionType {IDLE, ATTACK, MOVE} export(int) var damage = 1 +onready var alive = true onready var sprite = $Sprite3D func _ready(): @@ -18,6 +19,14 @@ func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction: func cor_attack(args : Array): yield() +func cor_dies(args : Array): + $AnimationPlayer.play("fucking_dies") + yield($AnimationPlayer, "animation_finished") + hide() + +func get_weakness(): + return ['1','2','3','4','5','6'] + class MonsterAction: var type : int var dir : Vector2 diff --git a/Scenes/Monster.tscn b/Scenes/Monster.tscn index 2120e93..5be54c8 100644 --- a/Scenes/Monster.tscn +++ b/Scenes/Monster.tscn @@ -1,9 +1,64 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://Scenes/Monster.gd" type="Script" id=2] [ext_resource path="res://Assets/blob_shadow.png" type="Texture" id=3] +[sub_resource type="Animation" id=1] +length = 0.001 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite3D:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ Vector3( 1, 1, 1 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Sprite3D:translation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ Vector3( 0, 0.605694, 0 ) ] +} + +[sub_resource type="Animation" id=2] +resource_name = "fucking_dies" +length = 0.2 +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite3D:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.2 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ Vector3( 1, 1, 1 ), Vector3( 1, 0, 1 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Sprite3D:translation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0, 0.2 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ Vector3( 0, 0.605694, 0 ), Vector3( 0, 0, 0 ) ] +} + [node name="Monster" type="Spatial"] script = ExtResource( 2 ) actionable = true @@ -24,3 +79,7 @@ pixel_size = 0.014 axis = 1 double_sided = false texture = ExtResource( 3 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/RESET = SubResource( 1 ) +anims/fucking_dies = SubResource( 2 ) diff --git a/Scenes/MonsterRandCardinal.gd b/Scenes/MonsterRandCardinal.gd index 4ced004..8689b51 100644 --- a/Scenes/MonsterRandCardinal.gd +++ b/Scenes/MonsterRandCardinal.gd @@ -2,30 +2,43 @@ extends Monster onready var cardinal = Vector2.UP onready var moved = false +onready var wait = -1 func _ready(): ._ready() if randf() < 0.5: cardinal = Vector2.RIGHT + if randf() < 0.5: + wait = 0 + +func get_weakness(): + return ['2','4','6'] func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction: + var action = MonsterAction.new() + + if wait != -1: + if wait == 0: + wait = 1 + action.type = MonsterActionType.IDLE + return action + else: + wait = 0 + var next_movement = cardinal if moved: next_movement *= -1 - moved = !moved var next_pos = monster_pos + next_movement - var action = MonsterAction.new() - if next_pos == player_pos: action.type = MonsterActionType.ATTACK else: action.type = MonsterActionType.MOVE action.dir = next_movement + moved = !moved return action - func cor_attack(args : Array): yield(.cor_attack(args), "completed") diff --git a/Scenes/MonsterRandCardinal.tscn b/Scenes/MonsterRandCardinal.tscn index 40da5e2..18ce934 100644 --- a/Scenes/MonsterRandCardinal.tscn +++ b/Scenes/MonsterRandCardinal.tscn @@ -1,26 +1,7 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Scenes/Monster.tscn" type="PackedScene" id=1] [ext_resource path="res://Scenes/MonsterRandCardinal.gd" type="Script" id=2] -[ext_resource path="res://Assets/blob_shadow.png" type="Texture" id=3] -[node name="Monster" type="Spatial"] +[node name="MonsterRandCardinal" instance=ExtResource( 1 )] script = ExtResource( 2 ) -actionable = true - -[node name="Sprite3D" type="Sprite3D" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.605694, 0 ) -cast_shadow = 0 -pixel_size = 0.014 -billboard = 1 -double_sided = false -texture = ExtResource( 1 ) - -[node name="BlobShadow" type="Sprite3D" parent="."] -transform = Transform( 2.13309, 0, 0, 0, 1, 0, 0, 0, 2.13309, 0, 0.01, 0 ) -cast_shadow = 0 -modulate = Color( 0, 0, 0, 1 ) -pixel_size = 0.014 -axis = 1 -double_sided = false -texture = ExtResource( 3 ) |