Skip to content

Commit

Permalink
Merge branch 'fature-spielfeld-generierung-mit-angabe-eines-seeds' in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
Fox-Alpha committed Sep 16, 2024
2 parents 1d0ca53 + 7207d60 commit c16e9e1
Show file tree
Hide file tree
Showing 74 changed files with 1,508 additions and 231 deletions.
7 changes: 7 additions & 0 deletions Cannon/Cannon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func _ready():
if !SignalBus.CannonShooting.is_connected(Preloads.PlayerShots._on_Player_Shoot):
if SignalBus.CannonShooting.connect(Preloads.PlayerShots._on_Player_Shoot)!=OK:
print("Error - Cannon.gd: connect signal CannonShooting")

SignalBus.MapGeneratorPlaceCannon.connect(_on_MapGenerator_PlaceCannon)


func _unhandled_input(event):
Expand Down Expand Up @@ -73,3 +75,8 @@ func _reset_CannonPower() -> void:
func _on_Cannon_ready():
muzzle_velocity = floori((float)(max_velocity - min_velocity) / 2)
SignalBus.CannonPowerChange.emit(muzzle_velocity)


func _on_MapGenerator_PlaceCannon(pos : Vector2) -> void:
global_position = pos
pass
6 changes: 3 additions & 3 deletions CannonBall/Cannonball.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func _physics_process(delta: float) -> void:
var collision = move_and_collide(velocity * delta)
if collision:
var collider = collision.get_collider()
if collider is TileMap:
if collider is TileMapLayerBase:
# Find the character's position in tile coordinates
var colpos = collision.get_position()
var tile_pos = collider.local_to_map(colpos)
# Find the colliding tile position
# Get the tile id
var tile_id = collider.get_cell_source_id(0,tile_pos)
if tile_id == 0:
var tile_id = collider.get_cell_source_id(tile_pos)
if tile_id == 8:
SignalBus.exploded.emit(position + transform.x * 37)
SignalBus.GroundHit.emit()
elif collider is StaticBody2D:
Expand Down
18 changes: 10 additions & 8 deletions DummyTarget/DummyTargetGroupNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ func _ready():
func _on_Create_Add_NewTarget() -> void:
var target : Node2D

randomize()
#randomize()
print("DummyTarget Seed: %s" % str(Preloads.rng.seed))

var tilecount = Preloads.Map.world_tiles_x
var randtile = ceil(randi_range(Preloads.Map.mod + 10, tilecount-1))
var tilecount = Preloads.TerrainLayer.world_tiles_count.x
var randtile = ceil(Preloads.rng.randi_range(Preloads.TerrainLayer.mod + 10, tilecount-1))
#var randtile = ceil(randi_range(Preloads.TerrainLayer.mod + 10, tilecount-1))

var tile_coord : Vector2i

for y in range(0, Preloads.Map.world_tiles_y-1):
var tid = Preloads.Map.get_cell_source_id(0,Vector2i(randtile, y))
if tid == 0:
for y in range(0, Preloads.TerrainLayer.world_tiles_count.y-1):
var tid = Preloads.TerrainLayer.get_cell_source_id(Vector2i(randtile, y))
if tid == 8:
tile_coord = Vector2i(randtile, y)
# print("Tile: %s" % str(tile_coord))
break

var posi:Vector2i = Preloads.Map.map_to_local(tile_coord)
var posi:Vector2i = Preloads.TerrainLayer.map_to_local(tile_coord)
# posi.x += 8
posi.y -= floori(Preloads.Map.tile_set.tile_size.y / 2.0)
#posi.y += floori(Preloads.TerrainLayer.tile_set.tile_size.y) # / 4.0)

