Statsscript with speed

This commit is contained in:
Jan Schuffenhauer
2020-04-18 17:01:16 +02:00
parent dd870a1aa9
commit dbd852190b
3 changed files with 39 additions and 1 deletions

View File

@@ -3,9 +3,20 @@ extends Node
export(int) var max_health := 1
onready var health := max_health setget set_health
export(int) var max_speed := 125
onready var speed := max_speed setget set_speed
signal no_health
func set_health(value):
health = value
if health < 1:
emit_signal("no_health")
func set_speed(value):
if value > max_speed:
speed = max_speed
else:
speed = value

View File

@@ -11,6 +11,8 @@ export(int, 0, 500) var ROLL_SPEED := 150
export(int, 0, 500) var FRICTION := 200 # Speed at which the player deaccelarates
export(int, 0, 500) var ACCELERATION := 450
# Reference for the current player
onready var debug_label := $DebugLabel
onready var player_stats := $Stats
onready var animation_player := $AnimationPlayer
onready var animation_tree := $AnimationTree
onready var animation_state = animation_tree.get("parameters/playback")
@@ -23,7 +25,12 @@ enum moveState{
var movementState = moveState.MOVE
func _debug_update():
debug_label.text = str(player_stats.health) + "/" + str(player_stats.max_health) + " HP"
func _physics_process(delta):
_debug_update()
match movementState:
moveState.MOVE:
movement_move(delta)

View File

@@ -1,9 +1,11 @@
[gd_scene load_steps=52 format=2]
[gd_scene load_steps=55 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
[ext_resource path="res://HurtHit_Box/Hurtbox.tscn" type="PackedScene" id=3]
[ext_resource path="res://HurtHit_Box/Hitbox.tscn" type="PackedScene" id=4]
[ext_resource path="res://Overlap/Stats.tscn" type="PackedScene" id=5]
[ext_resource path="res://Fonts/Harmonic/Harmonic.ttf" type="DynamicFontData" id=6]
[sub_resource type="CapsuleShape2D" id=1]
radius = 2.15976
@@ -606,6 +608,10 @@ height = 6.72939
radius = 4.03497
height = 6.99104
[sub_resource type="DynamicFont" id=48]
size = 12
font_data = ExtResource( 6 )
[node name="Player" type="KinematicBody2D"]
script = ExtResource( 1 )
FRICTION = 270
@@ -674,6 +680,20 @@ collision_mask = 12
position = Vector2( 8.43416, 0.0698299 )
shape = SubResource( 47 )
disabled = true
[node name="Stats" parent="." instance=ExtResource( 5 )]
max_health = 3
[node name="DebugLabel" type="Label" parent="."]
margin_left = -8.0
margin_top = -21.0
margin_right = 10.0
margin_bottom = -9.0
custom_fonts/font = SubResource( 48 )
text = "BLa"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
[editable path="Hurtbox"]