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
63958e89
Commit
63958e89
authored
Mar 30, 2021
by
dsxfbz
Browse files
Merge branch 'TurnOrderManager'
parents
b9c3781e
6e61282a
Changes
8
Hide whitespace changes
Inline
Side-by-side
CS 4096-97 Top Down Game/.mono/metadata/ide_messaging_meta.txt
deleted
100644 → 0
View file @
b9c3781e
58886
C:\Users\adam\Desktop\Godot_v3.2.3-stable_mono_win64\Godot_v3.2.3-stable_mono_win64.exe
CS 4096-97 Top Down Game/ActionManager.gd
0 → 100644
View file @
63958e89
extends
Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var
currActor
:
String
=
""
var
delay
:
float
=
0
#Which part of the turn is currently being processed
# 0: Start
# >Change current data/variables to the current entity's
# 1: Status effect updates
# >Decreasing duration
# >Applying effects (DoT, stat changes, triggering flags, etc.)
# 2: Action
# >Player:
# +Wait for user input
# +Process user input
# -If impossible due to rules of game, wait again.
# >AI:
# +Send signal to get action from AI decision-generation function
# +Process AI decision
# -1: End
var
phase
:
int
=
0
# Called when the node enters the scene tree for the first time.
func
_ready
():
phase
=
0
pass
# Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func
_process
(
delta
):
#Waiting for user input to process
# Should this script just hold variables and functions to keep track of variables?
# Current entity
# Current phase
# Rule processing
match
phase
:
0
:
#Start phase - Prepare everything for turn processing
print
(
"Start phase: "
+
currActor
)
#Load current actor
currActor
=
get_node
(
"../OrderManager"
)
.
curr_actor
()
phase
+=
1
1
:
#Status update phase
print
(
"Status update phase: "
+
currActor
)
#Process status effects
#Determine how much delay has passed?
phase
+=
1
print
(
"Action phase: "
+
currActor
)
print
(
get_node
(
"../OrderManager"
)
.
delay
)
2
:
#Action manager
# print("Action phase: "+currActor)
#Player turn
if
(
currActor
==
"Player"
):
#Wait for player input
#If legal action, process it and change phase
if
(
get_node
(
"../../"
+
"Player"
)
.
action_taken
==
true
):
phase
=
-
1
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
#Process returned action
pass
get_node
(
"../../"
+
currActor
)
.
move
(
"right"
)
#TEMPORARY
if
(
get_node
(
"../../"
+
currActor
)
.
action_taken
==
true
):
phase
=
-
1
get_node
(
"../../"
+
"Player"
)
.
action_taken
=
false
-
1
:
#End phase - Cleanup, prepare for next turn
print
(
"End phase: "
+
currActor
)
#Reset turn-specific variables
#Add delay
#Handled by next_actor()
#get_node("../OrderManager").change_delay(currActor, 1)
#Phase should only be reset by new actor
# next_actor() should set phase to 0?
currActor
=
get_node
(
"../OrderManager"
)
.
next_actor
()
phase
=
0
pass
CS 4096-97 Top Down Game/Main.tscn
View file @
63958e89
[gd_scene load_steps=
3
format=2]
[gd_scene load_steps=
6
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]
[node name="Main" type="Node2D"]
position = Vector2( 224, 112 )
...
...
@@ -10,3 +13,14 @@ position = Vector2( 224, 112 )
[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"]
script = ExtResource( 3 )
[node name="ActionManager" type="Node" parent="TurnManager"]
script = ExtResource( 4 )
CS 4096-97 Top Down Game/OrderManager.gd
0 → 100644
View file @
63958e89
extends
Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
#Turn calculation option 1: Timer-based
# Pseudo-Timer
# Think something like ticks in Minecraft
# Each entity assigned a "Wait" value
# Float; fraction
# Action taken when timer reaches 0
# As ticks pass, the timer decreases
# Each entity has a "Speed" Value
# Determines how much the wait decreases per tick
# When timers for multiple entities hit 0 on the same tick, the entity with the higher speed goes first
# Can interact with other game mechanics
# Actions with a delay before taking effect
# Actions that
# More complex
#Base wait: 1
# Arbitrary unit
#Base speed:
# speed_stat = .01 ?
# Wait decrement per tick
# 1 / (speed_stat == 10)
# Fraction of wait decreased per tick
#
#Stores delay data; how much delay is left before an entity can act
# (-inf, 1]
# node/entity name : delay remaining
var
delay
=
{}
var
tickLen
=
0.05
func
add_actor
(
ID
:
String
)
->
void
:
delay
[
ID
]
=
get_node
(
"../../"
+
ID
)
.
speed
return
func
remove_actor
(
ID
:
String
)
->
void
:
delay
.
erase
(
ID
)
return
func
curr_actor
()
->
String
:
var
temp
=
{}
var
current
=
""
#Get things with no delay left
for
i
in
delay
:
if
(
delay
[
i
]
<=
0
):
temp
[
i
]
=
get_node
(
"../../"
+
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
(
delay
[
i
]
<
delay
[
current
]):
current
=
i
else
:
current
=
delay
.
keys
()[
0
]
var
maxSpeed
:
float
=
get_node
(
"../../"
+
current
)
.
speed
for
i
in
delay
.
keys
():
if
maxSpeed
<
get_node
(
"../../"
+
i
)
.
speed
:
maxSpeed
=
get_node
(
"../../"
+
i
)
.
speed
#Return ID with lowest delay??? Highest speed???
return
current
#Moves turn order to next
#Should end with at least one entity in delay{} with (delay <= 0)
func
next_actor
()
->
String
:
#Reset delay on current actor
var
current
:
String
=
curr_actor
()
delay
[
current
]
=
1
+
delay
[
current
]
#tick() until new actor with delay <= 0
#while(not tick()):
# pass
tick_loop
()
return
curr_actor
()
#Returns true IFF a delay goes to 0 during a tick
# Processes exactly one tick
# Tick size = 0.05
func
tick
()
->
bool
:
var
action_triggered
:
bool
=
false
#Checking if any entity is ready to act
for
i
in
delay
:
if
(
delay
[
i
]
<=
0
):
action_triggered
=
true
#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
#Status update?
#get_node("../../"+i).statusUpdate()
if
(
delay
[
i
]
<=
0
):
action_triggered
=
true
return
action_triggered
#Basically tick(), except it automatically ticks until the next entity is ready
func
tick_loop
()
->
bool
:
var
action_triggered
:
bool
=
false
#Checking if any entity is ready to act
for
i
in
delay
:
if
(
delay
[
i
]
<=
0
):
action_triggered
=
true
#Processing ticks until next entity is ready to act
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
(
i
+
": "
+
String
(
delay
[
i
]))
#Status update?
#get_node("../../"+i).statusUpdate()
if
(
delay
[
i
]
<=
0
):
action_triggered
=
true
return
action_triggered
func
change_delay
(
ID
:
String
,
timespan
:
float
):
delay
[
ID
]
+=
timespan
#Called when moved to new room
#Clears delay
#Places all entities in room in delay
func
refresh
()
->
void
:
#Empty entity data
delay
.
clear
()
# TEMPORARY: FIND WAY TO ADD ALL ENTITIES ON THE MAP TO HERE
#Re-add entity data
#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"
)
return
# Called when the node enters the scene tree for the first time.
func
_ready
():
#initialize variables
delay
=
{}
tickLen
=
0.05
#Add enitites to list
refresh
()
tick_loop
()
return
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
CS 4096-97 Top Down Game/actors/Enemy.tscn
0 → 100644
View file @
63958e89
[gd_scene load_steps=4 format=2]
[ext_resource path="res://actors/TestEnemy.gd" type="Script" id=1]
[ext_resource path="res://assets/player.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )
[node name="Player" type="Area2D"]
position = Vector2( 4, 4 )
script = ExtResource( 1 )
[node name="player" type="Sprite" parent="."]
scale = Vector2( 2, 2 )
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
scale = Vector2( 0.45, 0.45 )
shape = SubResource( 1 )
[node name="RayCast2D" type="RayCast2D" parent="."]
cast_to = Vector2( 0, 12 )
CS 4096-97 Top Down Game/actors/Player.gd
View file @
63958e89
...
...
@@ -12,14 +12,23 @@ func _ready():
position
=
position
.
snapped
(
Vector2
.
ONE
*
tile_size
)
position
+=
Vector2
.
ONE
*
tile_size
/
2
speed
=
5
action_taken
=
false
# use this if you want to only move on keypress
func
_unhandled_input
(
event
):
for
dir
in
inputs
.
keys
():
if
event
.
is_action_pressed
(
dir
):
if
event
.
is_action_pressed
(
dir
)
and
(
get_node
(
"../TurnManager/ActionManager"
)
.
currActor
==
"Player"
)
:
move
(
dir
)
func
move
(
dir
):
func
move
(
dir
:
String
):
ray
.
cast_to
=
inputs
[
dir
]
*
tile_size
ray
.
force_raycast_update
()
if
!
ray
.
is_colliding
():
position
+=
inputs
[
dir
]
*
tile_size
action_taken
=
true
#Stats
var
speed
:
int
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
var
action_taken
:
bool
=
false
CS 4096-97 Top Down Game/actors/Player.tscn
View file @
63958e89
...
...
@@ -4,7 +4,7 @@
[ext_resource path="res://assets/player.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2(
8, 8
)
extents = Vector2(
3.1579, 3.15789
)
[node name="Player" type="Area2D"]
position = Vector2( 8, 8 )
...
...
@@ -19,7 +19,7 @@ scale = Vector2( 0.95, 0.95 )
shape = SubResource( 1 )
[node name="RayCast2D" type="RayCast2D" parent="."]
cast_to = Vector2( 0,
12
)
cast_to = Vector2( 0,
6
)
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2( 4, 4 )
...
...
CS 4096-97 Top Down Game/actors/TestEnemy.gd
0 → 100644
View file @
63958e89
extends
Area2D
onready
var
ray
=
$
RayCast2D
var
tile_size
=
16
var
inputs
=
{
"right"
:
Vector2
.
RIGHT
,
"left"
:
Vector2
.
LEFT
,
"up"
:
Vector2
.
UP
,
"down"
:
Vector2
.
DOWN
}
func
_ready
():
position
=
position
.
snapped
(
Vector2
.
ONE
*
tile_size
)
position
+=
Vector2
.
ONE
*
tile_size
/
2
speed
=
1
action_taken
=
false
# use this if you want to only move on keypress
#func _unhandled_input(event):
# for dir in inputs.keys():
# if event.is_action_pressed(dir):
# move(dir)
func
move
(
dir
:
String
):
ray
.
cast_to
=
inputs
[
dir
]
*
tile_size
ray
.
force_raycast_update
()
if
!
ray
.
is_colliding
():
position
+=
inputs
[
dir
]
*
tile_size
action_taken
=
true
#TEMPORARY
else
:
print
(
"TestEnemy ran into wall"
)
action_taken
=
true
#Stats
var
speed
:
int
=
1
#Controls how frequently the player can act; increases the rate at which delay is gone through
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