added a second slot you can equip a weapon to

This commit is contained in:
2023-11-28 16:52:15 +11:00
parent 66f7131c1b
commit d5d832f3f2
45 changed files with 722 additions and 104 deletions

View File

@ -1,8 +1,8 @@
extends Node3D
class_name AStarGraph3D
@export var grid_size := Vector2i(21, 13)
@export var point_gap := 1.2
@export var grid_size := Vector2i(15, 7)
@export var point_gap := 2.0
var non_build_locations = []
var astar := AStar3D.new()
@ -15,6 +15,8 @@ var astar := AStar3D.new()
var tower_base_scene = load("res://Scenes/tower_base.tscn")
var tower_frame_scene = load("res://Scenes/tower_frame.tscn")
var tower_bases = []
var tower_base_ids = {}
var tower_frames = []
var wall_id = 0
@ -46,18 +48,113 @@ func networked_toggle_point(point_id):
else:
astar.set_point_disabled(point_id, true)
find_path()
disable_path_tower_frames()
if is_multiplayer_authority():
networked_spawn_wall.rpc(astar.get_point_position(point_id), wall_id)
wall_id += 1
func get_north_point(point_id) -> int:
var x = point_id / grid_size.y
var y = point_id % grid_size.y
if x - 1 >= 0: #if the north point id could possibly exist as a neighbor
return (x - 1) * grid_size.y + y
return -1
func get_south_point(point_id) -> int:
var x = point_id / grid_size.y
var y = point_id % grid_size.y
if x + 1 <= grid_size.x - 1: #if the south point id could possibly exist as a neighbor
return (x + 1) * grid_size.y + y
return -1
func get_west_point(point_id) -> int:
var x = point_id / grid_size.y
var y = point_id % grid_size.y
if y + 1 <= grid_size.y - 1: #if the east point id could possibly exist as a neighbor
return x * grid_size.y + y + 1
return -1
func get_east_point(point_id) -> int:
var x = point_id / grid_size.y
var y = point_id % grid_size.y
if y - 1 >= 0: #if the west point id could possibly exist as a neighbor
return x * grid_size.y + y - 1
return -1
func count_valid_neighbours(point_id) -> int:
if !point_id:
return 0
var valid_neighbours = 0
var north_point = get_north_point(point_id)
var south_point = get_south_point(point_id)
var east_point = get_east_point(point_id)
var west_point = get_west_point(point_id)
if north_point and !astar.is_point_disabled(north_point):
valid_neighbours += 1
else: #add the spawn point which is always valid
valid_neighbours += 1
if south_point and !astar.is_point_disabled(south_point):
valid_neighbours += 1
else: #add the goal point which is always valid
valid_neighbours += 1
if east_point and !astar.is_point_disabled(east_point):
valid_neighbours += 1
if west_point and !astar.is_point_disabled(west_point):
valid_neighbours += 1
return valid_neighbours
func disable_all_tower_frames():
for frame in tower_frames:
frame.set_visible(false)
func enable_non_path_tower_frames():
for frame in tower_frames:
frame.set_visible(true)
disable_path_tower_frames()
func disable_path_tower_frames():
for id in astar.get_id_path(astar.get_point_count() - 2, astar.get_point_count() - 1):
if id < (grid_size.x * grid_size.y) and !test_path_if_point_toggled(id):
tower_frames[id].set_visible(false)
@rpc("reliable", "call_local")
func networked_spawn_wall(pos : Vector3, name_id : int):
var base = tower_base_scene.instantiate()
var base = tower_base_scene.instantiate() as TowerBase
base.position = pos
base.name = "Wall" + str(name_id)
var point_id = astar.get_closest_point(pos, true)
tower_base_ids[point_id] = base
tower_bases.append(base)
tower_path.add_child(base)
var north_point = get_north_point(point_id)
var south_point = get_south_point(point_id)
var east_point = get_east_point(point_id)
var west_point = get_west_point(point_id)
if north_point >= 0 and astar.is_point_disabled(north_point):
base.set_north_wall(true)
tower_base_ids[north_point].set_south_wall(true)
if south_point >= 0 and astar.is_point_disabled(south_point):
base.set_south_wall(true)
tower_base_ids[south_point].set_north_wall(true)
if east_point >= 0 and astar.is_point_disabled(east_point):
base.set_east_wall(true)
tower_base_ids[east_point].set_west_wall(true)
if west_point >= 0 and astar.is_point_disabled(west_point):
base.set_west_wall(true)
tower_base_ids[west_point].set_east_wall(true)
func build_random_maze(block_limit):
@ -102,6 +199,7 @@ func make_grid():
astar.add_point(int(x * grid_size.y + y), point_position)
var frame = tower_frame_scene.instantiate()
frame.position = point_position
tower_frames.append(frame)
add_child(frame)
for x in grid_size.x:

