Added basic region pathfinfing networking, transfering region info such as tiles and units works, but no moves can be requested yet.

This commit is contained in:
Joa2 2023-11-16 15:07:24 +01:00
parent 5c23804b71
commit 1a7ff9cd96
41 changed files with 656 additions and 141 deletions

View File

@ -0,0 +1,3 @@
source_md5="60fad784db3412e499a61e159fb0ab54"
dest_md5="8f21de330736bfda6b5c832cb18acbb8"

View File

@ -0,0 +1,3 @@
source_md5="a72e8867108b6ac04fc080a52599b278"
dest_md5="16e818811c57f4954b8f804f2b6a4bd4"

View File

@ -0,0 +1,3 @@
source_md5="97cea05c45971cc8ae3f0dbb70b26d39"
dest_md5="e9948a9e9f2c54d77ffbc60b4cf29da7"

View File

@ -0,0 +1,3 @@
source_md5="4649619802d7e43bcb178d0ca22d8f87"
dest_md5="7afddab8fa81674668efb848afc5a75e"

View File

@ -0,0 +1,3 @@
source_md5="f2f86a04a5e4e9f760d7a35d7a636bd9"
dest_md5="93f1454ca0c6306e7a64849450c73751"

View File

@ -0,0 +1,3 @@
source_md5="e9ff5f579208eb30fd1830c6d95b8da7"
dest_md5="b04a777d7a1923a84af05ebf47a14ddf"

View File

@ -41,9 +41,9 @@ func _ready():
func _process(delta): func _process(delta):
#smooth movement #smooth movement
var inpx = (int(Input.is_action_pressed("ui_right")) var inpx = (int(Input.is_action_pressed("ui_right"))
- int(Input.is_action_pressed("ui_left"))) - int(Input.is_action_pressed("ui_left")))
var inpy = (int(Input.is_action_pressed("ui_down")) var inpy = (int(Input.is_action_pressed("ui_down"))
- int(Input.is_action_pressed("ui_up"))) - int(Input.is_action_pressed("ui_up")))
self.position.x = lerp(position.x, position.x + inpx *speed,speed * delta) self.position.x = lerp(position.x, position.x + inpx *speed,speed * delta)
self.position.y = lerp(position.y, position.y + inpy *speed,speed * delta) self.position.y = lerp(position.y, position.y + inpy *speed,speed * delta)
if Input.is_key_pressed(KEY_CONTROL): if Input.is_key_pressed(KEY_CONTROL):

View File

@ -18,8 +18,9 @@ signal server_disconnected
func _ready(): func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected') get_tree().connect('network_peer_connected', self, '_on_player_connected')
connect_to_server("name","","")
yield(get_tree().create_timer(1),"timeout")
rpc_id(1, 'TESTFUNCTION', "TEST TEST TEST")
func connect_to_server(playerName,pw,serverpassword): func connect_to_server(playerName,pw,serverpassword):
self.serverpassword = serverpassword self.serverpassword = serverpassword
@ -33,7 +34,6 @@ func connect_to_server(playerName,pw,serverpassword):
# PlayerManager.authcache['password']=pw # PlayerManager.authcache['password']=pw
# PlayerManager.authcache['playername']=playerName # PlayerManager.authcache['playername']=playerName
func _connected_to_server(): func _connected_to_server():
var local_player_id = get_tree().get_network_unique_id() var local_player_id = get_tree().get_network_unique_id()
players[local_player_id] = self_data players[local_player_id] = self_data
@ -44,7 +44,6 @@ func _connected_to_server():
rpc_id(1, '_request_auth', local_player_id, self_data)# anstatt playerName und pw -> self_data rpc_id(1, '_request_auth', local_player_id, self_data)# anstatt playerName und pw -> self_data
rpc('_send_player_info', local_player_id, self_data) # requests all player in the current session rpc('_send_player_info', local_player_id, self_data) # requests all player in the current session
func _on_player_disconnected(id): func _on_player_disconnected(id):
players.erase(id) players.erase(id)
PlayerManager.player_disconnected(id) PlayerManager.player_disconnected(id)

View File

