Skip to content

Commit

Permalink
feat: add shild
Browse files Browse the repository at this point in the history
  • Loading branch information
bektaskemal committed Jan 16, 2024
1 parent bc301bc commit 7943789
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 7 deletions.
11 changes: 11 additions & 0 deletions resources/upgrades/shield.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="AbilityUpgrade" load_steps=2 format=3 uid="uid://oj5ee34brh6b"]

[ext_resource type="Script" path="res://resources/upgrades/ability_upgrade.gd" id="1_n4jlk"]

[resource]
script = ExtResource("1_n4jlk")
id = "shield"
parent_id = ""
max_quantity = 1
name = "Shield"
description = "A magical shield blocking damages every 15 s"
11 changes: 11 additions & 0 deletions resources/upgrades/shield_rate.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="AbilityUpgrade" load_steps=2 format=3 uid="uid://kw354v654xgu"]

[ext_resource type="Script" path="res://resources/upgrades/ability_upgrade.gd" id="1_jobut"]

[resource]
script = ExtResource("1_jobut")
id = "shield_rate"
parent_id = "shield"
max_quantity = 10
name = "Shield Cooldown"
description = "Reduce cooldown of the shield by 1 s"
10 changes: 9 additions & 1 deletion scenes/UI/main_menu.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
extends CanvasLayer

var pressed = false

func _ready():
%PlayButton.pressed.connect(on_play_pressed)
%QuitButton.pressed.connect(on_quit_pressed)
if OS.has_feature("web"):
%QuitButton.visible = false

func on_play_pressed():
get_tree().change_scene_to_file("res://scenes/main/main.tscn")
$AnimationPlayer.play("out")
pressed = true


func _process(delta):
if pressed and not $AnimationPlayer.is_playing():
get_tree().change_scene_to_file("res://scenes/main/main.tscn")

func on_quit_pressed():
get_tree().quit()

71 changes: 70 additions & 1 deletion scenes/UI/main_menu.tscn

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion scenes/game_objects/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class_name Player
@onready var abilities = $Abilities
@onready var animation_player = $AnimationPlayer as AnimationPlayer
@onready var visuals = $Visuals as Node2D
@onready var shield: MeshInstance2D = $Visuals/Sprite2D/Shield

const ACCELERATION = 20
const SPEED_INCREMENT = 5

var has_shield = false
var max_speed = 125
var number_of_colliding_bodies = 0

Expand All @@ -22,6 +24,8 @@ func _ready():
health_component.health_changed.connect(on_health_changed)
GameEvents.ability_upgrade_added.connect(on_ability_upgraded)
health_bar.value = health_component.get_health_percent()
$ShieldTimer.timeout.connect(enable_shield)


func _process(delta):
var movement_vector = get_movement_vector()
Expand All @@ -37,6 +41,11 @@ func _process(delta):
visuals.scale.x = move_dir
else:
animation_player.play("RESET")

if has_shield:
shield.visible = true
else:
shield.visible = false


func get_movement_vector():
Expand All @@ -47,6 +56,10 @@ func get_movement_vector():
func check_deal_damage():
if number_of_colliding_bodies == 0:
return
if has_shield:
has_shield = false
$ShieldTimer.start()
return
health_component.damage(min(number_of_colliding_bodies,4))
$HurtAudioPlayer.play_random()
dmg_timer.start()
Expand All @@ -62,12 +75,22 @@ func on_health_changed(change):
health_bar.value = health_component.get_health_percent()

func on_ability_upgraded(upgrade: AbilityUpgrade, current_upgrades: Dictionary):
if not upgrade is Ability and not upgrade.id == "speed" :
if not upgrade is Ability and not upgrade.id in ["speed", "shield", "shield_rate"]:
return

if upgrade.id == "speed":
max_speed += SPEED_INCREMENT
return

if upgrade.id == "shield":
has_shield = true
return
if upgrade.id == "shield_rate":
$ShieldTimer.wait_time -= 1
return

var ability = upgrade as Ability
abilities.add_child(ability.ability_controller_scene.instantiate())

func enable_shield():
has_shield = true
14 changes: 13 additions & 1 deletion scenes/game_objects/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://dvhud3fband4r"]
[gd_scene load_steps=19 format=3 uid="uid://dvhud3fband4r"]