View File

@ -17,12 +17,17 @@ var enemy_names = []
@export var enemy_sprites : Array[TextureRect]
@export var enemy_counts : Array[Label]
@export var weapon_energy_bar : TextureProgressBar
@export var offhand_energy_bar : TextureProgressBar
func set_energy_visible(value):
weapon_energy_bar.set_visible(value)
func set_offhand_energy_visible(value):
offhand_energy_bar.set_visible(value)
func _process(_delta: float) -> void:
fps_label.text = "FPS: " + str(Engine.get_frames_per_second())
@ -90,6 +95,10 @@ func set_weapon_energy(value):
weapon_energy_bar.value = value
func set_offhand_energy(value):
offhand_energy_bar.value = value
func maximise_minimap(anchor):
minimap_cam.anchor = anchor
minimap.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)

View File

@ -3,4 +3,5 @@ class_name HeroClass
@export var hero_name : String = "Default"
@export var texture : Texture
@export var hand_texture : Texture
@export var deck : Array[Card]

View File

@ -5,6 +5,7 @@ signal energy_changed(energy)
@export var stats : CardText
@export var animator : AnimationPlayer
@export var recharge_timer : Timer
var damage_particle_scene = preload("res://Scenes/damage_particle.tscn")
var hero : Hero
@ -16,6 +17,10 @@ var damage := 0.0
var max_energy := 100.0
var current_energy := 100.0
var energy_cost := 1.0
var recharging := false
var recharge_speed := 0.0
var recharge_acceleration = 2.0
var recharge_max_speed = 20.0
func _ready() -> void:
@ -29,9 +34,13 @@ func set_hero(value):
func _process(delta: float) -> void:
current_energy += 5.0 * delta
if current_energy >= max_energy:
current_energy = max_energy
if recharging:
recharge_speed += recharge_acceleration * delta
if recharge_speed > recharge_max_speed:
recharge_speed = recharge_max_speed
current_energy += recharge_speed * delta
if current_energy >= max_energy:
current_energy = max_energy
energy_changed.emit(current_energy)
if time_since_firing < time_between_shots:
time_since_firing += delta
@ -52,6 +61,7 @@ func hold_trigger():
func release_trigger():
trigger_held = false
recharge_timer.start()
func hold_second_trigger():
@ -72,8 +82,14 @@ func spawn_damage_indicator(pos):
func shoot():
animator.play("shoot")
recharging = false
recharge_timer.stop()
@rpc
func networked_shoot():
animator.play("shoot")
func _on_timer_timeout() -> void:
recharging = true

View File

@ -27,6 +27,8 @@ var interact_hold_time := 0.4
func _ready() -> void:
wall_preview.set_material(build_preview_material)
build_preview_material.albedo_color = Color.GREEN
build_preview_material.albedo_color.a = 0.8
wall_preview.toggle_collision()
@ -73,12 +75,12 @@ func _process(delta: float) -> void:
if obstacle_last_point != point_id:
obstacle_last_point = point_id
if Game.level.a_star_graph_3d.test_path_if_point_toggled(point_id):
build_preview_material.albedo_color = Color.GREEN
build_preview_material.albedo_color.a = 0.8
#build_preview_material.albedo_color = Color.GREEN
#build_preview_material.albedo_color.a = 0.8
valid_point = true
else:
build_preview_material.albedo_color = Color.RED
build_preview_material.albedo_color.a = 0.8
#build_preview_material.albedo_color = Color.RED
#build_preview_material.albedo_color.a = 0.8
valid_point = false
else:
ray_collider = null
@ -86,6 +88,8 @@ func _process(delta: float) -> void:
is_looking_at_tower_base = false
delete_tower_preview()
wall_preview.set_visible(false)
if !valid_point:
wall_preview.set_visible(false)
func spawn_tower_preview():

