Compare commits

..

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

13 changed files with 133 additions and 84 deletions

View File

@ -1,8 +1,7 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=9 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/TestBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Main.gd" type="Script" id=7]
[ext_resource path="res://src/ui/lobby.tscn" type="PackedScene" id=9]
@ -25,7 +24,6 @@ extents = Vector2( 160, 90 )
[node name="Main" type="Node2D"]
script = ExtResource( 7 )
starting_level = ExtResource( 3 )
[node name="MusicPlayer" type="AudioStreamPlayer" parent="."]
@ -58,6 +56,7 @@ position = Vector2( 160, 90 )
collision_layer = 0
collision_mask = 256
script = ExtResource( 1 )
debug_camera_guide = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="ViewportContainer/Viewport/CameraGuide"]
visible = false

View File

@ -66,9 +66,7 @@ var current_se_index :String
func _process(delta):
var sound_index = current_state.name + str(current_state.animation_frame)
if current_se_index != sound_index and sound_effects_dict.has(sound_index):
if debug_component:
print (get_path())
print("\tPlay sound: ", current_state.name, current_state.animation_frame)
print("Play sound: ", current_state.name, current_state.animation_frame)
current_se_index = sound_index
##TODO: Better to do an is check here or a cast
## We already assure these are SE_StateFrames

View File

@ -54,7 +54,7 @@ func _on_state_change(old_state_name:String, new_state :State):
else:
if default_shape_when_no_state_function:
if debug_component:
print (get_path(), " Returning to default collision shape")
print ("Returning to default collision shape")
if shape is RectangleShape2D:
shape.extents = default_shape.extents
transform = default_transform

View File

@ -29,6 +29,7 @@ export var name: String
func setup():
# Only add timout node if timer value was specified.
if(timeout_seconds > 0.0):
print("init timer...")
state_timeout = Timer.new()
state_timeout.wait_time = timeout_seconds
state_timeout.one_shot = true
@ -47,8 +48,7 @@ func enter() -> void:
if debug_state:
print("Got call to enter state ", name)
if state_timeout != null:
if debug_state:
print(name, "-Starting Timer")
print(name, "-Starting Timer")
state_timeout.start()
emit_signal("state_entered")
return

View File

@ -25,13 +25,12 @@ var states_index :Dictionary
# print ("init state machine.")
func _ready():
if debug_state_machine:
print (get_path(), " - ready state machine.")
print ("ready state machine.")
for s in states:
print ("sname: ", s.name)
var this_state = s
if this_state is State:
if debug_state_machine:
print("Adding state ", this_state.name)
print("Adding state ", this_state.name)
#check for empty state name
if this_state.name != '':
#check for unique state name
@ -49,7 +48,7 @@ func _ready():
else:
push_error("Multiple states with same name in: ")
else:
push_error("State missing name in: " + str(get_path()) )
print("State missing name in: " )
if states_index.has(starting_state_name):
change_state(states_index[starting_state_name])
@ -81,6 +80,17 @@ func change_state(new_state: State) -> void:
current_state = new_state
current_state.enter()
#puppet puppet_change_state(new_state: State) -> void:
# pass
# Seems like I don't have to do this every state change!
# if(state_modifiers.size() > 0):
# print("Active Modifiers:")
# for mods in state_modifiers:
# if mods is StateModifierAnimatedActor:
# print(mods.name, " <- asm")
emit_signal("state_changed",current_state_name,current_state)
puppet func puppet_change_to_known_state(new_state_name: String) -> void:
@ -111,6 +121,7 @@ func change_to_known_state(new_state_name: String) -> void:
# return false
func get_state_reference(state_name: String) -> State:
print ("what you want? ", state_name)
if states_index.has(state_name):
return states_index[state_name]
return null
@ -119,16 +130,30 @@ func push_state_modifier(_state_modifier: StateModifier) -> void:
if state_modifiers.has(_state_modifier) == false:
state_modifiers.push_front(_state_modifier)
_state_modifier.connect("modifier_event",self,"handle_modifier_events")
if debug_state_machine:
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
func handle_modifier_events(eventID :int):
if eventID == StateModifier.EVENT_ID.ACTIVATED:
if debug_state_machine:
print ("A mod activated! Which one though?")
print ("A mod activated! Which one though?")
merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
elif eventID == StateModifier.EVENT_ID.DEACTIVATED:
merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
# Disable to test whether actually needed.
## Pass through functions for the Player to call,
## handling state changes as needed.
#func process_physics(delta: float) -> void:
# change_to_known_state( current_state.process_physics(delta) )
#
#func process_input(event: InputEvent) -> void:
# var new_state = current_state.process_input(event)
# if new_state:
# change_state(new_state)
#
#func process_frame(delta: float) -> void:
# var new_state = current_state.process_frame(delta)
# if new_state:
# change_state(new_state)

