summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-07-16 01:11:51 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-07-16 01:11:51 -0300
commit476d62772d5f29129ef8e563d3dd0f1c75539b15 (patch)
tree29790918b1baab41ad8d808f362674d30364adb9
parentedb9bee47988c9d826badd61d9cbd99d0adec865 (diff)
downloadgamejam-gmtk-2022-476d62772d5f29129ef8e563d3dd0f1c75539b15.tar.gz
gamejam-gmtk-2022-476d62772d5f29129ef8e563d3dd0f1c75539b15.tar.bz2
gamejam-gmtk-2022-476d62772d5f29129ef8e563d3dd0f1c75539b15.zip
Moving enemies (sort of)
-rw-r--r--Scenes/Dungeon.gd49
-rw-r--r--Scenes/Monster.gd1
-rw-r--r--Scenes/MonsterRandCardinal.gd1
-rw-r--r--Scenes/MonsterRandCardinal.tscn26
4 files changed, 58 insertions, 19 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd
index 1c2dbd7..0f409b3 100644
--- a/Scenes/Dungeon.gd
+++ b/Scenes/Dungeon.gd
@@ -2,7 +2,7 @@ extends Spatial
const Player = preload("res://Scenes/Player.tscn")
const Obstacle = preload("res://Scenes/Obstacle.tscn")
-const MonsterScene = preload("res://Scenes/Monster.tscn")
+const MonsterScene = preload("res://Scenes/MonsterRandCardinal.tscn")
onready var camera = $Pitch
onready var player : Entity = null
@@ -10,29 +10,41 @@ onready var player : Entity = null
var input : Vector2
var tiles_entities = {}
+var entities_tiles = {}
+
var tiles_floor = {}
func _ready():
randomize()
build_floor()
+func set_tile(entity, tile):
+ if not entities_tiles.has(entity):
+ entities_tiles[entity] = tile
+ tiles_entities[tile] = entity
+ else:
+ var old_tile = entities_tiles[entity]
+ tiles_entities.erase(old_tile)
+ tiles_entities[tile] = entity
+ entities_tiles[entity] = tile
+
func build_floor():
player = Player.instance()
add_child(player)
var rand_pos = Vector2(-5, 0)
- tiles_entities[rand_pos] = player
+ set_tile(player, rand_pos)
for i in range(4):
rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3)
var obstacle = Obstacle.instance()
- tiles_entities[rand_pos] = obstacle
+ set_tile(obstacle, rand_pos)
add_child(obstacle)
for i in range(2):
rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3)
var monster = MonsterScene.instance()
- tiles_entities[rand_pos] = monster
+ set_tile(monster, rand_pos)
add_child(monster)
for key in tiles_entities:
@@ -60,7 +72,8 @@ func process_turn_logic():
# player attack
# player move
- move_player(input)
+ if move_entity(player, input):
+ player.roll(input)
input = Vector2.ZERO
# check tile player
@@ -69,19 +82,21 @@ func process_turn_logic():
var monsters = get_tree().get_nodes_in_group("monsters")
for monster in monsters:
monster = monster as Monster
- var monster_action = monster.try_moving(pos_to_tile(player.translation), pos_to_tile(monster.translation))
+ var monster_action = monster.try_moving(entities_tiles[player], entities_tiles[monster])
match monster_action.type:
Monster.MonsterActionType.IDLE:
pass
Monster.MonsterActionType.ATTACK:
pass
Monster.MonsterActionType.MOVE:
- pass
+ 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()
@@ -104,24 +119,20 @@ func _input(event):
KEY_ESCAPE:
get_tree().change_scene("res://Scenes/Dungeon.tscn")
-func player_check_attack(tile):
- pass
-
-func move_player(dir : Vector2):
- var cur_tile = pos_to_tile(player.translation)
+func move_entity(entity : Entity, dir : Vector2):
+ var cur_tile = entities_tiles[entity]
var new_tile = cur_tile + dir
if tiles_entities.has(new_tile):
- player.add_action("cor_shake", [0.2])
- return
+ entity.add_action("cor_shake", [0.2])
+ return false
- tiles_entities.erase(cur_tile)
- tiles_entities[new_tile] = player
+ set_tile(entity, new_tile)
#player_check_attack(new_tile)
-
- player.add_action("cor_move", [tile_to_pos(new_tile), 0.2])
- player.roll(dir)
+ print("foi")
+ entity.add_action("cor_move", [tile_to_pos(new_tile), 0.2])
+ return true
func tile_to_pos(tile : Vector2):
return Vector3(tile.x, 0, -tile.y)
diff --git a/Scenes/Monster.gd b/Scenes/Monster.gd
index 9f49d29..3e82d5d 100644
--- a/Scenes/Monster.gd
+++ b/Scenes/Monster.gd
@@ -9,6 +9,7 @@ export(int) var damage = 1
onready var sprite = $Sprite3D
func _ready():
+ ._ready()
add_to_group("monsters")
func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction:
diff --git a/Scenes/MonsterRandCardinal.gd b/Scenes/MonsterRandCardinal.gd
index 46a1d62..4ced004 100644
--- a/Scenes/MonsterRandCardinal.gd
+++ b/Scenes/MonsterRandCardinal.gd
@@ -4,6 +4,7 @@ onready var cardinal = Vector2.UP
onready var moved = false
func _ready():
+ ._ready()
if randf() < 0.5:
cardinal = Vector2.RIGHT
diff --git a/Scenes/MonsterRandCardinal.tscn b/Scenes/MonsterRandCardinal.tscn
new file mode 100644
index 0000000..40da5e2
--- /dev/null
+++ b/Scenes/MonsterRandCardinal.tscn
@@ -0,0 +1,26 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://icon.png" type="Texture" 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"]
+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 )