did building generation and a healthbar

This commit is contained in:
Florian 2025-09-16 15:12:40 +02:00
parent 20530bfd32
commit 5cb035656d
17 changed files with 133 additions and 22 deletions

View file

@ -1,9 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://djawvtdwp423v"]
[ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://building.gd" id="1_5j34s"]
[ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_5j34s"]
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_2yopf"]
[ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://building.gdshader" id="2_f1gjg"]
[ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://building_mesh.gd" id="4_qnfc1"]
[ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_f1gjg"]
[ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_qnfc1"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"]
resource_local_to_scene = true

View file

@ -3,5 +3,4 @@ extends Sprite2D
func _ready() -> void:
var location = Vector2i(get_parent().location)
var dimension = Vector2i(get_parent().dimension)
print(location, dimension)
self_modulate = Color8(location.x, location.y, dimension.x, dimension.y)

21
healthbar/healthbar.gd Normal file
View file

@ -0,0 +1,21 @@
extends HBoxContainer
@export var initial_health : int = 5
@export var packedHeart : PackedScene;
func _ready() -> void:
for i in range(initial_health):
add_child(packedHeart.instantiate())
func set_health(health : int):
var i = 0
for heart : Heart in get_children():
i += 1
if i <= health:
heart.restore()
else:
heart.fade()
func _on_player_health_changed(new_health: int) -> void:
set_health(new_health)

View file

@ -0,0 +1 @@
uid://b3fncqgyodcjc

11
healthbar/healthbar.tscn Normal file
View file

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://cjsrtswk4vgf2"]
[ext_resource type="Script" uid="uid://b3fncqgyodcjc" path="res://healthbar/healthbar.gd" id="1_ubhit"]
[ext_resource type="PackedScene" uid="uid://em0xambhywfv" path="res://healthbar/heart.tscn" id="2_y66kq"]
[node name="Healthbar" type="HBoxContainer"]
offset_right = 40.0
offset_bottom = 40.0
tooltip_text = "This shows your health. If you lose it all, you die."
script = ExtResource("1_ubhit")
packedHeart = ExtResource("2_y66kq")

12
healthbar/heart.gd Normal file
View file

@ -0,0 +1,12 @@
class_name Heart extends MarginContainer
func _ready():
restore()
func restore():
$UP.visible = true
$DOWN.visible = false
func fade():
$UP.visible = false
$DOWN.visible = true

1
healthbar/heart.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://c60wm212fu1ti

16
healthbar/heart.tscn Normal file
View file

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://em0xambhywfv"]
[ext_resource type="Script" uid="uid://c60wm212fu1ti" path="res://healthbar/heart.gd" id="1_c17c5"]
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_kepki"]
[node name="Heart" type="MarginContainer"]
script = ExtResource("1_c17c5")
[node name="UP" type="TextureRect" parent="."]
layout_mode = 2
texture = ExtResource("1_kepki")
[node name="DOWN" type="TextureRect" parent="."]
modulate = Color(0.03137255, 0.21568628, 0.28627452, 1)
layout_mode = 2
texture = ExtResource("1_kepki")

View file

@ -1,15 +1,20 @@
[gd_scene load_steps=5 format=3 uid="uid://cxo6bq26huau7"]
[gd_scene load_steps=7 format=3 uid="uid://cxo6bq26huau7"]
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player.tscn" id="2_1bvp3"]
[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://ghost.tscn" id="3_h2yge"]
[ext_resource type="PackedScene" uid="uid://jjoyj1ldafkf" path="res://earth.tscn" id="3_lquwl"]
[ext_resource type="Script" uid="uid://colvx6wq0e8n7" path="res://building_generator.gd" id="4_1bvp3"]
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"]
[ext_resource type="Script" uid="uid://vgxh2xdevat7" path="res://world/earth.gd" id="2_lquwl"]
[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="3_h2yge"]
[ext_resource type="PackedScene" uid="uid://jjoyj1ldafkf" path="res://world/earth.tscn" id="3_lquwl"]
[ext_resource type="Script" uid="uid://colvx6wq0e8n7" path="res://world/building_generator.gd" id="4_1bvp3"]
[ext_resource type="PackedScene" uid="uid://cjsrtswk4vgf2" path="res://healthbar/healthbar.tscn" id="6_7mycd"]
[node name="main" type="Node2D"]
[node name="Earth" parent="." instance=ExtResource("3_lquwl")]
unique_name_in_owner = true
script = ExtResource("2_lquwl")
[node name="Player" parent="." instance=ExtResource("2_1bvp3")]
unique_name_in_owner = true
position = Vector2(500, -3100)
scale = Vector2(3, 3)
@ -18,3 +23,16 @@ position = Vector2(0, -3200)
[node name="Building Generator" type="Node" parent="."]
script = ExtResource("4_1bvp3")
[node name="Timer" type="Timer" parent="Building Generator"]
wait_time = 5.0
autostart = true
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Healthbar" parent="CanvasLayer" instance=ExtResource("6_7mycd")]
offset_right = 128.0
offset_bottom = 128.0
[connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"]
[connection signal="timeout" from="Building Generator/Timer" to="Building Generator" method="_on_timer_timeout"]

View file

@ -16,7 +16,12 @@ var air_jumps_max = 1;
var air_jumps_current = 1;
# HP and Iframes
var current_hp = 5;
signal health_changed(new_health : int)
var current_hp = 5:
set(new_hp):
current_hp = new_hp
health_changed.emit(current_hp)
var max_hp = 5;
var hit_invulnerability = 0.5
var inv_time = 0;

View file

@ -1,8 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://cmaovvr15b3qk"]
[ext_resource type="Script" uid="uid://ddidj1uau28ck" path="res://player.gd" id="1_4flbx"]
[ext_resource type="Texture2D" uid="uid://cyvxm1hf1rc12" path="res://player_walk.png" id="2_onrkg"]
[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://earth_aligner.tscn" id="3_i3pqv"]
[ext_resource type="Script" uid="uid://ddidj1uau28ck" path="res://player/player.gd" id="1_4flbx"]
[ext_resource type="Texture2D" uid="uid://cyvxm1hf1rc12" path="res://player/player_walk.png" id="2_onrkg"]
[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="3_i3pqv"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_onrkg"]

View file

@ -7,6 +7,6 @@ var angle = 0
func _ready() -> void:
parent = get_parent()
func _physics_process(delta: float) -> void:
func _physics_process(_delta: float) -> void:
angle = -(parent.position - center).angle_to(Vector2.UP)
parent.rotation = angle;

View file

@ -1 +1,22 @@
extends Node
@onready var grid : Grid = %Earth.get_grid()
func random_oppostite_collumn() -> int:
var playerpos = %Player.position
var player_angle = atan2(playerpos.y, playerpos.x)
var offset = randf_range(TAU/3, 2*TAU/3)
var spawn_angle = player_angle + offset
var collumn = int(spawn_angle / TAU * grid.num_collumns + grid.num_collumns) % grid.num_collumns
return collumn
func _on_timer_timeout() -> void:
var collumn = random_oppostite_collumn()
var building : Building = grid.packed_buildings[0].instantiate()
grid.add_building_to_collumn(building, collumn)

4
world/earth.gd Normal file
View file

@ -0,0 +1,4 @@
extends Node2D
func get_grid() -> Grid:
return $Grid

1
world/earth.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://vgxh2xdevat7

View file

@ -19,6 +19,7 @@ script = ExtResource("2_2bhor")
radius = 3000.0
[node name="Grid" type="Node2D" parent="."]
unique_name_in_owner = true
script = ExtResource("3_2bhor")
ground_radius = 3000.0
cell_height = 300.0

View file

@ -34,11 +34,11 @@ func add_building_to_collumn(building : Building, collumn : int):
add_child(building)
# for testing
func _ready() -> void:
for i in range(100):
var test_building = packed_buildings[0].instantiate()
var collumn = randi() % 60
add_building_to_collumn(test_building, collumn)
#func _ready() -> void:
#
#
#
#for i in range(100):
#var test_building = packed_buildings[0].instantiate()
#var collumn = randi() % 60
#add_building_to_collumn(test_building, collumn)