View File

@ -9,7 +9,7 @@ signal health_depleted()
func take_damage(damage_amount :int):
if damage_amount < 0:
push_error("Only positive numbers in health component functions.")
print("ERROR: Only positive numbers in health component functions.")
health -= damage_amount
if health <= 0:
@ -18,7 +18,7 @@ func take_damage(damage_amount :int):
func heal(heal_amount :int):
if heal_amount < 0:
push_error("ERROR: Only positive numbers in health component functions.")
print("ERROR: Only positive numbers in health component functions.")
return
health += heal_amount

View File

@ -1,29 +1,19 @@
extends Node
## LevelInfo
# Intended to allow nodes to get info about game levels and aid
# in transition of levels.
# Resets the camera, translates start position for players from
# the previously loaded level to the new one.
# Also invokes scene transition while nodes load.
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
##TODO: Should be based on screen position for starter
onready var player_start_position := Vector2(50,50)
onready var current_music_track :AudioStream
##TODO: Main can probably be derived from project properties
onready var main = get_node("/root/Main")
onready var viewport_container = get_node("/root/Main/ViewportContainer") #$ViewportContainer
onready var viewport = get_node("/root/Main/ViewportContainer/Viewport") # $ViewportContainer/Viewport
onready var camera_guide :CameraGuide = get_node("/root/Main/ViewportContainer/Viewport/CameraGuide")
func _ready():
assert(main != null, "LevelInfo: No Main Scene found.")
assert(viewport_container != null, "LevelInfo: No Viewport Container")
assert(viewport != null, "LevelInfo: No Viewport node found.")
assert(camera_guide != null, "LevelInfo: No CameraGuide node found.")
NetworkManager.connect("game_started", self, "_on_game_started")
NetworkManager.connect("game_ended", self, "_on_game_ended")
@ -68,17 +58,25 @@ func change_level(_level_name :String, _position_name :String):
#SceneTransition.transition_dissolve("foo")
#yield(SceneTransition,"done")
yield(SceneTransition.transition_dissolve(), "completed")
if (main.debug_singletons):
print(l)
print(l)
viewport.remove_child(l)
viewport.add_child(new_level)
viewport.move_child(new_level,SceneTransition.get_index() + 1)
##TODO: make this right below scene transition
viewport.move_child(new_level,2)
#get_node("/root/Main/ViewportContainer/Viewport/World").remove_child(l)
#get_node("/root/Main/ViewportContainer/Viewport/World").add_child(new_level)
#get_node("/root/Main/ViewportContainer/Viewport/World").move_child(new_level,1)
##TODO: Probably set start position
if new_level.entrances.has(_position_name):
player_start_position = new_level.entrances[_position_name].transform.origin
#print (get_node("/root/Main/ViewportContainer/Viewport").get_children())
#get_node("/root/Main/ViewportContainer/Viewport/CameraGuide").global_position = Vector2(160,90)
SceneTransition.reset()
#camera_guide.transform.origin = Vector2(160,90)
camera_guide.reset_position()
camera_guide.transform.origin = Vector2(160,90)
camera_guide.enable_tracking()
#get_node("/root/Main").add_child_below_node(SceneTransition,new_level)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -1,8 +1,13 @@
extends Node
## PlayerInfo
# Tracks player info for other nodes
# and UI elements.
# Manages PlayerData objects for inventory and maybe saving later.
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var player_position: Vector2
var player_health: int
var player_stamina: int
var player_inventory: InventoryManager
## An array of player data objects
var _player_data :Array = []