[ext_resource type="Texture2D" uid="uid://dp32duuqu4emf" path="res://scenes/game_objects/player/player.png" id="1_0ooxu"]
[ext_resource type="Script" path="res://scenes/game_objects/player/player.gd" id="1_4k4ng"]
Expand Down Expand Up @@ -131,6 +131,8 @@ shader_parameter/color = Vector3(1, 1, 1)
[sub_resource type="CircleShape2D" id="CircleShape2D_yub0n"]
radius = 32.0

[sub_resource type="SphereMesh" id="SphereMesh_cng6q"]

[sub_resource type="CircleShape2D" id="CircleShape2D_5px35"]
radius = 7.0

Expand Down Expand Up @@ -178,6 +180,9 @@ health_component = NodePath("../HealthComponent")
sprite = NodePath("../Visuals/Sprite2D")
hit_flash_material = SubResource("ShaderMaterial_vfl1a")

[node name="ShieldTimer" type="Timer" parent="."]
wait_time = 15.0

[node name="PickupArea2D" type="Area2D" parent="."]
visible = false
collision_layer = 16
Expand All @@ -194,6 +199,13 @@ shape = SubResource("CircleShape2D_yub0n")
texture = ExtResource("1_0ooxu")
offset = Vector2(0, -8)

[node name="Shield" type="MeshInstance2D" parent="Visuals/Sprite2D"]
modulate = Color(0.490196, 0.619608, 0.796078, 0.509804)
show_behind_parent = true
position = Vector2(0, -7)
scale = Vector2(22, 22)
mesh = SubResource("SphereMesh_cng6q")

[node name="CollisionArea2D" type="Area2D" parent="."]
visible = false
collision_layer = 0
Expand Down
2 changes: 1 addition & 1 deletion scenes/main/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ y_sort_enabled = true

[node name="Player" parent="Entities" instance=ExtResource("1_4wts3")]
unique_name_in_owner = true
position = Vector2(512, 267)
position = Vector2(379, 229)

[node name="Foreground" type="Node2D" parent="." groups=["foreground_layer"]]

Expand Down
6 changes: 4 additions & 2 deletions scenes/manager/upgrade_manager.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://d0kxjmo8htbal"]
[gd_scene load_steps=11 format=3 uid="uid://d0kxjmo8htbal"]

[ext_resource type="Script" path="res://scenes/manager/upgrade_manager.gd" id="1_5tvyf"]
[ext_resource type="Resource" uid="uid://uli2uvjjdvj" path="res://resources/upgrades/sword_rate.tres" id="2_6sho2"]
Expand All @@ -8,8 +8,10 @@
[ext_resource type="Resource" uid="uid://duqnjcxraij5r" path="res://resources/upgrades/speed.tres" id="5_vanc6"]
[ext_resource type="Resource" uid="uid://c4spim2bceng3" path="res://resources/upgrades/sword_damage.tres" id="6_0ij4n"]
[ext_resource type="Resource" uid="uid://chdjk4xc06tsv" path="res://resources/upgrades/axe_damage.tres" id="7_jhao4"]
[ext_resource type="Resource" uid="uid://oj5ee34brh6b" path="res://resources/upgrades/shield.tres" id="8_3oqeo"]
[ext_resource type="Resource" uid="uid://kw354v654xgu" path="res://resources/upgrades/shield_rate.tres" id="9_nhl7k"]

[node name="UpgradeManager" type="Node"]
script = ExtResource("1_5tvyf")
upgrade_pool = Array[Resource("res://resources/upgrades/ability_upgrade.gd")]([ExtResource("2_6sho2"), ExtResource("3_dayt4"), ExtResource("4_0jb04"), ExtResource("5_vanc6"), ExtResource("6_0ij4n"), ExtResource("7_jhao4")])
upgrade_pool = Array[Resource("res://resources/upgrades/ability_upgrade.gd")]([ExtResource("2_6sho2"), ExtResource("3_dayt4"), ExtResource("4_0jb04"), ExtResource("5_vanc6"), ExtResource("6_0ij4n"), ExtResource("7_jhao4"), ExtResource("8_3oqeo"), ExtResource("9_nhl7k")])
upgrade_screen_scene = ExtResource("3_sf6aj")

0 comments on commit 7943789

Please sign in to comment.