Skip to content

Commit

Permalink
levelup restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
ricargoes committed Feb 18, 2024
1 parent 0448666 commit 85dae16
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scenes/global/game_library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const POWERUPS = {
'type': PowerUpType.Weapon,
'description': 'Slash nearby enermies with a mighty sword.',
'icon': preload("res://resources/ui/icons/sword.png"),
'scene': preload("res://scenes/powerups/boomerang.tscn")
'scene': preload("res://scenes/powerups/sword.tscn")
},
'Boomerang': {
'type': PowerUpType.Weapon,
Expand Down
18 changes: 10 additions & 8 deletions scenes/hero.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var life_steal: float = 0.0
var life_points: float = 50.0
var level: int = 0
var xp: int = 0
var xp_threshold: int = 100
var powerups = { "Pistol": 1, "Sword": 1 }
var xp_threshold: int = 1
var powerups = { "Pistol": 1 }
var enemies_slain: int = 0

var jump_impulse_time: float = 0.0
Expand Down Expand Up @@ -79,13 +79,15 @@ func get_xp(amount: int):

func level_up():
get_tree().paused = true
$UI/LevelUpScreen.pick_powerup(powerups)
var powerup = await $UI/LevelUpScreen.powerup_selected
var can_levelup = $UI/LevelUpScreen.pick_powerup(powerups)
if can_levelup:
var powerup = await $UI/LevelUpScreen.powerup_selected
level += 1
xp_threshold = level*1000
if powerup != "":
equip_powerup(powerup)
get_tree().paused = false
level += 1
xp_threshold = level*1000
if powerup != "":
equip_powerup(powerup)


func equip_powerup(powerup_name: String):
var powerup = GameLibrary.POWERUPS[powerup_name]
Expand Down
9 changes: 3 additions & 6 deletions scenes/hero.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://f31q7ameb6hm"]
[gd_scene load_steps=22 format=3 uid="uid://f31q7ameb6hm"]

[ext_resource type="Script" path="res://scenes/hero.gd" id="1_omy4t"]
[ext_resource type="Texture2D" uid="uid://cipplrmttgmy4" path="res://resources/sprites/pj/pjHead.png" id="2_3f0u1"]
Expand All @@ -11,7 +11,6 @@
[ext_resource type="Texture2D" uid="uid://ciownt0dopb4i" path="res://resources/sprites/pj/pjRunningLegs1.png" id="6_ejbq7"]
[ext_resource type="Texture2D" uid="uid://ced1gvm3ejp8b" path="res://resources/sprites/pj/pjRunningLegs2.png" id="7_34yky"]
[ext_resource type="PackedScene" uid="uid://cdxbhwtpcrqwx" path="res://scenes/level_up_screen.tscn" id="7_y4fjo"]
[ext_resource type="PackedScene" uid="uid://be7qt3ldbvjxr" path="res://scenes/powerups/sword.tscn" id="9_hr181"]
[ext_resource type="PackedScene" uid="uid://c8qbjfx63idyx" path="res://scenes/powerups/pistol.tscn" id="9_jqixl"]
[ext_resource type="Texture2D" uid="uid://bdexcucrlyfrt" path="res://resources/ui/full_life_bar.png" id="13_axndc"]
[ext_resource type="Texture2D" uid="uid://cuxvaqlgqpm2c" path="res://resources/ui/full_xp_bar.png" id="14_glpkk"]
Expand Down Expand Up @@ -87,10 +86,6 @@ sprite_frames = SubResource("SpriteFrames_rcvp2")
animation = &"run"
autoplay = "run"

[node name="Pistol" parent="." instance=ExtResource("9_jqixl")]

[node name="Sword" parent="." instance=ExtResource("9_hr181")]

[node name="RunningShape" type="CollisionShape2D" parent="."]
position = Vector2(0, 7)
shape = SubResource("CapsuleShape2D_itkei")
Expand Down Expand Up @@ -185,3 +180,5 @@ collision_mask = 2

[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerSight"]
shape = SubResource("RectangleShape2D_33dn5")

[node name="Pistol" parent="." instance=ExtResource("9_jqixl")]
35 changes: 29 additions & 6 deletions scenes/level_up_screen.gd
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
extends CenterContainer

const MAX_WEAPONS = 4
const MAX_PASSIVES = 2

signal powerup_selected(powerup_name)

func pick_powerup(powerup_levels: Dictionary):
show()
func pick_powerup(powerup_levels: Dictionary) -> bool:
for node in %Options.get_children():
node.queue_free()

var available_powerups = GameLibrary.POWERUPS.keys()
for powerup_name in available_powerups:
var weapon_count = 0
var passive_count = 0
for owned_powerup in powerup_levels:
var powerup_info = GameLibrary.POWERUPS[owned_powerup]
if powerup_info["type"] == GameLibrary.PowerUpType.Weapon:
weapon_count += 1
elif powerup_info["type"] == GameLibrary.PowerUpType.Passive:
passive_count += 1

var all_powerups: Array = GameLibrary.POWERUPS.keys()
var available_powerups = all_powerups.duplicate()
for powerup_name in all_powerups:
var powerup_info = GameLibrary.POWERUPS[powerup_name]
if weapon_count >= MAX_WEAPONS and powerup_info["type"] == GameLibrary.PowerUpType.Weapon and not powerup_levels.has(powerup_name):
available_powerups.erase(powerup_name)
continue
if passive_count >= MAX_PASSIVES and powerup_info["type"] == GameLibrary.PowerUpType.Passive and not powerup_levels.has(powerup_name):
available_powerups.erase(powerup_name)
continue
var level = powerup_levels.get(powerup_name, 0)
if level >= 5:
available_powerups.erase(powerup_name)
continue

if available_powerups.is_empty():
powerup_clicked("")
return false

show()
randomize()
var count = 0
var ramaining_powerups = available_powerups.duplicate()
while count < min(3, available_powerups.size()):
var powerup_name = available_powerups.pop_at(randi() % available_powerups.size())
var powerup_name = ramaining_powerups.pop_at(randi() % ramaining_powerups.size())
var powerup_info = GameLibrary.POWERUPS[powerup_name]
var button = Button.new()
button.icon = powerup_info['icon']
button.text = "{name}\n{description}".format({'name': powerup_name, 'description': powerup_info['description']})
button.pressed.connect(powerup_clicked.bind(powerup_name))
%Options.add_child(button)
count += 1
return true

func powerup_clicked(powerup_name: String):
powerup_selected.emit(powerup_name)
Expand Down
1 change: 1 addition & 0 deletions scenes/level_up_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 0
script = ExtResource("1_r55pw")

[node name="Panel" type="Panel" parent="."]
Expand Down
6 changes: 3 additions & 3 deletions scenes/terrain/terrain_chunk_1.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ destination = NodePath("../../Helpers/Dest1")
activator = NodePath("../../Helpers/Activator")

[node name="Spawner2" parent="Enemies" index="1" node_paths=PackedStringArray("destination", "activator") instance=ExtResource("3_eakqu")]
position = Vector2(4326, 327)
position = Vector2(7090, 221)
spawning_resource = 1
destination = NodePath("../../Helpers/Dest2")
activator = NodePath("../../Helpers/Activator")
Expand Down Expand Up @@ -69,10 +69,10 @@ position = Vector2(64, 543)
position = Vector2(3711, 753)

[node name="Dest1" type="Marker2D" parent="Helpers" index="0"]
position = Vector2(3594, 795)
position = Vector2(5249, 156)

[node name="Dest2" type="Marker2D" parent="Helpers" index="1"]
position = Vector2(5327, 311)
position = Vector2(8633, 210)

[node name="Activator" parent="Helpers" index="2" instance=ExtResource("4_jtunb")]
position = Vector2(1834, 428)
Expand Down

0 comments on commit 85dae16

Please sign in to comment.