Created
May 27, 2022 16:15
-
-
Save N-Carter/cf783ab870c4159639116052b1b28278 to your computer and use it in GitHub Desktop.
Pickup from Depths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name Pickup | |
extends RigidBody2D | |
export(Globals.PickupType) var type : int setget , get_type | |
export var sprite : NodePath | |
onready var sprite_node : AnimatedSprite = get_node(sprite) setget , get_sprite | |
# These should be translated strings, but let's keep it simple for now: | |
export var display_name : String setget , get_display_name | |
export(String, MULTILINE) var basic_description : String setget , get_basic_description | |
export var stack_size := 1 setget set_stack_size, get_stack_size | |
export var max_stack_size := 1 setget , get_max_stack_size # If set to zero, it will never stack and there should be only one | |
var item_slot setget set_item_slot, get_item_slot | |
func pick_up() -> void: | |
print("Picked up " + name) | |
get_parent().remove_child(self) | |
#func _physics_process(_delta): | |
# applied_force = Vector2() # Not necessary if you're only applying impulses. | |
func drop(dropper : Node2D) -> void: | |
# Need to pass the object which dropped it mainly so that we have a tree reference to add ourselves to. | |
var scene_root := dropper.get_tree().get_current_scene() | |
scene_root.add_child(self) | |
position = dropper.position | |
# Get it onto the pixel grid (doesn't help if it slides away, though, or even if it just falls): | |
position.x = round(position.x) | |
position.y = round(position.y) | |
if(dropper is RigidBody2D): | |
var velocity : Vector2 = dropper.linear_velocity | |
var length := min(velocity.length(), 1.0) * 1.5 | |
linear_velocity = dropper.linear_velocity * length | |
func get_type() -> int: | |
# Globals.PickupType | |
return type | |
func get_sprite() -> AnimatedSprite: | |
# This is just for temporary use in the inventory box, prior to some sensible implementation of pickup data: | |
return sprite_node | |
func get_portrait() -> Texture: | |
return sprite_node.frames.get_frame(sprite_node.animation, 0) | |
func get_display_name() -> String: | |
return display_name | |
func get_basic_description() -> String: | |
return basic_description | |
func set_stack_size(size : int) -> void: | |
stack_size = size if size >= 1 else 1 | |
func get_stack_size() -> int: | |
return stack_size | |
func get_max_stack_size() -> int: | |
return max_stack_size | |
func set_item_slot(slot) -> void: | |
item_slot = slot | |
func get_item_slot(): | |
return item_slot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment