1
0
Fork 0

Initial commit

This commit is contained in:
Fabio Iotti 2024-08-06 22:46:05 +02:00
commit 9e5712a9e4
Signed by: bruce965
GPG key ID: 4EC13D9158A96B4C
33 changed files with 902 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

47
game_logic/game_logic.gd Normal file
View file

@ -0,0 +1,47 @@
extends Node
class_name GameLogic
const LOGIC_TICKS_PER_SECOND: float = 20.;
const LOGIC_SECONDS_PER_TICK = 1. / LOGIC_TICKS_PER_SECOND;
## Neutral player owning all non-conquered planets.
@export var neutral_player: Player
## Game players.
@export var players: Array[Player] = []
## Game planets.
@export var planets: Array[Planet] = []
var ticks_count: int
var extra_time: float
signal game_start(game: GameLogic)
signal game_tick(game: GameLogic, tick: int)
func _ready() -> void:
_game_init()
game_start.emit(self)
func _game_init() -> void:
ticks_count = 0
extra_time = 0.
for player in players:
game_start.connect(player._on_game_start)
game_tick.connect(player._on_game_tick)
for i in range(planets.size()):
var planet := planets[i]
planet.player = players[i] if i < players.size() else neutral_player
planet.is_selected = false
game_start.connect(planet._on_game_start)
game_tick.connect(planet._on_game_tick)
func _process(delta: float) -> void:
extra_time += delta
while extra_time > LOGIC_SECONDS_PER_TICK:
extra_time -= LOGIC_SECONDS_PER_TICK
game_tick.emit(self, ticks_count)
ticks_count += 1

1
icon.svg Normal file
View file

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z" fill="#478cbf"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

After

Width:  |  Height:  |  Size: 949 B

37
icon.svg.import Normal file
View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://boxf3gcbj35ty"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