View File

@ -69,12 +69,26 @@ func parse_command(text : String, peer_id : int):
if text.substr(1, 7) == "prosper":
for id in connected_players_nodes:
connected_players_nodes[id].currency += 50
if text.substr(1, 8) == "set_wave":
if is_multiplayer_authority():
networked_set_wave.rpc(int(text.substr(10)))
else:
chatbox.append_message("SERVER", Color.TOMATO, "Unable to set wave")
# if text.substr(1, 17) == "show tower ranges":
# pass
# if text.substr(1, 20) = "show gauntlet ranges":
# pass
@rpc("reliable", "call_local")
func networked_set_wave(wave_number):
chatbox.append_message("SERVER", Color.TOMATO, "Set to wave " + str(wave_number))
for player in connected_players_nodes:
connected_players_nodes[player].hud.set_wave_count(wave_number)
wave = wave_number
set_upcoming_wave()
func spawn_level():
level = level_scene.instantiate() as Level
for x in level.enemy_spawns:
@ -123,6 +137,7 @@ func spawn_enemy_wave():
wave += 1
level.a_star_graph_3d.find_path()
level.a_star_graph_3d.visualized_path.disable_visualization()
level.a_star_graph_3d.disable_all_tower_frames()
for spawn in level.enemy_spawns:
spawn.spawn_wave(upcoming_wave)
wave_started.emit(wave)
@ -191,6 +206,7 @@ func end_wave():
connected_players_nodes[peer_id].currency += ceili(pot / connected_players_nodes.size())
connected_players_nodes[peer_id].ready_state = false
level.a_star_graph_3d.visualized_path.enable_visualization()
level.a_star_graph_3d.enable_non_path_tower_frames()
if is_multiplayer_authority():
if randf() <= shop_chance:
networked_spawn_shop.rpc()

View File

@ -13,6 +13,7 @@ func _ready() -> void:
bg_level.a_star_graph_3d.find_path()
bg_level.a_star_graph_3d.build_random_maze(50)
bg_level.a_star_graph_3d.place_random_towers(20)
bg_level.a_star_graph_3d.disable_all_tower_frames()
var new_wave = WaveManager.generate_wave(400, bg_level.enemy_pool)
for spawn in bg_level.enemy_spawns:
spawn.signal_for_after_enemy_died = enemy_died
@ -20,7 +21,7 @@ func _ready() -> void:
spawn.signal_for_when_enemy_spawns.connect(increase_enemy_count)
spawn.spawn_wave(new_wave)
func enemy_died(some_arg):
func enemy_died(_some_arg):
pass
func damage_goal():
pass

View File

@ -52,7 +52,7 @@ func randomize_cards():
choice_buttons[x+5].press_cost = price_dict[chosen_card.rarity]
choice_buttons[x+5].hover_text = "Spend $" + str(choice_buttons[x+5].press_cost) + " to acquire " + chosen_card.title + "?"
for x in choice_colliders:
x.disabled = false
x.set_deferred("disabled", false)
for x in choice_sprites:
x.set_visible(true)

View File

@ -5,6 +5,14 @@ class_name TowerBase
@export var block : Node3D
@export var collider : CollisionShape3D
@export var minimap_icon : Sprite3D
@export var north_mesh : CSGBox3D
@export var south_mesh : CSGBox3D
@export var east_mesh : CSGBox3D
@export var west_mesh : CSGBox3D
@export var north_collider : CollisionShape3D
@export var south_collider : CollisionShape3D
@export var east_collider : CollisionShape3D
@export var west_collider : CollisionShape3D
var tower = null
var has_card : bool :
@ -34,6 +42,26 @@ func toggle_collision():
collider.disabled = !collider.disabled
func set_north_wall(value : bool):
north_mesh.set_visible(value)
north_collider.disabled = !value
func set_south_wall(value : bool):
south_mesh.set_visible(value)
south_collider.disabled = !value
func set_east_wall(value : bool):
east_mesh.set_visible(value)
east_collider.disabled = !value
func set_west_wall(value : bool):
west_mesh.set_visible(value)
west_collider.disabled = !value
@rpc("reliable", "call_local", "any_peer")
func networked_spawn_tower():
tower = inventory.selected_item.turret_scene.instantiate() as Tower