Skip to content

Commit

Permalink
add aim effect
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTOXIN committed May 7, 2022
1 parent 92d8daf commit 3b9d06c
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 68 deletions.
43 changes: 41 additions & 2 deletions UI/Effect.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/effects/boost_whie.png" type="Texture" id=1]

[sub_resource type="Animation" id=2]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Background/TextureBoost:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=1]
resource_name = "effect_flash"
loop = true
step = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Background/TextureBoost:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5, 1 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}

[node name="Effect" type="MarginContainer"]
margin_right = 64.0
margin_bottom = 64.0

[node name="Background" type="NinePatchRect" parent="."]
margin_right = 64.0
margin_bottom = 64.0

[node name="TextureBoost" type="TextureRect" parent="Background"]
self_modulate = Color( 0.384314, 0.87451, 0.298039, 1 )
modulate = Color( 0.376471, 0.882353, 0.262745, 1 )
margin_bottom = 64.0
texture = ExtResource( 1 )
expand = true
stretch_mode = 6

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "effect_flash"
anims/RESET = SubResource( 2 )
anims/effect_flash = SubResource( 1 )
10 changes: 10 additions & 0 deletions UI/EffectAim.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://assets/effects/reloader_whie.png" type="Texture" id=1]
[ext_resource path="res://UI/Effect.tscn" type="PackedScene" id=2]

[node name="EffectAim" instance=ExtResource( 2 )]

[node name="TextureBoost" parent="Background" index="0"]
margin_right = 64.0
texture = ExtResource( 1 )
42 changes: 1 addition & 41 deletions UI/EffectBoost.tscn
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=2 format=2]

[ext_resource path="res://UI/Effect.tscn" type="PackedScene" id=1]

[sub_resource type="Animation" id=1]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Background/TextureBoost:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=2]
resource_name = "flash"
length = 0.5
loop = true
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Background/TextureBoost:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.25, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}

[node name="EffectBoost" instance=ExtResource( 1 )]

[node name="Background" parent="." index="0"]
margin_right = 64.0
rect_min_size = Vector2( 64, 64 )

[node name="TextureBoost" parent="Background" index="0"]
modulate = Color( 0.423529, 0.882353, 0.309804, 1 )
self_modulate = Color( 1, 1, 1, 1 )
margin_right = 64.0

[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="1"]
autoplay = "flash"
anims/RESET = SubResource( 1 )
anims/flash = SubResource( 2 )
6 changes: 6 additions & 0 deletions UI/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(NodePath) var player_path
var player
var bar_texture
var show_boost = false
var show_aim = false
var show_reload = false
var reload_time = 0

Expand All @@ -13,6 +14,7 @@ func _ready():
player = get_node(player_path)
reload_time = player.gun_cooldown
$HUD/GUI/Container/Effects/EffectBoost.visible = false
$HUD/GUI/Container/Effects/EffectAim.visible = false

func _process(_delta):
if player:
Expand Down Expand Up @@ -73,3 +75,7 @@ func start_reload():
$ReloadProgress, 'value', $ReloadProgress.value, 100, reload_time
)
$ReloadProgress/Tween.start()

func _on_Player_aim():
show_aim = !show_aim
$HUD/GUI/Container/Effects/EffectAim.visible = show_aim
16 changes: 10 additions & 6 deletions UI/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://UI/BulletsBar.tscn" type="PackedScene" id=1]
[ext_resource path="res://UI/HealthBar.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/Xolonium-Regular.ttf" type="DynamicFontData" id=3]
[ext_resource path="res://UI/HUD.gd" type="Script" id=4]
[ext_resource path="res://UI/EffectBoost.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/muzzle_cursor.png" type="Texture" id=6]
[ext_resource path="res://UI/EffectAim.tscn" type="PackedScene" id=7]

[sub_resource type="DynamicFont" id=4]
size = 22
Expand Down Expand Up @@ -43,15 +44,18 @@ margin_bottom = 34.0
margin_top = 38.0
margin_bottom = 60.0

