Skip to content

Commit

Permalink
Add a level with some water (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazedTinkerer authored Jan 18, 2023
1 parent 052f3f0 commit 4fed514
Show file tree
Hide file tree
Showing 14 changed files with 669 additions and 10 deletions.
8 changes: 7 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ _global_script_classes=[ {
"class": "TypeShootEnemy",
"language": "GDScript",
"path": "res://scripts/typeshoot/TypeShootEnemy.gd"
}, {
"base": "Area2D",
"class": "Water",
"language": "GDScript",
"path": "res://scenes/platformer/environment/water/BaseWater.gd"
} ]
_global_script_class_icons={
"Achievement": "",
Expand Down Expand Up @@ -375,7 +380,8 @@ _global_script_class_icons={
"TextTrigger": "",
"TextUtils": "",
"TrackParser": "",
"TypeShootEnemy": ""
"TypeShootEnemy": "",
"Water": ""
}

[application]
Expand Down
3 changes: 1 addition & 2 deletions scenes/levels/AdventureLand/Entrance.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ follow_vertically = true
[node name="CameraLimits" parent="Camera" instance=ExtResource( 5 )]
topLeft = Vector2( 0, -320 )
bottomRight = Vector2( 2240, 1216 )
doLimitsReset = false

[node name="CameraLimits2" parent="Camera" instance=ExtResource( 5 )]
topLeft = Vector2( 1088, -1024 )
bottomRight = Vector2( 4096, 1216 )
limitID = 1
doLimitsReset = false

[node name="LimitSetArea" parent="Camera" instance=ExtResource( 9 )]
position = Vector2( 1752, -184 )
Expand Down Expand Up @@ -202,6 +200,7 @@ bounce_count = 5

[node name="EndPortal" parent="." instance=ExtResource( 8 )]
position = Vector2( 2080, -162 )
next_level_path = "res://scenes/levels/AdventureLand/Pool.tscn"

[node name="WarningSign" parent="." instance=ExtResource( 10 )]
margin_left = 2560.0
Expand Down
385 changes: 385 additions & 0 deletions scenes/levels/AdventureLand/Pool.tscn

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions scenes/levels/AdventureLand/metadata/metadata.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" load_steps=2 format=2]

[ext_resource path="res://scenes/levels/LevelMetadata.gd" type="Script" id=1]

[resource]
script = ExtResource( 1 )
first_level_path = "res://scenes/levels/AdventureLand/Entrance.tscn"
tags = [ "platformer" ]
short_description = " "
description = "Just a few levels to explore."
9 changes: 5 additions & 4 deletions scenes/platformer/characters/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ signal collided(collision)

const MAXSPEED = 350
const CROUCH_MAXSPEED = MAXSPEED / 3
const JUMPFORCE = 1120
const MAXACCEL = 50
const MINACCEL = 0.25 * MAXACCEL
const JERK = 0.25
Expand All @@ -24,10 +23,12 @@ const SUPER_JUMP_MAX_TIME = 0.5
var gravity = preload("res://scripts/resources/Gravity.tres")
var stats = preload("res://scripts/resources/PlayerStats.tres")

var jump_force = 1120

var coyote_timer = COYOTE_TIME # used to give a bit of extra-time to jump after leaving the ground
var jump_buffer_timer = 0 # gives a bit of buffer to hit the jump button before landing
var x_motion = AxisMotion.new(AxisMotion.X, MAXSPEED, MAXACCEL, JERK)
var y_motion = AxisMotion.new(gravity.direction, JUMPFORCE, gravity.strength, 0.0)
var y_motion = AxisMotion.new(gravity.direction, jump_force, gravity.strength, 0.0)
var gravity_multiplier = 1 # used for jump height variability
var double_jump = true
var crouching = false
Expand Down Expand Up @@ -282,7 +283,7 @@ func jump():
stretch(0.2, 0, 0.5, 1.2)
jump_buffer_timer = 0
coyote_timer = 0
y_motion.set_speed(JUMPFORCE * -1)
y_motion.set_speed(jump_force * -1)
anticipating_jump = false
$JumpSFX.play()
EventBus.emit_signal("jumping")
Expand All @@ -295,7 +296,7 @@ func super_jump():
tween.stop_all()
uncrouch()
stretch(0.2, 0, 1.0, 2.5)
y_motion.set_speed(JUMPFORCE * -100)
y_motion.set_speed(jump_force * -100)
anticipating_jump = false
$JumpSFX.play()
EventBus.emit_signal("jumping")
Expand Down
49 changes: 49 additions & 0 deletions scenes/platformer/environment/water/BaseWater.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class_name Water
extends Area2D

#Warning: Although things can be in multiple water areas at the same time, do not allow
# anything to be in water areas with different multipliers at the same time.
# Strange things will happen.
export var gravity_multiplier := 0.2
export var jump_multiplier := 0.5

const IN_WATER_GROUP := "in_water"
const WATER_COUNT_META := "water_count"


func _physics_process(_delta):
var bodies := get_overlapping_bodies()
for temp_body in bodies:
var body : PhysicsBody2D = temp_body
if "double_jump" in body:
body.double_jump = true


func _on_body_entered(body: Node):
#This keeps a count of how many water areas a body is in.
#This count is needed so physics work correctly when a body is touching multiple water areas.
var old_water_count := 0
if body.has_meta(WATER_COUNT_META):
old_water_count = body.get_meta(WATER_COUNT_META)
body.set_meta(WATER_COUNT_META, old_water_count + 1)
body.add_to_group(IN_WATER_GROUP)

if old_water_count == 0: #The body was not in water already
if "gravity" in body:
body.gravity.strength *= gravity_multiplier
if "jump_force" in body:
body.jump_force *= jump_multiplier


func _on_body_exited(body: Node):
assert(body.has_meta(WATER_COUNT_META))
var old_water_count : int = body.get_meta(WATER_COUNT_META)
body.set_meta(WATER_COUNT_META, old_water_count - 1)

if old_water_count == 1: #The body just exited the last water area
body.remove_from_group(IN_WATER_GROUP)
if "gravity" in body:
body.gravity.strength /= gravity_multiplier
if "jump_force" in body:
body.jump_force /= jump_multiplier

49 changes: 49 additions & 0 deletions scenes/platformer/environment/water/WaterBox.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
tool
extends Water

export var size := Vector2(1024, 300) setget size_set
export var color := Color(0.0, 0.3, 0.7, 0.5) setget color_set
export var surface_color := Color(0.8, 0.8, 1.0, 0.7) setget surface_color_set
export var surface := true setget surface_set


var is_ready := false

func _ready():
is_ready = true
update_size()
update_params()

func size_set(value: Vector2):
size = value
if is_ready: #Make sure child nodes are loaded first
update_size()

func color_set(value):
color = value
if is_ready: #Make sure child nodes are loaded first
update_params()

func surface_color_set(value):
surface_color = value
if is_ready: #Make sure child nodes are loaded first
update_params()

func surface_set(value):
surface = value
if is_ready: #Make sure child nodes are loaded first
update_params()


func update_size():
$Display.scale = size
$Display.position = size
$CollisionShape2D.shape.extents = size / 2
$CollisionShape2D.position = size / 2
$Display.material.set_shader_param("size", size)


func update_params():
$Display.material.set_shader_param("color", color)
$Display.material.set_shader_param("surface_color", surface_color)
$Display.material.set_shader_param("surface", surface)
42 changes: 42 additions & 0 deletions scenes/platformer/environment/water/WaterBox.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://scenes/platformer/environment/water/WaterBox.gd" type="Script" id=1]
[ext_resource path="res://scenes/platformer/environment/water/water_shader.tres" type="Shader" id=2]
[ext_resource path="res://textures/flatcolor.png" type="Texture" id=4]

[sub_resource type="ShaderMaterial" id=1]
resource_local_to_scene = true
shader = ExtResource( 2 )
shader_param/size = Vector2( 1024, 300 )
shader_param/color = Color( 0, 0.301961, 0.701961, 0.501961 )
shader_param/surface_color = Color( 0.8, 0.8, 1, 0.701961 )
shader_param/surface = false
shader_param/surface_depth = 64.0

[sub_resource type="RectangleShape2D" id=2]
resource_local_to_scene = true
extents = Vector2( 512, 150 )

[node name="WaterBox" type="Area2D"]
collision_layer = 2
collision_mask = 72
space_override = 1
gravity = 0.2
linear_damp = 0.3
script = ExtResource( 1 )
color = Color( 0, 0.301961, 0.701961, 0.501961 )
surface_color = Color( 0.8, 0.8, 1, 0.701961 )

[node name="Display" type="Sprite" parent="."]
material = SubResource( 1 )
position = Vector2( 1024, 300 )
scale = Vector2( 1024, 300 )
texture = ExtResource( 4 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
position = Vector2( 512, 150 )
shape = SubResource( 2 )

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
47 changes: 47 additions & 0 deletions scenes/platformer/environment/water/water_shader.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[gd_resource type="Shader" format=2]

[resource]
code = "shader_type canvas_item;

uniform vec2 size;
uniform vec4 color;
uniform vec4 surface_color;
uniform bool surface;

uniform float surface_depth = 64.0;

vec2 unscaled_uv(vec2 uv){
uv.x *= size.x;
uv.y *= size.y;
return uv;
}

float waviness(float x, float y){
return y - (10.0 * (sin((x / 100.0) + TIME) + 1.0));
}


float get_surface_effect(vec2 uv){
if(surface == false){
return 0.0;
}
float x = unscaled_uv(uv).x;
float y = unscaled_uv(uv).y;

return smoothstep(surface_depth, 0, waviness(x, y));
}


void fragment(){
float x = unscaled_uv(UV).x;
float y = unscaled_uv(UV).y;

COLOR = color;

float surface_effect = get_surface_effect(UV);
if(surface_effect == 1.0){
discard;
} else {
COLOR = mix(color, surface_color, surface_effect)
}
}"
7 changes: 4 additions & 3 deletions scripts/objects/CameraLimits.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func _ready() -> void:
_find_current_camera()
if limitID == 0:
change_limits()
camera_reference.connect("tree_exiting", self, "_on_camera_exit_tree")


func _enter_tree() -> void:
EventBus.connect("cameraL_enter_set_area",self,"_on_enter_set_area")


func _exit_tree() -> void:
func _on_camera_exit_tree() -> void:
EventBus.disconnect("cameraL_enter_set_area",self,"_on_enter_set_area")
if camera_reference != null and doLimitsReset:
camera_reference.limit_left = -10000000
Expand All @@ -35,7 +36,7 @@ func _exit_tree() -> void:
camera_reference.limit_bottom = 10000000


func _process(delta):
func _process(_delta):
set_corners()

if Engine.editor_hint:
Expand All @@ -51,7 +52,7 @@ func _process(delta):
func reset_points():
if $Line2D.get_point_count() != 5:
$Line2D.clear_points()
for i in range(5):
for _i in range(5):
$Line2D.add_point(Vector2(0, 0))


Expand Down
Binary file added sprites/NPCs/sir_duckington.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions sprites/NPCs/sir_duckington.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/sir_duckington.png-b5ace318f90fd81c218a8737e7ebb50c.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://sprites/NPCs/sir_duckington.png"
dest_files=[ "res://.import/sir_duckington.png-b5ace318f90fd81c218a8737e7ebb50c.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
Binary file added textures/flatcolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions textures/flatcolor.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/flatcolor.png-264172cbb5ca60982552e47b75eea6cd.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://textures/flatcolor.png"
dest_files=[ "res://.import/flatcolor.png-264172cbb5ca60982552e47b75eea6cd.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

2 comments on commit 4fed514

@github-actions
Copy link

Choose a reason for hiding this comment

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.