This commit is contained in:
2021-11-29 14:42:40 -06:00
parent 614ad2009b
commit 1b1fe8c2f5
36 changed files with 154 additions and 596 deletions

View File

@@ -1,41 +1,76 @@
extends KinematicBody2D
const ACCELERATION = 1000
const MAX_SPEED = 120
const FRICTION = 1000
export var ACCELERATION: int = 1000
export var MAX_SPEED: int = 120
export var FRICTION: int = 1000
const HEALTH_SLICES: Array = [0, 18, 35, 50, 65, 82, 100]
var health_index: int = 6
var hud: CanvasLayer = null
var velocity: Vector2 = Vector2.ZERO
var isDash = false
var counter = 0
func _physics_process(delta) -> void:
var input_vector: Vector2 = Vector2.ZERO
func _physics_process(delta: float) -> void:
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 dashing, increase velocity by 4 for one frame
if Input.is_action_just_pressed("player_dash") and input_vector != Vector2.ZERO and isDash == false:
velocity = velocity * 4
isDash = true
# If the dash was previously pressed, start a counter
if isDash:
counter += 1
# wait time before you can dash again
if counter > 60:
counter = 0
isDash = false
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.update_health(HEALTH_SLICES[health_index])
hud.update_currency($Inventory.get_currency())
return
func add_currency(amount: int) -> void:
$Inventory.add_currency(amount)
return
func _on_Inventory_update_currency(amount: int) -> void:
hud.update_currency(amount)
return
func _on_Hitbox_body_entered(body: Node) -> void:
if not 'enemies' in body.get_groups():
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")
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()
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

View File

@@ -1,22 +1,23 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=20 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Sprites/Player.png" type="Texture" id=2]
[ext_resource path="res://Sprites/Player_Down.png" type="Texture" id=3]
[ext_resource path="res://Sprites/Player_Up.png" type="Texture" id=4]
[ext_resource path="res://Sprites/Player/Player.png" type="Texture" id=2]
[ext_resource path="res://Sprites/Player/Player_Down.png" type="Texture" id=3]
[ext_resource path="res://Sprites/Player/Player_Up.png" type="Texture" id=4]
[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 4 ) ],
"loop": false,
"name": "look_up",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"loop": false,
"name": "look_right",
"speed": 5.0
}, {
"frames": [ ExtResource( 4 ) ],
"loop": false,
"name": "look_up",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"loop": false,
"name": "look_left",
@@ -160,14 +161,14 @@ animation = "Look Up"
[sub_resource type="AnimationNodeBlendSpace2D" id=12]
blend_point_0/node = SubResource( 8 )
blend_point_0/pos = Vector2( -1.01, 0 )
blend_point_0/pos = Vector2( -1, 0 )
blend_point_1/node = SubResource( 9 )
blend_point_1/pos = Vector2( 0, 1.1 )
blend_point_2/node = SubResource( 10 )
blend_point_2/pos = Vector2( 1, 0 )
blend_point_3/node = SubResource( 11 )
blend_point_3/pos = Vector2( 0, -1.1 )
min_space = Vector2( -1.01, -1.1 )
min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
@@ -180,19 +181,25 @@ graph_offset = Vector2( -3591.37, -302.6 )
[sub_resource type="AnimationNodeStateMachinePlayback" id=14]
[node name="Player" type="KinematicBody2D"]
collision_layer = 2
script = ExtResource( 1 )
[node name="Sprite" type="AnimatedSprite" parent="."]
position = Vector2( 0, -5 )
light_mask = 2
frames = SubResource( 1 )
animation = "look_right"
offset = Vector2( 0, -5 )
[node name="Collision" type="CollisionShape2D" parent="."]
visible = false
rotation = 1.5708
shape = SubResource( 2 )
[node name="Hitbox" type="CollisionShape2D" parent="."]
[node name="Hitbox" type="Area2D" parent="."]
collision_layer = 2
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
visible = false
position = Vector2( 0, -5 )
shape = SubResource( 3 )
@@ -209,4 +216,9 @@ tree_root = SubResource( 13 )
anim_player = NodePath("../AnimationPlayer")
active = true
parameters/playback = SubResource( 14 )
parameters/Idle/blend_position = Vector2( 0.993787, 0.0189655 )
parameters/Idle/blend_position = Vector2( 0.0760697, 0 )
[node name="Inventory" parent="." instance=ExtResource( 5 )]
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]