Compare commits

..

No commits in common. "94302003d82a4bbf97384832680cd29341ae9006" and "742db5ee8c5984cb349240c67a8411358264f666" have entirely different histories.

19 changed files with 145 additions and 63 deletions

View File

@ -1,10 +1,9 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://src/classes/camera_guide.gd" type="Script" id=1]
[ext_resource path="res://src/Camera2D.gd" type="Script" id=2]
[ext_resource path="res://src/levels/CloneBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/levels/TestBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/ui/HUD.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Main.gd" type="Script" id=7]
[ext_resource path="res://src/ui/lobby.tscn" type="PackedScene" id=9]
@ -27,7 +26,6 @@ extents = Vector2( 160, 90 )
[node name="Main" type="Node2D"]
script = ExtResource( 7 )
starting_level = ExtResource( 3 )
player_hud = ExtResource( 5 )
[node name="MusicPlayer" type="AudioStreamPlayer" parent="."]
@ -41,7 +39,6 @@ rect_scale = Vector2( 2, 2 )
unique_name_in_owner = true
size = Vector2( 320, 180 )
handle_input_locally = false
usage = 0
render_target_update_mode = 3
[node name="Lobby" parent="ViewportContainer/Viewport" instance=ExtResource( 9 )]

View File

@ -62,13 +62,13 @@ func _on_animation_finished():
if animation_index >= current_state.animation_sequence.size():
#print("Stop!!!!!")
current_state.animation_finished = true
##TODO: Allow a way to stop animation even if in a looped sequence
# TODO: Allow a way to stop animation even if in a looped sequence
# If called, this will attempt to make the most appropriate animation change
# would likely be triggered from an animation sequence finishing or a
# modifier being applied/removed outside of enter/exit transitions.
func change_animation(enter_frame := 0, index := 0, suffix := ''):
##TODO:
## TODO:
# Need to find a way to attempt to keep and transfer the Index or frame
if modifier:
#print("hey you got one! -> ", modifier.animation_name)
@ -90,7 +90,7 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
current_animation_sequence = animation_index
if modifier:
##TODO: Apply the animation starting frame
#TODO: Apply the animation starting frame
#modifier.animation_starting_frame
match modifier.modifier_type:
modifier.TYPE.ANIMATION_SUFFIX:
@ -157,7 +157,7 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
play(mod_animation_sequence[animation_index] + '-' + animation_suffix)
else:
play(mod_animation_sequence[animation_index])
##TODO: maybe check current animation has this frame
#TODO: maybe check current animatio has this frame
if enter_frame != 0:
print ("alternate starting frame:", enter_frame)
frame = enter_frame
@ -197,7 +197,7 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
stop()
#animation_finished = true
elif mod_animation_sequence.size() > animation_index and current_animation_sequence != animation_index:
##TODO: why was I doing this before? Firgure out why?
#TODO: why was I doing this
# if animation_index >= mod_animation_sequence.size():
# animation_index = 0
##TODO: Add a safety check here.
@ -209,7 +209,7 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
##TODO: Could probably add some more checks here.
# Singal based frame call.
##TODO: reimplement frame subscriptions like this later.
#TODO: reimplement this later.
# if emitter_frame_subscriptions.has(animations.frame):
# if emitter_frame_subscriptions[animations.frame] == animations.animation:
# if frame_signal_emitted == false:
@ -225,12 +225,9 @@ func _on_state_change(old_state_name:String, new_state :State):
#print ("1? got the state change signal ", new_state.name)
# set current state to new_state
previous_state_name = old_state_name
##TODO: Confirm theres no need to keep resetting the state
## because it is always a reference to the state machine's current_state.
## this has been working fine but could cause issues if I assume otherwise.
#TODO: Confirm that this is a reference to the state in the
###### State machine
if new_state is StateAnimatedActor: #Testing this. Update: It works
## Confirmed that I do neet to update the current_state with the passed state.
current_state = new_state
if has_method('_on_state_change_' + current_state.name):
call('_on_state_change_' + current_state.name)

View File

