init
This commit is contained in:
93
levels/world_state/control.gd
Executable file
93
levels/world_state/control.gd
Executable file
@@ -0,0 +1,93 @@
|
||||
class_name WorldState
|
||||
extends Control
|
||||
@export var animation_player:AnimationPlayer
|
||||
@export var tilemap:Level
|
||||
@export var item_list:ItemList
|
||||
@export var stats_label:Label
|
||||
@export var stats_ui:Control
|
||||
@export var array:Array[Array] = [
|
||||
["A1", "A2", "A3"],
|
||||
["B1", "B2", "B3"],
|
||||
["C1", "C2", "C3"],
|
||||
[]
|
||||
]
|
||||
var world:World
|
||||
|
||||
var current_cords:Vector2 = Vector2(0, 0)
|
||||
|
||||
func do_command(command:String, input:String) -> void:
|
||||
match command:
|
||||
"WALK":
|
||||
move(input)
|
||||
"TALK":
|
||||
pass
|
||||
"INVENTORY":
|
||||
pass
|
||||
"BATTLE":
|
||||
battle(input)
|
||||
|
||||
func start(current_world:World) -> void:
|
||||
world = current_world
|
||||
world.player.stats_changed.connect(update_stats)
|
||||
update_stats()
|
||||
|
||||
func battle(input:String) -> void:
|
||||
match input:
|
||||
"UP":
|
||||
interactable_obj_exists(world.player.global_position + Vector2(0, -10))
|
||||
"DOWN":
|
||||
interactable_obj_exists(world.player.global_position + Vector2(0, 10))
|
||||
"LEFT":
|
||||
interactable_obj_exists(world.player.global_position + Vector2(-10, 0))
|
||||
"RIGHT":
|
||||
interactable_obj_exists(world.player.global_position + Vector2(10, 0))
|
||||
|
||||
func move(input:String) -> void:
|
||||
match input:
|
||||
"UP":
|
||||
if is_walkable(Vector2(0, -10)):
|
||||
world.player.global_position.y -= 10
|
||||
"DOWN":
|
||||
if is_walkable(Vector2(0, 10)):
|
||||
world.player.global_position.y += 10
|
||||
"LEFT":
|
||||
if is_walkable(Vector2(-10, 0)):
|
||||
world.player.global_position.x -= 10
|
||||
"RIGHT":
|
||||
if is_walkable(Vector2(10, 0)):
|
||||
world.player.global_position.x += 10
|
||||
|
||||
func is_walkable(direction:Vector2) -> bool:
|
||||
var clicked_cell:Vector2i = tilemap.local_to_map(world.player.global_position + direction)
|
||||
var cell:TileData = tilemap.get_cell_tile_data(clicked_cell)
|
||||
if cell:
|
||||
return cell.get_custom_data("walkable")
|
||||
return false
|
||||
|
||||
func interactable_obj_exists(pos:Vector2) -> void:
|
||||
if tilemap.interactble_objects.has(pos):
|
||||
tilemap.interactble_objects[pos].use_object(world)
|
||||
tilemap.interactble_objects[pos].queue_free()
|
||||
tilemap.interactble_objects.erase(pos)
|
||||
|
||||
func _on_item_list_item_selected(index: int) -> void:
|
||||
world.line_edit.text = item_list.get_item_text(index).to_upper()
|
||||
world.line_edit.caret_column = 30
|
||||
item_list.deselect(index)
|
||||
item_list.release_focus()
|
||||
world.line_edit.grab_focus()
|
||||
|
||||
|
||||
func update_stats():
|
||||
while(stats_ui.size.y > 0):
|
||||
stats_ui.size.y -= 10
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
|
||||
var stats:String = "Health: " + str(world.player.health) \
|
||||
+ "\nDamage: " + str(world.player.damage) \
|
||||
+ "\nSpeed: " + str(world.player.speed)
|
||||
stats_label.text = stats
|
||||
|
||||
while(stats_ui.size.y < 224.0):
|
||||
stats_ui.size.y += 10
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
Reference in New Issue
Block a user