target = Preloads.DummyTarget.instantiate()
target.position = posi
Expand Down
48 changes: 40 additions & 8 deletions Globals/GameConfig/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const CONFIGDATA_DEFAULT:Dictionary = {
"GameConditionMinMaxScore": -100,
"GameConditionMaxGameTimeEnabled": false,
"GameConditionMinMaxScoreValue": 1000,
"GameMapGeneratorSeed": 212197721011977,
"GameMapGeneratorState": 0,
"GameMapGeneratorLastState": 0,
"GameNetworkHostIPAdress": "127.0.0.1",
"GameNetworkHostGamePort": "21277",
"GameNetworkMaxPlayers": 2,
Expand All @@ -53,19 +56,23 @@ const CONFIGDATA_DEFAULT:Dictionary = {
"GameKeyBinding": null
}

signal ConfigValueChanged
#signal ConfigValueChanged


func _ready() -> void:
config_data = get_configdata()
config_data = load_configdata_from_file()
_check_DefaultConfig()

SignalBus.ConfigValueChanged.connect(_on_config_value_changed)
SignalBus.ConfigSaveDataToFile.connect(_on_ConfigSaveDataToFile)

ConfigValueChanged.connect(_on_config_value_changed)
SignalBus.ConfigSaveDataToFile.emit()


func get_configdata() -> Dictionary:
func load_configdata_from_file() -> Dictionary:
var json = JSON.new()
if not FileAccess.file_exists(GAMECONFIGFILE):
save_gameconfig(true)
SignalBus.ConfigSaveDataToFile.emit(true)

var file = FileAccess.open(GAMECONFIGFILE, FileAccess.READ)

Expand All @@ -87,11 +94,13 @@ func get_configdata_value(valuetoget: String, _vType : Variant.Type = Variant.Ty

if valuetoget in config_data:
v = config_data[valuetoget]

else:
return get_defaultvalue(valuetoget)

return v


func save_gameconfig (savedefault : bool = false):
func _save_gameconfig (savedefault : bool = false):
if savedefault:
config_data = CONFIGDATA_DEFAULT
var config = FileAccess.open(GAMECONFIGFILE, FileAccess.WRITE)
Expand All @@ -101,7 +110,6 @@ func save_gameconfig (savedefault : bool = false):
config.close()



#func _on_config_value_changed(obj: String= "", value : Variant = null, root: String = "Game", group: String= "") -> void:
func _on_config_value_changed(obj: String= "", value : Variant = null) -> void:
# Check Object for Empty
Expand All @@ -115,5 +123,29 @@ func _on_config_value_changed(obj: String= "", value : Variant = null) -> void:
# save new Value to Config Dict / conf_File
if obj in config_data:
config_data[obj] = value
else: #if not in memory, check if default value exists
var def = get_defaultvalue(obj)
if typeof(def) != Variant.Type.TYPE_NIL:
config_data[obj] = value

SignalBus.ConfigSaveDataToFile.emit()
print("Signal Received: ConfigValueChange: ", [obj, value])


func _check_DefaultConfig() -> void:
var keys = CONFIGDATA_DEFAULT.keys()
for k in keys:
if not k in config_data:
config_data[k] = get_defaultvalue(k)
pass


func get_defaultvalue(key : String) -> Variant:
if key in CONFIGDATA_DEFAULT:
return CONFIGDATA_DEFAULT.get(key)

return null


func _on_ConfigSaveDataToFile(savedefault : bool = false) -> void:
_save_gameconfig(savedefault)
3 changes: 2 additions & 1 deletion Globals/GameStateManager/GameStateManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ extends Node
@export var _shots:int = 0

var gameWin:int = -1
var pm
var pm:Node
var GameTimer:Timer
var GameTimerTimeElapsed:int = 0
var GameTimeTextLabel:Label
var GameTimerTimeout:int = -1

## ToDo: Change to global SignalBus ?
signal GameStateChange


Expand Down
30 changes: 28 additions & 2 deletions Globals/Preloads.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extends Node
@onready var GameSettingsScene :PackedScene = preload("res://UI/GameSettingsDialog/GameSettings.tscn")
@onready var GameOverScene :PackedScene = preload("res://UI/GameEndDialog/GameEndDialog.tscn")

@onready var rng : RandomNumberGenerator = RandomNumberGenerator.new()

# Player Node's
var PlayerRootNode:Node2D
var PlayerLeft:Node2D
Expand All @@ -30,5 +32,29 @@ var UIMain:Control
@onready var DummyTargetGroup:Node2D

#
## TileMap
var Map:TileMap
## TileMapLayer's
var TerrainLayer: TileMapLayerBase
var CannonLayer: TileMapLayerBase
var CastleLayer: TileMapLayerBase


func _ready():
SignalBus.RNGResetLastState.connect(_on_RNGResetLastState, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
pass


func _on_RNGResetLastState() -> void:
rng.state = Config.get_configdata_value("GameMapGeneratorLastState", Variant.Type.TYPE_INT)
pass


## Load from Config or Set Default value
func _initRNG() -> void:
var _seed = Config.get_configdata_value("GameMapGeneratorSeed")
if typeof(_seed) == Variant.Type.TYPE_INT:
rng.seed = _seed
else:
rng.seed = 212197721011977
SignalBus.ConfigValueChanged.emit("GameMapGeneratorSeed", rng.seed)
SignalBus.ConfigValueChanged.emit("GameMapGeneratorState", rng.state)
pass # Replace with function body.
30 changes: 30 additions & 0 deletions Globals/SignalBus/SignalBus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ extends Node
# global signals
signal FloatingText

# TileMap Signals
signal MapGeneratorGenerateTerrain
signal MapGeneratorPlaceCastle
signal MapGeneratorPlaceCannon

# Cannon Signals
signal CannonPowerChange
signal CannonAngelChange
Expand All @@ -19,9 +24,16 @@ signal GroundHit

# UI Signals
signal UIScoreChange
signal UIResetGame

# settings signals
signal PlayernameChange
signal ConfigValueChanged
signal ConfigSaveDataToFile

# RandomNumberGenerator signals
signal RNGSaveLastState
signal RNGResetLastState

## Dumy func to prevent UNUSED_SIGNAL Warning
func _ready():
Expand All @@ -41,13 +53,31 @@ func _ready():

# UI Signals
UIScoreChange.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
UIResetGame.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
PlayernameChange.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)

# Map Generator
MapGeneratorGenerateTerrain.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
MapGeneratorPlaceCastle.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
MapGeneratorPlaceCannon.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)

# Config
ConfigValueChanged.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
ConfigSaveDataToFile.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)

# RandomNumberGenerator signals
RNGSaveLastState.connect(_on_RNGSaveLastState, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)
RNGResetLastState.connect(_on_Dummy_Signal, ConnectFlags.CONNECT_PERSIST | ConnectFlags.CONNECT_DEFERRED)

func _on_Dummy_Signal(_var1=null, _var2=null, _var3=null):
pass


func _on_RNGSaveLastState(lastseed : int) -> void:
SignalBus.ConfigValueChanged.emit("GameMapGeneratorLastState", lastseed)
pass


func _on_Floating_Text_Signal(text : String, pos : Vector2) -> void:
#print(text)

Expand Down
2 changes: 1 addition & 1 deletion Globals/scene_transition/screen_transition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _ready() -> void:
animation_player.animation_finished.connect(on_animation_finished)


func on_animation_finished(anim: String):
func on_animation_finished(_anim: String):
color_rect.set_mouse_filter(Control.MOUSE_FILTER_IGNORE)
pass

Expand Down
16 changes: 11 additions & 5 deletions MainGameScene/MainGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var target


func _ready():
if !Preloads.UIMain.UIResetGame.is_connected(self._on_UI_ResetGame):
var _cn = Preloads.UIMain.UIResetGame.connect(self._on_UI_ResetGame)
if !SignalBus.UIResetGame.is_connected(self._on_UI_ResetGame):
var _cn = SignalBus.UIResetGame.connect(self._on_UI_ResetGame)

Preloads.Map.generate_world_tilemap_base()
SignalBus.MapGeneratorGenerateTerrain.emit()


func _enter_tree() -> void:
Expand All @@ -25,7 +25,12 @@ func _enter_tree() -> void:
Preloads.DummyTargetGroup = find_child("DummyTargets")

## TileMap
Preloads.Map = find_child("TerrainMap")
# ToDo: Using TileMapLayer TerrainLayer
Preloads.TerrainLayer = find_child("LayerTerrain")
Preloads.CannonLayer = find_child("LayerCannon")
Preloads.CastleLayer = find_child("LayerCastle")

pass


func _on_MainGame_ready() -> void:
Expand All @@ -40,5 +45,6 @@ func _on_UI_ResetGame() -> void:
GSM.GameTimeTextLabel.text = "00:00"
get_tree().call_group("Dummy", "queue_free")
get_tree().call_group("Shoots", "queue_free")
Preloads.Map.generate_world_tilemap_base()

SignalBus.MapGeneratorGenerateTerrain.emit()
SignalBus.CreateAndAddNewTarget.emit()
33 changes: 24 additions & 9 deletions MainGameScene/MainGame.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[gd_scene load_steps=13 format=3 uid="uid://h8vcng8ps4vd"]
[gd_scene load_steps=16 format=3 uid="uid://h8vcng8ps4vd"]

