Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tgw3ff
2021-SP-CS4096-97-TDG
Commits
406c4df6
Commit
406c4df6
authored
Mar 31, 2021
by
dsxfbz
Browse files
Added basic health system and death management.
parent
63958e89
Changes
3
Hide whitespace changes
Inline
Side-by-side
CS 4096-97 Top Down Game/ActionManager.gd
View file @
406c4df6
...
...
@@ -62,15 +62,16 @@ func _process(delta):
#Wait for player input
#If legal action, process it and change phase
if
(
get_node
(
"../../
"
+
"
Player"
)
.
action_taken
==
true
):
if
(
get_node
(
"../../Player"
)
.
action_taken
==
true
):
phase
=
-
1
get_node
(
"../../
"
+
"
Player"
)
.
action_taken
=
false
get_node
(
"../../Player"
)
.
action_taken
=
false
#AI turn
else
:
#Trigger the mob's decision function
# Should analyze the map and return a choice of what to do
pass
# get_node("../../"+currActor).choice()
#Process returned action
pass
...
...
@@ -78,12 +79,16 @@ func _process(delta):
if
(
get_node
(
"../../"
+
currActor
)
.
action_taken
==
true
):
phase
=
-
1
get_node
(
"../../"
+
"Player"
)
.
action_taken
=
false
get_node
(
"../../"
+
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
()
#Add delay
#Handled by next_actor()
#get_node("../OrderManager").change_delay(currActor, 1)
...
...
CS 4096-97 Top Down Game/actors/Player.gd
View file @
406c4df6
...
...
@@ -12,7 +12,7 @@ func _ready():
position
=
position
.
snapped
(
Vector2
.
ONE
*
tile_size
)
position
+=
Vector2
.
ONE
*
tile_size
/
2
speed
=
5
speed
=
3
action_taken
=
false
# use this if you want to only move on keypress
...
...
@@ -27,8 +27,22 @@ func move(dir: String):
if
!
ray
.
is_colliding
():
position
+=
inputs
[
dir
]
*
tile_size
action_taken
=
true
else
:
print
(
"-Collision"
)
func
harm
(
damage
:
float
):
health
-=
damage
print
(
">"
+
self
.
name
+
" took "
+
String
(
damage
)
+
" damage."
)
# if health <= 0:
# kill()
func
kill
():
print
(
">"
+
self
.
name
+
" is dying."
)
get_node
(
"../TurnManager/OrderManager"
)
.
remove_actor
(
self
.
name
)
get_parent
()
.
remove_child
(
self
)
#Stats
var
speed
:
int
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
var
speed
:
float
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
var
health
:
float
=
12
var
action_taken
:
bool
=
false
CS 4096-97 Top Down Game/actors/TestEnemy.gd
View file @
406c4df6
...
...
@@ -21,6 +21,16 @@ 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
move
(
dir
:
String
):
ray
.
cast_to
=
inputs
[
dir
]
*
tile_size
ray
.
force_raycast_update
()
...
...
@@ -30,10 +40,22 @@ func move(dir: String):
#TEMPORARY
else
:
print
(
"TestEnemy ran into wall"
)
print
(
">TestEnemy ran into wall; inflicting 6 damage"
)
harm
(
6
)
action_taken
=
true
func
harm
(
damage
:
float
):
health
-=
damage
print
(
">"
+
self
.
name
+
" took "
+
String
(
damage
)
+
" damage."
)
# if health <= 0:
# kill()
func
kill
():
print
(
">"
+
self
.
name
+
" is dying."
)
get_node
(
"../TurnManager/OrderManager"
)
.
remove_actor
(
self
.
name
)
get_parent
()
.
remove_child
(
self
)
#Stats
var
speed
:
int
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
var
speed
:
float
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
var
health
:
float
=
12
var
action_taken
:
bool
=
false
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment