diff --git a/building.gd b/building.gd new file mode 100644 index 0000000..e252fdd --- /dev/null +++ b/building.gd @@ -0,0 +1,27 @@ +class_name Building extends Node2D + +var location : Vector2i # x is the angle, y is the height in the grid +var dimension : Vector2i = Vector2.ONE # same as above +@onready var grid : Grid = get_parent() + +# make sure location is set before adding a building to the scene tree +# also make sure that the buildings are instantiated as children of the grid +func _ready() -> void: + var angle = location.x * TAU / grid.num_collumns; # currently assumes anchor is bottom left + var height = grid.ground_radius + location.y * grid.cell_height; + position = height * Vector2.from_angle(angle) + print(angle, " ", height, " ", position) + +func overlaps(other : Building): + # heights don't overlap + if location.y >= other.location.y + other.dimension.y: return false # other is below + if location.y + dimension.y <= other.location.y: return false # other is above + + # angles overlap. We can now assume heights overlap + var relative_other_loc = (other.location.x - location.x + grid.num_collumns) % grid.num_collumns + if dimension.x > relative_other_loc: return true + if relative_other_loc + other.dimension > grid.num_collumns: return true + + # If we get here, angles do not overlap + return false + diff --git a/building.gd.uid b/building.gd.uid new file mode 100644 index 0000000..9a1e17b --- /dev/null +++ b/building.gd.uid @@ -0,0 +1 @@ +uid://b2ji03ekijjnn diff --git a/building.gdshader b/building.gdshader new file mode 100644 index 0000000..2c950f1 --- /dev/null +++ b/building.gdshader @@ -0,0 +1,39 @@ +shader_type canvas_item; + +varying flat ivec2 location; +varying flat ivec2 dimension; + +uniform float ground_height = 3000.; +uniform float cell_height = 300.; +uniform int num_cells = 60; + +varying vec2 world_position; + +void vertex() +{ + world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy; + location = ivec2(256. * COLOR.xy); + dimension = ivec2(256. * COLOR.zw); + //location = ivec2(45, 1); + //dimension = ivec2(1, 1); +} + +void fragment() { + float radius = sqrt(world_position.x * world_position.x + world_position.y * world_position.y); + float angle = atan(world_position.y, world_position.x); + + float sample_y = 1. - ((radius - ground_height) / cell_height - float( location.y)) / float(dimension.y); + float sample_x = mod(fract(angle / TAU + 1.) * float(num_cells) - float(location.x) + float(num_cells), float(num_cells)) / float(dimension.x); + + if(sample_y > 1. || sample_y < 0. || sample_x > 1. || sample_x < 0.) { + discard; + } + COLOR = texture(TEXTURE, vec2(sample_x, sample_y)); + //COLOR = vec4(ivec4(location, dimension)); + +} + +//void light() { +// // Called for every pixel for every light affecting the CanvasItem. +// // Uncomment to replace the default light processing function with this one. +//} diff --git a/building.gdshader.uid b/building.gdshader.uid new file mode 100644 index 0000000..984dac8 --- /dev/null +++ b/building.gdshader.uid @@ -0,0 +1 @@ +uid://c7gb1nqwvkr37 diff --git a/building.tscn b/building.tscn new file mode 100644 index 0000000..7ccd539 --- /dev/null +++ b/building.tscn @@ -0,0 +1,23 @@ +[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="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"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"] +resource_local_to_scene = true +shader = ExtResource("2_f1gjg") +shader_parameter/ground_height = 3000.0 +shader_parameter/cell_height = 300.0 +shader_parameter/num_cells = 60 + +[node name="Building" type="Node2D"] +script = ExtResource("1_5j34s") + +[node name="Sprite2D" type="Sprite2D" parent="."] +self_modulate = Color(0.1764706, 0, 0.003921569, 0.003921569) +material = SubResource("ShaderMaterial_qnfc1") +scale = Vector2(7, 7) +texture = ExtResource("2_2yopf") +script = ExtResource("4_qnfc1") diff --git a/building_mesh.gd b/building_mesh.gd new file mode 100644 index 0000000..7a381f4 --- /dev/null +++ b/building_mesh.gd @@ -0,0 +1,7 @@ +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) diff --git a/building_mesh.gd.uid b/building_mesh.gd.uid new file mode 100644 index 0000000..fc7bbb1 --- /dev/null +++ b/building_mesh.gd.uid @@ -0,0 +1 @@ +uid://dj7d4d2xs3nci diff --git a/draw_circle.gd b/draw_circle.gd index 2d87a9c..d9ac2d5 100644 --- a/draw_circle.gd +++ b/draw_circle.gd @@ -1,4 +1,4 @@ -extends Sprite2D +extends Node2D @export var radius : float; func _draw(): diff --git a/earth.tscn b/earth.tscn index 8856c90..a9b60d5 100644 --- a/earth.tscn +++ b/earth.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://jjoyj1ldafkf"] -[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_qbwya"] [ext_resource type="Script" uid="uid://b5fhsy1xlreco" path="res://draw_circle.gd" id="2_2bhor"] +[ext_resource type="Script" uid="uid://m3vyyfk8gnma" path="res://grid.gd" id="3_2bhor"] [sub_resource type="CircleShape2D" id="CircleShape2D_5i67w"] radius = 3000.0 @@ -13,7 +13,14 @@ radius = 3000.0 [node name="CollisionShape2D" type="CollisionShape2D" parent="Ground"] shape = SubResource("CircleShape2D_5i67w") -[node name="Sprite2D" type="Sprite2D" parent="Ground"] -texture = ExtResource("1_qbwya") +[node name="GroundVisual" type="Node2D" parent="Ground"] script = ExtResource("2_2bhor") radius = 3000.0 + +[node name="Grid" type="Node2D" parent="."] +script = ExtResource("3_2bhor") +ground_radius = 3000.0 +cell_height = 300.0 +num_collumns = 60 +debug = true +metadata/_custom_type_script = "uid://m3vyyfk8gnma" diff --git a/grid.gd b/grid.gd new file mode 100644 index 0000000..44510ef --- /dev/null +++ b/grid.gd @@ -0,0 +1,46 @@ +class_name Grid extends Node2D + +@export var ground_radius : float +@export var cell_height : float +@export var num_collumns : int +@export var debug : bool + +var buildings : Array[Building] = [] + +func _draw() -> void: + if !debug: + return + + for i in range(10): + draw_arc(Vector2.ZERO, ground_radius + i * cell_height, 0, TAU, 250, Color.SKY_BLUE, 1.0, true); + + for i in range(num_collumns): + var angle = i * TAU / num_collumns; + draw_line(Vector2.ZERO, 10000 * Vector2.from_angle(angle), Color.SKY_BLUE); + +func add_building_to_collumn(building : Building, collumn : int): + # find the height of the top building in the buildings list: + building.location = Vector2(collumn, 0) + var height = 0 + + # TODO: support other dimensions for buildings + + # add the new building one higher than the previous + height += 1 + building.location = Vector2i(collumn, height); + +# for testing +func _ready() -> void: + var packed : PackedScene = preload("res://building.tscn") + + var test_building = packed.instantiate() + test_building.location = Vector2(45, 0) + add_child(test_building) + + test_building = packed.instantiate() + test_building.location = Vector2(44, 0) + add_child(test_building) + + test_building = packed.instantiate() + test_building.location = Vector2(45, 1) + add_child(test_building) diff --git a/grid.gd.uid b/grid.gd.uid new file mode 100644 index 0000000..5298a7a --- /dev/null +++ b/grid.gd.uid @@ -0,0 +1 @@ +uid://m3vyyfk8gnma diff --git a/main.tscn b/main.tscn index 76688cd..a6ce021 100644 --- a/main.tscn +++ b/main.tscn @@ -6,11 +6,11 @@ [node name="main" type="Node2D"] +[node name="Earth" parent="." instance=ExtResource("3_lquwl")] + [node name="Player" parent="." instance=ExtResource("2_1bvp3")] position = Vector2(500, -3100) scale = Vector2(3, 3) -[node name="Earth" parent="." instance=ExtResource("3_lquwl")] - [node name="Ghost" parent="." instance=ExtResource("3_h2yge")] position = Vector2(0, -3200) diff --git a/player_walk.png.import b/player_walk.png.import index 37dc416..e86412e 100644 --- a/player_walk.png.import +++ b/player_walk.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/player_walk.png-dd7b13f797aca66ef3a8a41ed9897 compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/project.godot b/project.godot index 9f3af5a..e7a6cbd 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="The Dark Side of Earth" run/main_scene="uid://cxo6bq26huau7" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" [display]