Commit 9152e61f authored by tgw3ff's avatar tgw3ff
Browse files

Merge branch 'ActorManager'

parents 745ee6bc 5847ade2
......@@ -39,6 +39,8 @@ func _process(delta):
# Rule processing
match phase:
0: #Start phase - Prepare everything for turn processing
print(get_node("../OrderManager").delay)
print("Start phase: "+currActor)
#Load current actor
......@@ -48,6 +50,9 @@ func _process(delta):
1: #Status update phase
print("Status update phase: "+currActor)
print("Position: "
+String(get_node("../../ActorManager/"+currActor).get_position()[0])+", "
+String(get_node("../../ActorManager/"+currActor).get_position()[1]))
#Process status effects
#Determine how much delay has passed?
phase += 1
......@@ -62,32 +67,30 @@ func _process(delta):
#Wait for player input
#If legal action, process it and change phase
if (get_node("../../Player").action_taken == true):
if(isDead(currActor)):
phase = -1
if (get_node("../../ActorManager/Player").action_taken == true):
phase = -1
get_node("../../Player").action_taken = false
get_node("../../ActorManager/Player").action_taken = false
#AI turn
else:
#Trigger the mob's decision function
#Trigger the mob's decision/action function
# Should analyze the map and return a choice of what to do
pass
# get_node("../../"+currActor).choice()
get_node("../../ActorManager/"+currActor).choice()
#Process returned action
pass
get_node("../../"+currActor).move("right") #TEMPORARY
#Check if died during actions
if (get_node("../../"+currActor).action_taken == true):
if(isDead(currActor)):
phase = -1
elif (get_node("../../ActorManager/"+currActor).action_taken == true):
phase = -1
get_node("../../"+currActor).action_taken = false
get_node("../../ActorManager/"+currActor).action_taken = false
-1: #End phase - Cleanup, prepare for next turn
print("End phase: "+currActor)
#Reset turn-specific variables
#Check if still alive. If not, kill.
if (get_node("../../"+currActor).health <= 0):
get_node("../../"+currActor).kill()
#Reset turn-specific variables
#Add delay
#Handled by next_actor()
......@@ -99,3 +102,12 @@ func _process(delta):
phase = 0
pass
func isDead(actor: String):
var exists: bool = false
for i in get_node("../OrderManager").delay.keys():
if(i == currActor):
exists = true
break
return (not exists)
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
#onready var ray = $RayCast2D
var inputs = {"right": Vector2.RIGHT,
"left": Vector2.LEFT,
"up": Vector2.UP,
"down": Vector2.DOWN}
var tile_size = 16
var dir_coords = {"right": [1*16, 0],
"left": [-1*16, 0],
"up": [0, -1*16],
"down": [0, 1*16]}
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
#Purpose: Gets the name of an actor node at the given coordinates
#Inputs:
# >Coordinate pair
#Outputs:
# >If there exists an actor at the coordinates:
# +Return that actor's node name
# >Else:
# +Return placeholder name "NULL"
func get_actor_id_coord(x: int, y: int) -> String:
for actor in get_children():
if(actor.get_position()[0] == x && actor.get_position()[1] == y):
return actor.name
return "NULL"
#Purpose: Gets the name of an actor node at a location relative to another node
#Inputs:
# >currActor: The actor whose location will be used as a reference point for the check
# +location = currActor.location + direction
# >dir: Direction to search in
#Outputs:
# >If there exists an actor at the calculated location:
# +Return that actor's node name
# >Else:
# +Return placeholder name "NULL"
func get_actor_id_dir(currActor: String, dir: String) -> String:
for actor in get_children():
if(actor.get_position()[0] == get_node("./"+currActor).get_position()[0] + dir_coords[dir][0]
&& actor.get_position()[1] == get_node("./"+currActor).get_position()[1] + dir_coords[dir][1]):
return actor.name
return "NULL"
#Purpose: Checks if there is an actor at a given set of coordinates
#Inputs:
# >Coordinate pair
#Outputs:
# >If there exists an actor at the coordinates:
# +Return true
# >Else:
# +Return false
func is_actor_coord(x: int, y: int) -> bool:
for actor in get_children():
if(actor.get_position()[0] == x && actor.get_position()[1] == y):
return true
return false
#Purpose: Checks if there is an actor node at a location relative to another node
#Inputs:
# >currActor: The actor whose location will be used as a reference point for the check
# +location = currActor.location + direction
# >dir: Direction to search in
#Outputs:
# >If there exists an actor at the calculated location:
# +Return true
# >Else:
# +Return false
func is_actor_dir(currActor: String, dir: String) -> bool:
print(currActor+" position: ("+String(get_node("./"+currActor).get_position()[0])+", "+String(get_node("./"+currActor).get_position()[0])+")")
for actor in get_children():
print(actor.name+
" position: ("+
String(get_node("./"+actor.name).get_position()[0])+
", "+
String(get_node("./"+actor.name).get_position()[0])+
")")
if(actor.get_position()[0] == get_node("./"+currActor).get_position()[0]+dir_coords[dir][0]
&& actor.get_position()[1] == get_node("./"+currActor).get_position()[1]+dir_coords[dir][1]):
return true
return false
#Return life at end?
#Use type to find modifiers
func harm(damage: float, type: String, actor: Node):
actor.health -= damage
print(">" + actor.name + " took " + String(damage) + " damage.")
# if actor.health <= 0:
# kill(actor)
pass
#Purpose: To remove an actor node from the game and adjust scripts to match
#Inputs: Name of actor node
#Outputs: None
func kill(actor: Node):
print(">" + actor.name + " is dying.")
get_node("../TurnManager/OrderManager").remove_actor(actor.name)
remove_child(get_node(actor.name))
#Inputs:
# +Two actor NDOES
# +Range as the number of TILES
#Outputs:
# +Bool representing whether or not two actors are within numTiles tiles of each other
func inRange(numTiles: int, actor1: Node, actor2: Node) -> bool:
if(dist(actor1, actor2) <= numTiles*tile_size): #Make is_visible() function?
return true
return false
#Inputs:
# +Two actor NODES
#Outputs:
# +Returns distance between two actors as number of PIXELS
# >divide by tile_size to get number of tiles
func dist(actor1: Node, actor2: Node) -> float:
return pow(pow(actor1.get_position[0]-actor2.get_position[0], 2) + pow(actor1.get_position[1]-actor2.get_position[1], 2), 0.5)
#Purpose: To push an actor in a certain direction a given amount, and to apply damage proportionate to the force behind the push
#Inputs:
# target: Name of actor's node being pushed
# strength: Distance (max) being pushed
# dir: Direction of push
# +Change to vector?
#Outputs: None
# +Change to trigger check for death?
func knockback(target: Node, strength: float, dir: String):
print("knockback("+target.name+", "+String(strength)+", "+dir+")")
# for actor in get_children():
# if(actor.name == target):
## Move actor in given direction (dir) stength tiles
## Detect collision; deal damage equal to strength remaining if collides with wall?
# break
for i in range(0, strength):
if(not move(target, dir)):
harm(1, "Crushing", target)
if target.health <= 0:
kill(target)
pass
#Outputs:
# Returns true if moved
# Returns false if can't be moved
func move(actor: Node, dir: String) -> bool:
actor.ray.cast_to = inputs[dir] * tile_size
actor.ray.force_raycast_update()
if !actor.ray.is_colliding():
actor.position += inputs[dir] * tile_size
return true
return false
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
# # # # #### ### # # ### ### # # ### ###
# # ## # # # ## # # # # # # # #
# # # # # ### # # # # # ## #### ### # #
# # # ## # # # ## # # # # # # #
### # # # ### # # ### ### # # ### ###
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://src/Tilemap01.tscn" type="PackedScene" id=1]
[ext_resource path="res://actors/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://OrderManager.gd" type="Script" id=3]
[ext_resource path="res://ActionManager.gd" type="Script" id=4]
[ext_resource path="res://actors/Enemy.tscn" type="PackedScene" id=5]
[ext_resource path="res://ActorManager.gd" type="Script" id=6]
[node name="Main" type="Node2D"]
position = Vector2( 224, 112 )
[node name="TileMap" parent="." instance=ExtResource( 1 )]
[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 288, 144 )
[node name="TestEnemy" parent="." instance=ExtResource( 5 )]
position = Vector2( 288, 160 )
[node name="TurnManager" type="Node" parent="."]
[node name="OrderManager" type="Node" parent="TurnManager"]
......@@ -24,3 +19,12 @@ script = ExtResource( 3 )
[node name="ActionManager" type="Node" parent="TurnManager"]
script = ExtResource( 4 )
[node name="ActorManager" type="Node" parent="."]
script = ExtResource( 6 )
[node name="Player" parent="ActorManager" instance=ExtResource( 2 )]
position = Vector2( 512, 256 )
[node name="TestEnemy" parent="ActorManager" instance=ExtResource( 5 )]
position = Vector2( 512, 272 )
......@@ -36,7 +36,7 @@ var delay = {}
var tickLen = 0.05
func add_actor(ID : String) -> void:
delay[ID] = get_node("../../"+ID).speed
delay[ID] = get_node("../../ActorManager/"+ID).speed
return
func remove_actor(ID : String) -> void:
......@@ -51,22 +51,22 @@ func curr_actor() -> String:
for i in delay:
if (delay[i] <= 0):
temp[i] = get_node("../../"+i).speed ####################
temp[i] = get_node("../../ActorManager/"+i).speed ####################
#Sort for highest speed/lowest delay?
#Finding entity with lowest delay left
if temp.size() > 0:
current = temp.keys()[0]
for i in temp.keys():
#if get_node("../../"+i).get_variable("speed")
#if get_node("../../ActorManager/"+i).get_variable("speed")
if (delay[i] < delay[current]):
current = i
else:
current = delay.keys()[0]
var maxSpeed: float = get_node("../../"+current).speed
var maxSpeed: float = get_node("../../ActorManager/"+current).speed
for i in delay.keys():
if maxSpeed < get_node("../../"+i).speed:
maxSpeed = get_node("../../"+i).speed
if maxSpeed < get_node("../../ActorManager/"+i).speed:
maxSpeed = get_node("../../ActorManager/"+i).speed
#Return ID with lowest delay??? Highest speed???
return current
......@@ -99,11 +99,11 @@ func tick() -> bool:
#Processing 1 tick
if (not action_triggered):
for i in delay:
# change_delay(i, get_node("../../"+i).get_variable("speed") * tickLen)
delay[i] -= get_node("../../"+i).get_variable("speed") * tickLen
# change_delay(i, get_node("../../ActorManager/"+i).get_variable("speed") * tickLen)
delay[i] -= get_node("../../ActorManager/"+i).get_variable("speed") * tickLen
#Status update?
#get_node("../../"+i).statusUpdate()
#get_node("../../ActorManager/"+i).statusUpdate()
if (delay[i] <= 0):
action_triggered = true
......@@ -124,13 +124,13 @@ func tick_loop() -> bool:
while (not action_triggered):
for i in delay:
print(i+": "+String(delay[i]))
print(" spd: "+String(get_node("../../"+i).speed))
# change_delay(i, get_node("../../"+i).get_variable("speed") * tickLen)
delay[i] -= get_node("../../"+i).speed * tickLen
print(" spd: "+String(get_node("../../ActorManager/"+i).speed))
# change_delay(i, get_node("../../ActorManager/"+i).get_variable("speed") * tickLen)
delay[i] -= get_node("../../ActorManager/"+i).speed * tickLen
print(i+": "+String(delay[i]))
#Status update?
#get_node("../../"+i).statusUpdate()
#get_node("../../ActorManager/"+i).statusUpdate()
if (delay[i] <= 0):
action_triggered = true
......@@ -154,9 +154,11 @@ func refresh() -> void:
#Find all entities in room and add them to delay{}
# for actor in get_node().actorList:
# addActor(actor)
add_actor("Player")
pass
add_actor("TestEnemy")
for actor in get_node("../../ActorManager").get_children():
add_actor(actor.name)
# add_actor("Player")
# pass
# add_actor("TestEnemy")
return
......
extends Area2D
onready var ray = $RayCast2D
var dashCharges = 2
var dashRange = 1
var tile_size = 16
var inputs = {"right": Vector2.RIGHT,
"left": Vector2.LEFT,
......@@ -13,7 +15,7 @@ func _ready():
position = position.snapped(Vector2.ONE * tile_size)
position += Vector2.ONE * tile_size/2
speed = 3
speed = 12
action_taken = false
# use this if you want to only move on keypress
......@@ -32,22 +34,69 @@ func move(dir: String):
ray.cast_to = inputs[dir] * tile_size
ray.force_raycast_update()
if !ray.is_colliding():
position += inputs[dir] * tile_size
if(not get_node("..").is_actor_dir(name, dir)):
position += inputs[dir] * tile_size * dashRange
if dashRange != 1:
dashCharges -= 1
dashRange = 1
else:
print("-Actor Collision: "+get_node("..").get_actor_id_dir(name, dir))
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, dir)), 10, dir)
action_taken = true
else:
print("-Collision")
func teleport(x: float, y: float):
print(String(x))
print(String(y))
position += Vector2.RIGHT * x * tile_size
position += Vector2.UP * y * tile_size
func harm(damage: float):
health -= damage
print(">" + self.name + " took " + String(damage) + " damage.")
life_update();
# if health <= 0:
# kill()
func kill():
print(">" + self.name + " is dying.")
get_node("../TurnManager/OrderManager").remove_actor(self.name)
get_parent().remove_child(self)
func life_update():
if health <= 0:
# kill()
get_node("..").kill(name)
func _input(ev):
if Input.is_key_pressed(KEY_SPACE):
if dashCharges > 0:
if dashRange == 1:
dashRange = 2
else:
dashRange = 1
if Input.is_key_pressed(KEY_T):
teleport(3,3)
func _draw():
var label = Label.new()
var font = label.get_font('')
label.queue_free()
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/5), 'Dashes: ' + str(dashCharges), Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/4), 'Health: ' + str(health),Color(1.0, 1.0, 0.0, 1.0))
func _process(_delta):
update()
#func kill():
# print(">" + self.name + " is dying.")
# get_node("../../TurnManager/OrderManager").remove_actor(self.name)
# get_parent().remove_child(self)
#Get name of actor-node being collided with
# +How to determine if something collided with is an actor?
#func get_actor_name():
# for()
# if:
# pass
# else:
# return "NULL"
#Stats
var speed: float = 1 #Controls how frequently the player can act; increases the rate at which delay is gone through
......
......@@ -13,7 +13,7 @@ func _ready():
position = position.snapped(Vector2.ONE * tile_size)
position += Vector2.ONE * tile_size/2
speed = 1
speed = 16
action_taken = false
# use this if you want to only move on keypress
......@@ -22,15 +22,52 @@ func _ready():
# if event.is_action_pressed(dir):
# move(dir)
#func choice():
# if(get_node("/Node2D").position < get_node("../Player/Node2D").position):
# move("up")
# elif(get_node("/Node2D").position > get_node("../Player/Node2D").position):
# move("Down")
# if(get_node("/Node2D").position > get_node("../Player/Node2D").position):
# move("Left")
# if(get_node("/Node2D").position < get_node("../Player/Node2D").position):
# move("Right")
func choice():
var max_sight_dist = 8 * 16
var playerPos = get_node("../Player").get_position()
var currPos = self.get_position()
print(">currPos: "+String(currPos[0])+", "+String(currPos[1]))
print(">playerPos: "+String(playerPos[0])+", "+String(playerPos[1]))
var xDist = playerPos[0]-currPos[0]
var yDist = playerPos[1]-currPos[1]
# print(">xDist: "+String(xDist))
# print(">yDist: "+String(yDist))
# if("""sqrt(xDist, yDist) < max sight""" && """Nothing_blocking_vision()""")
print(pow(pow(xDist, 2) + pow(yDist, 2), 0.5))
if(pow(pow(xDist, 2) + pow(yDist, 2), 0.5) < max_sight_dist): #Make is_visible() function?
if(abs(xDist) >= abs(yDist)):
if(xDist <= 0):
if(get_node("..").is_actor_dir(name, "left")):
print("ACTOR COLLISION: "+get_node("..").get_actor_id_dir(name, "left"))
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, "left")), 1, "left")
else:
move("left")
else:
if(get_node("..").is_actor_dir(name, "right")):
print("ACTOR COLLISION: "+get_node("..").get_actor_id_dir(name, "right"))
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, "right")), 1, "right")
else:
move("right")
else:
if(yDist <= 0):
if(get_node("..").is_actor_dir(name, "up")):
print("ACTOR COLLISION: "+get_node("..").get_actor_id_dir(name, "up"))
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, "up")), 1, "up")
else:
move("up")
else:
if(get_node("..").is_actor_dir(name, "down")):
print("ACTOR COLLISION: "+get_node("..").get_actor_id_dir(name, "down"))
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, "down")), 1, "down")
else:
move("down")
action_taken = true
func move(dir: String):
# Flip actor texture horizontally if needed
......@@ -44,25 +81,33 @@ func move(dir: String):
ray.cast_to = inputs[dir] * tile_size
ray.force_raycast_update()
if !ray.is_colliding():
position += inputs[dir] * tile_size
if(not get_node("..").is_actor_dir(name, dir)):
position += inputs[dir] * tile_size
else:
print("-Actor Collision: "+get_node("..").get_actor_id_dir(name, dir))
# get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, dir)), 10, dir)
action_taken = true
#TEMPORARY
else:
print(">TestEnemy ran into wall; inflicting 6 damage")
harm(6)
action_taken = true
print(">TestEnemy ran into wall")#; inflicting 6 damage")
#harm(6)
func harm(damage: float):
health -= damage
print(">" + self.name + " took " + String(damage) + " damage.")
life_update()
# if health <= 0:
# kill()
func kill():
print(">" + self.name + " is dying.")
get_node("../TurnManager/OrderManager").remove_actor(self.name)
get_parent().remove_child(self)
func life_update():
if health <= 0:
# kill()
get_node("..").kill(self)
#func kill():
# print(">" + self.name + " is dying.")
# get_node("../../TurnManager/OrderManager").remove_actor(self.name)
# get_parent().remove_child(self)
#Stats
var speed: float = 1 #Controls how frequently the player can act; increases the rate at which delay is gone through
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment