Commit 1b221393 authored by dsxfbz's avatar dsxfbz
Browse files

Knockback function done

parent b55c3a4f
......@@ -4,11 +4,19 @@ 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.
......@@ -82,21 +90,43 @@ func is_actor_dir(currActor: String, dir: String) -> bool:
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: String):
print(">" + actor + " is dying.")
get_node("../TurnManager/OrderManager").remove_actor(actor)
remove_child(get_node(actor))
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:
......@@ -106,13 +136,39 @@ func kill(actor: String):
# +Change to vector?
#Outputs: None
# +Change to trigger check for death?
#func knockback(target: String, strength: float, dir: String):
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
# # # # #### ### # # ### ### # # ### ###
# # ## # # # ## # # # # # # # #
# # # # # ### # # # # # ## #### ### # #
# # # ## # # # ## # # # # # # #
### # # # ### # # ### ### # # ### ###
......@@ -13,7 +13,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
......@@ -31,10 +31,10 @@ func move(dir: String):
if dashRange != 1:
dashCharges -= 1
dashRange = 1
action_taken = true
else:
print("-Actor Collision: "+get_node("..").get_actor_id_dir(name, dir))
# knockback(target)
get_parent().knockback(get_node("../"+get_node("..").get_actor_id_dir(name, dir)), 10, dir)
action_taken = true
else:
print("-Collision")
......
......@@ -12,7 +12,7 @@ func _ready():
position = position.snapped(Vector2.ONE * tile_size)
position += Vector2.ONE * tile_size/2
speed = 2
speed = 16
action_taken = false
# use this if you want to only move on keypress
......@@ -43,22 +43,26 @@ func choice():
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")
......@@ -68,13 +72,16 @@ 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)
print(">TestEnemy ran into wall")#; inflicting 6 damage")
#harm(6)
func harm(damage: float):
health -= damage
......@@ -86,7 +93,7 @@ func harm(damage: float):
func life_update():
if health <= 0:
# kill()
get_node("..").kill(name)
get_node("..").kill(self)
#func kill():
# print(">" + self.name + " is dying.")
......
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