@ -232,13 +232,13 @@ func _load_worldmap():
func requestTiles(unit = null): func requestTiles(unit = null):
print("a")
rpc_id(1, 'requestTiles', unit) rpc_id(1, 'requestTiles', unit)
signal receiveTiles signal receiveTiles
func receiveTiles(bundledTileStuff): remote func receiveTiles(bundledTileStuff):
var newTileRect = bundledTileStuff[0] var newTileRect = bundledTileStuff[0]
var newTiles = bundledTileStuff[1] var newTiles = bundledTileStuff[1]
var newSuperTiles = bundledTileStuff[2] var newSuperTiles = bundledTileStuff[2]
@ -249,19 +249,5 @@ func requestUnits():
signal receiveUnits signal receiveUnits
func receiveUnits(newBoardUnits): remote func receiveUnits(newBoardUnits):
var boardUnits = newBoardUnits
for child in $TileMap/Units.get_children():
child.queue_free()
var boardUnitsIndex = 0
for unit in boardUnits:
var newUnit
if unit.superUnit:
newUnit = (load("res://SuperUnit.tscn")).instance()
else:
newUnit = (load("res://Unit.tscn")).instance()
newUnit.boardUnitsIndex = boardUnitsIndex
$TileMap/Units.add_child(newUnit)
newUnit.on_ready()
boardUnitsIndex +=1
emit_signal("receiveUnits", newBoardUnits) emit_signal("receiveUnits", newBoardUnits)

View File

@ -0,0 +1,102 @@
extends Node2D
var red = Color( 1, 0, 0, 1 )
var yellow = Color( 1, 1, 0, 1 )
var blue = Color( 0, 1, 1, 1 )
var route1 = []#blue line
var route2 = []#yellow line
var route3 = []#redline
var vertices1 = []#blue line
var vertices2 = []#yellow line
var vertices3 = []#redline
func _ready():#this sets colors to the different lines
$Line1.default_color = blue
$Line2.default_color = yellow
$Line3.default_color = red
func drawAdvancedLine(route, vertices, unitAp, unitMoveAp):#this creates the seperate lines and draws them
route1 = []
route2 = []
route3 = []
vertices1 = []
vertices2 = []
vertices3 = []
#blue
route1 = route.duplicate()
vertices1 = vertices.duplicate()
while addUpArray(vertices1) > unitMoveAp:
route1.pop_back()
vertices1.pop_back()
#yellow
route2 = route.duplicate()
vertices2 = vertices.duplicate()
while addUpArray(vertices2) > unitMoveAp+unitAp:
route2.pop_back()
vertices2.pop_back()
#red
route3 = route.duplicate()
vertices3 = vertices.duplicate()
subtractPaths(route3, route2)
subtractPaths(route2, route1)
$Line1.points = convertMapRouteToWorldRoute(route1)
$Line2.points = convertMapRouteToWorldRoute(route2)
$Line3.points = convertMapRouteToWorldRoute(route3)
func addUpArray(array):#this adds up each int in an array. useful for calculating total distance.
var total = 0
for number in array:
total += number
return(total)
func convertMapRouteToWorldRoute(route):#this uses the map_to_world function on each coord of a route
var returnRoute = []
for point in route:
returnRoute.append(get_parent().map_to_world(point)+Vector2(32,32))
return(returnRoute)
func subtractPaths(path1, path2):#this produces a path1 that only overlaps path2 in their first coord. Or something.
var lastDuplicateValue
for value in path2:
path1.erase(value)
lastDuplicateValue = value
if lastDuplicateValue != null:
path1.push_front(lastDuplicateValue)
return path1
func drawAdvancedSuperLine(route, vertices, unitAp, unitMoveAp):#this creates the seperate lines and draws them
route1 = []
route2 = []
route3 = []
vertices1 = []
vertices2 = []
vertices3 = []
#blue
route1 = route.duplicate()
vertices1 = vertices.duplicate()
while addUpArray(vertices1) > unitMoveAp:
route1.pop_back()
vertices1.pop_back()
#yellow
route2 = route.duplicate()
vertices2 = vertices.duplicate()
while addUpArray(vertices2) > unitMoveAp+unitAp:
route2.pop_back()
vertices2.pop_back()
#red
route3 = route.duplicate()
vertices3 = vertices.duplicate()
subtractPaths(route3, route2)
subtractPaths(route2, route1)
$Line1.points = convertSuperMapRouteToWorldRoute(route1)
$Line2.points = convertSuperMapRouteToWorldRoute(route2)
$Line3.points = convertSuperMapRouteToWorldRoute(route3)
func convertSuperMapRouteToWorldRoute(route):#this uses the map_to_world function on each coord of a route
var returnRoute = []
for point in route:
returnRoute.append(get_parent().map_to_world(point)+Vector2(64,64))
return(returnRoute)

View File

@ -17,24 +17,26 @@ var routeVertices
var hoveredCoords var hoveredCoords
func _ready():#this mostly just builds a bunch of stuff func _ready():#this mostly just builds a bunch of stuff
yield(get_tree().create_timer(0.01), "timeout") WorldManager.connect("receiveTiles", self, "receiveTiles")
WorldManager.connect("receiveUnits", self, "receiveUnits")
yield(get_tree().create_timer(1), "timeout")
buildWorld() buildWorld()
func buildWorld(): func buildWorld():
requestTiles() requestTiles()
requestUnits() requestUnits()
$TileMap.buildTileMap(tiles)
func requestTiles(unit = null): func requestTiles(unit = null):
rpc_id(1, 'requestTiles', unit, self) WorldManager.requestTiles(unit)
func receiveTiles(newTileRect, newTiles, newSuperTiles): func receiveTiles(newTileRect, newTiles, newSuperTiles):
tileRect = tileRect tileRect = newTileRect
tiles = newTiles tiles = newTiles
superTiles = newSuperTiles superTiles = newSuperTiles
$TileMap.buildTileMap(tiles)
func requestUnits(): func requestUnits():
rpc_id(1, 'requestUnits', self) WorldManager.requestUnits()
func receiveUnits(newBoardUnits): func receiveUnits(newBoardUnits):
boardUnits = newBoardUnits boardUnits = newBoardUnits
@ -44,9 +46,9 @@ func receiveUnits(newBoardUnits):
for unit in boardUnits: for unit in boardUnits:
var newUnit var newUnit
if unit.superUnit: if unit.superUnit:
newUnit = (load("res://SuperUnit.tscn")).instance() newUnit = (load("res://region/SuperUnit.tscn")).instance()
else: else:
newUnit = (load("res://Unit.tscn")).instance() newUnit = (load("res://region/Unit.tscn")).instance()
newUnit.boardUnitsIndex = boardUnitsIndex newUnit.boardUnitsIndex = boardUnitsIndex
$TileMap/Units.add_child(newUnit) $TileMap/Units.add_child(newUnit)
newUnit.on_ready() newUnit.on_ready()
@ -73,14 +75,14 @@ func _input(event):#this responds to any input. Has various functions depending
# print("region ",boardUnits) # print("region ",boardUnits)
# print("server ",server.boardUnits) # print("server ",server.boardUnits)
if selectedUnit != null: if selectedUnit != null:
if event is InputEventMouseButton and Input.is_action_just_released("left_click"): if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"):
if !selectedUnit.superUnit: if !selectedUnit.superUnit:
clickPath() clickPath()
else: else:
clickSuperPath() clickSuperPath()
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
if true: if true:
hoveredCoords = event.position hoveredCoords = (self.make_input_local(event)).position
if !selectedUnit.superUnit: if !selectedUnit.superUnit:
hoverPath() hoverPath()
else: else:
@ -109,7 +111,7 @@ func clickPath():#this finalizes the selected path while calculating ap and new
func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the pathfinding to make the path and tells the line to draw the returned path func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the pathfinding to make the path and tells the line to draw the returned path
if selectedUnit !=null and coord != null: if selectedUnit !=null and coord != null:
coord = $ground.world_to_map(hoveredCoords) coord = $TileMap.world_to_map(hoveredCoords)
coord.x=clamp(coord.x,0,tileRect.x-1) coord.x=clamp(coord.x,0,tileRect.x-1)
coord.y=clamp(coord.y,0,tileRect.y-1) coord.y=clamp(coord.y,0,tileRect.y-1)
if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy
@ -130,7 +132,7 @@ func executePath(route, vertices):#this takes the current selected route and tel
rpc_id(1, 'moveUnit', route, selectedUnit.id) rpc_id(1, 'moveUnit', route, selectedUnit.id)
var convertedRoute = [] var convertedRoute = []
for coords in route: for coords in route:
convertedRoute.append($ground.map_to_world(coords)) convertedRoute.append($TileMap.map_to_world(coords))
selectedNode.moveOnPath(convertedRoute) selectedNode.moveOnPath(convertedRoute)
animationInProgress = true animationInProgress = true
clearPathingInfo() clearPathingInfo()
@ -341,7 +343,7 @@ func findSuperPath(start,end):
a.append(1) a.append(1)
func hoverSuperPath(coord = hoveredCoords): func hoverSuperPath(coord = hoveredCoords):
coord = $ground.world_to_map(hoveredCoords+Vector2(-32,-32)) coord = $TileMap.world_to_map(hoveredCoords+Vector2(-32,-32))
coord.x=clamp(coord.x,0,tileRect.x-2) coord.x=clamp(coord.x,0,tileRect.x-2)
coord.y=clamp(coord.y,0,tileRect.y-2) coord.y=clamp(coord.y,0,tileRect.y-2)
if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy if animationInProgress == false:# and occupiedTiles.has(coord) == false: #might be buggy
@ -376,7 +378,7 @@ func executeSuperPath(route, vertices):#this takes the current selected route an
rpc_id(1, 'moveUnit', route, selectedUnit.id) rpc_id(1, 'moveUnit', route, selectedUnit.id)
var convertedRoute = [] var convertedRoute = []
for coords in route: for coords in route:
convertedRoute.append($ground.map_to_world(coords)) convertedRoute.append($TileMap.map_to_world(coords))
selectedNode.moveOnPath(convertedRoute) selectedNode.moveOnPath(convertedRoute)
animationInProgress = true animationInProgress = true
clearPathingInfo() clearPathingInfo()

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,49 @@
[gd_resource type="TileSet" load_steps=4 format=2]
[ext_resource path="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie.png" type="Texture" id=1]
[ext_resource path="res://region/Unbenannt.png" type="Texture" id=2]
[ext_resource path="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png" type="Texture" id=3]
[resource]
0/name = "Unbenannt.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 64, 64 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
4/name = "Unbenannt - Kopie - Kopie - Kopie - Kopie.png 4"
4/texture = ExtResource( 1 )
4/tex_offset = Vector2( 0, 0 )
4/modulate = Color( 1, 1, 1, 1 )
4/region = Rect2( 0, 0, 64, 64 )
4/tile_mode = 0
4/occluder_offset = Vector2( 0, 0 )
4/navigation_offset = Vector2( 0, 0 )
4/shape_offset = Vector2( 0, 0 )
4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
4/shape_one_way = false
4/shape_one_way_margin = 0.0
4/shapes = [ ]
4/z_index = 0
5/name = "Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png 5"
5/texture = ExtResource( 3 )
5/tex_offset = Vector2( 0, 0 )
5/modulate = Color( 1, 1, 1, 1 )
5/region = Rect2( 0, 0, 64, 64 )
5/tile_mode = 0
5/occluder_offset = Vector2( 0, 0 )
5/navigation_offset = Vector2( 0, 0 )
5/shape_offset = Vector2( 0, 0 )
5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
5/shape_one_way = false
5/shape_one_way_margin = 0.0
5/shapes = [ ]
5/z_index = 0

