change start placement based on ranking

This commit is contained in:
interfisch 2024-12-28 21:37:30 +01:00
parent bc53034a1c
commit 45e337b295
6 changed files with 63 additions and 16 deletions

View file

@ -193,6 +193,7 @@ sources/0 = SubResource("TileSetAtlasSource_hclam")
[node name="Map" type="Node"]
[node name="Background" type="TileMapLayer" parent="."]
visible = false
tile_map_data = PackedByteArray("AAD6//z/AQAAAAAAAAD6//3/AQAAAAAAAAD6//7/AQAAAAAAAAD6////AQAAAAAAAAD6/wAAAQAAAAAAAAD6/wEAAQAAAAAAAAD6/wIAAQAAAAAAAAD6/wMAAQAAAAAAAAD6/wQAAQAAAAAAAAD6/wUAAQAAAAAAAAD6/wYAAQAAAAAAAAD6/wcAAQAAAAAAAAD7//z/AQAAAAAAAAD7//3/AQAAAAAAAAD7//7/AQAAAAAAAAD7////AQAAAAAAAAD7/wAAAQAAAAAAAAD7/wEAAQAAAAAAAAD7/wIAAQAAAAAAAAD7/wMAAQAAAAAAAAD7/wQAAQAAAAAAAAD7/wUAAQAAAAAAAAD7/wYAAQAAAAAAAAD7/wcAAQAAAAAAAAD8//z/AQAAAAAAAAD8//3/AQAAAAAAAAD8//7/AQAAAAAAAAD8////AQAAAAAAAAD8/wAAAQAAAAAAAAD8/wEAAQAAAAAAAAD8/wIAAQAAAAAAAAD8/wMAAQAAAAAAAAD8/wQAAQAAAAAAAAD8/wUAAQAAAAAAAAD8/wYAAQAAAAAAAAD8/wcAAQAAAAAAAAD9//z/AQAAAAAAAAD9//3/AQAAAAAAAAD9//7/AQAAAAAAAAD9////AQAAAAAAAAD9/wAAAQAAAAAAAAD9/wEAAQAAAAAAAAD9/wIAAQAAAAAAAAD9/wMAAQAAAAAAAAD9/wQAAQAAAAAAAAD9/wUAAQAAAAAAAAD9/wYAAQAAAAAAAAD9/wcAAQAAAAAAAAD+//z/AQAAAAAAAAD+//3/AQAAAAAAAAD+//7/AQAAAAAAAAD+////AQAAAAAAAAD+/wAAAQAAAAAAAAD+/wEAAQABAAAAAAD+/wIAA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9//v/AQAAAAAAAAD+//r/AQAAAAAAAAD+//v/AQAAAAAAAAD///r/AQAAAAAAAAD///v/AQAAAAAAAAAAAPr/AQAAAAAAAAAAAPv/AQAAAAAAAAABAPr/AQAAAAAAAAABAPv/AQAAAAAAAAACAPr/AQAAAAAAAAACAPv/AQAAAAAAAAADAPr/AQAAAAAAAAADAPv/AQAAAAAAAAAEAPr/AQAAAAAAAAAEAPv/AQAAAAAAAAAFAPr/AQAAAAAAAAAFAPv/AQAAAAAAAAAGAPr/AQAAAAAAAAAGAPv/AQAAAAAAAAAHAPr/AQAAAAAAAAAHAPv/AQAAAAAAAAAIAPr/AQAAAAAAAAAIAPv/AQAAAAAAAAAJAPr/AQAAAAAAAAAJAPv/AQAAAAAAAAAKAPr/AQAAAAAAAAAKAPv/AQAAAAAAAAA=")
tile_set = SubResource("TileSet_5knbn")
collision_enabled = false
@ -202,10 +203,12 @@ tile_map_data = PackedByteArray("AAD/////AgAAAAAAAGD//wAAAgAAAAAAAFAAAP//AgAAAAA
tile_set = ExtResource("2_1kitx")
[node name="road_bg2" type="TileMapLayer" parent="."]
visible = false
tile_map_data = PackedByteArray("AAD7/wEAAgABAAEAADD//wQAAAAAAAAAAGAHAAQAAgAHAAIAADAHAP//AAAAAAIAAAAIAAAAAAABAAMAAAAHAAUAAAABAAMAAFAIAAQAAAAAAAIAAFAEAAMAAAABAAAAAHAEAAQAAAAAAAAAAHADAAMAAAABAAEAAHAAAAMAAAABAAEAAGD//wMAAAABAAAAAGACAAQAAgAHAAIAAFAHAAAAAgAGAAAAAAAHAAEAAgAHAAIAADAGAAAAAgAHAAIAAFD8/wAAAgAHAAIAAFA=")
tile_set = ExtResource("2_1kitx")
[node name="road_bg_fixes" type="TileMapLayer" parent="."]
visible = false
tile_map_data = PackedByteArray("AAD//wQAAgABAAEAAFAEAAQAAAAAAAAAAEAFAAUAAAABAAEAAEAEAAUAAAABAAAAAEAHAAQAAgAHAAIAAGA=")
tile_set = ExtResource("2_1kitx")

View file

@ -1,10 +1,9 @@
[gd_scene load_steps=14 format=3 uid="uid://b1uhymisifcho"]
[gd_scene load_steps=12 format=3 uid="uid://b1uhymisifcho"]
[ext_resource type="Script" path="res://scripts/menu.gd" id="1_fushn"]
[ext_resource type="Script" path="res://scripts/menudisplay.gd" id="2_jc4pv"]
[ext_resource type="Script" path="res://scripts/map_selection.gd" id="3_c0mhk"]
[ext_resource type="Texture2D" uid="uid://my0glsan1h2e" path="res://scenes/map_preview/map_00.png" id="3_p822h"]
[ext_resource type="Shader" path="res://shader/menubg.gdshader" id="3_vry7a"]
[ext_resource type="Texture2D" uid="uid://bk32usoetq3b" path="res://scenes/map_preview/map_01.png" id="4_ac8w4"]
[ext_resource type="Texture2D" uid="uid://ole07xte1dxp" path="res://scenes/map_preview/map_02.png" id="5_pnyq7"]
[ext_resource type="Texture2D" uid="uid://mkjrrv20lhkc" path="res://scenes/map_preview/map_03.png" id="7_5f67q"]
@ -13,13 +12,6 @@
[ext_resource type="Texture2D" uid="uid://bst8p5s1sgurm" path="res://sprites/menu_bg.png" id="10_equk1"]
[ext_resource type="Texture2D" uid="uid://drgqjl330tj2p" path="res://scenes/map_preview/no_preview.png" id="11_3sx36"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_kpdum"]
shader = ExtResource("3_vry7a")
shader_parameter/rotationpivot = Vector2(0.5, 0.49)
shader_parameter/speed = 0.1
shader_parameter/strength = 8.5
shader_parameter/iChannel0 = ExtResource("10_equk1")
[node name="Menu" type="Node"]
script = ExtResource("1_fushn")
@ -27,7 +19,6 @@ script = ExtResource("1_fushn")
script = ExtResource("2_jc4pv")
[node name="MenuBg" type="Sprite2D" parent="MenuDisplay"]
material = SubResource("ShaderMaterial_kpdum")
position = Vector2(1170, 338)
scale = Vector2(2.65635, 2.65635)
texture = ExtResource("10_equk1")

View file

@ -210,12 +210,14 @@ func get_input(delta:float):
if distance_min<steering_distance_far: #wall close, start steering away
steer_direction += turndirection*deg_to_rad(constrain(remap(distance_min,steering_distance_far,steering_distance_close,0,steering_angle), 0,steering_angle))
'''
if Input.is_action_pressed("ui_left"):
autosteer_enabled=false
steer_direction=-1
elif Input.is_action_pressed("ui_right"):
autosteer_enabled=false
steer_direction=1
'''
applied_engine_power=0

View file

@ -2,6 +2,7 @@ extends Node2D
@onready var cbcar: CharacterBody2D = $CharacterBody_Car
@onready var carbody: Sprite2D = $CharacterBody_Car/sprite_body
var reference_gamestateplayer
func getSpeed() -> float:
return cbcar.velocity.length()
@ -16,9 +17,10 @@ func getPositionLookahead(t:float):
func setPosition(p:Vector2):
cbcar.position=p
func setPlayerinformation(playerid, playercolor):
func setPlayerinformation(playerid, playercolor,preference_gamestateplayer):
cbcar.playerid=playerid
carbody.modulate = playercolor
reference_gamestateplayer=preference_gamestateplayer
func setCheckpoints(cps,rounds):

View file

@ -13,6 +13,8 @@ extends Node2D
const caroffset= 32+4 #space cars on start line
const caroffset_side= 32+16
const caroffset_rear= 64
var viewCarMargin=Vector2(0.7,0.7) #1=zoom out full speed when car is at border. 0.9 zoom out full speed when car is 10% away from border
var viewCarMargin_zoomstart=viewCarMargin-Vector2(0.2,0.2) #start zooming
@ -51,20 +53,34 @@ func _ready() -> void:
print(str(checkpoints.size())+" Checkpoints found")
var i=0
var players_ranked :Array = Gamestate.getPlayers().duplicate()
players_ranked.sort_custom(custom_array_sort_rank) #arrange players by handicap/rank
for player in Gamestate.getPlayers(): #create all players
#get player rank
var i_position=0
while i_position<players_ranked.size() and player.inputkey!=players_ranked[i_position].inputkey:
i_position+=1
var newcarscene=load("res://scenes/car.tscn")
var newcarinstance=newcarscene.instantiate()
cars.add_child(newcarinstance)
newcarinstance.setPlayerinformation(i,player.color)
newcarinstance.setPlayerinformation(i,player.color,player)
newcarinstance.setPosition(Vector2(0,ceil(i/2.0)*(fmod(i,2)-0.5)*2.0*caroffset))
#newcarinstance.setPosition(Vector2(0,ceil(i/2.0)*(fmod(i,2)-0.5)*2.0*caroffset)) #all in a row, alternating up/down
newcarinstance.setPosition(Vector2(caroffset_rear*-1*i_position,0)) #TODO, nicer start placement
#caroffset_rear
#caroffset_side
newcarinstance.setCheckpoints(checkpoints,Gamestate.getRounds())
newcarinstance.getCharacterBody().car_finished.connect(_on_car_finished)
print("carpos is ="+str(newcarinstance.getPosition())+" instancepos="+str(newcarinstance.position))
print("i_position="+str(i_position)+" carpos is ="+str(newcarinstance.getPosition())+" instancepos="+str(newcarinstance.position)+" colori="+str(player.colori)+" color="+str(player.color))
i+=1
func custom_array_sort_rank(a, b):
return a.rank > b.rank #a>b = higher rank (more wins) -> better start position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if running:
@ -196,11 +212,38 @@ func finishGame():
print("Game Finished")
running=false
game_ended=true
#change rank for players
var players_ranked :Array = Gamestate.getPlayers().duplicate()
players_ranked.sort_custom(custom_array_sort_player_finaltime) #arrange players by handicap/rank
var i=0
for p in players_ranked:
print("Player "+str(i)+" key="+str(OS.get_keycode_string(p.inputkey))+" was rank "+str(p.rank))
var floatrank=1.0-(i*1.0/(Gamestate.getPlayers().size()-1)) #winning player=1.0, losing player=0.0
var rankchangedown=-0.2 #change rank down limit
var rankchangeup=0.5 #change rank up limit
p.rank=p.rank+min(max((floatrank-p.rank),rankchangedown),rankchangeup)
print(" changed to rank "+str(p.rank))
i+=1
game_hud_animations.play("game_end")
timer_close.start()
#overlaycolor.visible=true
func custom_array_sort_player_finaltime(a, b):
var cars=cars.get_children()
var finalTimeA=-1
var finalTimeB=-1
for c in cars:
if c.reference_gamestateplayer==a:
finalTimeA=c.getCharacterBody().finalTime
elif c.reference_gamestateplayer==b:
finalTimeB=c.getCharacterBody().finalTime
return finalTimeA < finalTimeB
func _on_timer_close_timeout() -> void:
print("Close Map")

View file

@ -43,15 +43,20 @@ func addPlayer(key:int):
#return -1 if player already exists with this key. else return id of player added
if not getPlayerkeys().has(key): #key is not yet registered
var prefered_colori=0
var setrank=((randf()-0.5)/10.0)+0.5
for p in last_players:
if p.inputkey==key: #key was used in last round
prefered_colori=p.colori
setrank=p.rank
print("Player found in last_players. rank="+str(setrank)+" colori="+str(prefered_colori))
#check if color is free, else assign next free
while not checkColoriFree(prefered_colori):
prefered_colori+=1
players.append(Player.new(key,prefered_colori))
var newplayer: Player = Player.new(key,prefered_colori)
newplayer.rank=setrank
players.append(newplayer)
return prefered_colori
else:
@ -76,6 +81,7 @@ class Player:
var inputkey:int
var color:Color
var colori
var rank:float #0-1, nonlinear, higher when player wins often
func _init(key:int, pcolori:int=-1):
inputkey=key
@ -86,7 +92,7 @@ class Player:
if colori<0:
color=Color.from_hsv(randf_range(0.0,1.0), sat,val,1.0)
else:
color=Color.from_hsv(fmod(0.3*colori,1.0), sat,val,1.0)
color=Color.from_hsv(fmod(0.3*colori,1.0), sat,val,1.0) #todo: make colorwheel smaller when whitelist enabled
func startGame():