Initial commit

This commit is contained in:
ItsDrike 2025-02-27 23:50:12 +01:00
commit a0b34dd454
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
54 changed files with 1826 additions and 0 deletions

11
scripts/boost.gd Normal file
View file

@ -0,0 +1,11 @@
extends Area2D
@export var boost_strength: float = 450.0 # Acceleration applied over time
@onready var audio_stream_player: AudioStreamPlayer2D = $AudioStreamPlayer2D
func _on_body_entered(body: Node2D) -> void:
if body is CharacterBody2D:
var direction = Vector2.RIGHT.rotated(rotation)
body.velocity += direction * boost_strength
audio_stream_player.play()

9
scripts/coin.gd Normal file
View file

@ -0,0 +1,9 @@
extends Area2D
@onready var game_manager: Node = %GameManager
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func _on_body_entered(body: Node2D) -> void:
game_manager.add_score_point()
animation_player.play("pickup")

9
scripts/game_manager.gd Normal file
View file

@ -0,0 +1,9 @@
extends Node
@onready var score_label: Label = $ScoreLabel
var score: int = 0
func add_score_point():
score += 1
score_label.text = "You collected " + str(score) + " coins."

16
scripts/kill_zone.gd Normal file
View file

@ -0,0 +1,16 @@
extends Area2D
@onready var timer: Timer = $Timer
@onready var hurt_audio_player: AudioStreamPlayer2D = $HurtAudioPlayer
func _on_body_entered(body: Node2D) -> void:
# Slow down everything
Engine.time_scale = 0.5
# Remove the player's collider, making them fall through the map
body.get_node("CollisionShape2D").queue_free()
hurt_audio_player.play()
timer.start()
func _on_timer_timeout() -> void:
Engine.time_scale = 1
get_tree().reload_current_scene()

48
scripts/player.gd Normal file
View file

@ -0,0 +1,48 @@
extends CharacterBody2D
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
const JUMP_VELOCITY = -300.0
const MAX_WALK_SPEED = 130.0
const ACCELERATION = 800.0 # Acceleration for smoother movement
const FRICTION = 600.0 # Deceleration when no input is given
var direction: float = 0
func _process(delta: float) -> void:
# Flip the sprite based on current direction
if direction != 0:
animated_sprite.flip_h = direction == -1
# Play animatinos
if not is_on_floor():
animated_sprite.play("jump")
elif direction != 0:
animated_sprite.play("run")
else:
animated_sprite.play("idle")
func _physics_process(delta: float) -> void:
# Add the gravity
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump30
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y += JUMP_VELOCITY
# Get the input direction and handle the movement.
direction = Input.get_axis("move_left", "move_right")
if direction:
# Only apply more move acceleration if we're at/past max walk speed
# (only if accelerating towards opposite direction, or not yet at max speed)
#
# This implementation makes sure we don't accientaly decelerate by moving if we
# got velocity from something else (e.g. a boost), which the move_towards func
# would otherwise do.
if sign(velocity.x) != sign(direction) or abs(velocity.x) < MAX_WALK_SPEED:
velocity.x = move_toward(velocity.x, direction * MAX_WALK_SPEED, ACCELERATION * delta)
else:
velocity.x = move_toward(velocity.x, 0, FRICTION * delta)
move_and_slide()

21
scripts/slime.gd Normal file
View file

@ -0,0 +1,21 @@
extends Node2D
@export var speed = 50
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
var direction = 1
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if direction == 1 and ray_cast_right.is_colliding():
direction = -1
animated_sprite.flip_h = true
if direction == -1 and ray_cast_left.is_colliding():
direction = 1
animated_sprite.flip_h = false
position.x += direction * speed * delta