View File

@ -0,0 +1,75 @@
extends Sprite
signal positionReached
var Route
signal pathAnimationCompleted
signal unitSelected(unit)
var isSelected = false
var isMoving = false
var boardUnitsIndex
onready var region = get_parent().get_parent().get_parent()
func on_ready():#this connects the unit to the main node using signals
connect("unitSelected",region, "unitSelectedMethod")
connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted")
snapToPosition()
if region.boardUnits[boardUnitsIndex].faction == "enemyFaction":
modulate = Color(1,0,0,1)
if region.boardUnits[boardUnitsIndex].faction == "allyFaction":
modulate = Color(0,1,0,1)
# emit_signal("pathAnimationCompleted")
func snapToPosition():
self.position = get_parent().get_parent().map_to_world(region.boardUnits[boardUnitsIndex].coords)
var undertiles = []
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x,region.boardUnits[boardUnitsIndex].coords.y))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x,region.boardUnits[boardUnitsIndex].coords.y+1))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x+1,region.boardUnits[boardUnitsIndex].coords.y))
undertiles.append(Vector2(region.boardUnits[boardUnitsIndex].coords.x+1,region.boardUnits[boardUnitsIndex].coords.y+1))
# unitCurrentUndertiles = undertiles
pass
func _input(event):#this selects unit and signals the selected node to the main node
if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event))
if isSelected== true:
emit_signal("unitSelected",null)
isSelected = false
if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 128 and localEvent.position.y < self.position.y + 128:
print("superunit")
if isSelected== false:
emit_signal("unitSelected",self)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0
for coords in route:
if route[0] == coords:
var t = Transform2D()
t.origin = coords
else:
moveTo(route[indexPosition],coords)
yield(self,"positionReached")
indexPosition+=1
emit_signal("pathAnimationCompleted")
isMoving = false
var speed =4
onready var motion = Vector2(0,0)
func moveTo(start:Vector2, destination:Vector2):#this does a step of the movement/animation. coordinated by moveOnPath
var travel = destination-start
motion = travel*speed
yield(get_tree().create_timer(travel.length()/motion.length()), "timeout")
motion= Vector2(0,0)
var t = Transform2D()
t.origin = destination
transform = t
emit_signal("positionReached")
# unitCurrentPosition=GlobalTileMap.world_to_map(destination)
snapToPosition()
func _physics_process(delta):
position += motion*delta