6
icons/character.svg Normal file
View file

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs/>
<g>
<path stroke="none" fill="#FFFFFF" d="M-23.45 4.9 Q-19.7 -3.1 -14.05 -7.5 -11.9 -9.3 -10.25 -10.2 -8.5 -11.2 -8.85 -13.2 L-9 -15 Q-9 -18.7 -6.35 -21.35 -3.75 -24 0 -24 3.7 -24 6.35 -21.35 9 -18.7 9 -15 L8.8 -13.2 Q8.5 -11.2 10.25 -10.2 11.85 -9.3 14.05 -7.5 19.75 -3.1 23.45 4.9 L23.95 6.75 24 7.4 23.75 8.85 23.7 9.05 22.75 10.45 Q21.45 11.7 19.7 11.7 17.95 11.7 16.65 10.45 L16.2 9.9 13.55 5.7 13.45 5.6 13.3 5.45 Q12.95 5.05 12.4 5.05 11.85 5.05 11.45 5.45 11.1 5.8 11.1 6.35 L11.1 6.4 Q11.1 7.6 13.1 12.3 15.1 16.95 15.85 19.75 L15.85 19.95 16 20.8 Q15.95 22.1 15.2 22.85 L13.75 23.85 12.7 24 11.6 24 5.45 24 5.35 24 Q4.35 24 3.6 23.5 L3.05 23.05 2.55 22.45 2.2 21.5 2.05 20.9 1 14.95 1 14.9 0.7 14.35 Q0.4 14.05 0 14.05 -0.45 14.05 -0.75 14.35 L-1 14.9 -1 14.95 -2.05 20.9 -2.2 21.5 -2.6 22.45 -3.05 23.05 -3.6 23.5 Q-4.4 24 -5.35 24 L-5.45 24 -11.6 24 -12.75 24 -13.8 23.85 -15.2 22.85 Q-15.95 22.1 -16 20.8 L-15.9 19.95 -15.85 19.75 Q-15.15 16.95 -13.1 12.3 -11.15 7.6 -11.15 6.4 L-11.15 6.35 Q-11.15 5.8 -11.45 5.45 -11.9 5.05 -12.4 5.05 -12.95 5.05 -13.3 5.45 L-13.45 5.6 -13.55 5.7 -16.25 9.9 -16.7 10.45 Q-17.95 11.7 -19.7 11.7 -21.5 11.7 -22.75 10.45 L-23.75 9.05 -23.75 8.85 -24 7.4 -24 6.75 -23.45 4.9"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://1xh0qil16bkh"
path="res://.godot/imported/character.svg-980139dddf48522251091267b0dd013b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/character.svg"
dest_files=["res://.godot/imported/character.svg-980139dddf48522251091267b0dd013b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=0.35
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

5
icons/chip.svg Normal file
View file

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" >
<path d="M7.075 7.075h33.849v33.849H7.075z" fill="#fff"/>
<path stroke="#fff" stroke-width="6" stroke-linecap="round" d="M44.987 24H3.013m41.974 10H3.013m41.974-20H3.013M24 44.987V3.013M14 44.987V3.013m20 41.974V3.013"/>
</svg>

After

Width:  |  Height:  |  Size: 275 B

37
icons/chip.svg.import Normal file
View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dx1wjviioa8u5"
path="res://.godot/imported/chip.svg-38da4fcc64986263507aa38009bdad12.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/chip.svg"
dest_files=["res://.godot/imported/chip.svg-38da4fcc64986263507aa38009bdad12.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=0.35
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

51
icons/paw_print.svg Normal file
View file

@ -0,0 +1,51 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="1085.000000pt" height="1280.000000pt" viewBox="0 0 1085.000000 1280.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)"
fill="#fff" stroke="none">
<path d="M4016 12755 c4 -16 107 -408 230 -870 l222 -840 -28 -40 c-66 -96
-136 -273 -159 -402 -6 -32 -15 -116 -20 -188 -8 -115 -6 -148 15 -290 84
-567 210 -1001 421 -1448 35 -76 62 -141 59 -144 -8 -9 43 -97 144 -248 245
-364 526 -654 805 -830 309 -194 586 -255 824 -180 634 200 710 1343 166 2473
-348 722 -863 1279 -1365 1476 -158 62 -369 159 -384 175 -8 9 -218 320 -466
691 -249 371 -457 680 -462 685 -6 6 -7 -1 -2 -20z"/>
<path d="M1452 11660 c3 -8 22 -67 42 -130 21 -63 114 -349 208 -635 93 -286
192 -587 218 -670 l49 -150 -43 -170 c-24 -93 -53 -201 -65 -240 -45 -149 -55
-236 -55 -490 0 -254 10 -350 60 -580 101 -469 310 -952 594 -1375 496 -741
1164 -1150 1624 -996 269 91 436 332 508 736 17 98 17 492 -1 620 -28 209 -91
470 -161 673 -49 142 -77 207 -95 221 -8 6 -37 63 -65 125 -60 136 -125 260
-228 433 -155 260 -314 461 -567 714 -148 148 -215 207 -305 269 -130 89 -268
157 -385 190 -85 25 -257 50 -279 42 -7 -3 -52 26 -99 64 l-86 69 -427 637
c-235 351 -431 643 -437 648 -7 7 -8 5 -5 -5z"/>
<path d="M7980 11278 c-19 -5 -36 -11 -38 -12 -1 -2 32 -54 73 -116 210 -314
376 -773 429 -1185 22 -164 21 -175 -7 -175 -57 0 -189 -59 -272 -120 -300
-223 -510 -680 -587 -1280 -19 -154 -16 -609 5 -773 113 -852 502 -1472 967
-1539 495 -73 931 517 1035 1399 20 171 20 575 0 746 -41 347 -122 636 -256
916 -57 120 -69 153 -69 195 0 70 -25 217 -60 356 -144 568 -528 1215 -880
1477 -118 89 -260 135 -340 111z"/>
<path d="M123 7451 c-69 -43 -110 -155 -120 -326 -27 -514 373 -1415 819
-1840 87 -84 99 -99 147 -200 133 -279 298 -504 560 -765 256 -255 536 -458
836 -605 603 -297 1141 -309 1415 -33 152 153 208 406 150 687 -103 509 -527
1080 -1115 1503 -356 256 -758 423 -1125 468 -256 31 -483 -19 -649 -142 l-53
-40 -75 73 c-164 161 -351 399 -472 601 -111 186 -271 553 -271 622 0 21 -8
20 -47 -3z"/>
<path d="M6120 6183 c-319 -23 -648 -174 -877 -402 -158 -157 -257 -310 -292
-452 -65 -263 -88 -550 -72 -894 24 -498 24 -495 7 -592 -36 -207 -140 -454
-262 -623 -33 -46 -96 -114 -152 -162 -162 -142 -334 -343 -465 -543 -196
-302 -257 -487 -272 -830 -16 -340 82 -674 286 -981 98 -146 294 -344 435
-437 175 -116 382 -202 589 -244 73 -15 132 -18 315 -16 452 3 586 53 865 324
164 159 226 238 365 462 58 92 146 223 197 292 103 137 285 331 402 429 227
189 510 327 821 400 222 53 311 61 655 61 288 -1 343 -3 555 -29 181 -22 257
-27 332 -22 321 20 578 145 844 410 95 95 150 160 199 234 351 539 338 1227
-36 1788 -83 124 -280 329 -391 408 -165 116 -335 196 -518 245 -209 55 -241
56 -505 10 -286 -50 -385 -59 -551 -48 -265 17 -530 108 -744 255 -46 31 -252
211 -459 400 -373 342 -375 344 -485 398 -180 89 -348 137 -546 155 -112 11
-145 11 -240 4z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bydmcc5d53ldx"
path="res://.godot/imported/paw_print.svg-fd2b5b3c4380c761c0e8f755d2e1017e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/paw_print.svg"
dest_files=["res://.godot/imported/paw_print.svg-fd2b5b3c4380c761c0e8f755d2e1017e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=0.01
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

74
main.tscn Normal file
View file

@ -0,0 +1,74 @@
[gd_scene load_steps=11 format=3 uid="uid://cdaf4bh0jaa45"]
[ext_resource type="PackedScene" uid="uid://dq00mi6jwsa1f" path="res://scenes/planet/planet.tscn" id="1_0p552"]
[ext_resource type="Script" path="res://game_logic/game_logic.gd" id="1_kb05v"]
[ext_resource type="Script" path="res://scenes/player/player.gd" id="2_plgh6"]
[ext_resource type="Texture2D" uid="uid://bydmcc5d53ldx" path="res://icons/paw_print.svg" id="3_mxakn"]
[ext_resource type="Texture2D" uid="uid://1xh0qil16bkh" path="res://icons/character.svg" id="3_qxmev"]
[ext_resource type="Script" path="res://scenes/player/local_player.gd" id="4_7rlmh"]
[ext_resource type="Texture2D" uid="uid://dx1wjviioa8u5" path="res://icons/chip.svg" id="4_pgo63"]
[ext_resource type="Script" path="res://ui.gd" id="7_khbdl"]
[ext_resource type="PackedScene" uid="uid://cpffyaoh8x5bp" path="res://scenes/ships_fleet/ships_fleet.tscn" id="9_be18b"]
[ext_resource type="PackedScene" uid="uid://ckfk1xgxfk1c3" path="res://scenes/trail/trail.tscn" id="10_b5ql7"]
[node name="Main" type="Node"]
[node name="Logic" type="Node" parent="." node_paths=PackedStringArray("neutral_player", "players", "planets")]
script = ExtResource("1_kb05v")
neutral_player = NodePath("Players/0_Nature")
players = [NodePath("Players/1_LocalPlayer"), NodePath("Players/2_AI")]
planets = [NodePath("../Game/Planets/Planet1"), NodePath("../Game/Planets/Planet2"), NodePath("../Game/Planets/Planet3"), NodePath("../Game/Planets/Planet4")]
[node name="Players" type="Node" parent="Logic"]
[node name="0_Nature" type="Node" parent="Logic/Players"]
script = ExtResource("2_plgh6")
color = Color(0.745, 0.745, 0.745, 1)
icon = ExtResource("3_mxakn")
[node name="1_LocalPlayer" type="Node" parent="Logic/Players" node_paths=PackedStringArray("ui")]
script = ExtResource("4_7rlmh")
ui = NodePath("../../../UI")
color = Color(0.184314, 0.329412, 1, 1)
icon = ExtResource("3_qxmev")
[node name="2_AI" type="Node" parent="Logic/Players"]
script = ExtResource("2_plgh6")
color = Color(0.835294, 0.160784, 0, 1)
icon = ExtResource("4_pgo63")
[node name="Game" type="Node2D" parent="."]
[node name="Planets" type="Node2D" parent="Game"]
[node name="Planet1" parent="Game/Planets" instance=ExtResource("1_0p552")]
position = Vector2(200, 200)
[node name="Planet2" parent="Game/Planets" instance=ExtResource("1_0p552")]
position = Vector2(952, 448)
[node name="Planet3" parent="Game/Planets" instance=ExtResource("1_0p552")]
position = Vector2(450, 234)
[node name="Planet4" parent="Game/Planets" instance=ExtResource("1_0p552")]
position = Vector2(702, 414)
[node name="ShipsFleet" parent="." instance=ExtResource("9_be18b")]
position = Vector2(246, 394)
count = 29
[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("7_khbdl")
[node name="Trail" parent="UI" instance=ExtResource("10_b5ql7")]
position = Vector2(577.094, 325.561)
rotation = 0.610903
scale = Vector2(4.53022, 1)
color = Color(0.184314, 0.329412, 1, 1)

21
project.godot Normal file
View file

@ -0,0 +1,21 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Space Capture"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"
[rendering]
renderer/rendering_method="mobile"
environment/defaults/default_clear_color=Color(0, 0, 0, 1)

51
scenes/planet/planet.gd Normal file
View file

@ -0,0 +1,51 @@
extends Node2D
class_name Planet
## The player currenly controlling this planet.
var player: Player :
set(value):
player = value
var color := Color.MAGENTA if player == null else player.color
%Selection.color = color
%PopulationLabel.modulate = color
%PopulationIcon.modulate = color
%PopulationIcon.texture = null if player == null else player.icon
## Number of units currently stationed at the planet.
@export var population: int :
set(value):
population = value
%PopulationLabel.text = "%s" % value
func _ready() -> void:
is_selected = false
func _on_game_start(game: GameLogic) -> void:
pass
func _on_game_tick(game: GameLogic, tick: int) -> void:
if player != game.neutral_player and tick % 10 == 0:
population += 1
@export_category("UI")
signal selected(planet: Planet)
signal pointer_entered(planet: Planet)
signal pointer_exited(planet: Planet)
var is_selected: bool :
get:
return %Selection.visible
set(value):
%Selection.visible = value
func _on_input_listener_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
# TODO: handle touch appropriately (InputEventScreenTouch).
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed():
selected.emit(self)
func _on_input_listener_mouse_entered() -> void:
pointer_entered.emit(self)
func _on_input_listener_mouse_exited() -> void:
pointer_exited.emit(self)

78
scenes/planet/planet.tscn Normal file
View file

@ -0,0 +1,78 @@
[gd_scene load_steps=7 format=3 uid="uid://dq00mi6jwsa1f"]
[ext_resource type="PackedScene" uid="uid://dnerbdusnaofr" path="res://scenes/procedural_planet/procedural_planet.tscn" id="1_8mf3x"]
[ext_resource type="Script" path="res://scenes/planet/planet.gd" id="1_e208c"]
[ext_resource type="Shader" path="res://scenes/planet/planet_selection.gdshader" id="2_bl05u"]
[ext_resource type="Texture2D" uid="uid://1xh0qil16bkh" path="res://icons/character.svg" id="2_kglxp"]
[sub_resource type="CircleShape2D" id="CircleShape2D_tsywx"]
radius = 50.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_lnvto"]
shader = ExtResource("2_bl05u")
shader_parameter/size = 100.0
[node name="Planet" type="Node2D"]
script = ExtResource("1_e208c")
[node name="InputListener" type="Area2D" parent="."]
monitoring = false
monitorable = false
[node name="CollisionShape" type="CollisionShape2D" parent="InputListener"]
shape = SubResource("CircleShape2D_tsywx")
[node name="Earth" parent="." instance=ExtResource("1_8mf3x")]
[node name="Selection" type="ColorRect" parent="."]
unique_name_in_owner = true
visible = false
material = SubResource("ShaderMaterial_lnvto")
offset_left = -100.0
offset_top = -100.0
offset_right = 100.0
offset_bottom = 100.0
mouse_filter = 2
[node name="Population" type="PanelContainer" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -0.5
offset_top = -11.5
offset_right = 0.5
offset_bottom = 11.5
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
mouse_filter = 2
[node name="PopulationMargin" type="MarginContainer" parent="Population"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_left = 4
theme_override_constants/margin_right = 2
[node name="PopulationBox" type="HBoxContainer" parent="Population/PopulationMargin"]
layout_mode = 2
mouse_filter = 2
[node name="PopulationLabel" type="Label" parent="Population/PopulationMargin/PopulationBox"]
unique_name_in_owner = true
layout_mode = 2
text = "0"
[node name="PopulationIcon" type="TextureRect" parent="Population/PopulationMargin/PopulationBox"]
unique_name_in_owner = true
layout_mode = 2
mouse_filter = 2
texture = ExtResource("2_kglxp")
stretch_mode = 3
[connection signal="input_event" from="InputListener" to="." method="_on_input_listener_input_event"]
[connection signal="mouse_entered" from="InputListener" to="." method="_on_input_listener_mouse_entered"]
[connection signal="mouse_exited" from="InputListener" to="." method="_on_input_listener_mouse_exited"]
[connection signal="gui_input" from="Selection" to="." method="_on_selection_gui_input"]

View file

@ -0,0 +1,18 @@
shader_type canvas_item;
// Size in pixels.
uniform float size = 100.;
// Zoom level assuming a planet of normalized size.
varying float zoom;
void vertex() {
zoom = 8. / (size * CANVAS_MATRIX[0][0]);
}
void fragment() {
float r = length(UV - .5) * -8. + 2.;
float d = abs(r);
COLOR *= vec4(1., 1., 1., smoothstep(zoom, 0., d));
}

View file

@ -0,0 +1,10 @@
extends Player
class_name LocalPlayer
@export var ui: GameUI
func _on_game_start(game: GameLogic) -> void:
ui._on_game_started(game)
func _on_game_tick(game: GameLogic, tick: int) -> void:
pass

12
scenes/player/player.gd Normal file
View file

@ -0,0 +1,12 @@
extends Node
class_name Player
@export var color: Color = Color.MAGENTA
@export var icon: Texture2D
func _on_game_start(game: GameLogic) -> void:
pass
func _on_game_tick(game: GameLogic, tick: int) -> void:
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dr8pb2ip0k08j"
path="res://.godot/imported/albedo.png-2491354286e62c1834bccf9d59be1546.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scenes/procedural_planet/albedo.png"
dest_files=["res://.godot/imported/albedo.png-2491354286e62c1834bccf9d59be1546.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,48 @@
extends Node2D
@export_group("Planet")
## Size of the planet in pixels.
@export_range(30, 500, .001, "or_greater", "or_less") var size: float = 100 :
set(value):
scale = value * Vector2.ONE
material.set_shader_parameter('size', value)
# Rotation speed of the planet in rad/sec.
@export_range(0, 1, .001, "or_greater", "or_less") var rotation_speed: float = 0.05 :
set(value):
material.set_shader_parameter('rotationSpeed', value)
@export_group("Weather")
# Size of clouds between 0 (no clouds) and 1 (covered in clouds completely).
@export_range(0, 1, .001) var clouds_size: float = 0.05 :
set(value):
material.set_shader_parameter('cloudsSize', value)
# Density of clouds between 0 (very thin) and 1 (very thick).
@export_range(0, 1, .001) var cloud_density: float = 0.22 :
set(value):
material.set_shader_parameter('cloudsDensity', value)
# How often clouds change shape.
@export_range(0, 1, .001, "or_greater") var cloud_turbulence: float = 0.01 :
set(value):
material.set_shader_parameter('cloudsTurbulence', value)
# Wind speed in rad/sec.
@export_range(0, 1, .001, "or_greater") var wind_speed: float = 0.22 :
set(value):
material.set_shader_parameter('windSpeed', value)
@export_group("Atmosphere")
## Size of the atmosphere halo around the planet.
@export_range(0, 1, .001) var atmosphere_size: float = .3 :
set(value):
material.set_shader_parameter('atmosphereSize', value)
## Color of the atmosphere halo around the planet.
@export var atmosphere_color: Color = Color(0., .3, 1., .3) :
set(value):
material.set_shader_parameter('atmosphereColor', value)

View file

@ -0,0 +1,80 @@
shader_type canvas_item;
// Noise texture.
uniform sampler3D noise: repeat_enable;
// Planet.
uniform float size = 100.; // Size in pixels, not including atmosphere.
uniform float rotationSpeed = 0.05;
uniform sampler2D albedo; // Left side = water color (deep to shallow), right size = terrain color (low to high).
// Atmosphere.
uniform vec4 atmosphereColor: source_color = vec4(0., .3, 1., .3);
uniform float atmosphereSize = .3; // Range: [0, 1]
// Weather.
uniform float cloudsSize = 0.05;
uniform float cloudsDensity = 0.22;
uniform float cloudsTurbulence = 0.01;
uniform float windSpeed = 0.03;
// Zoom level assuming a planet of normalized size.
varying float zoom;
void vertex() {
zoom = 4. / (size * CANVAS_MATRIX[0][0]);
}
vec4 blend(vec4 bg, vec4 fg) {
float alpha = fg.a + bg.a * (1. - fg.a);
vec3 color = (fg.rgb * fg.a + bg.rgb * bg.a * (1. - fg.a)) / alpha;
return vec4(color, alpha);
}
vec4 drawPlanet(float r, vec3 p) {
float angle = TIME * rotationSpeed;
//mat3 rotX = mat3(vec3(1., 0., 0.), vec3(0., cos(angle), -sin(angle)), vec3(0., sin(angle), cos(angle)));
mat3 rotY = mat3(vec3(cos(angle), 0., -sin(angle)), vec3(0., 1., 0.), vec3(sin(angle), 0., cos(angle)));
//mat3 rotZ = mat3(vec3(cos(angle), -sin(angle), 0.), vec3(sin(angle), cos(angle), 0.), vec3(0., 0., 1.));
float height = texture(noise, p * 0.3 * rotY).r;
float rand = texture(noise, p * 0.3 * rotY + vec3(0.1, 0.2, 0.3)).r * .5 + .5;
//float rand = texture(noise, p + vec3(n + TIME * 0.02)).r;
vec3 color = texture(albedo, vec2(height, ((p.y + rand * sign(p.y)) * .5 + 1.) * .5)).rgb;
vec3 lit = max(vec3(0.), color * dot(p, vec3(0., 0., 1.)));
return vec4(lit, smoothstep(0., zoom, r));
}
vec4 drawClouds(float r, vec3 p) {
float angle = TIME * 0.08;
mat3 rotY = mat3(vec3(cos(angle), 0., -sin(angle)), vec3(0., 1., 0.), vec3(sin(angle), 0., cos(angle)));
float angle2 = TIME * (rotationSpeed - windSpeed);
mat3 rotY2 = mat3(vec3(cos(angle2), 0., -sin(angle2)), vec3(0., 1., 0.), vec3(sin(angle2), 0., cos(angle2)));
float rand = texture(noise, p * 0.5 * rotY2 + vec3(0., 0., TIME * cloudsTurbulence)).r * .5 + .5;
float rand2 = texture(noise, p * 0.8 * rotY2 + vec3(0., 0., rand)).r * .5 + .5;
return vec4(vec3(1.), smoothstep(1. - cloudsDensity - cloudsSize, 1. - cloudsSize, rand2) * smoothstep(0., .3, r * 3.));
}
vec4 drawAtmosphere(float r) {
return vec4(atmosphereColor.rgb, smoothstep(1.-atmosphereSize, 1., r + 1.) * atmosphereColor.a);
}
void fragment() {
float r = length(UV - .25) * -8. + 1.;
vec2 xy = UV * 8. - 2.;
float z = sqrt(1. - xy.x*xy.x - xy.y*xy.y);
vec3 p = vec3(xy, z);
vec4 atmosphere = drawAtmosphere(r);
vec4 planet = drawPlanet(r, p);
vec4 clouds = drawClouds(r, p);
COLOR = blend(blend(atmosphere, planet), clouds);
// DEBUG
//COLOR = vec4(p, smoothstep(0., zoom, r));
}

View file

@ -0,0 +1,37 @@
[gd_scene load_steps=8 format=3 uid="uid://dnerbdusnaofr"]
[ext_resource type="Script" path="res://scenes/procedural_planet/procedural_planet.gd" id="1_2swpa"]
[ext_resource type="Shader" path="res://scenes/procedural_planet/procedural_planet.gdshader" id="1_tl7a6"]
[ext_resource type="Texture2D" uid="uid://dr8pb2ip0k08j" path="res://scenes/procedural_planet/albedo.png" id="3_pc1s8"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_xihql"]
fractal_octaves = 8
[sub_resource type="NoiseTexture3D" id="NoiseTexture3D_bt5w2"]
width = 256
height = 256
depth = 256
seamless = true
noise = SubResource("FastNoiseLite_xihql")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_m4mhh"]
shader = ExtResource("1_tl7a6")
shader_parameter/size = 100.0
shader_parameter/rotationSpeed = 0.05
shader_parameter/atmosphereColor = Color(0, 0.3, 1, 0.3)
shader_parameter/atmosphereSize = 0.3
shader_parameter/cloudsSize = 0.05
shader_parameter/cloudsDensity = 0.22
shader_parameter/cloudsTurbulence = 0.01
shader_parameter/windSpeed = 0.03
shader_parameter/noise = SubResource("NoiseTexture3D_bt5w2")
shader_parameter/albedo = ExtResource("3_pc1s8")
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_ipvyw"]
size = Vector2(2, 2)
[node name="ProceduralPlanet" type="Sprite2D"]
material = SubResource("ShaderMaterial_m4mhh")
scale = Vector2(100, 100)
texture = SubResource("PlaceholderTexture2D_ipvyw")
script = ExtResource("1_2swpa")

View file

@ -0,0 +1,12 @@
shader_type canvas_item;
float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
void fragment() {
if (rand(SCREEN_UV) > COLOR.a - abs(UV.y * 2. - 1.))
discard;
COLOR = vec4(1., 1., 1., COLOR.a);
}

View file

@ -0,0 +1,22 @@
[gd_scene load_steps=5 format=3 uid="uid://ctybb4niolni3"]
[ext_resource type="Shader" path="res://scenes/ships_fleet/fading_trail.gdshader" id="1_tajfm"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ys3et"]
shader = ExtResource("1_tajfm")
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_gcgjo"]
size = Vector2(12, 4)
[sub_resource type="Gradient" id="Gradient_6a1ig"]
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
[node name="Ship" type="CPUParticles2D"]
material = SubResource("ShaderMaterial_ys3et")
amount = 100
lifetime = 3.0
lifetime_randomness = 0.3
texture = SubResource("PlaceholderTexture2D_gcgjo")
particle_flag_align_y = true
gravity = Vector2(0, 0)
color_ramp = SubResource("Gradient_6a1ig")

View file

@ -0,0 +1,22 @@
extends Node2D
var instances: Array[Node2D] = []
@export var ship_template: PackedScene
@export var count: int :
set(value):
count = value
var diff = count - instances.size()
for i in range(diff):
var j = float(1 + instances.size())
var ship := ship_template.instantiate()
add_child(ship)
ship.position = Vector2.from_angle(j) * j * 2.
instances.push_back(ship)
for i in range(-diff):
var ship: Node2D = instances.pop_back()
remove_child(ship)

View file

@ -0,0 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://cpffyaoh8x5bp"]
[ext_resource type="Script" path="res://scenes/ships_fleet/ships_fleet.gd" id="1_qfy0m"]
[ext_resource type="PackedScene" uid="uid://ctybb4niolni3" path="res://scenes/ships_fleet/ship.tscn" id="2_6eafk"]
[node name="ShipsFleet" type="Node2D"]
script = ExtResource("1_qfy0m")
ship_template = ExtResource("2_6eafk")

5
scenes/trail/trail.gd Normal file
View file

@ -0,0 +1,5 @@
extends Sprite2D
@export var color: Color :
set(value):
material.set_shader_parameter('color', value)

View file

@ -0,0 +1,16 @@
shader_type canvas_item;
uniform vec4 color: source_color = vec4(1., 0., 1., 1.);
varying float len;
void vertex() {
len = length(MODEL_MATRIX[0]);
}
void fragment() {
float col = texture(TEXTURE, UV * vec2(len, 1.) + vec2(TIME * -.2, 0.)).r;
float fade = min(1., min(UV.x, 1. - UV.x) * len);
COLOR = color * vec4(vec3(1.), col * fade);
}

BIN
scenes/trail/trail.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://qb1fvyepkup2"
path="res://.godot/imported/trail.png-d1fbf3ba061e82749354c2b2d8480770.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scenes/trail/trail.png"
dest_files=["res://.godot/imported/trail.png-d1fbf3ba061e82749354c2b2d8480770.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

16
scenes/trail/trail.tscn Normal file
View file

@ -0,0 +1,16 @@
[gd_scene load_steps=5 format=3 uid="uid://ckfk1xgxfk1c3"]
[ext_resource type="Shader" path="res://scenes/trail/trail.gdshader" id="1_fjdrv"]
[ext_resource type="Texture2D" uid="uid://qb1fvyepkup2" path="res://scenes/trail/trail.png" id="2_nw1t2"]
[ext_resource type="Script" path="res://scenes/trail/trail.gd" id="3_cnvkj"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_f7lnm"]
shader = ExtResource("1_fjdrv")
shader_parameter/color = Color(1, 0, 1, 1)
[node name="Trail" type="Sprite2D"]
texture_repeat = 2
material = SubResource("ShaderMaterial_f7lnm")
scale = Vector2(10, 1)
texture = ExtResource("2_nw1t2")
script = ExtResource("3_cnvkj")

42
ui.gd Normal file
View file

@ -0,0 +1,42 @@
extends Control
class_name GameUI
var game: GameLogic
var selected_planet: Planet
var pointed_planet: Planet
func _on_game_started(game: GameLogic) -> void:
self.game = game
for planet in game.planets:
planet.selected.connect(_on_planet_selected)
planet.pointer_entered.connect(_on_planet_pointer_entered)
planet.pointer_exited.connect(_on_planet_pointer_exited)
func _on_planet_selected(planet: Planet) -> void:
if selected_planet != null:
selected_planet.is_selected = false
selected_planet = planet
selected_planet.is_selected = true
func _on_planet_pointer_entered(planet: Planet) -> void:
pointed_planet = planet
func _on_planet_pointer_exited(planet: Planet) -> void:
if pointed_planet == planet:
pointed_planet = null
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_released():
if selected_planet != null and pointed_planet != null:
var count = ceil(selected_planet.population / 2)
selected_planet.population -= count
if selected_planet.player == pointed_planet.player:
pointed_planet.population += count
else:
pointed_planet.population -= count
if pointed_planet.population <= 0:
pointed_planet.player = selected_planet.player
pointed_planet.population = abs(pointed_planet.population)