Skip to content

Commit

Permalink
Merge branch 'ayan/healthbar' of https://github.com/tetra-devs/maingame
Browse files Browse the repository at this point in the history
… into Sayantan_v7
  • Loading branch information
Sayantan0013 committed Jan 2, 2021
2 parents 93ab07d + 55c23da commit e08474f
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 1 deletion.
20 changes: 20 additions & 0 deletions UI/HealthBars/HealthBar.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends Control

onready var bar_over = $BarOver
onready var bar_under = $BarBack
onready var tween = $Tween
onready var shaker = $Shaker

export (float) var shake_amplitude = 3.0

onready var reset_value = rect_position

func set_max_health(value):
bar_over.max_value = value
bar_under.max_value = value

func _on_health_updated(value):
bar_over.value = value
tween.interpolate_property(bar_under, "value", bar_under.value, value, 0.5, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
tween.start()
shaker.start(self, "rect_position", reset_value, 0.2, 15, shake_amplitude)
35 changes: 35 additions & 0 deletions UI/HealthBars/HealthBar.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://UI/HealthBars/HealthBar.gd" type="Script" id=1]
[ext_resource path="res://UI/HealthBars/health_bar_back.png" type="Texture" id=2]
[ext_resource path="res://UI/HealthBars/health_bar_damage.png" type="Texture" id=3]
[ext_resource path="res://UI/HealthBars/health_bar_health.png" type="Texture" id=4]
[ext_resource path="res://Utils/Shaker.tscn" type="PackedScene" id=5]

[node name="HealthBar" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )

[node name="BarBack" type="TextureProgress" parent="."]
margin_left = -8.0
margin_top = -2.0
margin_right = 32.0
margin_bottom = 38.0
step = 0.1
value = 100.0
texture_under = ExtResource( 2 )
texture_progress = ExtResource( 3 )

[node name="BarOver" type="TextureProgress" parent="."]
margin_left = -8.0
margin_top = -2.0
margin_right = 32.0
margin_bottom = 38.0
step = 0.1
value = 100.0
texture_progress = ExtResource( 4 )

[node name="Tween" type="Tween" parent="."]

[node name="Shaker" parent="." instance=ExtResource( 5 )]
26 changes: 26 additions & 0 deletions UI/HealthBars/PlayerHealthBar.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://UI/HealthBars/HealthBar.tscn" type="PackedScene" id=1]
[ext_resource path="res://UI/HealthBars/player-health-bar-under.png" type="Texture" id=2]
[ext_resource path="res://UI/HealthBars/player-health-bar-damage.png" type="Texture" id=3]
[ext_resource path="res://UI/HealthBars/player-health-bar-over.png" type="Texture" id=4]
[ext_resource path="res://UI/HealthBars/player-health-bar-health.png" type="Texture" id=5]

[node name="PlayerHealthBar" instance=ExtResource( 1 )]
shake_amplitude = 5.0

[node name="BarBack" parent="." index="0"]
margin_left = 8.0
margin_top = 8.0
margin_right = 48.0
margin_bottom = 48.0
texture_under = ExtResource( 2 )
texture_progress = ExtResource( 3 )

[node name="BarOver" parent="." index="1"]
margin_left = 8.0
margin_top = 8.0
margin_right = 48.0
margin_bottom = 48.0
texture_over = ExtResource( 4 )
texture_progress = ExtResource( 5 )
Binary file added UI/HealthBars/health_bar_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/health_bar_back.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/health_bar_back.png-13ed6a7ac67e18ebd8c89df95eb71b0c.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/health_bar_back.png"
dest_files=[ "res://.import/health_bar_back.png-13ed6a7ac67e18ebd8c89df95eb71b0c.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/health_bar_damage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/health_bar_damage.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/health_bar_damage.png-6fa3f04d83cd2e1caf8eadb8f7291152.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/health_bar_damage.png"
dest_files=[ "res://.import/health_bar_damage.png-6fa3f04d83cd2e1caf8eadb8f7291152.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/health_bar_health.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/health_bar_health.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/health_bar_health.png-557d74422a11d42d09c7736322a6ac5b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/health_bar_health.png"
dest_files=[ "res://.import/health_bar_health.png-557d74422a11d42d09c7736322a6ac5b.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/player-health-bar-damage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/player-health-bar-damage.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/player-health-bar-damage.png-90015cd681a37a5b3c62960925dd62dc.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/player-health-bar-damage.png"
dest_files=[ "res://.import/player-health-bar-damage.png-90015cd681a37a5b3c62960925dd62dc.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/player-health-bar-health.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/player-health-bar-health.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/player-health-bar-health.png-9677bb6d43a8e660b96e7a06cc6d19d9.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/player-health-bar-health.png"
dest_files=[ "res://.import/player-health-bar-health.png-9677bb6d43a8e660b96e7a06cc6d19d9.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/player-health-bar-over.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/player-health-bar-over.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/player-health-bar-over.png-c7c0e6dd1d4472ba41678c541b63b6da.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/player-health-bar-over.png"
dest_files=[ "res://.import/player-health-bar-over.png-c7c0e6dd1d4472ba41678c541b63b6da.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added UI/HealthBars/player-health-bar-under.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions UI/HealthBars/player-health-bar-under.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/player-health-bar-under.png-003e4c142bd43a04ad637eb017fccbe0.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://UI/HealthBars/player-health-bar-under.png"
dest_files=[ "res://.import/player-health-bar-under.png-003e4c142bd43a04ad637eb017fccbe0.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
46 changes: 46 additions & 0 deletions Utils/Shaker.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
extends Node

const TRANS = Tween.TRANS_SINE
const EASE = Tween.EASE_IN_OUT

onready var duration_timer = $Duration
onready var frequency_timer = $Frequency
onready var shake_tween = $ShakeTween

var amplitude = 0
var priority = 0
var obj = null
var property = null
var reset_value

func start(obj, property, reset_value, duration = 0.2, frequency = 15, amplitude = 16, priority = 0):
if priority >= self.priority:
self.priority = priority
self.amplitude = amplitude
self.obj = obj
self.property = property
self.reset_value = reset_value

duration_timer.wait_time = duration
frequency_timer.wait_time = 1 / float(frequency)
duration_timer.start()
frequency_timer.start()

_new_shake()

func _new_shake():
var rand = Vector2()
rand.x = rand_range(-amplitude, amplitude)
rand.y = rand_range(-amplitude, amplitude)
shake_tween.interpolate_property(obj, property, obj.get(property), reset_value + rand, frequency_timer.wait_time, TRANS, EASE)
shake_tween.start()

func _reset():
shake_tween.interpolate_property(obj, property, obj.get(property), reset_value, frequency_timer.wait_time, TRANS, EASE)

func _on_Frequency_timeout():
_new_shake()

func _on_Duration_timeout():
_reset()
frequency_timer.stop()
14 changes: 14 additions & 0 deletions Utils/Shaker.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Utils/Shaker.gd" type="Script" id=1]

[node name="Shaker" type="Node"]
script = ExtResource( 1 )

[node name="Duration" type="Timer" parent="."]

[node name="Frequency" type="Timer" parent="."]

[node name="ShakeTween" type="Tween" parent="."]
[connection signal="timeout" from="Duration" to="." method="_on_Duration_timeout"]
[connection signal="timeout" from="Frequency" to="." method="_on_Frequency_timeout"]
Loading

0 comments on commit e08474f

Please sign in to comment.