Skip to content
Binary file modified Assets/Images/Terrain/Terrain (16x16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Images/Terrain/special_tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Assets/Images/Terrain/special_tiles.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://gdcgbdiwbqkm"
path="res://.godot/imported/special_tiles.png-255ed16611815f9bd3f797a6f3943b03.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Images/Terrain/special_tiles.png"
dest_files=["res://.godot/imported/special_tiles.png-255ed16611815f9bd3f797a6f3943b03.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
102 changes: 100 additions & 2 deletions Scenes/Game/game.tscn

Large diffs are not rendered by default.

75 changes: 67 additions & 8 deletions Scenes/Player/player.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
class_name Player
extends CharacterBody2D

enum {
NULL,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like NULL being in an ENUM. NULL = Nothing, an ENUM defines something.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bouncy layer is set to 4 in your bitwise math.

My solution was to implement

enum {
	NULL = 0,
	DEFAULT_LAYER = 1,
	ONE_WAY_LAYER = 2,
	BOUNCY_LAYER = 4
}

DEFAULT_LAYER,
ONE_WAY_LAYER,
BOUNCY_LAYER
}


@export var animated_sprite_2d: AnimatedSprite2D
@export var player_name: Label

Expand Down Expand Up @@ -31,6 +39,7 @@ var is_infected: bool = false
@onready var wall_check_left: RayCast2D = $WallCheckLeft
@onready var wall_check_right: RayCast2D = $WallCheckRight
@onready var infection_area: Area2D = $InfectionArea
@onready var one_way_check: Area2D = $OneWayCheck
@onready var fart_sound: AudioStreamPlayer = $FartSound


Expand All @@ -52,36 +61,86 @@ func _physics_process(delta: float) -> void:
# Only process input for the player we control
if not is_multiplayer_authority():
return

# Apply gravity
if not is_on_floor():
velocity.y = min(velocity.y + get_gravity().y * gravity_scale * delta, max_fall_speed)

# Track floor state for jump resets
if is_on_floor() and not was_on_floor:
_on_landed()
was_on_floor = is_on_floor()

#Handle one-way platforms

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after # for readability

_handle_one_way()

# Handle wall sliding
_handle_wall_slide()

# Handle jumping
_handle_jump()

# Handle horizontal movement
_handle_movement(delta)

# Apply movement
move_and_slide()
_apply_physics()

# Update animations
_update_animation()


func _apply_physics() -> void:
# store velocity and position and then call move_and_slide()
var vel: Vector2 = velocity
var pos1: Vector2 = global_position
move_and_slide()

var pos2: Vector2 = global_position

var col: KinematicCollision2D = get_last_slide_collision()
if !col: return

# If it detects a bouncy thing, bounce.
if !(PhysicsServer2D.body_get_collision_layer(col.get_collider_rid()) & BOUNCY_LAYER):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I prefer using not to !, they do the same thing but being verbose makes it easier for me to understand and read at a glance.

I frequently still use ! though so not a major change

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a double negative? I'm not sure we need this here because then it's checking collision layer on every collision, not just bouncy collisions.

var new_vel: Vector2 = _bouncy_col_math(vel, col.get_normal())
velocity = new_vel
move_and_slide()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this double move_and_slide() solution and will provide my solution in the PR review comment.

_bouncy_position_correction(pos1, pos2, col.get_normal())

_on_landed()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Bug: I think this should be wrapped in an is_on_floor() to prevent the function accidentally firing before the player collides with the platform.



# when you call move_and_slide(), it steps the position forward in physics space. doing it a second time for the second move_and_slide() causes kinetic energy increases over time.
# youve gotta correct the second move_and_slide() call so you dont gain energy by just bouncing. this puts you at the same distance you had to the surface before colliding.
func _bouncy_position_correction(pos1: Vector2, pos2: Vector2, normal: Vector2) -> void:
global_position = pos2 - normal * (pos2 - pos1).dot(normal)


# Does the math for a bouncy collision against a static object.
func _bouncy_col_math(vel: Vector2, normal: Vector2) -> Vector2:
# First, project the vel vector onto the normal
# This shortened version of projection math only works cuz we know normal is a unit vector
var proj: Vector2 = normal * vel.dot(normal)

#Then, we take that component and minus it twice off the current velocity. boom. elastic collision against static wall.
return vel - 2 * proj


# Handles the one-way platform functionality.
func _handle_one_way() -> void:
# The only time that a one way platform should have collision is when: its detected by the check, the player is moving downwards or resting, and the down direction is not pressed.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is way too long, there's guide lines in the Godot editor for soft / hard limit.

Image

if you go past the first line it's okay, if you reach the second line you need to line break for readability.

if one_way_check.has_overlapping_bodies() && velocity.y >= 0 && !Input.is_action_pressed("fall_through"):
# We set the collision by modifying our own collision layers.
set_collision_mask_value(ONE_WAY_LAYER,true)
else:
set_collision_mask_value(ONE_WAY_LAYER,false)


# Handles horizontal movement with acceleration and friction
func _handle_movement(delta: float) -> void:
var input_direction: float = Input.get_axis("move_left", "move_right")

# Fallback to UI actions if custom actions don't exist
if input_direction == 0.0:
input_direction = Input.get_axis("ui_left", "ui_right")
Expand Down Expand Up @@ -184,7 +243,7 @@ func _update_animation() -> void:
func _on_infection_area_body_entered(body: Node2D) -> void:
if not multiplayer.is_server() or not is_infected:
return

if body is Player and not body.is_infected:
var game: Game = get_tree().get_first_node_in_group("game")
if game:
Expand Down
13 changes: 12 additions & 1 deletion Scenes/Player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://drqmqwoh706dl"]
[gd_scene load_steps=12 format=3 uid="uid://drqmqwoh706dl"]

[ext_resource type="Script" uid="uid://ds0q8ob5wehgr" path="res://Scenes/Player/player.gd" id="1_a3d8c"]
[ext_resource type="SpriteFrames" uid="uid://cfy6mnakd0y3w" path="res://Scenes/Player/CharacterSprites/pink_man.tres" id="2_a3d8c"]
Expand Down Expand Up @@ -46,7 +46,10 @@ radius = 15.0

[sub_resource type="CircleShape2D" id="CircleShape2D_7g0yx"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_mtuoh"]

[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("animated_sprite_2d", "player_name")]
collision_mask = 7
script = ExtResource("1_a3d8c")
animated_sprite_2d = NodePath("AnimatedSprite2D")
player_name = NodePath("PlayerName")
Expand Down Expand Up @@ -99,3 +102,11 @@ target_position = Vector2(15, 0)
[node name="FartSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("4_mtuoh")
volume_db = -15.0

[node name="OneWayCheck" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 2

[node name="CollisionShape2D2" type="CollisionShape2D" parent="OneWayCheck"]
position = Vector2(0, 25)
shape = SubResource("RectangleShape2D_mtuoh")
15 changes: 15 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ gdscript/warnings/untyped_declaration=1

window/stretch/mode="viewport"

[dotnet]

project/assembly_name="Cooties"

[file_customization]

folder_colors={
Expand Down Expand Up @@ -58,6 +62,17 @@ jump={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
fall_through={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}

[layer_names]

2d_physics/layer_1="Default Collision"
2d_physics/layer_2="One-Way Platforms"

[physics]

Expand Down