View File

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://region/SuperUnit.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Sprite" type="Sprite"]
scale = Vector2( 2, 2 )
z_index = 1
z_as_relative = false
texture = ExtResource( 2 )
centered = false
script = ExtResource( 1 )

22
Client/region/TileMap.gd Normal file
View File

@ -0,0 +1,22 @@
extends TileMap
var mountainTiles = []
var roadTiles = []
func buildTileMap(tiles):#this builds the tilemap by looking up on the special tile arrays whether a tile belongs to a special category (road/mountain etc) if not the tile is grass
var x=0
for column in tiles:
var y=0
for tile in column:
if tile.type == "mountain":
set_cell(x,y,4)
elif tile.type == "road":
set_cell(x,y,5)
else:
set_cell(x, y, 0)
y += 1
x += 1
func setTerrain():#this sets the special tile arrays to what is placed on the tilemap
roadTiles= get_used_cells_by_id(5)
mountainTiles = get_used_cells_by_id(4)
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png-25669cdb99469b4149cec015f84e52b1.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie - Kopie.png-25669cdb99469b4149cec015f84e52b1.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie.png-9720aced28368a22298ccaf2a68942cc.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie - Kopie.png-9720aced28368a22298ccaf2a68942cc.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie - Kopie.png-87c11b1469a9d84d4f76a51d1203572a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie - Kopie.png-87c11b1469a9d84d4f76a51d1203572a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie - Kopie.png-efca2ee418235964b71d2c06816282db.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie - Kopie.png-efca2ee418235964b71d2c06816282db.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt - Kopie.png-039fc52b1d6966267896d4c3bf84548a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt - Kopie.png"
dest_files=[ "res://.import/Unbenannt - Kopie.png-039fc52b1d6966267896d4c3bf84548a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
Client/region/Unbenannt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/Unbenannt.png-33f6792a5bb8046827aa692c8732e313.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://region/Unbenannt.png"
dest_files=[ "res://.import/Unbenannt.png-33f6792a5bb8046827aa692c8732e313.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

64
Client/region/Unit.gd Normal file
View File

@ -0,0 +1,64 @@
extends Sprite
signal positionReached
var Route
signal pathAnimationCompleted
signal unitSelected(unit)
var isSelected = false
var isMoving = false
var boardUnitsIndex
onready var region = get_parent().get_parent().get_parent()
func on_ready():#this connects the unit to the main node using signals
connect("unitSelected",region, "unitSelectedMethod")
connect("pathAnimationCompleted",region, "_on_pathAnimationCompleted")
snapToPosition()
if region.boardUnits[boardUnitsIndex].faction == "enemyFaction":
modulate = Color(1,0,0,1)
if region.boardUnits[boardUnitsIndex].faction == "allyFaction":
modulate = Color(0,1,0,1)
# emit_signal("pathAnimationCompleted")
func snapToPosition():
self.position = get_parent().get_parent().map_to_world(region.boardUnits[boardUnitsIndex].coords)
func _input(event):#this selects unit and signals the selected node to the main node
if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event))
if isSelected== true:
emit_signal("unitSelected",null)
isSelected = false
elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64:
emit_signal("unitSelected",self)
isSelected = true
return
func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true
var indexPosition = 0
for coords in route:
if route[0] == coords:
var t = Transform2D()
t.origin = coords
else:
moveTo(route[indexPosition],coords)
yield(self,"positionReached")
indexPosition+=1
emit_signal("pathAnimationCompleted")
isMoving = false
snapToPosition()
var speed =4
onready var motion = Vector2(0,0)
func moveTo(start:Vector2, destination:Vector2):#this does a step of the movement/animation. coordinated by moveOnPath
var travel = destination-start
motion = travel*speed
yield(get_tree().create_timer(travel.length()/motion.length()), "timeout")
motion= Vector2(0,0)
position = destination
emit_signal("positionReached")
func _physics_process(delta):
# print(position)
position += motion*delta