[node name="Effects" type="HBoxContainer" parent="HUD/GUI/Container"]
[node name="Effects" type="VBoxContainer" parent="HUD/GUI/Container"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -66.0
margin_right = -2.0
margin_bottom = 64.0
margin_left = -62.0
margin_right = 2.0
margin_bottom = 145.0

[node name="EffectBoost" parent="HUD/GUI/Container/Effects" instance=ExtResource( 5 )]
margin_right = 64.0

[node name="EffectAim" parent="HUD/GUI/Container/Effects" instance=ExtResource( 7 )]
margin_top = 68.0
margin_bottom = 68.0

[node name="Speed" type="MarginContainer" parent="HUD/GUI/Container"]
anchor_top = 1.0
Expand Down
7 changes: 0 additions & 7 deletions UI/TitleScreen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ ghost = true
[node name="Obstacle" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 672, 481 )
rotation = -1.57012
strength = 1
type = 10

[node name="Obstacle2" parent="Obstacles" instance=ExtResource( 5 )]
Expand All @@ -123,33 +122,27 @@ type = 14

[node name="Obstacle5" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 366, 39 )
strength = 1
type = 7

[node name="Obstacle10" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 290, 38 )
rotation = 0.374279
strength = 1
type = 6

[node name="Obstacle6" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 162, 312 )
rotation = -0.118422
strength = 1
type = 9

[node name="Obstacle7" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 365, 497 )
strength = 1
type = 19

[node name="Obstacle8" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 454, 490 )
rotation = -0.759753
strength = 1
type = 19

[node name="Obstacle9" parent="Obstacles" instance=ExtResource( 5 )]
position = Vector2( 284, 483 )
strength = 1
type = 19
5 changes: 2 additions & 3 deletions bullets/Bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ func _process(delta):
position += velocity * delta

func _on_Bullet_body_entered(body):
if body == holder:
return
if body == holder: return
explode()
if body.has_method('take_damage'):
body.take_damage(damage)
body.take_damage(damage * holder.bullet_boost)

func _on_Lifetime_timeout():
explode()
Expand Down
2 changes: 1 addition & 1 deletion items/Pickup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func _on_Pickup_body_entered(body):
Items.boost:
body.boost(rand.randi_range(5, 10))
Items.aim:
print("FAST RELOAD") #TODO FAST RELOAD AND AIM RAY
body.aim(rand.randi_range(5, 10))
queue_free()
2 changes: 1 addition & 1 deletion maps/Map.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node2D

#TODO sounds, DESTROY OBJECTS
#TODO sounds,map,test,counterdamage,config,bugs

signal enemy_counter

Expand Down
4 changes: 1 addition & 3 deletions maps/Map.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ position = Vector2( 119.064, 64 )
rotation = 3.11802

[node name="Enemy" parent="Paths/Path2D/PathFollow2D" instance=ExtResource( 3 )]
disable = true
detect_radius = 400

[node name="HUD" parent="." instance=ExtResource( 9 )]
Expand All @@ -56,15 +55,13 @@ position = Vector2( 863, 365 )
offroad_friction = 0.75
gun_shots = 3
gun_spread = 0.1
disable = true

[node name="EnemyMissile" parent="." instance=ExtResource( 3 )]
position = Vector2( 539, 243 )
rotation = -2.18088
Bullet = ExtResource( 4 )
gun_cooldown = 1.5
max_ammo = 10
disable = true
detect_radius = 250

[node name="Obstacles" type="Node2D" parent="."]
Expand Down Expand Up @@ -112,6 +109,7 @@ position = Vector2( 1058, 546 )
type = 3

[connection signal="enemy_counter" from="." to="HUD" method="_on_Map01_enemy_counter"]
[connection signal="aim" from="Player" to="HUD" method="_on_Player_aim"]
[connection signal="ammo_changed" from="Player" to="HUD" method="_on_Player_ammo_changed"]
[connection signal="boost" from="Player" to="HUD" method="_on_Player_boost"]
[connection signal="dead" from="Player" to="." method="_on_Player_dead"]
Expand Down
1 change: 0 additions & 1 deletion tanks/Enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func _process(delta):
if result.collider.name == "Player":
targeting(result.position, delta)
break #oprimze ray cast
update()

func ray_cast_points():
var collision_shape = target.get_node('CollisionShape2D')
Expand Down
5 changes: 5 additions & 0 deletions tanks/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func turret_aim(_delta):
else:
$AimSprite.modulate = Globals.color_red

func _draw():
if aim_effect:
draw_line($Turret/Muzzle.position, $AimSprite.position, Globals.color_red, 5)
pass

func _on_Area2D_body_entered(body):
if head_collide():
if speed > 200:
Expand Down
4 changes: 2 additions & 2 deletions tanks/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ region_rect = Rect2( 584, 58, 56, 32 )

[node name="Aim" type="Position2D" parent="Turret" index="2"]

[node name="LookHead1" parent="." index="10"]
[node name="LookHead1" parent="." index="11"]
position = Vector2( 0, -35 )
rotation = 0.0

[node name="LookHead2" parent="." index="11"]
[node name="LookHead2" parent="." index="12"]
position = Vector2( 0, 35 )
rotation = 0.0

Expand Down
25 changes: 24 additions & 1 deletion tanks/Tank.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ signal shoot
signal boost
signal speeder
signal track
signal aim

export (PackedScene) var Bullet
export (int) var max_speed
Expand All @@ -33,6 +34,9 @@ var speed_boost = 1.0
var speed_road = 1.0
var map: TileMap
var reload = false
var aim_effect = false
var default_turret_speed
var bullet_boost = 1

func _ready():
$GunTimer.wait_time = gun_cooldown
Expand All @@ -41,6 +45,7 @@ func _ready():
health = max_health
speed = 0
rotation_speed = max_rotation_speed
default_turret_speed = turret_speed
change_health()
change_ammo()

Expand All @@ -54,6 +59,7 @@ func _physics_process(delta):
func _process(_delta):
can_shoot = !reload and ammo != 0
emit_signal("speeder", speed)
update()

func check_offroad():
if map:
Expand Down Expand Up @@ -100,11 +106,21 @@ func boost(amount):
emit_signal("boost")
$BoostTimer.wait_time = amount
speed_boost = 2
# rotation_speed *= 2 HMM
rotation_speed *= 1.5
$BoostTimer.one_shot = true
$BoostTimer.start()
$Boost.show()

func aim(time):
emit_signal("aim")
turret_speed = 1
bullet_boost = 2
aim_effect = true
$GunTimer.wait_time = 0.5
$AimTimer.wait_time = time
$AimTimer.one_shot = true
$AimTimer.start()

func shoot(target_pos):
if can_shoot:
reload = true
Expand Down Expand Up @@ -152,3 +168,10 @@ func _on_BoostTimer_timeout():
speed_boost = 1
rotation_speed = max_rotation_speed
$Boost.hide()

func _on_AimTimer_timeout():
emit_signal("aim")
turret_speed = default_turret_speed
$GunTimer.wait_time = gun_cooldown
bullet_boost = 1
aim_effect = false
Loading

0 comments on commit 3b9d06c

Please sign in to comment.