diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..391d43a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "godot_tools.scene_file_config": "c:\\Users\\Jakob\\Documents\\Godot\\Wumper\\src\\Levels\\ApproxLevel.tscn.tmp" +} \ No newline at end of file diff --git a/project.godot b/project.godot index 9ed8854..bad7c2b 100644 --- a/project.godot +++ b/project.godot @@ -10,9 +10,9 @@ config_version=4 _global_script_classes=[ { "base": "KinematicBody2D", -"class": "Actor", +"class": "Player", "language": "GDScript", -"path": "res://src/Actor/Actor.gd" +"path": "res://src/Actor/Player.gd" }, { "base": "Line2D", "class": "RayCastDebugLines", @@ -30,7 +30,7 @@ _global_script_classes=[ { "path": "res://src/StateMachines/StateMachine.gd" } ] _global_script_class_icons={ -"Actor": "", +"Player": "", "RayCastDebugLines": "", "RayCaster": "", "StateMachine": "" @@ -84,6 +84,12 @@ pause={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) ] } +boost_move={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null) + ] +} [layer_names] diff --git a/src/Actor/Actor.gd b/src/Actor/Actor.gd deleted file mode 100644 index 3e28b46..0000000 --- a/src/Actor/Actor.gd +++ /dev/null @@ -1,14 +0,0 @@ -extends KinematicBody2D -class_name Actor - -const FLOOR_NORMAL := Vector2.UP - -# TODO Round everyone up whoever still uses this variable and fucking kill them -export var speed := Vector2(300, 1000) -# newtonmeters is the unit -export var acceleration_force := Vector2(3050, 4575) -export var gravity := 4000.0 -# Kilograms -export var mass := 6 - -var _velocity := Vector2.ZERO diff --git a/src/Actor/Blobby.gd b/src/Actor/Blobby.gd index 7953c99..c723d7b 100644 --- a/src/Actor/Blobby.gd +++ b/src/Actor/Blobby.gd @@ -1,43 +1,39 @@ -extends Actor - -export var stomp_impulse := 1000.0 +extends Player func _on_EnemyDetector_area_entered(area: Area2D) -> void: - _velocity = calculate_stomp_velocity(_velocity, stomp_impulse) + _velocity = calculate_stomp_velocity(_velocity, stomp_feedback) func _on_EnemyDetector_body_entered(body: Node) -> void: die() -func handle_grounded_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_grounded_velocity(_velocity, delta, speed, direction) +func handle_grounded_movement(delta: float, direction: Vector2, state: String) -> Vector2: + return calculate_grounded_velocity(_velocity, delta, direction, state) func handle_jump_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_jump_velocity(_velocity, delta, speed, direction) + return calculate_jump_velocity(_velocity, delta, direction) func handle_fall_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_fall_velocity(_velocity, delta, speed, direction) - - -func apply_gravity(delta, velocity: Vector2): - velocity.y += gravity * delta - return velocity + return calculate_fall_velocity(_velocity, delta, direction) func calculate_grounded_velocity( - linear_velocity: Vector2, delta: float, speed: Vector2, direction: Vector2 + linear_velocity: Vector2, delta: float, direction: Vector2, state: String ) -> Vector2: var out_vel := linear_velocity var velocity_direction = 1.0 if _velocity.x < 0: velocity_direction = -1.0 + # Stopping movement if direction.x == 0.0: - var deceleration_force = calculate_deceleration_force(gravity, mass, delta) + var deceleration_force = calculate_deceleration_force( + gravity, mass, delta + ) # Translates velocity back to force and subtracts deceleration force var result_force = ( abs(convert_velocity_to_force(_velocity.x, mass, delta)) @@ -46,49 +42,96 @@ func calculate_grounded_velocity( if result_force <= 0: out_vel.x = 0 else: - out_vel.x = convert_force_to_velocity(result_force, mass, delta) * velocity_direction + out_vel.x = ( + convert_force_to_velocity(result_force, mass, delta) + * velocity_direction + ) else: + # Reversing movement # When turning the opposite direction, friction is added to the opposite acceleration movement - if is_reverse_horizontal_direction(direction): - out_vel.x -= convert_force_to_velocity(calculate_deceleration_force(gravity, mass, delta), mass, delta) * velocity_direction - out_vel.x += (delta * ((acceleration_force.x / mass) * direction.x)) - + var reverse_move = is_reversing_horizontal_movement(direction) + if reverse_move: + out_vel.x -= ( + convert_force_to_velocity( + calculate_deceleration_force(gravity, mass, delta), + mass, + delta + ) + * velocity_direction + ) + # Normal movement + if abs(_velocity.x) < max_velocity[state]: + out_vel.x += ( + delta + * ( + ( + ( + acceleration_force[state].x + + init_acceleration_force[state] * int(init_boost) + ) + / mass + ) + * direction.x + ) + ) + elif ! reverse_move: + out_vel.x = max_velocity[state] * direction.x # TODO Is this the right place to determine this? - if is_on_floor(): - var additive_jump_force = 0.2 * abs(_velocity.x) * mass + # Jumping when grounded + if is_on_floor() && Input.is_action_pressed("jump"): + var additive_jump_force = 0.2383 * abs(_velocity.x) * mass out_vel.y = ( - ((acceleration_force.y + additive_jump_force) / mass) - * direction.y + ((acceleration_force[state].y + additive_jump_force) / mass) + * -1 ) + else: + out_vel.y = gravity * delta return out_vel -func is_reverse_horizontal_direction(direction: Vector2) -> bool: - return (direction.x > 0 && _velocity.x < 0) || (direction.x < 0 && _velocity.x > 0) + +func is_reversing_horizontal_movement(direction: Vector2) -> bool: + return ( + (direction.x > 0 && _velocity.x < 0) + || (direction.x < 0 && _velocity.x >= 0) + ) + func convert_velocity_to_force(velocity, mass, delta) -> float: - return (velocity*mass)/delta + return (velocity * mass) / delta + func convert_force_to_velocity(force, mass, delta) -> float: - return (force/mass)*delta + return (force / mass) * delta + func get_ground_friction() -> float: - return 30.5 + return 25.0 + # TODO Comments for parameters func calculate_deceleration_force(gravity: float, mass: float, delta: float) -> float: return get_ground_friction() * gravity * mass * delta + func calculate_jump_velocity( - linear_velocity: Vector2, delta: float, speed: Vector2, direction: Vector2 + linear_velocity: Vector2, delta: float, direction: Vector2 ) -> Vector2: linear_velocity.y += gravity * delta + if _velocity.x == 0: + linear_velocity.x += inair_velocity * direction.x return linear_velocity +# Only applicable to downwards gravity func calculate_fall_velocity( - linear_velocity: Vector2, delta: float, speed: Vector2, direction: Vector2 + linear_velocity: Vector2, delta: float, direction: Vector2 ) -> Vector2: - linear_velocity.y += gravity * delta + if _velocity.y < max_velocity["fall"]: + linear_velocity.y += gravity * delta + else: + linear_velocity.y = max_velocity["fall"] + if _velocity.x == 0: + linear_velocity.x += inair_velocity * direction.x return linear_velocity diff --git a/src/Actor/Enemy.gd b/src/Actor/Enemy.gd index 40f7f62..76a4513 100644 --- a/src/Actor/Enemy.gd +++ b/src/Actor/Enemy.gd @@ -1,16 +1,18 @@ -extends Actor +extends Player + +export var score := 100 -export var score: = 100 func _ready() -> void: set_physics_process(false) - _velocity.x = -speed.x + _velocity.x = -300 + func _on_StompDetector_body_entered(body: Node) -> void: if body.global_position.y > get_node("StompDetector").global_position.y: return get_node("CollisionShape2D").disabled = true - die() + die() func _physics_process(delta: float) -> void: @@ -19,6 +21,7 @@ func _physics_process(delta: float) -> void: _velocity.x *= -1.0 _velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y + func die() -> void: queue_free() PlayerData.score += score diff --git a/src/Actor/Player.gd b/src/Actor/Player.gd new file mode 100644 index 0000000..06df6f2 --- /dev/null +++ b/src/Actor/Player.gd @@ -0,0 +1,20 @@ +extends KinematicBody2D +class_name Player + +const FLOOR_NORMAL := Vector2.UP + +export var stomp_feedback := 1000.0 +export var init_boost := false +export var inair_velocity := 18.3 +export var max_velocity := {"walk": 183, "run": 305, "fall": 832} +# This is added to the acceleration force initially +export var init_acceleration_force := {"walk": 3904, "run": 6506.67} +# newtonmeters is the unit +export var acceleration_force := { + "walk": Vector2(2928, 4575), "run": Vector2(2928, 4575) +} +export var gravity := 3904.0 +# Kilograms +export var mass := 6 + +var _velocity := Vector2.ZERO diff --git a/src/Actor/PlayerStateMachine.gd b/src/Actor/PlayerStateMachine.gd index 4573da7..6531b22 100644 --- a/src/Actor/PlayerStateMachine.gd +++ b/src/Actor/PlayerStateMachine.gd @@ -5,6 +5,7 @@ extends StateMachine func _ready(): add_state("idle") add_state("run") + add_state("walk") add_state("jump") add_state("fall") print_debug(states) @@ -27,6 +28,8 @@ func _state_logic(delta): match self.state: "idle": handle_input_ref = funcref(self, 'handle_idle_input') + "walk": + handle_input_ref = funcref(self, 'handle_walk_input') "run": handle_input_ref = funcref(self, 'handle_run_input') "jump": @@ -40,56 +43,74 @@ func _state_logic(delta): parent.execute_movement() -func handle_idle_input(delta, direction := get_direction()) -> Vector2: - return parent.handle_grounded_movement(delta, direction) +func handle_idle_input(delta, direction := get_horizontal_direction()) -> Vector2: + if Input.is_action_pressed("boost_move"): + return parent.handle_grounded_movement(delta, direction, "run") + else: + return parent.handle_grounded_movement(delta, direction, "walk") -func handle_run_input(delta, direction := get_direction()) -> Vector2: - return parent.handle_grounded_movement(delta, direction) +func handle_walk_input(delta, direction := get_horizontal_direction()) -> Vector2: + return parent.handle_grounded_movement(delta, direction, state) -func handle_jump_input(delta, direction := get_direction()) -> Vector2: +func handle_run_input(delta, direction := get_horizontal_direction()) -> Vector2: + return parent.handle_grounded_movement(delta, direction, state) + + +func handle_jump_input(delta, direction := get_horizontal_direction()) -> Vector2: return parent.handle_jump_movement(delta, direction) -func handle_fall_input(delta, direction := get_direction()) -> Vector2: +func handle_fall_input(delta, direction := get_horizontal_direction()) -> Vector2: return parent.handle_fall_movement(delta, direction) -func get_direction() -> Vector2: +func get_horizontal_direction() -> Vector2: return Vector2( ( Input.get_action_strength("move_right") - Input.get_action_strength("move_left") ), - -1.0 if Input.is_action_pressed("jump") else 1.0 + 0 ) # Determines which state should be active at the moment func _get_transition(delta): - parent.get_node("StateLable").text = self.state + parent.get_node("StateLable").text = ( + self.state + + " x vel:" + + String(round(parent._velocity.x)) + ) var new_state # TODO Can get stuck in Fall on ledges - if !parent.is_on_floor(): + if ! parent.is_on_floor(): if parent._velocity.y < 0: - new_state = states.jump + new_state = states.jump if parent._velocity.y >= 0: # if self.state == states.run: # parent._velocity.y = 0 new_state = states.fall elif parent._velocity.x != 0: - new_state = states.run + if Input.is_action_pressed("boost_move"): + new_state = states.run + else: + new_state = states.walk else: # TODO How does this apply to enviornment induced movement? new_state = states.idle if new_state != self.state: return new_state + parent.init_boost = false return null func _enter_state(new_state, old_state): - pass + if new_state == "run" || "walk": + parent.init_boost = true + if old_state == "run" && new_state == "walk": + parent.init_boost = false func _exit_state(old_state, new_state): diff --git a/src/Levels/ApproxLevel.tscn b/src/Levels/ApproxLevel.tscn index 186712c..5cfb383 100644 --- a/src/Levels/ApproxLevel.tscn +++ b/src/Levels/ApproxLevel.tscn @@ -90,7 +90,7 @@ cell_custom_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) collision_layer = 8 collision_mask = 0 format = 1 -tile_data = PoolIntArray( -196576, 0, 0, -196575, 0, 0, -196574, 0, 0, -196573, 0, 0, -196572, 0, 0, -196571, 0, 0, -196570, 0, 0, -196569, 0, 0, -131040, 0, 0, -131032, 0, 0, -131031, 0, 0, -131030, 0, 0, -131029, 0, 0, -131028, 0, 0, -131027, 0, 0, -131026, 0, 0, -131025, 0, 0, -131024, 0, 0, -131023, 0, 0, -131022, 0, 0, -131021, 0, 0, -131020, 0, 0, -131019, 0, 0, -131018, 0, 0, -131017, 0, 0, -131016, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, -65534, 0, 0, -65533, 0, 0, -65532, 0, 0, -65531, 0, 0, -65530, 0, 0, -65529, 0, 0, -65528, 0, 0, -65527, 0, 0, -65526, 0, 0, -65525, 0, 0, -65524, 0, 0, -65523, 0, 0, -65522, 0, 0, -65521, 0, 0, -65520, 0, 0, -65519, 0, 0, -65518, 0, 0, -65517, 0, 0, -65516, 0, 0, -65515, 0, 0, -65514, 0, 0, -65513, 0, 0, -65512, 0, 0, -65511, 0, 0, -65510, 0, 0, -65509, 0, 0, -65508, 0, 0, -65507, 0, 0, -65506, 0, 0, -65505, 0, 0, -65504, 0, 0, -65480, 0, 0, -65479, 0, 0, -65478, 0, 0, 65534, 0, 0, 0, 0, 0, 32, 0, 0, 33, 0, 0, 34, 0, 0, 35, 0, 0, 36, 0, 0, 37, 0, 0, 38, 0, 0, 39, 0, 0, 40, 0, 0, 41, 0, 0, 42, 0, 0, 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, 0, 0, 47, 0, 0, 48, 0, 0, 49, 0, 0, 50, 0, 0, 51, 0, 0, 52, 0, 0, 53, 0, 0, 54, 0, 0, 55, 0, 0, 56, 0, 0, 57, 0, 0, 58, 0, 0, 59, 0, 0, 131070, 0, 0, 65536, 0, 0, 65569, 0, 0, 65592, 0, 0, 65593, 0, 0, 65594, 0, 0, 196606, 0, 0, 131072, 0, 0, 131105, 0, 0, 131128, 0, 0, 131130, 0, 0, 262142, 0, 0, 196608, 0, 0, 196642, 0, 0, 196664, 0, 0, 196666, 0, 0, 327678, 0, 0, 262144, 0, 0, 262178, 0, 0, 262200, 0, 0, 262202, 0, 0, 393214, 0, 0, 327680, 0, 0, 327713, 0, 0, 327714, 0, 0, 327736, 0, 0, 327738, 0, 0, 327739, 0, 0, 458750, 0, 0, 393216, 0, 0, 393249, 0, 0, 393272, 0, 0, 393274, 0, 0, 393275, 0, 0, 524286, 0, 0, 458752, 0, 0, 458785, 0, 0, 458808, 0, 0, 458810, 0, 0, 458811, 0, 0, 589822, 0, 0, 524288, 0, 0, 524321, 0, 0, 524344, 0, 0, 524346, 0, 0, 524347, 0, 0, 655358, 0, 0, 589824, 0, 0, 589857, 0, 0, 589880, 0, 0, 589883, 0, 0, 720894, 0, 0, 655360, 0, 0, 655393, 0, 0, 655416, 0, 0, 655418, 0, 0, 655419, 0, 0, 786430, 0, 0, 720896, 0, 0, 720916, 0, 0, 720928, 0, 0, 720952, 0, 0, 720954, 0, 0, 851966, 0, 0, 786432, 0, 0, 786452, 0, 0, 786453, 0, 0, 786464, 0, 0, 786488, 0, 0, 786490, 0, 0, 917501, 0, 0, 917502, 0, 0, 851968, 0, 0, 851985, 0, 0, 851988, 0, 0, 851989, 0, 0, 852000, 0, 0, 852024, 0, 0, 852026, 0, 0, 983037, 0, 0, 983038, 0, 0, 917504, 0, 0, 917505, 0, 0, 917506, 0, 0, 917507, 0, 0, 917508, 0, 0, 917509, 0, 0, 917510, 0, 0, 917511, 0, 0, 917512, 0, 0, 917513, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 917523, 0, 0, 917524, 0, 0, 917525, 0, 0, 917526, 0, 0, 917527, 0, 0, 917528, 0, 0, 917529, 0, 0, 917530, 0, 0, 917531, 0, 0, 917532, 0, 0, 917533, 0, 0, 917534, 0, 0, 917535, 0, 0, 917536, 0, 0, 917537, 0, 0, 917538, 0, 0, 917539, 0, 0, 917540, 0, 0, 917541, 0, 0, 917542, 0, 0, 917543, 0, 0, 917544, 0, 0, 917545, 0, 0, 917546, 0, 0, 917547, 0, 0, 917548, 0, 0, 917549, 0, 0, 917550, 0, 0, 917551, 0, 0, 917552, 0, 0, 917553, 0, 0, 917554, 0, 0, 917555, 0, 0, 917556, 0, 0, 917557, 0, 0, 917558, 0, 0, 917559, 0, 0, 917560, 0, 0, 917562, 0, 0, 1048574, 0, 0, 1048575, 0, 0, 983040, 0, 0, 983041, 0, 0, 983045, 0, 0, 983046, 0, 0, 983047, 0, 0, 983048, 0, 0, 983049, 0, 0, 983054, 0, 0, 983098, 0, 0, 1114110, 0, 0, 1048579, 0, 0, 1048580, 0, 0, 1048581, 0, 0, 1048585, 0, 0, 1048586, 0, 0, 1048591, 0, 0, 1048634, 0, 0, 1179646, 0, 0, 1179647, 0, 0, 1114114, 0, 0, 1114115, 0, 0, 1114122, 0, 0, 1114123, 0, 0, 1114127, 0, 0, 1114150, 0, 0, 1114151, 0, 0, 1114152, 0, 0, 1114153, 0, 0, 1114154, 0, 0, 1114155, 0, 0, 1114156, 0, 0, 1114157, 0, 0, 1114158, 0, 0, 1114163, 0, 0, 1114164, 0, 0, 1114165, 0, 0, 1114166, 0, 0, 1114167, 0, 0, 1114169, 0, 0, 1114170, 0, 0, 1245183, 0, 0, 1179648, 0, 0, 1179649, 0, 0, 1179650, 0, 0, 1179660, 0, 0, 1179661, 0, 0, 1179662, 0, 0, 1179663, 0, 0, 1179664, 0, 0, 1179665, 0, 0, 1179666, 0, 0, 1179667, 0, 0, 1179668, 0, 0, 1179669, 0, 0, 1179670, 0, 0, 1179671, 0, 0, 1179672, 0, 0, 1179673, 0, 0, 1179674, 0, 0, 1179675, 0, 0, 1179676, 0, 0, 1179677, 0, 0, 1179678, 0, 0, 1179679, 0, 0, 1179680, 0, 0, 1179683, 0, 0, 1179684, 0, 0, 1179685, 0, 0, 1179694, 0, 0, 1179695, 0, 0, 1179697, 0, 0, 1179698, 0, 0, 1179699, 0, 0, 1179704, 0, 0, 1179705, 0, 0, 1245184, 0, 0, 1245185, 0, 0, 1245216, 0, 0, 1245217, 0, 0, 1245218, 0, 0, 1245219, 0, 0, 1245231, 0, 0, 1245232, 0, 0, 1245233, 0, 0 ) +tile_data = PoolIntArray( -196576, 0, 0, -196575, 0, 0, -196574, 0, 0, -196573, 0, 0, -196572, 0, 0, -196571, 0, 0, -196570, 0, 0, -196569, 0, 0, -196544, 0, 0, -196543, 0, 0, -196542, 0, 0, -196541, 0, 0, -196540, 0, 0, -196539, 0, 0, -196538, 0, 0, -196537, 0, 0, -131040, 0, 0, -131032, 0, 0, -131031, 0, 0, -131030, 0, 0, -131029, 0, 0, -131028, 0, 0, -131027, 0, 0, -131026, 0, 0, -131025, 0, 0, -131024, 0, 0, -131023, 0, 0, -131022, 0, 0, -131021, 0, 0, -131020, 0, 0, -131019, 0, 0, -131018, 0, 0, -131017, 0, 0, -131016, 0, 0, -131010, 0, 0, -131009, 0, 0, -131008, 0, 0, -131000, 0, 0, -130999, 0, 0, -130998, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, -65534, 0, 0, -65533, 0, 0, -65532, 0, 0, -65531, 0, 0, -65530, 0, 0, -65529, 0, 0, -65528, 0, 0, -65527, 0, 0, -65526, 0, 0, -65525, 0, 0, -65524, 0, 0, -65523, 0, 0, -65522, 0, 0, -65521, 0, 0, -65520, 0, 0, -65519, 0, 0, -65518, 0, 0, -65517, 0, 0, -65516, 0, 0, -65515, 0, 0, -65514, 0, 0, -65513, 0, 0, -65512, 0, 0, -65511, 0, 0, -65510, 0, 0, -65509, 0, 0, -65508, 0, 0, -65507, 0, 0, -65506, 0, 0, -65505, 0, 0, -65504, 0, 0, -65480, 0, 0, -65479, 0, 0, -65478, 0, 0, -65476, 0, 0, -65475, 0, 0, -65474, 0, 0, -65461, 0, 0, 65534, 0, 0, 0, 0, 0, 32, 0, 0, 33, 0, 0, 34, 0, 0, 35, 0, 0, 36, 0, 0, 37, 0, 0, 38, 0, 0, 39, 0, 0, 40, 0, 0, 41, 0, 0, 42, 0, 0, 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, 0, 0, 47, 0, 0, 48, 0, 0, 49, 0, 0, 50, 0, 0, 51, 0, 0, 52, 0, 0, 53, 0, 0, 54, 0, 0, 55, 0, 0, 56, 0, 0, 57, 0, 0, 58, 0, 0, 59, 0, 0, 60, 0, 0, 76, 0, 0, 77, 0, 0, 78, 0, 0, 131070, 0, 0, 65536, 0, 0, 65615, 0, 0, 65616, 0, 0, 65617, 0, 0, 196606, 0, 0, 131072, 0, 0, 131154, 0, 0, 131155, 0, 0, 262142, 0, 0, 196608, 0, 0, 196691, 0, 0, 196692, 0, 0, 327678, 0, 0, 262144, 0, 0, 262228, 0, 0, 262229, 0, 0, 262230, 0, 0, 393214, 0, 0, 327680, 0, 0, 327766, 0, 0, 327767, 0, 0, 327768, 0, 0, 327769, 0, 0, 327770, 0, 0, 327771, 0, 0, 327772, 0, 0, 327773, 0, 0, 327774, 0, 0, 458750, 0, 0, 393216, 0, 0, 393310, 0, 0, 393311, 0, 0, 393312, 0, 0, 524286, 0, 0, 458752, 0, 0, 458821, 0, 0, 458822, 0, 0, 458823, 0, 0, 458824, 0, 0, 458848, 0, 0, 458849, 0, 0, 589822, 0, 0, 524288, 0, 0, 524357, 0, 0, 524360, 0, 0, 524385, 0, 0, 655358, 0, 0, 589824, 0, 0, 589893, 0, 0, 589896, 0, 0, 589897, 0, 0, 589921, 0, 0, 589922, 0, 0, 720894, 0, 0, 655360, 0, 0, 655419, 0, 0, 655420, 0, 0, 655421, 0, 0, 655424, 0, 0, 655425, 0, 0, 655426, 0, 0, 655427, 0, 0, 655429, 0, 0, 655433, 0, 0, 655458, 0, 0, 786430, 0, 0, 720896, 0, 0, 720916, 0, 0, 720951, 0, 0, 720952, 0, 0, 720955, 0, 0, 720958, 0, 0, 720959, 0, 0, 720960, 0, 0, 720963, 0, 0, 720965, 0, 0, 720969, 0, 0, 720970, 0, 0, 720993, 0, 0, 720994, 0, 0, 851966, 0, 0, 786432, 0, 0, 786452, 0, 0, 786453, 0, 0, 786490, 0, 0, 786491, 0, 0, 786499, 0, 0, 786500, 0, 0, 786501, 0, 0, 786505, 0, 0, 786507, 0, 0, 786508, 0, 0, 786529, 0, 0, 917501, 0, 0, 917502, 0, 0, 851968, 0, 0, 851985, 0, 0, 851988, 0, 0, 851989, 0, 0, 852026, 0, 0, 852027, 0, 0, 852035, 0, 0, 852036, 0, 0, 852041, 0, 0, 852042, 0, 0, 852043, 0, 0, 852044, 0, 0, 852045, 0, 0, 852049, 0, 0, 852065, 0, 0, 983037, 0, 0, 983038, 0, 0, 917504, 0, 0, 917505, 0, 0, 917506, 0, 0, 917507, 0, 0, 917508, 0, 0, 917509, 0, 0, 917510, 0, 0, 917511, 0, 0, 917512, 0, 0, 917513, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 917523, 0, 0, 917524, 0, 0, 917525, 0, 0, 917526, 0, 0, 917527, 0, 0, 917528, 0, 0, 917529, 0, 0, 917530, 0, 0, 917531, 0, 0, 917532, 0, 0, 917533, 0, 0, 917534, 0, 0, 917535, 0, 0, 917536, 0, 0, 917537, 0, 0, 917538, 0, 0, 917539, 0, 0, 917540, 0, 0, 917541, 0, 0, 917542, 0, 0, 917543, 0, 0, 917544, 0, 0, 917545, 0, 0, 917546, 0, 0, 917547, 0, 0, 917548, 0, 0, 917549, 0, 0, 917550, 0, 0, 917551, 0, 0, 917552, 0, 0, 917553, 0, 0, 917554, 0, 0, 917555, 0, 0, 917556, 0, 0, 917557, 0, 0, 917558, 0, 0, 917559, 0, 0, 917560, 0, 0, 917561, 0, 0, 917562, 0, 0, 917563, 0, 0, 917571, 0, 0, 917572, 0, 0, 917581, 0, 0, 917601, 0, 0, 1048574, 0, 0, 1048575, 0, 0, 983040, 0, 0, 983041, 0, 0, 983045, 0, 0, 983046, 0, 0, 983047, 0, 0, 983048, 0, 0, 983049, 0, 0, 983054, 0, 0, 983098, 0, 0, 983117, 0, 0, 983124, 0, 0, 983125, 0, 0, 983126, 0, 0, 983137, 0, 0, 1114110, 0, 0, 1048579, 0, 0, 1048580, 0, 0, 1048581, 0, 0, 1048585, 0, 0, 1048586, 0, 0, 1048591, 0, 0, 1048634, 0, 0, 1048653, 0, 0, 1048673, 0, 0, 1179646, 0, 0, 1179647, 0, 0, 1114114, 0, 0, 1114115, 0, 0, 1114122, 0, 0, 1114123, 0, 0, 1114127, 0, 0, 1114150, 0, 0, 1114151, 0, 0, 1114152, 0, 0, 1114153, 0, 0, 1114154, 0, 0, 1114155, 0, 0, 1114156, 0, 0, 1114157, 0, 0, 1114158, 0, 0, 1114163, 0, 0, 1114164, 0, 0, 1114165, 0, 0, 1114166, 0, 0, 1114167, 0, 0, 1114169, 0, 0, 1114170, 0, 0, 1114188, 0, 0, 1114189, 0, 0, 1114208, 0, 0, 1114209, 0, 0, 1245183, 0, 0, 1179648, 0, 0, 1179649, 0, 0, 1179650, 0, 0, 1179660, 0, 0, 1179661, 0, 0, 1179662, 0, 0, 1179663, 0, 0, 1179664, 0, 0, 1179665, 0, 0, 1179666, 0, 0, 1179667, 0, 0, 1179668, 0, 0, 1179669, 0, 0, 1179670, 0, 0, 1179671, 0, 0, 1179672, 0, 0, 1179673, 0, 0, 1179674, 0, 0, 1179675, 0, 0, 1179676, 0, 0, 1179677, 0, 0, 1179678, 0, 0, 1179679, 0, 0, 1179680, 0, 0, 1179683, 0, 0, 1179684, 0, 0, 1179685, 0, 0, 1179694, 0, 0, 1179695, 0, 0, 1179697, 0, 0, 1179698, 0, 0, 1179699, 0, 0, 1179704, 0, 0, 1179705, 0, 0, 1179724, 0, 0, 1179736, 0, 0, 1179737, 0, 0, 1179738, 0, 0, 1179744, 0, 0, 1245184, 0, 0, 1245185, 0, 0, 1245216, 0, 0, 1245217, 0, 0, 1245218, 0, 0, 1245219, 0, 0, 1245231, 0, 0, 1245232, 0, 0, 1245233, 0, 0, 1245260, 0, 0, 1245280, 0, 0, 1310796, 0, 0, 1310814, 0, 0, 1310815, 0, 0, 1310816, 0, 0, 1376332, 0, 0, 1376349, 0, 0, 1376350, 0, 0, 1441868, 0, 0, 1441886, 0, 0, 1507404, 0, 0, 1507419, 0, 0, 1507420, 0, 0, 1507421, 0, 0, 1572940, 0, 0, 1572955, 0, 0, 1638476, 0, 0, 1638490, 0, 0, 1638491, 0, 0, 1704012, 0, 0, 1704027, 0, 0, 1769548, 0, 0, 1769549, 0, 0, 1769561, 0, 0, 1769562, 0, 0, 1769563, 0, 0, 1835085, 0, 0, 1835096, 0, 0, 1835097, 0, 0, 1900621, 0, 0, 1900633, 0, 0, 1966157, 0, 0, 1966167, 0, 0, 1966168, 0, 0, 1966169, 0, 0, 2031693, 0, 0, 2031705, 0, 0, 2097229, 0, 0, 2097237, 0, 0, 2097238, 0, 0, 2097239, 0, 0, 2097240, 0, 0, 2097241, 0, 0, 2097242, 0, 0, 2162765, 0, 0, 2162778, 0, 0, 2228301, 0, 0, 2228302, 0, 0, 2228314, 0, 0, 2293838, 0, 0, 2293839, 0, 0, 2293840, 0, 0, 2293841, 0, 0, 2293842, 0, 0, 2293843, 0, 0, 2293844, 0, 0, 2293845, 0, 0, 2293846, 0, 0, 2293847, 0, 0, 2293848, 0, 0, 2293849, 0, 0, 2293850, 0, 0 ) [node name="Blobby" parent="." instance=ExtResource( 1 )] position = Vector2( 131.28, 398.61 ) @@ -107,7 +107,7 @@ visible = true position = Vector2( 0, 0 ) zoom = Vector2( 1, 1.1 ) limit_top = -32 -limit_right = 2826 +limit_right = 5000 limit_bottom = 10000 smoothing_enabled = false diff --git a/src/StateMachines/StateMachine.gd b/src/StateMachines/StateMachine.gd index a98e0cb..c9e488d 100644 --- a/src/StateMachines/StateMachine.gd +++ b/src/StateMachines/StateMachine.gd @@ -1,13 +1,14 @@ extends Node -class_name StateMachine - +class_name StateMachine + var state = null setget set_state -var previous_state = null +var previous_state = null var states = {} # Parent Node that uses these states onready var parent = get_parent() + # Basic process flow for every SM func _physics_process(delta): if state != null: @@ -16,19 +17,24 @@ func _physics_process(delta): if transition != null: set_state(transition) + # Game logic consequences of state func _state_logic(_delta): pass + func _get_transition(_delta): return null + func _enter_state(_new_state, _previous_state): pass + func _exit_state(_previous_state, _new_state): pass + func set_state(new_state): previous_state = state state = new_state @@ -38,5 +44,6 @@ func set_state(new_state): if new_state != null: _enter_state(new_state, previous_state) + func add_state(state_name): states[state_name] = state_name