@ -33,8 +33,7 @@ func _ready():
parent = get_parent()
default_shape = shape.duplicate()
##DONE: Are transforms primitives? Do they get passed by value?
## Transforms are passed by value.
##TODO: Are transforms primitives? Do they get passed by value?
default_transform = transform
@ -49,7 +48,6 @@ func _physics_process(delta):
func _on_state_change(old_state_name:String, new_state :State):
###### State machine
if new_state is StateAnimatedActor: #Testing this. Update: It works
## Confirmed that I do neet to update the current_state with the passed state.
current_state = new_state
if has_method('_on_state_change_' + current_state.name):
call('_on_state_change_' + current_state.name)

View File

@ -125,9 +125,11 @@ func get_climb_shape_location() -> Vector2:
return Vector2(-1,-1)
func _on_state_change(old_state_name:String, new_state :State):
#print ("got the state change signal (MC) ", new_state.name)
# set current state to new_state
#TODO: Confirm that this is a reference to the state in the
###### State machine
if new_state is StateAnimatedActor: #Testing this. Update: It works
## Confirmed that I do neet to update the current_state with the passed state.
current_state = new_state
if has_method('_on_state_change_' + current_state.name):
call('_on_state_change_' + current_state.name)

View File

@ -35,7 +35,7 @@ func setup():
state_timeout.autostart = false
#add_child(state_timeout)
#get_tree().get_root().add_child(state_timeout)
##DONE: Need to figure out how to add this to tree
#TODO: Need to figure out how to add this to tree
#modifier = StateModifier.new()
#Hopefully this passes by reference.

View File

@ -3,12 +3,14 @@ extends State
## Animation and movement state class
##
## A state intended to control the movement and animation
## functions of a KinimaticBody2D node.
## functions of a KinimaticBody2D node. Initialized with a
## player, movement node, and kinematicbody2d
## I think if we also had modifier states that transfered along with the enter and entrance of nodes, that would be helpful.
##
## @WIP
# Movement Speed in Pixels Per Second
# The base movement speed and accelleration
# The b
export var horizontal_speed: float = 60
export var horizontal_acceleration: float = 0
## Movement Speed Offsets (Positive or Negative)
@ -17,9 +19,9 @@ export var horizontal_speed_offset: float = 0
export var horizontal_speed_offset_acceleration: float = 0
export var jerk_factor: float = 0
## Default state gravity is the project's gravity
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
#var adjusted_move_speed: float
var jerk: float
## Variables intended to allow state receivers to communicate
@ -41,3 +43,16 @@ func enter() -> void:
return
#func transfer_modifiers(exiting_state_modifier : StateModifier):
# if modifier == null: # We have no existing modifier applied.
# match exiting_state_modifier.modifier_type:
# exiting_state_modifier.TYPE.ANIMATION_SUFFIX:
# if debug_state:
# print("Transferring Animation Suffix")
# modifier = exiting_state_modifier
# exiting_state_modifier.TYPE.EXIT_ANIMATION:
# if debug_state:
# print("Exit Animation: well this was useless.")
# else:
# print("Insert modifier merge function here...")

View File

@ -1,7 +1,12 @@
class_name StateMachine extends Node
#export (NodePath) var starting_state
export var debug_state_machine: bool = false
# I guess I would declare a number of states here
#export (Reference) var states # Doesn't work
#var starting_state: State
signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid)
@ -14,6 +19,10 @@ export var starting_state_name = 'default'
export(Array,Resource) var states
var states_index :Dictionary
# Initialize the state machine by giving each child state a reference to the
# parent object it belongs to and enter the default starting_state.
#func _init() -> void:
# print ("init state machine.")
func _ready():
if debug_state_machine:
@ -93,7 +102,7 @@ func change_to_known_state(new_state_name: String) -> void:
rpc("puppet_change_to_known_state", new_state_name)
#func check_parent_before_state_change(new_state_name: String) -> bool:
# ##CANCELLED: Make this a verifiable funcref or something
# ##TODO: Make this a verifiable funcref or something
# if get_parent().has_method("check_state_change"):
# var _check_result = get_parent().check_state_change(new_state_name)
# if _check_result:

View File

