Skip to content

Instantly share code, notes, and snippets.

@default1200
default1200 / player.gd
Last active June 18, 2023 19:07
Player Godot Script for Jumping GDquest
extends Actor
func _physics_process(delta: float) -> void:
var is_jump_interrupted: = Input.is_action_just_released("jump") and velocity.y < 0.0
var direction = get_direction()
velocity = calculate_move_velocity(velocity, direction, speed, is_jump_interrupted)
velocity = move_and_slide(velocity, FLOOR_NORMAL)
@default1200
default1200 / Actor.gd
Created June 18, 2023 19:09
Actor Godot Script for Jumping GDquest
extends KinematicBody2D
class_name Actor
const FLOOR_NORMAL: = Vector2.UP
export var speed: = Vector2(300.0, 1000.0)
export var gravity: = 4000.0
var velocity: = Vector2.ZERO
@default1200
default1200 / Actor.gd
Created June 19, 2023 14:12
Actor GD with raycast and direction
extends KinematicBody2D
class_name Actor
var direction = -1
func _ready():
if direction == 1.0:
$RayCast2D.position.x = $collisionShape2D.shape.get_extents().x * direction
const FLOOR_NORMAL: = Vector2.UP
@default1200
default1200 / player.gd
Created June 19, 2023 14:13
Player GD with raycast and direction
extends Actor
func _physics_process(delta: float) -> void:
if is_on_wall():
$RayCast2D.position.x = $collisionShape2D.shape.get_extents().x * direction
direction = direction * -1.0
var is_jump_interrupted: = Input.is_action_just_released("jump") and velocity.y < 0.0
var direction = get_direction()
velocity = calculate_move_velocity(velocity, direction, speed, is_jump_interrupted)
@default1200
default1200 / health.gd
Created July 11, 2023 23:00
Health.gd for progress bar help
extends Node
signal max_changed(new_max)
signal changed(new_amount)
export(int) var max_amount = 10 setget set_max
onready var current = max_amount setget set_current
func _ready():
_initialize()
extends Node
signal max_changed(new_max)
signal changed(new_amount)
export(int) var max_amount = 10 setget set_max
onready var current = max_amount setget set_current
var current_hp
func _ready():
_initialize()
extends Node
export(int) var max_amount = 10
var current_hp : int = 1
onready var health_bar = $"../HealthBar"
func hp_changed(_value : int):
current_hp += _value