This commit is contained in:
2021-11-29 14:45:41 -06:00
111 changed files with 2555 additions and 126 deletions

45
Player/Inventory.gd Normal file
View File

@@ -0,0 +1,45 @@
extends Node
signal update_currency(amount)
var __currency: int
var __weapons: Array
var __accessories: Array
var __categories: Dictionary
func _ready() -> void:
self.__currency = 100
self.__weapons = []
self.__accessories = []
self.__categories = {
'Weapon': self.__weapons,
'Accessory': self.__accessories}
return
func get_currency() -> int:
return self.__currency
func add_currency(amount: int) -> void:
self.__currency += amount
emit_signal('update_currency', self.__currency)
return
func add(item) -> void:
self.__categories[item.type].append(item)
return
func discard(item) -> void:
var index: int = 0
for itr in self.__categories[item.type]:
if itr.equals(item):
self.__categories[item.type].remove(index)
break
index += 1
return

6
Player/Inventory.tscn Normal file
View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Player/Inventory.gd" type="Script" id=1]
[node name="Inventory" type="Node"]
script = ExtResource( 1 )

16
Player/Item.gd Normal file
View File

@@ -0,0 +1,16 @@
# Item Class
var name: String
var type: String
func _init(name: String, type: String) -> void:
self.name = name
self.type = type
return
func equals(other) -> bool:
if(self.name == other.name and self.type == other.type):
return true
return false

View File

@@ -12,65 +12,65 @@ var velocity: Vector2 = Vector2.ZERO
func _physics_process(delta: float) -> void:
var input_vector: Vector2 = Vector2.ZERO
var input_vector: Vector2 = Vector2.ZERO
input_vector.x = Input.get_action_strength('player_right') \
- Input.get_action_strength('player_left')
input_vector.y = Input.get_action_strength('player_down') \
- Input.get_action_strength('player_up')
input_vector = input_vector.normalized()
input_vector.x = Input.get_action_strength('player_right') \
- Input.get_action_strength('player_left')
input_vector.y = Input.get_action_strength('player_down') \
- Input.get_action_strength('player_up')
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
if input_vector != Vector2.ZERO:
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
return
velocity = move_and_slide(velocity)
return
func load_hud(node: CanvasLayer) -> void:
hud = node
if hud.connect('add_currency', self, 'add_currency') != OK:
print('ERROR: HUD "add_currency" signal already connected.')
hud = node
if hud.connect('add_currency', self, 'add_currency') != OK:
print('ERROR: HUD "add_currency" signal already connected.')
hud.update_health(HEALTH_SLICES[health_index])
hud.update_currency($Inventory.get_currency())
return
hud.update_health(HEALTH_SLICES[health_index])
hud.update_currency($Inventory.get_currency())
return
func add_currency(amount: int) -> void:
$Inventory.add_currency(amount)
return
$Inventory.add_currency(amount)
return
func _on_Inventory_update_currency(amount: int) -> void:
hud.update_currency(amount)
return
hud.update_currency(amount)
return
func _on_Hitbox_body_entered(body: Node) -> void:
if not 'enemies' in body.get_groups():
return
if not 'enemies' in body.get_groups():
return
if health_index != 0:
health_index -= 1
hud.update_health(HEALTH_SLICES[health_index])
return
if health_index != 0:
health_index -= 1
hud.update_health(HEALTH_SLICES[health_index])
return
func _input(event: InputEvent) -> void:
if event.is_action_pressed('screenshot'):
var img: Image = get_viewport().get_texture().get_data()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
if event.is_action_pressed('screenshot'):
var img: Image = get_viewport().get_texture().get_data()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
img.flip_y()
img.flip_y()
var time: Dictionary = OS.get_datetime_from_unix_time(OS.get_unix_time())
var time_msecs: int = OS.get_system_time_msecs()
var time: Dictionary = OS.get_datetime_from_unix_time(OS.get_unix_time())
var time_msecs: int = OS.get_system_time_msecs()
if img.save_png('user://Screenshot_%d%d%d_%d.png' % [time.year, time.month, time.day, time_msecs]) != OK:
print('ERROR: Failed saving screenshot.')
return
if img.save_png('user://Screenshot_%d%d%d_%d.png' % [time.year, time.month, time.day, time_msecs]) != OK:
print('ERROR: Failed saving screenshot.')
return