@ -38,7 +38,7 @@ func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
_copy_state.animation_starting_frame = animation_starting_frame
_copy_state.animation_speed = animation_speed
##TODO: finish these
#TODO: finish these
_copy_state.horizontal_speed = horizontal_speed
_copy_state.horizontal_acceleration = horizontal_acceleration

View File

@ -6,7 +6,7 @@ func set_hitbox(enabled: bool):
for child in get_children():
if child is CollisionShape2D:
child.set_deferred("disabled", !enabled)
##TODO: This breaks now I guess because I moved the process functions out to parent class
## TODO: This breaks now I guess because I moved the process functions out to parent class
#player_hurtbox.set_deferred("disabled", !enabled) #WTF Apparently this is how to do it

View File

@ -120,15 +120,9 @@ remote func load_scene_on_all_clients(_scene :String, _node_path :NodePath, _glo
remote func pre_start_game(spawn_points):
# Change scene.
var _game_starting_level_scene = get_tree().get_root().get_node("/root/Main").starting_level
var _in_game_player_hud = get_tree().get_root().get_node("/root/Main").player_hud
#var world :Node = load("res://src/levels/TestBox.tscn").instance()
var world :Node = _game_starting_level_scene.instance()
#var ui :Node = load("res://src/ui/HUD.tscn").instance()
var ui :Node = _in_game_player_hud.instance()
## No need to name world anymore
#world.set_name("World")
var world :Node = load("res://src/levels/TestBox.tscn").instance()
var ui :Node = load("res://src/ui/HUD.tscn").instance()
world.set_name("World")
world.add_to_group('world')
ui.add_to_group('world')

View File

@ -0,0 +1,19 @@
extends StateAnimatedActor
export (NodePath) var idle_node
onready var idle_state: State = get_node(idle_node)
func process_physics(delta: float) -> State:
#parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if move_component.get_movement_direction() != 0.0:
parent.transform.x.x = move_component.get_movement_direction()
if parent.is_on_floor():
return idle_state
return null

View File

@ -0,0 +1,28 @@
extends StateAnimatedActor
# Do states need to have references to the states they want to transition
# to? I suppose if on exit/entrance we needed to do something
func enter() -> void:
#.enter()
# parent.set_hurtbox(true)
move_component.velocity.x = 0
print ("this doesn't work does it? ")
# if debug_state:
# print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
func process_physics(delta: float) -> String:
return ''
# parent.velocity.y += gravity * delta
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
# parent.velocity.x = move_component.desired_movement_vector.x * move_speed
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_actor_as_desired(delta)
if move_component.velocity.x != 0.0:
return 'move'
if !parent.is_on_floor():
return 'fall'
return ''

View File

@ -0,0 +1,17 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/templates/Actor/states/idle.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
script = ExtResource( 1 )
debug_state = false
timeout_seconds = 0.0
move_speed = 60.0
move_acceleration = 20.0
move_speed_modifier = 0.0
move_modifier_move_acceleration = 0.0
jerk_factor = 0.0
animation_sequence = [ "idle" ]
emitter_frame_subscriptions = {
}

View File

@ -0,0 +1,21 @@
extends StateAnimatedActor
export (NodePath) var fall_node
export (NodePath) var idle_node
onready var fall_state: State = get_node(fall_node)
onready var idle_state: State = get_node(idle_node)
func process_physics(delta: float) -> State:
move_actor_as_desired(delta)
if move_component.velocity.x == 0.0:
return idle_state
#Flip the character before tha actual move maybe.
parent.transform.x.x = move_component.get_movement_direction()
if !parent.is_on_floor():
return fall_state
return null

View File

@ -6,6 +6,9 @@ extends Camera2D
# var b = "text"
export var debug_component :bool = false
var game_size := Vector2(320,180)
onready var window_scale :float = (OS.window_size / game_size).x
onready var actual_cam_pos := global_position
export var acceleration := 2
@ -18,7 +21,6 @@ var _tracking_node :KinematicBody2D
func _ready():
_tracking_node = get_node(tracking_node_path)
assert(is_instance_valid(_tracking_node), "Camera2D has no tracking object.")
var velocity :float = 0
var tracking_pos := Vector2(0,0)

View File

@ -1,31 +1,17 @@
extends Node2D
##TODO Would really like to adjust the viewports, cameras, and
# overall scale from here.
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var debug_singletons :bool = false
export var starting_level: PackedScene
export var player_hud: PackedScene
export var start_screen: PackedScene
onready var viewport_container = $ViewportContainer
onready var viewport = $"%Viewport"
var game_size :Vector2
onready var window_scale :float
export var debug_singletons :bool = false
# Called when the node enters the scene tree for the first time.
func _ready():
game_size = viewport.size
window_scale = (OS.window_size / game_size).x
assert(starting_level != null, "Main: starting level not specified.")
assert(player_hud != null, "Main: player HUD not specified.")
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):

View File

@ -15,7 +15,7 @@ func _ready():
var state_name :String
state_name = 'jump'
state_ref = get_node(callable_state_machine).get_state_reference(state_name)
##TODO Should probably assert here or something.
#TODO Should probably assert here or something.
state_ref.connect("state_entered", self, "_on_state_entered_" + state_name)
parent_request_state_change = funcref(get_node(callable_state_machine), 'check_parent_before_state_change')
@ -101,7 +101,7 @@ func wants_climb() -> bool:
_wants_climb = false
return false
##DONE: This is probably not a good way to do this.
#TODO: This is probably not a good way to do this.
# we want to check input once and make decisions based on
# velocity and desired movement.
#func _state_process_physics_input_idle():
@ -137,7 +137,7 @@ func _state_process_physics_idle():
if _wants_crouch == true:
request_state_change.call_func('crouch')
##TODO: May need that 'bump' logic to make velocity work.
#TODO: May need that 'bump' logic to make velocity work.
if desired_movement_vector.x != 0: # and velocity.x != 0:
request_state_change.call_func('move')
@ -431,7 +431,7 @@ func _state_process_physics_crouch_move():
func _on_state_entered_jump():
print ("how many times do I get called?")
##TODO: Make this a state export variable
#TODO: Make this a state variable
# I used to call it 'jump_force' like an idiot.
velocity.y = -200

View File

@ -45,7 +45,6 @@ func _ready():
player_data.player_inventory = player_inventory
player_data.player_stamina = stamina_component.stamina
else:
## puppets cannot get hurt, only network master.
$Hurtbox_Component.hurtbox_entered_function = ''
# Set initial player position in world.
@ -132,7 +131,7 @@ func enough_stamina_for(_state_name :String) -> bool:
##DONE: We need to find a way to 'use' the item.
##TODO: We need to find a way to 'use' the item.
func use_primary_item() -> String:
if player_inventory.primary_selection != null: # Have to make sure we even have a second
var _item_name :String = player_inventory.primary_selection.name
@ -144,7 +143,7 @@ func use_primary_item() -> String:
player_inventory.remove_from_inventory(player_inventory.primary_selection)
return state_to_item_map[_item_name]
else:
##TODO: maybe some sort of 'fail' animation state
## TODO: maybe some sort of 'fail' animation state
#print("Nope: ", state_stamina_cost[state_name], "<=", stamina_component.stamina)
return '' ## you can't use this
## use item even if no stamina usage needed for it.

View File

@ -6,8 +6,7 @@ export var debug_camera_guide :bool = false
var game_size :Vector2
onready var window_scale :float
onready var viewport = $"%Viewport"
## Camera guide doesn't really need to care if there's a camera
#onready var camera_2d = $"%Camera2D"
onready var camera_2d = $"%Camera2D"
var _is_tracking :bool = true
@ -16,8 +15,7 @@ func _ready():
game_size = viewport.size
window_scale = (OS.window_size / game_size).x
assert(game_size != Vector2(0,0), str(get_path()) + " : No game_size set.")
## Camera guide doesn't really need to care if there's a camera
#assert(camera_2d != null, str(get_path()) + " : No Camera Node Found.")
assert(camera_2d != null, str(get_path()) + " : No Camera Node Found.")
if debug_camera_guide:
print(get_path(), "\n",