Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupling code from Player even further + bonus 🦎 #359

Merged
merged 8 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _global_script_classes=[ {
"base": "Object",
"class": "AxisMotion",
"language": "GDScript",
"path": "res://scripts/AxisMotion.gd"
"path": "res://scenes/platformer/characters/AxisMotion.gd"
}, {
"base": "KinematicBody2D",
"class": "BallPlayer",
Expand Down Expand Up @@ -137,7 +137,7 @@ _global_script_classes=[ {
"base": "KinematicBody2D",
"class": "Player",
"language": "GDScript",
"path": "res://scripts/Player.gd"
"path": "res://scenes/platformer/characters/Player.gd"
}, {
"base": "RigidBody2D",
"class": "PlayerFlying",
Expand Down
3 changes: 2 additions & 1 deletion scenes/BallPlayer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[ext_resource path="res://scripts/BallPlayer.gd" type="Script" id=1]
[ext_resource path="res://sprites/ballmario.png" type="Texture" id=2]
[ext_resource path="res://scenes/CoinInventoryHandle.tscn" type="PackedScene" id=3]
[ext_resource path="res://scripts/Trail.gd" type="Script" id=4]
[ext_resource path="res://scenes/platformer/characters/Trail.gd" type="Script" id=4]
[ext_resource path="res://sprites/flag.jpg" type="Texture" id=5]


[sub_resource type="CircleShape2D" id=1]
radius = 12.0

Expand Down
5 changes: 2 additions & 3 deletions scenes/levels/CameraFollow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ func _exit_tree() -> void:

func _get_follow_candidates() -> void:
follow_candidates = get_tree().get_nodes_in_group("CameraFCandidates")
print(follow_candidates.size())


func _get_camera_candidates() -> Array:
return get_tree().get_nodes_in_group("Cameras")

func _find_current_camera() -> void:
var camera_candidates = _get_camera_candidates()
if camera_candidates.size()>0:
Expand Down
3 changes: 2 additions & 1 deletion scenes/levels/Default/Level03.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

[ext_resource path="res://scenes/levels/TileSet.tres" type="TileSet" id=1]
[ext_resource path="res://scenes/Coin/Coin.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/platformer/characters/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/EndPortal.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/enemies/GassyRandal.tscn" type="PackedScene" id=6]
[ext_resource path="res://scenes/SpawnPoint.tscn" type="PackedScene" id=7]
[ext_resource path="res://fonts/ALittleNameCalle.ttf" type="DynamicFontData" id=8]
[ext_resource path="res://scripts/QuickText.gd" type="Script" id=9]


[sub_resource type="DynamicFont" id=1]
font_data = ExtResource( 8 )

Expand Down
8 changes: 7 additions & 1 deletion scenes/levels/paulloz/002.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]

[ext_resource path="res://scenes/levels/TileSet.tres" type="TileSet" id=1]
[ext_resource path="res://scenes/CameraFollow.tscn" type="PackedScene" id=2]
Expand All @@ -9,6 +9,7 @@
[ext_resource path="res://scenes/SpawnPoint.tscn" type="PackedScene" id=7]
[ext_resource path="res://scenes/boxes/CoinBox.tscn" type="PackedScene" id=8]
[ext_resource path="res://scenes/Star/Star.tscn" type="PackedScene" id=9]
[ext_resource path="res://scenes/platformer/characters/gex/Gex.tscn" type="PackedScene" id=10]

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 64, 96 )
Expand All @@ -30,6 +31,7 @@ follow_vertically = true

[node name="SpawnPoint" parent="." instance=ExtResource( 7 )]
position = Vector2( 96, 480 )
player_scene = ExtResource( 10 )

[node name="EndPortal2" parent="." instance=ExtResource( 4 )]
position = Vector2( 3296, 1184 )
Expand All @@ -46,6 +48,7 @@ position = Vector2( 1760, 1888 )
shape = SubResource( 1 )

[node name="GravityZone3" parent="GravityZones" instance=ExtResource( 5 )]
modulate = Color( 1, 1, 1, 0.3 )
position = Vector2( 1952, 1536 )
gravity_vec = Vector2( 0, 1 )
shape = SubResource( 1 )
Expand All @@ -55,6 +58,7 @@ position = Vector2( 2144, 1888 )
shape = SubResource( 1 )

[node name="GravityZone5" parent="GravityZones" instance=ExtResource( 5 )]
modulate = Color( 1, 1, 1, 0.3 )
position = Vector2( 2336, 928 )
gravity_vec = Vector2( 0, 1 )
shape = SubResource( 1 )
Expand All @@ -64,11 +68,13 @@ position = Vector2( 2656, 1472 )
shape = SubResource( 1 )

[node name="GravityZone7" parent="GravityZones" instance=ExtResource( 5 )]
modulate = Color( 1, 1, 1, 0.3 )
position = Vector2( 3296, 304 )
gravity_vec = Vector2( 0, 1 )
shape = SubResource( 1 )

[node name="GravityZone9" parent="GravityZones" instance=ExtResource( 5 )]
modulate = Color( 1, 1, 1, 0.3 )
position = Vector2( 1440, 416 )
gravity_vec = Vector2( 0, 1 )
shape = SubResource( 3 )
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ func _activate_bus() -> void:
func _update_player() -> void:
player.sprite.visible = false
player.get_node("CollisionShape2D").set_deferred("disabled", true)
player.trail.height = 15
var trail: Line2D = player.get_node_or_null("Trail")
if trail != null:
trail.height = 15
41 changes: 19 additions & 22 deletions scripts/Player.gd → scenes/platformer/characters/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ var powerupaccel = 1
onready var sprite = $Sprite
onready var anim = $Sprite/Anims
onready var tween = $Tween
onready var trail: Line2D = $Trail
onready var run_particles: CPUParticles2D = $RunParticles
onready var moustache = $BouncyMoustache # Gorgeous bouncy moustache!

onready var original_scale = sprite.scale
onready var squash_scale = Vector2(original_scale.x * 1.4, original_scale.y * 0.4)
Expand Down Expand Up @@ -87,12 +84,10 @@ func _physics_process(delta: float) -> void:
jerk_right(JERK * jerk_modifier)
anim.playAnim("Run")
# pointing the character in the direction he's running
run_particles.emitting = true
look_right()
elif Input.is_action_pressed("left"):
jerk_left(JERK * jerk_modifier)
anim.playAnim("Run")
run_particles.emitting = true
look_left()
else:
anim.playAnim("Idle")
Expand All @@ -104,7 +99,6 @@ func _physics_process(delta: float) -> void:
x_motion.set_speed(0)
x_motion.set_jerk(0)
x_motion.set_accel(0)
run_particles.emitting = false

jump_buffer_timer -= delta
if Input.is_action_just_pressed("jump") and not super_jumping:
Expand Down Expand Up @@ -152,12 +146,10 @@ func _physics_process(delta: float) -> void:
else:
gravity_multiplier = 1
anim.playAnim("Jump")
run_particles.emitting = false

if crouching and not Input.is_action_pressed("down"):
crouching = false
set_hitbox_crouching(false)
moustache.position.y = 0
unsquash()

y_motion.set_accel(gravity.strength * gravity_multiplier)
Expand Down Expand Up @@ -199,7 +191,6 @@ func try_slip(angle: float):
func crouch():
crouching = true
set_hitbox_crouching(true)
moustache.position.y = 17.5 # Moves gorgeous bouncy moustache lower when rouching
squash()


Expand Down Expand Up @@ -240,12 +231,10 @@ func land():

func look_right():
sprite.flip_h = false
moustache.position.x = 0 # Moves gorgeous bouncy moustache to the mouth


func look_left():
sprite.flip_h = true
moustache.position.x = -10 # Moves gorgeous bouncy moustache to the mouth


func squash(time = 0.1, _returnDelay = 0, squash_modifier = 1.0):
Expand All @@ -259,9 +248,11 @@ func squash(time = 0.1, _returnDelay = 0, squash_modifier = 1.0):
Tween.TRANS_BACK,
Tween.EASE_OUT
)
tween.interpolate_property(
trail, "height", trail.height, 20 * squash_modifier, time, Tween.TRANS_BACK, Tween.EASE_OUT
)
var trail: Line2D = get_node_or_null("Trail")
if trail != null:
tween.interpolate_property(
trail, "height", trail.height, 20 * squash_modifier, time, Tween.TRANS_BACK, Tween.EASE_OUT
)
tween.start()


Expand Down Expand Up @@ -300,9 +291,11 @@ func unsquash(time = 0.1, _returnDelay = 0, squash_modifier = 1.0):
Tween.TRANS_BACK,
Tween.EASE_OUT
)
tween.interpolate_property(
trail, "height", trail.height, 0, time, Tween.TRANS_BACK, Tween.EASE_OUT
)
var trail: Line2D = get_node_or_null("Trail")
if trail != null:
tween.interpolate_property(
trail, "height", trail.height, 0, time, Tween.TRANS_BACK, Tween.EASE_OUT
)
tween.start()


Expand All @@ -320,9 +313,9 @@ func jerk_right(jerk: float):

func reset() -> void:
look_right()
run_particles.emitting = false
run_particles.restart()
trail.reset()
for child in get_children():
if child.has_method("reset"):
child.reset()
_end_flash_sprite()


Expand Down Expand Up @@ -364,13 +357,17 @@ func _on_enemy_hit_fireball():


func flash_sprite(duration: float = 0.05) -> void:
$Sprite.material.set_shader_param("flash_modifier", 1.0)
var material: ShaderMaterial = sprite.material as ShaderMaterial
if material != null:
$Sprite.material.set_shader_param("flash_modifier", 1.0)
$HitFlashTimer.wait_time = duration
$HitFlashTimer.start()


func _end_flash_sprite() -> void:
$Sprite.material.set_shader_param("flash_modifier", 0.0)
var material: ShaderMaterial = sprite.material as ShaderMaterial
if material != null:
material.set_shader_param("flash_modifier", 0.0)


func set_hitbox_crouching(value: bool):
Expand Down
Loading