11
Client/region/Unit.tscn Normal file
View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://region/Unit.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Unit" type="Sprite"]
z_index = 1
z_as_relative = false
texture = ExtResource( 2 )
centered = false
script = ExtResource( 1 )

View File

@ -16,6 +16,10 @@ signal server_disconnected
func _ready(): func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected') get_tree().connect('network_peer_connected', self, '_on_player_connected')
create_server()
remote func TESTFUNCTION(string):
print(string)
remote func checkServerPassword(serverPassword): remote func checkServerPassword(serverPassword):
if (serverPassword=="myPW"): if (serverPassword=="myPW"):
@ -54,8 +58,9 @@ func firstStart():
# file.close() # file.close()
func _on_player_disconnected(id): func _on_player_disconnected(id):
players.erase(id) pass
PlayerManager.player_disconnected(id) # players.erase(id)
# PlayerManager.player_disconnected(id)
func _on_player_connected(connected_player_id): func _on_player_connected(connected_player_id):
print(">>>>>>>>>>> on player connected <<<<<<<<<<<<< ", connected_player_id) print(">>>>>>>>>>> on player connected <<<<<<<<<<<<< ", connected_player_id)

View File

@ -129,8 +129,9 @@ func identifyPlayer(playerName, pw = ''): # get the data from the json file
func player_disconnected(id): func player_disconnected(id):
if clients_factions[id]: pass
clients_factions.erase(id) # if clients_factions[id]:
# clients_factions.erase(id)
remote func receiveAuth(response): remote func receiveAuth(response):

View File

@ -201,12 +201,18 @@ remote func settle(tile, army, ascending): #if ascending, the cheapest ressource
var finish = buildingtime + ['turn'] var finish = buildingtime + ['turn']
var regions = {} var regions = {}
func _ready(): func _ready():
var newRegion = load("res://region/Region.gd") var newRegion = load("res://region/Region.gd").new()
regions["123"] = newRegion newRegion.buildWorld()
regions[123] = newRegion
func requestTiles(unit,regionId = 123): remote func requestTiles(unit,regionId = 123):
rpc_id(1, 'requestTiles',regions["123"].requestTiles()) var clientId = get_tree().get_rpc_sender_id()
var tileStuff = regions[regionId].requestTiles(unit)
rpc_id(clientId, 'receiveTiles', tileStuff)
func requestUnits(regionId = 123): remote func requestUnits(regionId = 123):
rpc_id(1, 'requestUnits', regions["123"].requestUnits()) var clientId = get_tree().get_rpc_sender_id()
var boardUnits = regions[regionId].requestUnits()
rpc_id(clientId, 'receiveUnits', boardUnits)

View File

@ -26,9 +26,6 @@ margin_top = -2.96259
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 1021.04 margin_bottom = 1021.04
alignment = 1 alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer"] [node name="Label" type="Label" parent="VBoxContainer"]
margin_top = 203.0 margin_top = 203.0

View File

@ -337,10 +337,10 @@ func addEnemyOccupiedTilesToMap(enemyOccupiedTiles):#this creates the tiles arra
return mapTiles return mapTiles
func requestTiles(unit, clientID): func requestTiles(unit):
var newTiles = setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1])) var newTiles = setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1]))
var newSuperTiles = buildSuperTiles(setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1]))) var newSuperTiles = buildSuperTiles(setVertices(addEnemyOccupiedTilesToMap(getOccupiedTiles(unit)[1])))
return [tileRect, newTiles, newSuperTiles] return [tileRect, newTiles, newSuperTiles]
func requestUnits(clientID): func requestUnits():
return boardUnits return boardUnits