[ext_resource type="TileSet" uid="uid://di4l1ben37h3b" path="res://MainGameScene/TerrainTiles/blocks_tileset_16x16.tres" id="1"]
[ext_resource type="Script" path="res://MainGameScene/MainGame.gd" id="2"]
[ext_resource type="PackedScene" uid="uid://dmyeg6ldx2orv" path="res://UI/components/vignette/vignette.tscn" id="2_jfj17"]
[ext_resource type="Script" path="res://scripts/players.gd" id="4"]
[ext_resource type="PackedScene" uid="uid://ncuxb50cjisf" path="res://UI/InGameUI/IngameUI_Redesign.tscn" id="5_y7iba"]
[ext_resource type="PackedScene" uid="uid://lci12xbkaqx2" path="res://Cannon/Cannon.tscn" id="6"]
[ext_resource type="PackedScene" uid="uid://lci12xbkaqx2" path="res://Cannon/Cannon.tscn" id="6_6q48v"]
[ext_resource type="PackedScene" uid="uid://dx02vnjoiqc0n" path="res://DummyTarget/DummyTargetGroupNode.tscn" id="7"]
[ext_resource type="Script" path="res://DummyTarget/DummyTargetGroupNode.gd" id="8"]
[ext_resource type="Script" path="res://MainGameScene/Background/parallaxLayer.gd" id="9"]
[ext_resource type="Texture2D" uid="uid://d23fg0a10hltc" path="res://MainGameScene/Background/uncolored_plain.png" id="10"]
[ext_resource type="Script" path="res://MainGameScene/TerrainMapGenerator.gd" id="10_uxs7w"]
[ext_resource type="Script" path="res://MainGameScene/terrain.gd" id="12_6ypvd"]
[ext_resource type="Script" path="res://MainGameScene/terrain_layer/layer_terrain.gd" id="13_sxh5i"]
[ext_resource type="Script" path="res://MainGameScene/terrain_layer/layer_cannon.gd" id="14_k42sh"]
[ext_resource type="Script" path="res://MainGameScene/terrain_layer/layer_castle.gd" id="15_5fhnt"]

[sub_resource type="Environment" id="Environment_47r24"]
background_mode = 3
Expand Down Expand Up @@ -47,8 +50,8 @@ size_flags_vertical = 3

[node name="Player1" type="Node2D" parent="Players"]

[node name="Cannon" parent="Players/Player1" instance=ExtResource("6")]
position = Vector2(186, 388)
[node name="Cannon" parent="Players/Player1" instance=ExtResource("6_6q48v")]
position = Vector2(205, 395)

[node name="Player2" type="Node2D" parent="Players"]

Expand All @@ -58,10 +61,22 @@ script = ExtResource("4")
[node name="DummyTargetGroupNode" parent="." instance=ExtResource("7")]
script = ExtResource("8")

[node name="TerrainMap" type="TileMap" parent="." groups=["Ground"]]
[node name="Terrain" type="Node2D" parent="."]
script = ExtResource("12_6ypvd")

[node name="LayerTerrain" type="TileMapLayer" parent="Terrain" groups=["Ground"]]
use_parent_material = true
tile_set = ExtResource("1")
script = ExtResource("13_sxh5i")

[node name="LayerCannon" type="TileMapLayer" parent="Terrain"]
use_parent_material = true
tile_set = ExtResource("1")
script = ExtResource("14_k42sh")

[node name="LayerCastle" type="TileMapLayer" parent="Terrain"]
use_parent_material = true
tile_set = ExtResource("1")
format = 2
layer_0/tile_data = PackedInt32Array(1310721, 6, 0, 1310723, 6, 0, 1376257, 6, 0, 1376258, 6, 0, 1376259, 6, 0, 1441793, 6, 0, 1441795, 6, 0, 1507329, 6, 0, 1507330, 6, 0, 1507331, 6, 0, 1572865, 6, 0, 1572866, 6, 0, 1572867, 6, 0, 1572869, 6, 0, 1572871, 6, 0, 1572873, 6, 0, 1572875, 6, 0, 1638401, 6, 0, 1638402, 6, 0, 1638403, 6, 0, 1638404, 6, 0, 1638405, 6, 0, 1638406, 6, 0, 1638407, 6, 0, 1638408, 6, 0, 1638409, 6, 0, 1638410, 6, 0, 1638411, 6, 0, 1703937, 6, 0, 1703938, 6, 0, 1703940, 6, 0, 1703942, 6, 0, 1703944, 6, 0, 1703946, 6, 0, 1703947, 6, 0, 1769473, 6, 0, 1769474, 6, 0, 1769475, 6, 0, 1769476, 6, 0, 1769477, 6, 0, 1769478, 6, 0, 1769479, 6, 0, 1769480, 6, 0, 1769481, 6, 0, 1769482, 6, 0, 1769483, 6, 0, 1835008, 6, 0, 1835009, 6, 0, 1835010, 6, 0, 1835011, 6, 0, 1835012, 6, 0, 1835013, 6, 0, 1835014, 6, 0, 1835015, 6, 0, 1835016, 6, 0, 1835017, 6, 0, 1835018, 6, 0, 1835019, 6, 0)
script = ExtResource("10_uxs7w")
script = ExtResource("15_5fhnt")

[connection signal="ready" from="." to="." method="_on_MainGame_ready"]
Loading

0 comments on commit c16e9e1

Please sign in to comment.