Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Felis 3e251d2843 Intermediate commit 2024-05-07 18:49:04 +02:00
Martin Felis a74145fc57 Moved Action UI 2024-02-28 21:47:40 +01:00
8 changed files with 261 additions and 79 deletions

View File

@ -79,8 +79,8 @@ tracks/2/keys = {
[sub_resource type="PrismMesh" id=15]
[sub_resource type="BoxShape" id=16]
extents = Vector3( 0.19, 0.19, 0.33 )
[sub_resource type="SphereShape" id=19]
radius = 0.359562
[sub_resource type="CubeMesh" id=17]
size = Vector3( 0.38, 0.38, 0.66 )
@ -133,8 +133,8 @@ skeleton = NodePath("../..")
[node name="ResourceContainer" type="Node" parent="."]
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( -0.866026, 0, 0.5, 0, 1, 0, -0.5, 0, -0.866026, 0, 0.240716, 0 )
shape = SubResource( 16 )
transform = Transform( -0.866026, 0, 0.5, 0, 1, 0, -0.5, 0, -0.866026, 0, 0.110576, 0 )
shape = SubResource( 19 )
[node name="MeshInstance" type="MeshInstance" parent="CollisionShape" groups=["PhysicsGeometry"]]
mesh = SubResource( 17 )

View File

@ -88,7 +88,6 @@ script = ExtResource( 3 )
[node name="MountPoint" type="Spatial" parent="."]
transform = Transform( -0.524001, 0, -0.851718, 0, 1, 0, 0.851718, 0, -0.524001, 0.717306, 0, 0.400936 )
visible = false
[node name="Arrow" type="Spatial" parent="MountPoint"]
transform = Transform( -1, 0, -8.74227e-08, 0, 1, 0, 8.74227e-08, 0, -1, 2.38419e-07, 0, 0 )

View File

@ -1,10 +1,45 @@
using System.Diagnostics;
using Godot;
public class Workbench : Entity {
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
public bool IsMouseOver;
private MeshInstance _geometry;
[Signal]
public delegate void EntityClicked(Entity entity);
// Called when the node enters the scene tree for the first time.
public override void _Ready() { }
public override void _Ready() {
_geometry = GetNode<MeshInstance>("Geometry/workbench");
Debug.Assert(_geometry != null);
Connect("input_event", this, nameof(OnAreaInputEvent));
Connect("mouse_entered", this, nameof(OnAreaMouseEntered));
Connect("mouse_exited", this, nameof(OnAreaMouseExited));
}
public void OnAreaInputEvent(Node camera, InputEvent inputEvent, Vector3 position, Vector3 normal,
int shapeIndex) {
if (IsMouseOver && inputEvent is InputEventMouseButton) {
InputEventMouseButton mouseButtonEvent = (InputEventMouseButton)inputEvent;
if (mouseButtonEvent.ButtonIndex == 1 && mouseButtonEvent.Pressed) {
EmitSignal("EntityClicked", this);
}
}
}
public void OnAreaMouseEntered() {
IsMouseOver = true;
SpatialMaterial overrideMaterial = new();
overrideMaterial.AlbedoColor = new Color(1, 0, 0);
_geometry.MaterialOverride = overrideMaterial;
}
public void OnAreaMouseExited() {
IsMouseOver = false;
_geometry.MaterialOverride = null;
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://assets/KenneySurvivalKit/Models/workbench.glb" type="PackedScene" id=1]
[ext_resource path="res://entities/Workbench.cs" type="Script" id=2]
@ -13,6 +13,10 @@ size = Vector3( 0.38, 0.38, 0.66 )
flags_transparent = true
albedo_color = Color( 0.380392, 0.145098, 0.145098, 0.501961 )
[sub_resource type="CubeMesh" id=4]
[sub_resource type="PrismMesh" id=5]
[node name="Workbench" type="KinematicBody"]
script = ExtResource( 2 )
@ -24,5 +28,24 @@ transform = Transform( -1.29904, 0, 0.5, 0, 1.5, 0, -0.749999, 0, -0.866026, 0,
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="CollisionShape" groups=["PhysicsGeometry"]]
visible = false
mesh = SubResource( 2 )
material/0 = SubResource( 3 )
[node name="MountPoint" type="Spatial" parent="."]
transform = Transform( -0.861434, 0, 0.507869, 0, 1, 0, -0.507869, 0, -0.861434, -0.429363, 0, 0.763898 )
[node name="Arrow" type="Spatial" parent="MountPoint"]
transform = Transform( -1, 0, -8.74227e-08, 0, 1, 0, 8.74227e-08, 0, -1, 2.38419e-07, 0, 0 )
[node name="MeshInstance" type="MeshInstance" parent="MountPoint/Arrow"]
transform = Transform( -0.1, 0, -1.24676e-08, 0, 0.1, 0, 1.24676e-08, 0, -0.1, 0, 0, 0.0394838 )
mesh = SubResource( 4 )
skeleton = NodePath("../..")
[node name="MeshInstance2" type="MeshInstance" parent="MountPoint/Arrow"]
transform = Transform( -0.1, -1.24676e-08, 6.04182e-16, 0, -4.37114e-09, -0.1, 1.24676e-08, -0.1, 4.37114e-09, 0, 0, -0.151838 )
mesh = SubResource( 5 )
skeleton = NodePath("../..")
[editable path="Geometry"]

View File

@ -49,7 +49,7 @@ ivec2 voronoiCellId(vec2 uv, vec2 grid_size) {
vec2 index_uv = floor(uv * grid_size);
vec2 fract_uv = fract(uv * grid_size);
float minimum_dist = 1.0;
float minimum_dist = 1.0;
vec2 minimum_point;
vec2 minimum_neighbour;
@ -72,51 +72,95 @@ ivec2 voronoiCellId(vec2 uv, vec2 grid_size) {
return ivec2(minimum_neighbour);
}
void fragment() {
// float worley = worley(UV, 6.0, 6.0);
vec3 voronoi_cell_id_and_border_dist(vec2 uv, vec2 grid_size) {
vec2 index_uv = floor(uv * grid_size);
vec2 fract_uv = fract(uv * grid_size);
int biome_count = 4;
float big_columns = 0.2;
float big_rows = 0.2;
float minimum_dist = 1.0;
vec2 minimum_neighbour;
vec2 cell_point = rand2d(index_uv);
float border_dist = 1.0;
float columns = 0.1;
float rows = 0.1;
vec2 uv = UV / 0.01;
vec2 offset = vec2(sin(TIME * 0.1), cos(TIME * 0.1));
uv += offset;
vec2 index_uv = floor(vec2(uv.x * columns, uv.y * rows));
vec2 segment_big = voronoi_segment(uv + offset + vec2(1.0, 3.0), big_columns, big_rows);
int biome_big = int(floor(rand1d(segment_big) * float(5)));
vec2 segment = voronoi_segment(uv + offset, columns, rows);
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 neighbour = vec2(float(x), float(y));
vec2 point = rand2d(index_uv + neighbour);
vec2 diff = neighbour + point - fract_uv;
float dist = length(diff);
if (dist < minimum_dist) {
minimum_dist = dist;
minimum_neighbour = index_uv + neighbour;
// segment = index_uv;
int biome_id = int(ceil(rand1d(segment) * float(biome_count)));
if (biome_big < 4) {
biome_id = 0;
float cell_point_dist = length(neighbour + point - cell_point);
border_dist = (cell_point_dist * 0.5 - dist);
border_dist = 1.0 - dist;
}
}
}
int cell_rows = 6;
int cell_cols = 6;
return vec3(minimum_neighbour, border_dist);
}
vec4 biomeValue (vec2 uv, vec2 grid_size) {
vec2 index_uv = floor(uv * grid_size);
vec2 fract_uv = fract(uv * grid_size);
float minimum_dist = 1.0;
vec2 minimum_point;
vec2 minimum_neighbour;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 neighbour = vec2(float(x), float(y));
vec2 point = rand2d(index_uv + neighbour);
vec2 diff = neighbour + point - fract_uv;
float dist = length(diff);
if (dist < minimum_dist) {
minimum_dist = dist;
minimum_point = point;
minimum_neighbour = index_uv + neighbour;
}
}
}
float biomeId = rand1d(minimum_neighbour);
if (biomeId < 0.2) {
return SandColor;
} else if (biomeId < 0.4) {
return GrassColor;
} else if (biomeId < 0.6) {
return RockColor;
} else if (biomeId < 0.8) {
return SnowColor;
} else {
return ForestColor;
}
}
void fragment() {
vec2 uv = UV / 0.01;
vec2 offset = vec2(sin(TIME * 0.6), cos(TIME * 0.6)) * 14.0;
ivec2 cellId = voronoiCellId(uv + offset, vec2(0.125, 0.125));
vec4 water_land_value = rand1d(vec2(cellId)) < 0.66 ? GrassColor : DeepWaterColor;
vec4 water_land_value = rand1d(vec2(cellId)) < 0.66 ? DeepWaterColor : GrassColor;
vec4 biome_id_value = biomeValue(uv + offset, vec2(0.14, 0.14));
// COLOR = vec4(water_land_value.xyz, 0.4) + vec4 (biome_id_value.xyz, 0.3);
if (water_land_value == DeepWaterColor) {
COLOR = water_land_value;
} else {
COLOR = biome_id_value;
}
COLOR = water_land_value;
vec3 cellIdAndBorderDist = voronoi_cell_id_and_border_dist(uv + offset, vec2(0.125, 0.125));
// COLOR = vec4(float((cellId.x)) * 0.01, 0.0, 0.0, 1.0);
// if (biome_id == 0) {
// COLOR = DeepWaterColor;
// } else if (biome_id == 1) {
// COLOR = GrassColor;
// } else if (biome_id == 2) {
// COLOR = SandColor;
// } else if (biome_id == 3) {
// COLOR = RockColor;
// } else if (biome_id == 4) {
// COLOR = SnowColor;
// } else {
// COLOR = vec4(float(biome_id) / float(biome_count), 0.0, 0.0, 1.0);
// }
//COLOR = vec4(rand2d(vec2(cellIdAndBorderDist.xy)), 0.0, cellIdAndBorderDist.z);
COLOR = vec4(cellIdAndBorderDist.z, 0., 0., 1.0);
}

View File

@ -67,9 +67,9 @@ public class Game : Spatial {
Debug.Assert(_woodCountLabel != null);
_goldCountLabel = _gameUi.GetNode<Label>("TopRight/GoldCount");
Debug.Assert(_goldCountLabel != null);
_walkActionButton = _gameUi.GetNode<Button>("BottomCenter/WalkActionButton");
_walkActionButton = _gameUi.GetNode<Button>("Actions/WalkActionButton");
Debug.Assert(_walkActionButton != null);
_buildActionButton = _gameUi.GetNode<Button>("BottomCenter/BuildActionButton");
_buildActionButton = _gameUi.GetNode<Button>("Actions/BuildActionButton");
Debug.Assert(_buildActionButton != null);
// scene nodes
@ -216,7 +216,9 @@ public class Game : Spatial {
if (_actionMode == ActionMode.Building) {
Workbench workbench = (Workbench)_workbenchScene.Instance();
workbench.Connect("EntityClicked", this, nameof(OnEntityClicked));
workbench.Transform = tile.GlobalTransform;
AddChild(workbench);
_world.MarkCellUnwalkable(tile.Cell);

View File

@ -135,17 +135,12 @@ align = 1
root_node = NodePath("../..")
anims/FlashLabel = SubResource( 25 )
[node name="BottomCenter" type="HBoxContainer" parent="GameUI"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -61.0
margin_top = -46.0
margin_right = 59.0
margin_bottom = -6.0
[node name="Actions" type="HBoxContainer" parent="GameUI"]
margin_left = 10.0
margin_top = 10.0
margin_bottom = 40.0
[node name="WalkActionButton" type="Button" parent="GameUI/BottomCenter"]
[node name="WalkActionButton" type="Button" parent="GameUI/Actions"]
margin_right = 58.0
margin_bottom = 40.0
rect_min_size = Vector2( 40, 40 )
@ -154,7 +149,7 @@ pressed = true
group = ExtResource( 13 )
text = "Walk"
[node name="BuildActionButton" type="Button" parent="GameUI/BottomCenter"]
[node name="BuildActionButton" type="Button" parent="GameUI/Actions"]
margin_left = 62.0
margin_right = 120.0
margin_bottom = 40.0
@ -407,8 +402,9 @@ text = "4"
[node name="WorldGenerateButton" type="Button" parent="Generator Container/WorldGeneratorWidget"]
visible = false
margin_top = 20.0
margin_right = 135.0
margin_bottom = 20.0
margin_bottom = 40.0
text = "Generate"
[node name="ShowTexturesCheckButton" type="CheckButton" parent="Generator Container/WorldGeneratorWidget"]
@ -428,9 +424,9 @@ flip_v = true
[node name="HeightTextureRect" type="TextureRect" parent="Generator Container/WorldGeneratorWidget"]
visible = false
margin_top = 88.0
margin_top = 192.0
margin_right = 135.0
margin_bottom = 188.0
margin_bottom = 292.0
rect_min_size = Vector2( 100, 100 )
expand = true
stretch_mode = 5
@ -501,12 +497,44 @@ anchor_top = 0.1
anchor_right = 0.9
anchor_bottom = 0.9
[node name="Panel" type="Panel" parent="GameMenu"]
[node name="MainMenu" type="Panel" parent="GameMenu"]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="MainMenu" type="VBoxContainer" parent="GameMenu/Panel"]
[node name="MainMenu" type="VBoxContainer" parent="GameMenu/MainMenu"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -41.0
margin_top = -22.0
margin_right = 41.0
margin_bottom = 22.0
[node name="Label" type="Label" parent="GameMenu/MainMenu/MainMenu"]
margin_right = 82.0
margin_bottom = 14.0
text = "Pirate Game"
align = 1
[node name="NewGameButton" type="Button" parent="GameMenu/MainMenu/MainMenu"]
margin_top = 18.0
margin_right = 82.0
margin_bottom = 38.0
text = "New Game"
[node name="QuitButton" type="Button" parent="GameMenu/MainMenu/MainMenu"]
margin_top = 42.0
margin_right = 82.0
margin_bottom = 62.0
text = "Quit"
[node name="NewGameMenu" type="Panel" parent="GameMenu"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
[node name="MainMenu" type="VBoxContainer" parent="GameMenu/NewGameMenu"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
@ -516,18 +544,18 @@ margin_top = -10.0
margin_right = 41.0
margin_bottom = 10.0
[node name="NewGameButton" type="Button" parent="GameMenu/Panel/MainMenu"]
[node name="NewGameButton" type="Button" parent="GameMenu/NewGameMenu/MainMenu"]
margin_right = 82.0
margin_bottom = 20.0
text = "New Game"
[node name="QuitButton" type="Button" parent="GameMenu/Panel/MainMenu"]
[node name="QuitButton" type="Button" parent="GameMenu/NewGameMenu/MainMenu"]
margin_top = 24.0
margin_right = 82.0
margin_bottom = 44.0
text = "Quit"
[node name="WorldGeneratorUI" parent="GameMenu/Panel" instance=ExtResource( 8 )]
[node name="WorldGeneratorUI" parent="GameMenu/NewGameMenu" instance=ExtResource( 8 )]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
@ -537,11 +565,55 @@ margin_top = -160.0
margin_right = 143.5
margin_bottom = 160.0
[node name="VBoxContainer" parent="GameMenu/Panel/WorldGeneratorUI" index="0"]
[node name="VBoxContainer" parent="GameMenu/NewGameMenu/WorldGeneratorUI" index="0"]
margin_left = 0.0
margin_top = 41.0
margin_top = 21.0
margin_right = 287.0
margin_bottom = 279.0
margin_bottom = 299.0
[node name="Label" parent="GameMenu/NewGameMenu/WorldGeneratorUI/VBoxContainer" index="0"]
text = "New World"
[node name="GameRunningMenu" type="Panel" parent="GameMenu"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="VBoxContainer" type="VBoxContainer" parent="GameMenu/GameRunningMenu"]
margin_left = 107.0
margin_top = 113.0
margin_right = 148.0
margin_bottom = 207.0
custom_constants/separation = 20
[node name="Label" type="Label" parent="GameMenu/GameRunningMenu/VBoxContainer"]
margin_right = 42.0
margin_bottom = 14.0
align = 1
[node name="SaveButton" type="Button" parent="GameMenu/GameRunningMenu/VBoxContainer"]
margin_top = 34.0
margin_right = 42.0
margin_bottom = 54.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Save"
[node name="LoadButton" type="Button" parent="GameMenu/GameRunningMenu/VBoxContainer"]
margin_top = 74.0
margin_right = 42.0
margin_bottom = 94.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Load"
[node name="QuitButton" type="Button" parent="GameMenu/GameRunningMenu/VBoxContainer"]
margin_top = 114.0
margin_right = 42.0
margin_bottom = 134.0
text = "Quit"
[connection signal="toggled" from="DebugContainer/DebugStatsContainer/DebugMenuButton" to="DebugContainer/DebugStatsContainer" method="_on_DebugMenuButton_toggled"]
[connection signal="value_changed" from="Generator Container/WorldGeneratorWidget/HBoxContainer/WorldSizeSlider" to="Generator Container/WorldGeneratorWidget" method="_on_HSlider_value_changed"]
@ -550,4 +622,4 @@ margin_bottom = 279.0
[editable path="Player"]
[editable path="Player/Geometry/PirateAsset"]
[editable path="World"]
[editable path="GameMenu/Panel/WorldGeneratorUI"]
[editable path="GameMenu/NewGameMenu/WorldGeneratorUI"]

View File

@ -9,9 +9,9 @@ script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 16.0
margin_top = 81.0
margin_top = 61.0
margin_right = 303.0
margin_bottom = 319.0
margin_bottom = 339.0
custom_constants/separation = 20
[node name="Label" type="Label" parent="VBoxContainer"]
@ -110,12 +110,19 @@ pressed = true
text = "Rocks"
[node name="GenerateButton" type="Button" parent="VBoxContainer"]
margin_left = 216.0
margin_top = 218.0
margin_right = 287.0
margin_bottom = 238.0
size_flags_horizontal = 8
size_flags_horizontal = 3
text = "Generate"
[node name="Back" type="Button" parent="VBoxContainer"]
margin_top = 258.0
margin_right = 287.0
margin_bottom = 278.0
size_flags_horizontal = 3
text = "Back"
[connection signal="pressed" from="VBoxContainer/GridContainer/RefreshSeedButton" to="." method="_on_RefreshSeedButton_pressed"]
[connection signal="pressed" from="VBoxContainer/GenerateButton" to="." method="_on_GenerateButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Back" to="." method="_on_GenerateButton_pressed"]