Changed the way the fades work, and brought back in the Player

This commit is contained in:
2024-01-22 17:00:30 -08:00
parent 630670d5b1
commit bde3cc5976
14 changed files with 626 additions and 36 deletions
+38
View File
@@ -0,0 +1,38 @@
extends Node2D
var G: Node2D
var L: Node2D
var P: CharacterBody2D
var curr_lives: int = PDash.STARTING_LIVES
var curr_lvl: int = 1
func load_lvl( lvl_index: int ):
var lvl_path = PDash.lvl_paths[ lvl_index-1 ]
var lvl: Node = load( lvl_path ).instantiate()
G.add_child( lvl )
L = $Game/Level
func load_plyr():
var plyr = load("res://scenes/Player.tscn").instantiate()
G.add_child( plyr )
P = $Game/Player
func init_plyr():
P.set_gravity_vector( Vector2(0,1) )
# Called when the node enters the scene tree for the first time.
func _ready():
G = $Game
PDash.fade( "in" , 1 )
load_lvl(curr_lvl)
load_plyr()
init_plyr()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
+30
View File
@@ -0,0 +1,30 @@
extends Node
var game_name: String = "pDash"
var game_version: float = 0.1
## Resources
var lvl_paths: Array[String] = [
"res://scenes/levels/level_0.tscn",
"res://scenes/levels/level_1.tscn"
]
## Variables
const STARTING_LIVES: int = 3
## Preferences
var show_splash: bool = false
func fade( type: String , t: float ):
var fade = load("res://scenes/ui/fade.tscn").instantiate();
if type == "in":
fade.type = 0
elif type == "out":
fade.type = 1
fade.speed = 1/t
get_node("/root/Main/Curtains").add_child( fade )
func splash():
var splash = load("res://scenes/ui/Splash.tscn").instantiate();
get_node("/root/Main/Splash").add_child( splash )
await splash.get_node("AnimationPlayer").animation_finished
+89
View File
@@ -0,0 +1,89 @@
extends CharacterBody2D
const SPEED = 300
const JUMP_VELOCITY = -400.0
const ANGULAR_ACCELERATION = 7.5;
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var gravity_vector: Vector2
var direction: int = 1
var World: Node2D
var ap: AnimationPlayer
var asp: AudioStreamPlayer
var cam: Camera2D
var jumping: bool = false
var lives: int = 3
var jump_sound = preload("res://audio/jump.wav")
var land_sound = preload("res://audio/land.wav")
var fall_sound = preload("res://audio/fall.wav")
var switch_direction_sound = preload("res://audio/switch_direction.wav")
func switch_direction():
velocity.x *= -1
set_direction( direction * -1 )
asp.stream = switch_direction_sound
asp.play()
func _ready():
ap = $AnimationPlayer;
asp = $AudioStreamPlayer;
## Setters
func set_direction( d: int ):
direction = d
func set_gravity_vector( gv: Vector2 ):
gravity_vector = gv
func _physics_process(delta):
if Input.is_action_just_pressed("debug"):
switch_direction()
#if direction != World.direction:
#swap_direction()
# Add the gravity.
self.up_direction = -gravity_vector;
$CollisionShape2D.skew = lerp( $CollisionShape2D.skew, (.001) * self.velocity.x * sin(gravity_vector.angle()) , delta * ANGULAR_ACCELERATION )
self.rotation = lerp( self.rotation , -gravity_vector.angle() + (.5*PI) , delta * ANGULAR_ACCELERATION ) ;
if not is_on_floor():
velocity.y += gravity * (sin(gravity_vector.angle())) * delta
velocity.x += gravity * (cos(gravity_vector.angle())) * delta
else:
# Handle jump.
if jumping:
jumping = false
ap.play("land")
asp.stream = land_sound
asp.play()
if Input.is_action_just_pressed("jump") and is_on_floor():
#velocity.x = JUMP_VELOCITY * cos(jump_vector.angle())
jumping = true
ap.play("jump")
asp.stream = jump_sound
asp.play()
velocity.y = JUMP_VELOCITY * sin(gravity_vector.angle())
if direction != 0:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func _on_activate_camera():
cam.make_current()
func _on_fall():
asp.stream = fall_sound
asp.play()
+12
View File
@@ -0,0 +1,12 @@
extends CanvasLayer
@export var res: Resource
func _ready():
if PDash.show_splash:
await $AnimationPlayer.animation_finished
get_tree().change_scene_to_packed( res )
#queue_free()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
+17
View File
@@ -0,0 +1,17 @@
extends Control
var in_p : Vector2
var out_p : Vector2
var width : float
@export var weight : float
# Called when the node enters the scene tree for the first time.
func _ready():
in_p = $"../in".position
out_p = $"../out".position
width = $TextureRect.texture.get_size().x
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
position = lerp(in_p -Vector2( width ,0 ), out_p +Vector2( width ,0 ),weight)
pass
+19
View File
@@ -0,0 +1,19 @@
extends ColorRect
@export var type: int = 0
@export var speed: float = 1
# Called when the node enters the scene tree for the first time.
func _ready():
if type == 0:
$AnimationPlayer.play("fade_in")
elif type == 1:
$AnimationPlayer.play("fade_out")
$AnimationPlayer.speed_scale = speed
await $AnimationPlayer.animation_finished
queue_free()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass