Get Map Gernation in #17
6 changed files with 20 additions and 11 deletions
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@ class_name Bunny
|
||||||
@export var min_distance_to_player := 80.0
|
@export var min_distance_to_player := 80.0
|
||||||
@export var max_distance_to_player := 800.0
|
@export var max_distance_to_player := 800.0
|
||||||
@export var agent : NavigationAgent2D
|
@export var agent : NavigationAgent2D
|
||||||
@export var speed := 200.0
|
@export var speed := 100.0
|
||||||
|
|
||||||
var health : int
|
var health : int
|
||||||
var team : int
|
var team : int
|
||||||
|
@ -19,7 +19,7 @@ var collisions : int
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
seed(int(str(self)))
|
seed(int(str(self)))
|
||||||
spread_time = randf() * 3
|
spread_time = randf() * 2 + 0.1
|
||||||
current_time = spread_time
|
current_time = spread_time
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
@ -29,10 +29,12 @@ func _physics_process(delta):
|
||||||
current_time = spread_time
|
current_time = spread_time
|
||||||
agent.target_position = player.global_position
|
agent.target_position = player.global_position
|
||||||
if min_distance_to_player and agent.is_target_reachable():
|
if min_distance_to_player and agent.is_target_reachable():
|
||||||
var next_location = agent.get_next_path_position() + Vector2(randf() - 0.5 * 10, randf() - 0.5 * 10)
|
var next_location = agent.get_next_path_position() + Vector2(randf() - 0.5 * 2, randf() - 0.5 * 2)
|
||||||
dir = self.global_position.direction_to(next_location).normalized()
|
dir = self.global_position.direction_to(next_location).normalized()
|
||||||
if self.global_position.distance_to(player.global_position) > min_distance_to_player:
|
if self.global_position.distance_to(player.global_position) > min_distance_to_player:
|
||||||
self.velocity = dir * delta * 60 * speed
|
self.velocity = dir * delta * 60 * speed
|
||||||
|
if delta > 0.5:
|
||||||
|
print(delta)
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ extends Node2D
|
||||||
|
|
||||||
var bunnys = []
|
var bunnys = []
|
||||||
var gen_data : Dictionary
|
var gen_data : Dictionary
|
||||||
var wave := 0
|
var wave : int
|
||||||
|
var in_wave_gen : bool
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
gen_data = map_generator.generate() as Dictionary
|
gen_data = map_generator.generate() as Dictionary
|
||||||
|
@ -13,10 +14,12 @@ func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
if(bunnys.size() == 0):
|
if bunnys.size() == 0 and !in_wave_gen:
|
||||||
|
in_wave_gen = true
|
||||||
wave += 1
|
wave += 1
|
||||||
bunnys = await bunny_generator.spawn_batched_wave(10.0, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 1, 3)
|
bunnys = await bunny_generator.spawn_batched_wave(5.0, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 10.0, 3)
|
||||||
for bunny in bunnys:
|
for bunny in bunnys:
|
||||||
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
||||||
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
||||||
|
in_wave_gen = false
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -39,7 +39,7 @@ func get_free_tiles() -> Array:
|
||||||
var free_tiles = []
|
var free_tiles = []
|
||||||
for x in width:
|
for x in width:
|
||||||
for y in height:
|
for y in height:
|
||||||
if get_tile_non_solid(x, y): free_tiles.push_back(Vector2(x, y) * self.cell_quadrant_size * self.scale + (Vector2(self.cell_quadrant_size, self.cell_quadrant_size) / 2))
|
if get_tile_non_solid(x, y): free_tiles.push_back(Vector2(x, y) * self.cell_quadrant_size * self.scale + (Vector2(self.cell_quadrant_size, self.cell_quadrant_size) * self.scale / 2))
|
||||||
return free_tiles
|
return free_tiles
|
||||||
|
|
||||||
func setup_tile_data_array():
|
func setup_tile_data_array():
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
@export var speed : float = 250.0
|
@export var speed : float = 80.0
|
||||||
@export var damage : int = 1
|
@export var damage : int = 1
|
||||||
|
|
||||||
@export_flags_2d_physics var map_collision_layer : int
|
@export_flags_2d_physics var map_collision_layer : int
|
||||||
@export_flags_2d_physics var bunny_collision_layer : int
|
@export_flags_2d_physics var bunny_collision_layer : int
|
||||||
|
|
||||||
|
var dir : float
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
self.translate(Vector2(cos(self.rotation), sin(self.rotation)) * speed * delta)
|
self.translate(Vector2(cos(dir), sin(dir)) * speed * delta)
|
||||||
|
self.rotate(delta * 30)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _on_collision(body):
|
func _on_collision(body):
|
||||||
|
|
|
@ -7,7 +7,7 @@ func _process(_delta):
|
||||||
rotate_to_pointer()
|
rotate_to_pointer()
|
||||||
|
|
||||||
if Input.is_action_just_pressed("attack"):
|
if Input.is_action_just_pressed("attack"):
|
||||||
spawn_projectile(self.global_position, self.rotation, 100, 1)
|
spawn_projectile(self.global_position, self.rotation, 350.0, 1)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func rotate_to_pointer():
|
func rotate_to_pointer():
|
||||||
|
@ -17,7 +17,7 @@ func rotate_to_pointer():
|
||||||
func spawn_projectile(pos : Vector2, dir : float, speed: float, damage : int):
|
func spawn_projectile(pos : Vector2, dir : float, speed: float, damage : int):
|
||||||
var projectile = projectilePrefab.instantiate()
|
var projectile = projectilePrefab.instantiate()
|
||||||
projectile.global_position = pos
|
projectile.global_position = pos
|
||||||
projectile.rotation = dir
|
projectile.dir = dir
|
||||||
projectile.speed = speed
|
projectile.speed = speed
|
||||||
projectile.damage = damage
|
projectile.damage = damage
|
||||||
projectile.is_displayed_folded()
|
projectile.is_displayed_folded()
|
||||||
|
|
Reference in a new issue