View File

@ -10,7 +10,7 @@ export var debug_singletons :bool = false
# Called when the node enters the scene tree for the first time.
func _ready():
assert(starting_level != null, "Main: starting level not specified.")
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@ -2,12 +2,15 @@ extends Actor
export var player_number: int = 1
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var player_inventory :InventoryManager = InventoryManager.new()
onready var stamina_component = $"%Stamina_Component"
onready var health_component = $"%Health_Component"
var punch_item :Item = preload("res://assets/items/punch.tres")
const state_stamina_cost :Dictionary = {
"jump": 10,
@ -22,26 +25,23 @@ const state_damage_amount :Dictionary = {
"attack_punch":10,
}
const state_to_item_map :Dictionary = {
"sword": "attack_sword" ,
"gun": "attack_shoot",
"punch" : "attack_punch",
"mushroom" : "attack_shoot"
}
var player_info_index :int
var player_data :PlayerData
# Called when the node enters the scene tree for the first time.
func _ready():
# PlayerInfo.player_health = health_component.health
PlayerInfo.player_inventory = player_inventory
# PlayerInfo.player_stamina = stamina_component.stamina
# I think we only want to do this for network master players now
if is_network_master():
player_info_index = PlayerInfo.register_player()
if debug_actor:
print ("Registered as player: ", player_info_index)
print ("Registered as player: ", player_info_index)
player_data = PlayerInfo.get_player_data(player_info_index)
PlayerInfo.get_player_data(player_info_index).player_health = health_component.health
print ("My health is: ", player_data.player_health)
player_data.player_inventory = player_inventory
player_data.player_stamina = stamina_component.stamina
else:
@ -50,8 +50,6 @@ func _ready():
# Set initial player position in world.
global_position = LevelInfo.player_start_position
## Give player punch ability at start.
var punch_item :Item = preload("res://assets/items/punch.tres")
player_inventory.add_to_inventory(punch_item)
player_inventory.select_primary(punch_item)
@ -62,8 +60,15 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if is_network_master():
## Update position and stamina in player data
#PlayerInfo.player_position = global_position.round()
player_data.player_position = global_position.round()
# stamina_recovery += delta
# if stamina_recovery > 1.0:
# stamina_component.recover(1)
# stamina_recovery = 0.0
# #print("recover ", stamina_component.stamina)
#PlayerInfo.player_stamina = stamina_component.stamina
player_data.player_stamina = stamina_component.stamina
##TODO: well I'm not sure I like this but making a whole state receiver is silly
@ -129,10 +134,20 @@ func enough_stamina_for(_state_name :String) -> bool:
## Return true by default because we don't have a cost for this move
return true
var state_to_item_map :Dictionary = {
"sword": "attack_sword" ,
"gun": "attack_shoot",
"punch" : "attack_punch",
"mushroom" : "attack_shoot"
}
##TODO: We need to find a way to 'use' the item.
func use_primary_item() -> String:
# if player_inventory.primary_selection.consumable == false:
# if state_to_item_map.has(player_inventory.primary_selection.name):
# player_inventory.remove_from_inventory(player_inventory.primary_selection)
# return state_to_item_map[player_inventory.primary_selection.name]
if player_inventory.primary_selection != null: # Have to make sure we even have a second
var _item_name :String = player_inventory.primary_selection.name
if state_to_item_map.has(_item_name):
@ -146,7 +161,6 @@ func use_primary_item() -> String:
## 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.
player_inventory.remove_from_inventory(player_inventory.primary_selection)
return state_to_item_map[_item_name]
@ -163,15 +177,23 @@ func use_secondary_item() -> String:
else:
## TODO: maybe some sort of 'fail' animation state
return ''
## use item even if no stamina usage needed for it.
player_inventory.remove_from_inventory(player_inventory.secondary_selection)
return state_to_item_map[_item_name]
return ''
#func check_state_change(_new_state_name: String) -> bool:
# match _new_state_name:
# "attack_sword":
# print("nope.")
# return false
# "attack_shoot":
# return true
# _: # None
# return true
# return true
func _on_Movement_StateMachine_state_changed(old_state_name, new_state):
## Reduce stamina if this state has a cost
# if new_state.name == "jump":
# stamina_component.reduce_stamina(state_stamina_cost["jump"])
if state_stamina_cost.has(new_state.name):
stamina_component.reduce_stamina(state_stamina_cost[new_state.name])

View File

@ -136,6 +136,7 @@ sound_effects = [ SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ]
position = Vector2( 0, 2 )
shape = SubResource( 1 )
script = ExtResource( 31 )
debug_component = true
callable_state_machine = NodePath("../Movement_StateMachine")
[node name="Health_Component" parent="." index="8" instance=ExtResource( 17 )]

View File

@ -6,7 +6,6 @@ export var debug_camera_guide :bool = false
var game_size :Vector2
onready var window_scale :float
onready var viewport = $"%Viewport"
onready var camera_2d = $"%Camera2D"
var _is_tracking :bool = true
@ -15,8 +14,6 @@ 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.")
assert(camera_2d != null, str(get_path()) + " : No Camera Node Found.")
if debug_camera_guide:
print(get_path(), "\n",
"\tSize:", game_size,
@ -60,17 +57,21 @@ func _physics_process(_delta):
elif !(is_on_wall() or is_on_floor() or is_on_ceiling()) and abs(diff_to.y) > 10:
dir_to = pos.direction_to(player_position)
if debug_camera_guide:
UiManager.debug_text = ( "-Camera Guide-" +
# str(PlayerInfo.player_position.snapped(Vector2(0.01,0.01))) +
"\n" + str(is_on_ceiling()) + str(is_on_floor()) + str(is_on_wall()) +
"\nPP: {0}, {1}".format({"0":"%7.2f" % PlayerInfo.player_position.x, "1":"%7.2f" % PlayerInfo.player_position.y}) +
#"\nKB: " + str(global_position.snapped(Vector2(0.01,0.01))) +
"\nKB: {0}, {1}".format({"0":"%7.2f" % global_position.x, "1":"%7.2f" % global_position.y}) +
"\nDir to: {0}, {1}".format({"0":"%7.2f" % dir_to.x, "1":"%7.2f" % dir_to.y}) +
"\nPoint to: {0}, {1}".format({"0":"%7.2f" % diff_to.x, "1":"%7.2f" % diff_to.y})
#"\nDT: %7.2f" % dist_to
)
# UiManager.debug_text = ( UiManager.debug_text +
# # str(PlayerInfo.player_position.snapped(Vector2(0.01,0.01))) +
# "\n" + str(is_on_ceiling()) + str(is_on_floor()) + str(is_on_wall()) +
# "\nPP: {0}, {1}".format({"0":"%7.2f" % PlayerInfo.player_position.x, "1":"%7.2f" % PlayerInfo.player_position.y}) +
# #"\nKB: " + str(global_position.snapped(Vector2(0.01,0.01))) +
# "\nKB: {0}, {1}".format({"0":"%7.2f" % global_position.x, "1":"%7.2f" % global_position.y}) +
# "\nDir to: {0}, {1}".format({"0":"%7.2f" % dir_to.x, "1":"%7.2f" % dir_to.y}) +
# "\nPoint to: {0}, {1}".format({"0":"%7.2f" % diff_to.x, "1":"%7.2f" % diff_to.y})
# #"\nDT: %7.2f" % dist_to
# )
# "Hi, {0} v{version}".format({0:"Godette", "version":"%0.2f" % 3.114})
#"Hi, {0} v{1}".format(["Godette", "3.0"], "{_}")
move_and_slide(dir_to * 180.0 )
# flip_tracker += delta

View File

@ -13,12 +13,12 @@ onready var _secondary_item_count = $SecondaryItem/Label
var _player_number :int
# Called when the node enters the scene tree for the first time.
#func _ready():
# if primary_item == null:
# print("--------WTF is going oN")
# else:
# print("----------thats find. ")
# pass
func _ready():
if primary_item == null:
print("--------WTF is going oN")
else:
print("----------thats find. ")
pass
#secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
func set_player_number(_player_num: int) -> void: